CMakeLists.txt 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261
  1. # CMakeList.txt
  2. #
  3. # Copyright (C) 2006-2020 wolfSSL Inc.
  4. #
  5. # This file is part of wolfSSL. (formerly known as CyaSSL)
  6. #
  7. # Usage:
  8. # $ mkdir build
  9. # $ cd build
  10. # $ cmake ..
  11. # $ cmake --build .
  12. #
  13. # To build with debugging use:
  14. # $ cmake .. -DCMAKE_BUILD_TYPE=Debug
  15. #
  16. # See "Building with CMake" in INSTALL for more.
  17. ####################################################
  18. # Project
  19. ####################################################
  20. cmake_minimum_required(VERSION 3.16)
  21. if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
  22. message(FATAL_ERROR "In-source builds are not allowed.\
  23. Run cmake from a separate directory from where CMakeLists.txt lives.\
  24. NOTE: cmake will now create CMakeCache.txt and CMakeFiles/*.\
  25. You must delete them, or cmake will refuse to work.")
  26. endif()
  27. project(wolfssl VERSION 5.5.1 LANGUAGES C ASM)
  28. # shared library versioning
  29. # increment if interfaces have been added, removed or changed
  30. set(LIBTOOL_CURRENT 36)
  31. # increment if source code has changed set to zero if current is incremented
  32. set(LIBTOOL_REVISION 0)
  33. # increment if interfaces have been added set to zero if interfaces have been
  34. # removed or changed
  35. set(LIBTOOL_AGE 1)
  36. math(EXPR LIBTOOL_SO_VERSION "${LIBTOOL_CURRENT} - ${LIBTOOL_AGE}")
  37. set(LIBTOOL_FULL_VERSION ${LIBTOOL_SO_VERSION}.${LIBTOOL_AGE}.${LIBTOOL_REVISION})
  38. set(WOLFSSL_DEFINITIONS)
  39. set(WOLFSSL_LINK_LIBS)
  40. set(WOLFSSL_INCLUDE_DIRS)
  41. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
  42. include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/functions.cmake)
  43. ####################################################
  44. # Compiler
  45. ####################################################
  46. # Let CMake choose default compiler
  47. # TODO: See gl_VISIBILITY in visibility.m4. Need to perform
  48. # the same checks.
  49. # TODO: Turn on warnings.
  50. if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
  51. # Silence ranlib warning "has no symbols"
  52. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  53. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  54. set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  55. set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  56. endif()
  57. if(APPLE)
  58. find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
  59. if(NOT CORE_FOUNDATION_FRAMEWORK)
  60. message(FATAL_ERROR "Couldn't find CoreFoundation framework.")
  61. endif()
  62. find_library(SECURITY_FRAMEWORK Security)
  63. if(NOT SECURITY_FRAMEWORK)
  64. message(FATAL_ERROR "Couldn't find Security framework.")
  65. endif()
  66. endif()
  67. include(CheckIncludeFile)
  68. check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
  69. check_include_file("fcntl.h" HAVE_FCNTL_H)
  70. check_include_file("limits.h" HAVE_LIMITS_H)
  71. check_include_file("netdb.h" HAVE_NETDB_H)
  72. check_include_file("netinet/in.h" HAVE_NETINET_IN_H)
  73. check_include_file("stddef.h" HAVE_STDDEF_H)
  74. check_include_file("time.h" HAVE_TIME_H)
  75. check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  76. check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H)
  77. check_include_file("sys/time.h" HAVE_SYS_TIME_H)
  78. check_include_file("errno.h" HAVE_ERRNO_H)
  79. check_include_file("dlfcn.h" HAVE_DLFCN_H)
  80. check_include_file("inttypes.h" HAVE_INTTYPES_H)
  81. check_include_file("memory.h" HAVE_MEMORY_H)
  82. check_include_file("stdint.h" HAVE_STDINT_H)
  83. check_include_file("stdlib.h" HAVE_STDLIB_H)
  84. check_include_file("string.h" HAVE_STRING_H)
  85. check_include_file("strings.h" HAVE_STRINGS_H)
  86. check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
  87. check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
  88. check_include_file("unistd.h" HAVE_UNISTD_H)
  89. include(CheckFunctionExists)
  90. # TODO: Also check if these functions are declared by the
  91. # expected headers. See comments around
  92. # AC_CHECK_FUNCS/AC_CHECK_DECLS in configure.ac.
  93. check_function_exists("gethostbyname" HAVE_GETHOSTBYNAME)
  94. check_function_exists("getaddrinfo" HAVE_GETADDRINFO)
  95. check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY)
  96. check_function_exists("gmtime_r" HAVE_GMTIME_R)
  97. check_function_exists("inet_ntoa" HAVE_INET_NTOA)
  98. check_function_exists("memset" HAVE_MEMSET)
  99. check_function_exists("socket" HAVE_SOCKET)
  100. check_function_exists("strftime" HAVE_STRFTIME)
  101. include(CheckTypeSize)
  102. check_type_size("__uint128_t" __UINT128_T)
  103. check_type_size("long long" SIZEOF_LONG_LONG)
  104. check_type_size("long" SIZEOF_LONG)
  105. check_type_size("time_t" SIZEOF_TIME_T)
  106. # By default, HAVE___UINT128_T gets defined as TRUE,
  107. # but we want it as 1.
  108. if(HAVE___UINT128_T)
  109. set(HAVE___UINT128_T "1" CACHE INTERNAL "Result of TRY_COMPILE" FORCE)
  110. endif()
  111. include(TestBigEndian)
  112. test_big_endian(WORDS_BIGENDIAN)
  113. # Thread local storage
  114. include(CheckCSourceCompiles)
  115. set(TLS_KEYWORDS "__thread" "__declspec(thread)")
  116. foreach(TLS_KEYWORD IN LISTS TLS_KEYWORDS)
  117. set(TLS_CODE "#include <stdlib.h>
  118. static void foo(void) {
  119. static ${TLS_KEYWORD} int bar\;
  120. exit(1)\;
  121. }
  122. int main() {
  123. return 0\;
  124. }"
  125. )
  126. check_c_source_compiles(${TLS_CODE} THREAD_LS_ON)
  127. if(THREAD_LS_ON)
  128. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_THREAD_LS")
  129. break()
  130. else()
  131. # THREAD_LS_ON is cached after each call to
  132. # check_c_source_compiles, and the function
  133. # won't run subsequent times if the variable
  134. # is in the cache. To make it run again, we
  135. # need to remove the variable from the cache.
  136. unset(THREAD_LS_ON CACHE)
  137. endif()
  138. endforeach()
  139. # TODO: AX_PTHREAD does a lot. Need to implement the
  140. # rest of its logic.
  141. find_package(Threads)
  142. ####################################################
  143. # Cross Compile Example
  144. ####################################################
  145. #set(CMAKE_SYSTEM_NAME Linux)
  146. #set(CMAKE_SYSTEM_PROCESSOR arm)
  147. #set(CMAKE_C_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc")
  148. #set(CMAKE_CXX_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-g++")
  149. #set(CMAKE_SYSROOT "/opt/arm-linux-musleabihf-cross/arm-linux-musleabihf/")
  150. # Example for setting CFLAGS
  151. #set(CMAKE_C_FLAGS "-std=gnu89 ${CMAKE_C_FLAGS}")
  152. # Example for map file and custom linker script
  153. #set(CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=output.map -T\"${CMAKE_CURRENT_SOURCE_DIR}/linker.ld\"")
  154. if(DEFINED WARNING_C_FLAGS)
  155. set(CMAKE_C_FLAGS "${WARNING_C_FLAGS} ${CMAKE_C_FLAGS}")
  156. elseif(WIN32)
  157. # Windows cl.exe does not support the -Wextra, -Wno-unused and -Werror flags.
  158. set(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}")
  159. else()
  160. set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused -Werror ${CMAKE_C_FLAGS}")
  161. endif()
  162. ####################################################
  163. # Build Options
  164. ####################################################
  165. # TODO: - FIPS
  166. # - Distro
  167. # - Linux Kernel Module
  168. # - Single precision math
  169. # - Enable all
  170. # - Enable all crypto
  171. # For reproducible build, gate out from the build anything that might
  172. # introduce semantically frivolous jitter, maximizing chance of
  173. # identical object files.
  174. add_option("WOLFSSL_REPRODUCIBLE_BUILD"
  175. "Enable maximally reproducible build (default: disabled)"
  176. "no" "yes;no")
  177. if(WOLFSSL_REPRODUCIBLE_BUILD)
  178. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_REPRODUCIBLE_BUILD")
  179. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
  180. set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
  181. set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
  182. endif()
  183. # Support for forcing 32-bit mode
  184. # TODO: detect platform from other options
  185. add_option("WOLFSSL_32BIT"
  186. "Enables 32-bit support (default: disabled)"
  187. "no" "yes;no")
  188. # 16-bit compiler support
  189. add_option("WOLFSSL_16BIT"
  190. "Enables 16-bit support (default: disabled)"
  191. "no" "yes;no")
  192. if(WOLFSSL_16BIT)
  193. list(APPEND WOLFSSL_DEFINITIONS "-DWC_16BIT_CPU")
  194. endif()
  195. # Support for disabling all ASM
  196. add_option("WOLFSSL_ASM"
  197. "Enables option for assembly (default: enabled)"
  198. "yes" "yes;no")
  199. if(NOT WOLFSSL_ASM)
  200. list(APPEND WOLFSSL_DEFINITIONS
  201. "-DTFM_NO_ASM"
  202. "-DWOLFSSL_NO_ASM")
  203. endif()
  204. # Enable Debugging
  205. add_option("WOLFSSL_DEBUG"
  206. "Enables option for debug (default: disabled)"
  207. "no" "yes;no")
  208. if(WOLFSSL_DEBUG)
  209. set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}")
  210. list(APPEND WOLFSSL_DEFINITIONS
  211. "-DDEBUG_WOLFSSL"
  212. "-DDEBUG")
  213. endif()
  214. # Single threaded
  215. add_option("WOLFSSL_SINGLE_THREADED"
  216. "Enable wolfSSL single threaded (default: disabled)"
  217. "no" "yes;no")
  218. # TODO: Logic here isn't complete, yet (see AX_PTHREAD)
  219. if(NOT WOLFSSL_SINGLE_THREADED)
  220. if(CMAKE_USE_PTHREADS_INIT)
  221. list(APPEND WOLFSSL_LINK_LIBS Threads::Threads)
  222. set(HAVE_PTHREAD 1)
  223. list(APPEND WOLFSSL_DEFINITIONS
  224. "-DHAVE_PTHREAD"
  225. "-D_POSIX_THREADS")
  226. endif()
  227. endif()
  228. # DTLS
  229. add_option("WOLFSSL_DTLS"
  230. "Enables wolfSSL DTLS (default: disabled)"
  231. "no" "yes;no")
  232. if(WOLFSSL_DTLS)
  233. list(APPEND WOLFSSL_DEFINITIONS
  234. "-DWOLFSSL_DTLS")
  235. endif()
  236. # TLS v1.3
  237. add_option("WOLFSSL_TLS13"
  238. "Enable wolfSSL TLS v1.3 (default: enabled)"
  239. "yes" "yes;no")
  240. if("${FIPS_VERSION}" STREQUAL "v1")
  241. override_cache(WOLFSSL_TLS13 "no")
  242. endif()
  243. # Post-handshake authentication
  244. add_option("WOLFSSL_POSTAUTH"
  245. "Enable wolfSSL Post-handshake Authentication (default: disabled)"
  246. "no" "yes;no")
  247. if(WOLFSSL_POSTAUTH)
  248. if(NOT WOLFSSL_TLS13)
  249. message(WARNING "TLS 1.3 is disabled - disabling Post-handshake Authentication")
  250. override_cache(WOLFSSL_POSTAUTH "no")
  251. else()
  252. list(APPEND WOLFSSL_DEFINITIONS
  253. "-DWOLFSSL_POST_HANDSHAKE_AUTH")
  254. endif()
  255. endif()
  256. # Hello Retry Request Cookie
  257. add_option("WOLFSSL_HRR_COOKIE"
  258. "Enable the server to send Cookie Extension in HRR with state (default: disabled)"
  259. "undefined" "yes;no;undefined")
  260. if("${WOLFSSL_HRR_COOKIE}" STREQUAL "yes")
  261. if(NOT WOLFSSL_TLS13)
  262. message(WARNING "TLS 1.3 is disabled - disabling HRR Cookie")
  263. override_cache(WOLFSSL_HRR_COOKIE "no")
  264. else()
  265. list(APPEND WOLFSSL_DEFINITIONS
  266. "-DWOLFSSL_SEND_HRR_COOKIE")
  267. endif()
  268. endif()
  269. # DTLS v1.3
  270. add_option("WOLFSSL_DTLS13"
  271. "Enable wolfSSL DTLS v1.3 (default: disabled)"
  272. "no" "yes;no")
  273. if(WOLFSSL_DTLS13)
  274. if (NOT WOLFSSL_DTLS)
  275. message(FATAL_ERROR "DTLS13 requires DTLS")
  276. endif()
  277. if (NOT WOLFSSL_TLS13)
  278. message(FATAL_ERROR "DTLS13 requires TLS13")
  279. endif()
  280. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_DTLS13")
  281. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_W64_WRAPPER")
  282. if ("${WOLFSSL_HRR_COOKIE}" STREQUAL "undefined")
  283. message(WARNING "DTLS1.3 is enabled - enabling HRR Cookie")
  284. override_cache(WOLFSSL_HRR_COOKIE "yes")
  285. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SEND_HRR_COOKIE")
  286. endif()
  287. if (WOLFSSL_AES)
  288. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_DIRECT")
  289. endif()
  290. endif()
  291. # DTLS ConnectionID support
  292. add_option("WOLFSSL_DTLS_CID"
  293. "Enables wolfSSL DTLS CID (default: disabled)"
  294. "no" "yes;no")
  295. if(WOLFSSL_DTLS_CID)
  296. if(NOT WOLFSSL_DTLS13)
  297. message(FATAL_ERROR "CID are supported only for DTLSv1.3")
  298. endif()
  299. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_DTLS_CID")
  300. endif()
  301. # RNG
  302. add_option("WOLFSSL_RNG"
  303. "Enable compiling and using RNG (default: enabled)"
  304. "yes" "yes;no")
  305. if(NOT WOLFSSL_RNG)
  306. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_RNG")
  307. endif()
  308. # TODO: - DTLS-SCTP
  309. # - DTLS multicast
  310. # - OpenSSH
  311. # - OpenVPN
  312. # - Nginx
  313. # - HAProxy
  314. # - wpa_supplicant
  315. # - Fortress
  316. # - libwebsockets
  317. # - IP alternative name
  318. # - Qt
  319. # - SSL bump
  320. # - sniffer
  321. # - Signal
  322. # - OpenSSL coexist
  323. # - OpenSSL compatibility all
  324. # - OpenSSL compatibility extra
  325. # - Max strength
  326. # Harden, enable Timing Resistance and Blinding by default
  327. add_option("WOLFSSL_HARDEN"
  328. "Enable Hardened build, Enables Timing Resistance and Blinding (default: enabled)"
  329. "yes" "yes;no")
  330. if(WOLFSSL_HARDEN)
  331. list(APPEND WOLFSSL_DEFINITIONS "-DTFM_TIMING_RESISTANT" "-DECC_TIMING_RESISTANT")
  332. if(WOLFSSL_RNG)
  333. list(APPEND WOLFSSL_DEFINITIONS "-DWC_RSA_BLINDING")
  334. endif()
  335. else()
  336. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HARDEN")
  337. endif()
  338. add_option(WOLFSSL_OPENSSLEXTRA
  339. "Enable extra OpenSSL API, size+ (default: disabled)"
  340. "no" "yes;no")
  341. if (WOLFSSL_OPENSSLEXTRA AND NOT WOLFSSL_OPENSSLCOEXIST)
  342. list(APPEND WOLFSSL_DEFINITIONS
  343. "-DOPENSSL_EXTRA"
  344. "-DWOLFSSL_ALWAYS_VERIFY_CB"
  345. "-DWOLFSSL_VERIFY_CB_ALL_CERTS"
  346. "-DWOLFSSL_EXTRA_ALERTS"
  347. "-DHAVE_EXT_CACHE"
  348. "-DWOLFSSL_FORCE_CACHE_ON_TICKET")
  349. endif()
  350. # TODO: - IPv6 test apps
  351. set(WOLFSSL_SLOW_MATH "yes")
  352. # liboqs
  353. add_option(WOLFSSL_OQS
  354. "Enable integration with the OQS (Open Quantum Safe) liboqs library (default: disabled)"
  355. "no" "yes;no")
  356. if (WOLFSSL_OQS)
  357. find_package(OQS)
  358. if (OQS_FOUND)
  359. list(APPEND WOLFSSL_LINK_LIBS ${OQS_LIBRARY})
  360. list(APPEND WOLFSSL_INCLUDE_DIRS ${OQS_INCLUDE_DIR})
  361. set(HAVE_LIBOQS 1)
  362. list(APPEND WOLFSSL_DEFINITIONS
  363. "-DHAVE_TLS_EXTENSIONS"
  364. "-DHAVE_LIBOQS")
  365. endif()
  366. endif()
  367. # TODO: - Lean PSK
  368. # - Lean TLS
  369. # - Low resource
  370. # - Titan cache
  371. # - Huge cache
  372. # - Big cache
  373. # - Small cache
  374. # - Persistent session cache
  375. # - Persistent cert cache
  376. # - Write duplicate
  377. # - Atomic user record layer
  378. # - Public key callbacks
  379. # - Microchip/Atmel CryptoAuthLib
  380. # AES-CBC
  381. add_option("WOLFSSL_AESCBC"
  382. "Enable wolfSSL AES-CBC support (default: enabled)"
  383. "yes" "yes;no")
  384. if(NOT WOLFSSL_AESCBC)
  385. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES_CBC")
  386. endif()
  387. # AES-GCM
  388. add_option("WOLFSSL_AESGCM"
  389. "Enable wolfSSL AES-GCM support (default: enabled)"
  390. "yes" "yes;no;table;small;word32;4bit")
  391. # leanpsk and leantls don't need gcm
  392. if(WOLFSSL_LEAN_PSK OR (WOLFSSL_LEAN_TLS AND NOT WOLFSSL_TLS13))
  393. override_cache(WOLFSSL_AESGCM "no")
  394. endif()
  395. if(WOLFSSL_AESGCM AND NOT WORDS_BIGENDIAN)
  396. override_cache(WOLFSSL_AESGCM "4bit")
  397. endif()
  398. if(WOLFSSL_AESGCM)
  399. if("${WOLFSSL_AESGCM}" STREQUAL "word32")
  400. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_WORD32")
  401. override_cache(WOLFSSL_AESGCM "yes")
  402. endif()
  403. if(("${WOLFSSL_AESGCM}" STREQUAL "small") OR WOLFSSL_LOW_RESOURCE)
  404. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_SMALL")
  405. override_cache(WOLFSSL_AESGCM "yes")
  406. endif()
  407. if("${WOLFSSL_AESGCM}" STREQUAL "table")
  408. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_TABLE")
  409. override_cache(WOLFSSL_AESGCM "yes")
  410. endif()
  411. if("${WOLFSSL_AESGCM}" STREQUAL "4bit")
  412. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_TABLE_4BIT")
  413. override_cache(WOLFSSL_AESGCM "yes")
  414. endif()
  415. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_AESGCM")
  416. endif()
  417. # AES-SIV
  418. add_option("WOLFSSL_AESSIV"
  419. "Enable wolfSSL AES-SIV support (default: disabled)"
  420. "no" "yes;no")
  421. if(WOLFSSL_AESSIV)
  422. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_SIV")
  423. endif()
  424. # AES-CTR
  425. add_option("WOLFSSL_AESCTR"
  426. "Enable wolfSSL AES-CTR support (default: disabled)"
  427. "no" "yes;no")
  428. if(WOLFSSL_OPENVPN OR
  429. WOLFSSL_LIBSSH2 OR
  430. WOLFSSL_AESSIV)
  431. override_cache(WOLFSSL_AESCTR "yes")
  432. endif()
  433. if(WOLFSSL_AESCTR AND NOT WOLFSSL_FORTRESS)
  434. list(APPEND WOLFSSL_DEFINITIONS
  435. "-DWOLFSSL_AES_COUNTER"
  436. "-DWOLFSSL_AES_DIRECT")
  437. endif()
  438. # AES-CCM
  439. add_option("WOLFSSL_AESCCM"
  440. "Enable wolfSSL AES-CCM support (default: disabled)"
  441. "no" "yes;no")
  442. # AES-OFB
  443. add_option("WOLFSSL_AESOFB"
  444. "Enable wolfSSL AES-OFB support (default: disabled)"
  445. "no" "yes;no")
  446. # TODO: - AES-GCM stream
  447. # - AES-ARM
  448. # - Xilinx hardened crypto
  449. # - Intel AES-NI
  450. # - Intel ASM
  451. # - Intel RDRAND
  452. # - Linux af_alg
  453. # - Linux dev crpyto calls
  454. # - Camellia
  455. # - MD2
  456. # - NULL cipher
  457. # - RIPEMD
  458. # - BLAKE2
  459. add_option("WOLFSSL_AESCFB"
  460. "Enable wolfSSL AES-CFB support (default: disabled)"
  461. "no" "yes;no")
  462. # Align data
  463. add_option("WOLFSSL_ALIGN_DATA"
  464. "Align data for ciphers (default: enabled)"
  465. "yes" "yes;no")
  466. if(WOLFSSL_ALIGN_DATA)
  467. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_USE_ALIGN")
  468. endif()
  469. # SHA224
  470. set(SHA224_DEFAULT "no")
  471. if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR
  472. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  473. if(NOT WOLFSSL_AFALG AND NOT WOLFSSL_DEVCRYPTO AND
  474. (NOT WOLFSSL_FIPS OR ("${FIPS_VERSION}" STREQUAL "v2")))
  475. set(SHA224_DEFAULT "yes")
  476. endif()
  477. endif()
  478. add_option("WOLFSSL_SHA224"
  479. "Enable wolfSSL SHA-224 support (default: enabled on x86_64/aarch64)"
  480. ${SHA224_DEFAULT} "yes;no")
  481. # SHA3
  482. set(SHA3_DEFAULT "no")
  483. if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR
  484. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  485. if(NOT WOLFSSL_FIPS OR ("${FIPS_VERSION}" STREQUAL "v2"))
  486. set(SHA3_DEFAULT "yes")
  487. endif()
  488. endif()
  489. add_option("WOLFSSL_SHA3"
  490. "Enable wolfSSL SHA-3 support (default: enabled on x86_64/aarch64)"
  491. ${SHA3_DEFAULT} "yes;no;small")
  492. # SHAKE256
  493. add_option("WOLFSSL_SHAKE256"
  494. "Enable wolfSSL SHAKE256 support (default: enabled on x86_64/aarch64)"
  495. "no" "yes;no;small")
  496. # SHAKE128
  497. add_option("WOLFSSL_SHAKE128"
  498. "Enable wolfSSL SHAKE128 support (default: enabled on x86_64/aarch64)"
  499. "no" "yes;no;small")
  500. # SHA512
  501. add_option("WOLFSSL_SHA512"
  502. "Enable wolfSSL SHA-512 support (default: enabled)"
  503. "yes" "yes;no")
  504. # options that don't require sha512
  505. if(WOLFSSL_LEAN_PSK OR
  506. WOLFSSL_LEAN_TLS OR
  507. WOLFSSL_32BIT OR
  508. WOLFSSL_16BIT)
  509. override_cache(WOLFSSL_SHA512 "no")
  510. endif()
  511. # options that require sha512
  512. if(WOLFSSL_OPENSSH OR
  513. WOLFSSL_WPAS OR
  514. WOLFSSL_FORTRESS)
  515. override_cache(WOLFSSL_SHA512 "yes")
  516. endif()
  517. if(WOLFSSL_SHA512)
  518. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA512")
  519. endif()
  520. # SHA384
  521. add_option("WOLFSSL_SHA384"
  522. "Enable wolfSSL SHA-384 support (default: enabled)"
  523. "yes" "yes;no")
  524. # options that don't require sha384
  525. if(WOLFSSL_LEAN_PSK OR
  526. WOLFSSL_LEAN_TLS OR
  527. WOLFSSL_32BIT OR
  528. WOLFSSL_16BIT)
  529. override_cache(WOLFSSL_SHA384 "no")
  530. endif()
  531. # options that require sha384
  532. if(WOLFSSL_OPENSSH OR
  533. WOLFSSL_WPAS OR
  534. WOLFSSL_FORTRESS)
  535. override_cache(WOLFSSL_SHA384 "yes")
  536. endif()
  537. if(WOLFSSL_SHA384)
  538. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA384")
  539. endif()
  540. # TODO: - Session certs
  541. # - SEP
  542. add_option("WOLFSSL_KEYGEN"
  543. "Enable key generation (default: disabled)])"
  544. "no" "yes;no")
  545. add_option("WOLFSSL_CERTGEN"
  546. "Enable cert generation (default: disabled)"
  547. "no" "yes;no")
  548. add_option("WOLFSSL_CERTREQ"
  549. "Enable cert request generation (default: disabled)"
  550. "no" "yes;no")
  551. add_option("WOLFSSL_CERTEXT"
  552. "Enable cert request extensions (default: disabled)"
  553. "no" "yes;no")
  554. add_option("WOLFSSL_CERTGENCACHE"
  555. "Enable decoded cert caching (default: disabled)"
  556. "no" "yes;no")
  557. # HKDF
  558. add_option("WOLFSSL_HKDF"
  559. "Enable HKDF (HMAC-KDF) support (default: disabled)"
  560. "no" "yes;no")
  561. if(WOLFSSL_TLS13)
  562. override_cache(WOLFSSL_HKDF "yes")
  563. endif()
  564. if(WOLFSSL_HKDF)
  565. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HKDF")
  566. endif()
  567. # DSA
  568. add_option("WOLFSSL_DSA"
  569. "Enable DSA (default: disabled)"
  570. "no" "yes;no")
  571. if(NOT WOLFSSL_DSA AND NOT WOLFSSL_OPENSSH)
  572. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DSA")
  573. endif()
  574. # ECC Shamir
  575. add_option("WOLFSSL_ECCSHAMIR"
  576. "Enable ECC Shamir (default: enabled)"
  577. "yes" "yes;no")
  578. # ECC
  579. add_option("WOLFSSL_ECC"
  580. "Enable ECC (default: enabled)"
  581. "yes" "yes;no;nonblock")
  582. # lean psk doesn't need ecc
  583. if(WOLFSSL_LEAN_PSK)
  584. override_cache(WOLFSSL_ECC "no")
  585. endif()
  586. if(WOLFSSL_OPENSSH OR
  587. WOLFSSL_NGINX OR
  588. WOLFSSL_SIGNAL)
  589. override_cache(WOLFSSL_ECC "yes")
  590. endif()
  591. if(WOLFSSL_ECC)
  592. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ECC" "-DTFM_ECC256")
  593. if(WOLFSSL_ECCSHAMIR AND NOT WOLFSSL_LOW_RESOURCE)
  594. list(APPEND WOLFSSL_DEFINITIONS "-DECC_SHAMIR")
  595. endif()
  596. if("${WOLFSSL_ECC}" STREQUAL "nonblock")
  597. list(APPEND WOLFSSL_DEFINITIONS "-DWC_ECC_NONBLOCK")
  598. endif()
  599. endif()
  600. # TODO: - ECC custom curves
  601. # - Compressed key
  602. # - FP ECC, fixed point cache ECC
  603. # - ECC encrypt
  604. # - PSK
  605. # - Single PSK identity
  606. # CURVE25519
  607. set(WOLFSSL_CURVE25519_SMALL "no")
  608. add_option("WOLFSSL_CURVE25519"
  609. "Enable Curve25519 (default: disabled)"
  610. "no" "yes;no;small;no128bit")
  611. if(WOLFSSL_OPENSSH)
  612. override_cache(WOLFSSL_CURVE25519 "yes")
  613. endif()
  614. if(WOLFSSL_CURVE25519)
  615. if("${WOLFSSL_CURVE25519}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  616. list(APPEND WOLFSSL_DEFINITIONS "-DCURVE25519_SMALL")
  617. set(WOLFSSL_CURVE25519_SMALL "yes")
  618. endif()
  619. if("${WOLFSSL_CURVE25519}" STREQUAL "no128bit" OR WOLFSSL_32BIT)
  620. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CURVED25519_128BIT")
  621. endif()
  622. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CURVE25519")
  623. set(WOLFSSL_FEMATH "yes")
  624. endif()
  625. # ED25519
  626. set(WOLFSSL_ED25519_SMALL "no")
  627. add_option("WOLFSSL_ED25519"
  628. "Enable ED25519 (default: disabled)"
  629. "no" "yes;no")
  630. if(WOLFSSL_OPENSSH)
  631. override_cache(WOLFSSL_ED25519 "yes")
  632. endif()
  633. if(WOLFSSL_ED25519 AND NOT WOLFSSL_32BIT)
  634. if("${WOLFSSL_ED25519}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  635. list(APPEND WOLFSSL_DEFINITIONS "-DED25519_SMALL")
  636. set(WOLFSSL_ED25519_SMALL "yes")
  637. set(WOLFSSL_CURVE25519_SMALL "yes")
  638. endif()
  639. if(NOT WOLFSSL_SHA512)
  640. message(FATAL_ERROR "cannot enable ed25519 without enabling sha512.")
  641. endif()
  642. set(WOLFSSL_FEMATH "yes")
  643. set(WOLFSSL_GEMATH "yes")
  644. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ED25519")
  645. endif()
  646. # CURVE448
  647. set(WOLFSSL_CURVE448_SMALL "no")
  648. add_option("WOLFSSL_CURVE448"
  649. "Enable Curve448 (default: disabled)"
  650. "no" "yes;no;small")
  651. if(WOLFSSL_CURVE448)
  652. if("${WOLFSSL_CURVE448}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  653. list(APPEND WOLFSSL_DEFINITIONS "-DCURVE448_SMALL")
  654. set(WOLFSSL_CURVE448_SMALL "yes")
  655. endif()
  656. if("${WOLFSSL_CURVE448}" STREQUAL "no128bit" OR WOLFSSL_32BIT)
  657. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CURVED448_128BIT")
  658. endif()
  659. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CURVE448")
  660. set(WOLFSSL_FE448 "yes")
  661. endif()
  662. # ED448
  663. set(WOLFSSL_ED448_SMALL "no")
  664. add_option("WOLFSSL_ED448"
  665. "Enable ED448 (default: disabled)"
  666. "no" "yes;no;small")
  667. if(WOLFSSL_ED448 AND NOT WOLFSSL_32BIT)
  668. if("${WOLFSSL_ED448}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  669. list(APPEND WOLFSSL_DEFINITIONS "-DED448_SMALL")
  670. set(WOLFSSL_ED448_SMALL "yes")
  671. set(WOLFSSL_CURVE448_SMALL "yes")
  672. endif()
  673. if(NOT WOLFSSL_SHA512)
  674. message(FATAL_ERROR "cannot enable ed448 without enabling sha512.")
  675. endif()
  676. set(WOLFSSL_FE448 "yes")
  677. set(WOLFSSL_GE448 "yes")
  678. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ED448")
  679. # EdDSA448 requires SHAKE256 which requires SHA-3
  680. override_cache(WOLFSSL_SHAKE256 "yes")
  681. endif()
  682. # Error strings
  683. add_option("WOLFSSL_ERROR_STRINGS"
  684. "Enable error strings table (default: enabled)"
  685. "yes" "yes;no")
  686. if(NOT WOLFSSL_ERROR_STRINGS)
  687. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_STRINGS")
  688. else()
  689. # turn off error strings if leanpsk or leantls on
  690. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  691. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_STRINGS")
  692. override_cache(WOLFSSL_ERROR_STRINGS "no")
  693. endif()
  694. endif()
  695. # Error queue
  696. add_option("WOLFSSL_ERROR_QUEUE"
  697. "Enables adding nodes to error queue when compiled with OPENSSL_EXTRA (default: enabled)"
  698. "yes" "yes;no")
  699. if(NOT WOLFSSL_ERROR_QUEUE)
  700. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_QUEUE")
  701. endif()
  702. # Old TLS
  703. add_option("WOLFSSL_OLD_TLS"
  704. "Enable old TLS versions < 1.2 (default: enabled)"
  705. "yes" "yes;no")
  706. if(NOT WOLFSSL_OLD_TLS)
  707. list(APPEND WOLFSSL_DEFINITIONS "-DNO_OLD_TLS")
  708. else()
  709. # turn off old if leanpsk or leantls on
  710. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  711. list(APPEND WOLFSSL_DEFINITIONS "-DNO_OLD_TLS")
  712. override_cache(WOLFSSL_OLD_TLS "no")
  713. endif()
  714. endif()
  715. # TLSv1.2
  716. add_option("WOLFSSL_TLSV12"
  717. "Enable TLS versions 1.2 (default: enabled)"
  718. "yes" "yes;no")
  719. if(NOT WOLFSSL_TLSV12)
  720. list(APPEND WOLFSSL_DEFINITIONS
  721. "-DWOLFSSL_NO_TLS12"
  722. "-DNO_OLD_TLS")
  723. endif()
  724. # TODO: - TLSv1.0
  725. # - SSLv3
  726. # - Stack size
  727. # - Stack size verbose
  728. # Memory
  729. add_option("WOLFSSL_MEMORY"
  730. "Enable memory callbacks (default: enabled)"
  731. "yes" "yes;no")
  732. if(NOT WOLFSSL_MEMORY)
  733. list(APPEND WOLFSSL_DEFINITIONS "-DNO_WOLFSSL_MEMORY")
  734. else()
  735. # turn off memory cb if leanpsk or leantls on
  736. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  737. # but don't turn on NO_WOLFSSL_MEMORY because using own
  738. override_cache(WOLFSSL_MEMORY "no")
  739. endif()
  740. endif()
  741. # TODO: - Track memory
  742. # - Memory log
  743. # - Stack log
  744. # RSA
  745. add_option("WOLFSSL_RSA"
  746. "Enable RSA (default: enabled)"
  747. "yes" "yes;no")
  748. if(NOT WOLFSSL_RSA)
  749. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RSA")
  750. else()
  751. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  752. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RSA")
  753. override_cache(WOLFSSL_RSA "no")
  754. endif()
  755. endif()
  756. # OAEP
  757. add_option("WOLFSSL_OAEP"
  758. "Enable RSA OAEP (default: enabled)"
  759. "yes" "yes;no")
  760. if(NOT WOLFSSL_OAEP)
  761. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_RSA_OAEP")
  762. endif()
  763. # TODO: - RSA public only
  764. # - RSA verify inline only
  765. # RSA-PSS
  766. add_option("WOLFSSL_RSA_PSS"
  767. "Enable RSA-PSS (default: disabled)"
  768. "no" "yes;no")
  769. if(NOT WOLFSSL_RSA)
  770. override_cache(WOLFSSL_RSA_PSS "no")
  771. else()
  772. if(WOLFSSL_TLS13)
  773. override_cache(WOLFSSL_RSA_PSS "yes")
  774. endif()
  775. endif()
  776. if(WOLFSSL_RSA_PSS)
  777. list(APPEND WOLFSSL_DEFINITIONS "-DWC_RSA_PSS")
  778. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_PSS_LONG_SALT")
  779. endif()
  780. # DH
  781. add_option("WOLFSSL_DH"
  782. "Enable DH (default: enabled)"
  783. "yes" "yes;no")
  784. if(WOLFSSL_OPENSSH)
  785. override_cache(WOLFSSL_DH "yes")
  786. endif()
  787. if(NOT WOLFSSL_DH)
  788. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DH")
  789. else()
  790. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  791. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DH")
  792. override_cache(WOLFSSL_DH "no")
  793. endif()
  794. endif()
  795. # TODO: - Anonymous
  796. # ASN
  797. # turn off asn, which means no certs, no rsa, no dsa, no ecc,
  798. # and no big int (unless dh is on)
  799. add_option("WOLFSSL_ASN"
  800. "Enable ASN (default: enabled)"
  801. "yes" "yes;no")
  802. if(NOT WOLFSSL_ASN)
  803. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ASN" "-DNO_CERTS")
  804. if(NOT WOLFSSL_DH AND NOT WOLFSSL_ECC)
  805. # DH and ECC need bigint
  806. list(APPEND WOLFSSL_DEFINITIONS "-DNO_BIG_INT")
  807. endif()
  808. else()
  809. # turn off ASN if leanpsk on
  810. if(WOLFSSL_LEAN_PSK)
  811. list(APPEND WOLFSSL_DEFINITIONS
  812. "-DNO_ASN"
  813. "-DNO_CERTS"
  814. "-DNO_BIG_INT")
  815. override_cache(WOLFSSL_ASN "no")
  816. else()
  817. if("${WOLFSSL_ASN}" STREQUAL "nocrypt")
  818. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ASN_CRYPT")
  819. # TODO: verify that this is correct
  820. override_cache(WOLFSSL_PWDBASED "no")
  821. endif()
  822. endif()
  823. endif()
  824. if(WOLFSSL_RSA AND NOT WOLFSSL_RSA_VFY AND NOT WOLFSSL_ASN)
  825. message(FATAL_ERROR "please disable rsa if disabling asn.")
  826. endif()
  827. if(WOLFSSL_DSA AND NOT WOLFSSL_ASN)
  828. message(FATAL_ERROR "please disable dsa if disabling asn.")
  829. endif()
  830. # DH and ECC need bigint
  831. if(NOT WOLFSSL_ASN AND
  832. NOT WOLFSSL_DH AND
  833. NOT WOLFSSL_ECC AND
  834. NOT WOLFSSL_RSA)
  835. override_cache(WOLFSSL_FAST_MATH "no")
  836. set(WOLFSSL_SLOWMATH "no")
  837. endif()
  838. # AES
  839. add_option("WOLFSSL_AES"
  840. "Enable AES (default: enabled)"
  841. "yes" "yes;no")
  842. if(NOT WOLFSSL_AES)
  843. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
  844. if(WOLFSSL_FORTRESS)
  845. message(FATAL_ERROR "fortress requires aes")
  846. endif()
  847. if(WOLFSSL_ECC_ENCRYPT)
  848. message(FATAL_ERROR "cannot enable eccencrypt and hkdf without aes.")
  849. endif()
  850. if(WOLFSSL_AESGCM)
  851. message(FATAL_ERROR "AESGCM requires AES.")
  852. endif()
  853. if(WOLFSSL_AESCCM)
  854. message(FATAL_ERROR "AESCCM requires AES.")
  855. endif()
  856. if(WOLFSSL_AESCTR)
  857. message(FATAL_ERROR "AESCTR requires AES.")
  858. endif()
  859. else()
  860. if(WOLFSSL_LEAN_PSK)
  861. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
  862. override_cache(WOLFSSL_AES "no")
  863. endif()
  864. endif()
  865. # Coding
  866. add_option("WOLFSSL_CODING"
  867. "Enable coding base 16/64 (default: enabled)"
  868. "yes" "yes;no")
  869. if(NOT WOLFSSL_CODING)
  870. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CODING")
  871. else()
  872. # turn off CODING if leanpsk on
  873. if(WOLFSSL_LEAN_PSK)
  874. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CODING")
  875. override_cache(WOLFSSL_CODING "no")
  876. endif()
  877. endif()
  878. # Base64
  879. set(BASE64_ENCODE_DEFAULT "no")
  880. if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  881. set(BASE64_ENCODE_DEFAULT "yes")
  882. endif()
  883. set(WOLFSSL_BASE64_ENCODE_HELP_STRING "Enable Base64 encoding (default: enabled on x86_64)")
  884. add_option("WOLFSSL_BASE64_ENCODE" ${WOLFSSL_BASE64_ENCODE_HELP_STRING} ${BASE64_ENCODE_DEFAULT} "yes;no")
  885. if(WOLFSSL_BASE64_ENCODE)
  886. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_BASE64_ENCODE")
  887. endif()
  888. # TODO: - Base16
  889. # DES3
  890. set(WOLFSSL_DES3_HELP_STRING "Enable DES3 (default: disabled)")
  891. add_option("WOLFSSL_DES3" ${WOLFSSL_DES3_HELP_STRING} "no" "yes;no")
  892. if(WOLFSSL_OPENSSH OR
  893. WOLFSSL_QT OR
  894. WOLFSSL_OPENVPN OR
  895. WOLFSSL_WPAS)
  896. override_cache(WOLFSSL_DES3 "yes")
  897. endif()
  898. # ARC4
  899. set(WOLFSSL_ARC4_HELP_STRING "Enable ARC4 (default: disabled)")
  900. add_option("WOLFSSL_ARC4" ${WOLFSSL_ARC4_HELP_STRING} "no" "yes;no")
  901. if(WOLFSSL_OPENSSH OR WOLFSSL_WPAS)
  902. override_cache(WOLFSSL_ARC4 "yes")
  903. endif()
  904. # MD5
  905. set(WOLFSSL_MD5_HELP_STRING "Enable MD5 (default: enabled)")
  906. add_option("WOLFSSL_MD5" ${WOLFSSL_MD5_HELP_STRING} "yes" "yes;no")
  907. if(NOT WOLFSSL_MD5)
  908. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD5" "-DNO_OLD_TLS")
  909. else()
  910. # turn off MD5 if leanpsk or leantls on
  911. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  912. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD5" "-DNO_OLD_TLS")
  913. override_cache(WOLFSSL_MD5 "no")
  914. endif()
  915. endif()
  916. # SHA
  917. add_option("WOLFSSL_SHA"
  918. "Enable SHA (default: enabled)"
  919. "yes" "yes;no")
  920. if(NOT WOLFSSL_SHA)
  921. list(APPEND WOLFSSL_DEFINITIONS "-DNO_SHA" "-DNO_OLD_TLS")
  922. else()
  923. # turn off SHA if leanpsk or leantls on
  924. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  925. list(APPEND WOLFSSL_DEFINITIONS "-DNO_SHA" "-DNO_OLD_TLS")
  926. override_cache(WOLFSSL_SHA "no")
  927. endif()
  928. endif()
  929. # TODO: - AES-XTS
  930. # - Web server
  931. # - Web client
  932. add_option("WOLFSSL_CMAC"
  933. "Enable CMAC (default: disabled)"
  934. "no" "yes;no")
  935. if(WOLFSSL_WPAS OR
  936. WOLFSSL_NTP OR
  937. WOLFSSL_AESSIV)
  938. override_cache(WOLFSSL_CMAC "yes")
  939. endif()
  940. if(WOLFSSL_CMAC)
  941. if (NOT WOLFSSL_AES)
  942. message(FATAL_ERROR "Cannot use CMAC without AES.")
  943. else()
  944. list(APPEND WOLFSSL_DEFINITIONS
  945. "-DWOLFSSL_CMAC"
  946. "-DWOLFSSL_AES_DIRECT")
  947. endif()
  948. endif()
  949. # TODO: - RC2
  950. # - FIPS, again (there's more logic for FIPS in configure.ac)
  951. # - Selftest
  952. # SHA224
  953. if(WOLFSSL_SHA224)
  954. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA224")
  955. endif()
  956. # SHA3
  957. if("${WOLFSSL_SHA3}" STREQUAL "small")
  958. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA3_SMALL")
  959. override_cache(WOLFSSL_SHA3 "yes")
  960. endif()
  961. if(WOLFSSL_SHA3 AND NOT WOLFSSL_32BIT)
  962. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA3")
  963. endif()
  964. # SHAKE256
  965. if(WOLFSSL_SHAKE256)
  966. if(NOT WOLFSSL_32BIT)
  967. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHAKE256")
  968. if(NOT WOLFSSL_SHA3)
  969. message(FATAL_ERROR "Must have SHA-3 enabled: --enable-sha3")
  970. endif()
  971. endif()
  972. else()
  973. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_NO_SHAKE256")
  974. endif()
  975. # SHAKE128
  976. if(WOLFSSL_SHAKE128)
  977. if(NOT WOLFSSL_32BIT)
  978. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHAKE128")
  979. if(NOT WOLFSSL_SHA3)
  980. message(FATAL_ERROR "Must have SHA-3 enabled: --enable-sha3")
  981. endif()
  982. endif()
  983. else()
  984. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_NO_SHAKE128")
  985. endif()
  986. # POLY1305
  987. set(POLY1305_DEFAULT "yes")
  988. if(WOLFSSL_FIPS)
  989. set(POLY1305_DEFAULT "no")
  990. endif()
  991. set(WOLFSSL_POLY1305_HELP_STRING "Enable wolfSSL POLY1305 support (default: enabled)")
  992. add_option("WOLFSSL_POLY1305" ${WOLFSSL_POLY1305_HELP_STRING} ${POLY1305_DEFAULT} "yes;no")
  993. # leanpsk and leantls don't need poly1305
  994. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  995. override_cache(WOLFSSL_POLY1305 "no")
  996. endif()
  997. if(WOLFSSL_POLY1305)
  998. list(APPEND WOLFSSL_DEFINITIONS
  999. "-DHAVE_POLY1305"
  1000. "-DHAVE_ONE_TIME_AUTH")
  1001. endif()
  1002. # CHACHA
  1003. set(CHACHA_DEFAULT "yes")
  1004. if(WOLFSSL_FIPS)
  1005. set(CHACHA_DEFAULT "no")
  1006. endif()
  1007. add_option("WOLFSSL_CHACHA"
  1008. "Enable CHACHA (default: enabled). Use `=noasm` to disable ASM AVX/AVX2 speedups"
  1009. ${CHACHA_DEFAULT} "yes;no;noasm")
  1010. # leanpsk and leantls don't need chacha
  1011. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1012. override_cache(WOLFSSL_CHACHA "no")
  1013. endif()
  1014. if(("${WOLFSSL_CHACHA}" STREQUAL "noasm") OR NOT WOLFSSL_ASM)
  1015. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CHACHA_ASM")
  1016. endif()
  1017. if(NOT ("${WOLFSSL_CHACHA}" STREQUAL "noasm") AND WOLFSSL_CHACHA)
  1018. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CHACHA")
  1019. endif()
  1020. # TODO: - XCHACHA
  1021. # Hash DRBG
  1022. add_option("WOLFSSL_HASH_DRBG"
  1023. "Enable Hash DRBG support (default: enabled)"
  1024. "yes" "yes;no")
  1025. if(WOLFSSL_HASH_DRBG)
  1026. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HASHDRBG")
  1027. else()
  1028. # turn on Hash DRBG if FIPS is on
  1029. if(WOLFSSL_FIPS)
  1030. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HASHDRBG")
  1031. override_cache(WOLFSSL_HASH_DRBG "yes")
  1032. else()
  1033. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HASHDRBG")
  1034. endif()
  1035. endif()
  1036. # Filesystem
  1037. if(WOLFSSL_LINUX_KM)
  1038. set(FILESYSTEM_DEFAULT "no")
  1039. else()
  1040. set(FILESYSTEM_DEFAULT "yes")
  1041. endif()
  1042. add_option("WOLFSSL_FILESYSTEM"
  1043. "Enable Filesystem support (default: enabled)"
  1044. ${FILESYSTEM_DEFAULT} "yes;no")
  1045. if(NOT WOLFSSL_FILESYSTEM)
  1046. list(APPEND WOLFSSL_DEFINITIONS "-DNO_FILESYSTEM")
  1047. else()
  1048. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1049. list(APPEND WOLFSSL_DEFINITIONS "-DNO_FILESYSTEM")
  1050. override_cache(WOLFSSL_FILESYSTEM "no")
  1051. endif()
  1052. endif()
  1053. # Inline function support
  1054. add_option("WOLFSSL_INLINE"
  1055. "Enable inline functions (default: enabled)"
  1056. "yes" "yes;no")
  1057. if(NOT WOLFSSL_INLINE)
  1058. list(APPEND WOLFSSL_DEFINITIONS "-DNO_INLINE")
  1059. endif()
  1060. # TODO:
  1061. # - CRL monitor
  1062. # - User crypto
  1063. # - Whitewood netRandom client library
  1064. # - SNI
  1065. # - Max fragment length
  1066. # - ALPN
  1067. # - Trusted CA indication
  1068. # - Truncated HMAC
  1069. # - Renegotiation indication
  1070. # - Secure renegotiation
  1071. # - Fallback SCSV
  1072. add_option(WOLFSSL_OCSP "Enable OCSP (default: disabled)" "no" "yes;no")
  1073. add_option(WOLFSSL_OCSPSTAPLING "Enable OCSP Stapling (default: disabled)" "no" "yes;no")
  1074. add_option(WOLFSSL_OCSPSTAPLING_V2 "Enable OCSP Stapling v2 (default: disabled)" "no" "yes;no")
  1075. add_option(WOLFSSL_CRL
  1076. "Enable CRL (Use =io for inline CRL HTTP GET) (default: disabled)"
  1077. "no" "yes;no;io")
  1078. set(WOLFSSL_SNI_HELP_STRING "Enable SNI (default: disabled)")
  1079. add_option(WOLFSSL_SNI ${WOLFSSL_SNI_HELP_STRING} "no" "yes;no")
  1080. set(WOLFSSL_TLSX_HELP_STRING "Enable all TLS Extensions (default: disabled)")
  1081. add_option(WOLFSSL_TLSX ${WOLFSSL_TLSX_HELP_STRING} "no" "yes;no")
  1082. # Supported elliptic curves extensions
  1083. add_option("WOLFSSL_SUPPORTED_CURVES"
  1084. "Enable Supported Elliptic Curves (default: enabled)"
  1085. "yes" "yes;no")
  1086. if(WOLFSSL_SUPPORTED_CURVES)
  1087. if(NOT WOLFSSL_ECC AND NOT WOLFSSL_CURVE25519 AND NOT WOLFSSL_CURVE448)
  1088. override_cache(WOLFSSL_SUPPORTED_CURVES "no")
  1089. else()
  1090. list(APPEND WOLFSSL_DEFINITIONS
  1091. "-DHAVE_TLS_EXTENSIONS"
  1092. "-DHAVE_SUPPORTED_CURVES")
  1093. endif()
  1094. endif()
  1095. # Diffie-Hellman
  1096. if(WOLFSSL_DH)
  1097. if(WOLFSSL_TLS13 OR WOLFSSL_SUPPORTED_CURVES)
  1098. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_FFDHE_2048")
  1099. endif()
  1100. endif()
  1101. # TODO: - FFDHE params only
  1102. # TLS 1.3 Requires either ECC or (RSA/DH), or CURVE25519/ED25519 or CURVE448/ED448
  1103. if (NOT WOLFSSL_ECC AND
  1104. (NOT WOLFSSL_RSA OR NOT WOLFSSL_DH) AND
  1105. (NOT WOLFSSL_CURVE25519 OR NOT WOLFSSL_ED25519) AND
  1106. (NOT WOLFSSL_CURVE448 AND NOT WOLFSSL_ED448))
  1107. override_cache(WOLFSSL_TLS13 "no")
  1108. endif()
  1109. if (WOLFSSL_TLS13)
  1110. list(APPEND WOLFSSL_DEFINITIONS
  1111. "-DHAVE_SUPPORTED_CURVES"
  1112. "-DWOLFSSL_TLS13"
  1113. "-DHAVE_TLS_EXTENSIONS"
  1114. )
  1115. endif()
  1116. # Session Ticket Extension
  1117. add_option("WOLFSSL_SESSION_TICKET"
  1118. "Enable Session Ticket (default: disabled)"
  1119. "no" "yes;no")
  1120. if(WOLFSSL_NGINX OR WOLFSSL_WPAS OR WOLFSSL_HAPROXY OR WOLFSSL_LIGHTY)
  1121. override_cache(WOLFSSL_SESSION_TICKET "yes")
  1122. endif()
  1123. if(WOLFSSL_SESSION_TICKET)
  1124. list(APPEND WOLFSSL_DEFINITIONS
  1125. "-DHAVE_TLS_EXTENSIONS"
  1126. "-DHAVE_SESSION_TICKET")
  1127. endif()
  1128. add_option("WOLFSSL_TICKET_NONCE_MALLOC"
  1129. "Enable dynamic allocation of ticket nonces (default: disabled)"
  1130. "no" "yes;no")
  1131. if(WOLFSSL_TICKET_NONCE_MALLOC)
  1132. list(APPEND WOLFSSL_DEFINITIONS
  1133. "-DWOLFSSL_TICKET_NONCE_MALLOC")
  1134. endif()
  1135. # Extended master secret extension
  1136. add_option("WOLFSSL_EXTENDED_MASTER"
  1137. "Enable Extended Master Secret (default: enabled)"
  1138. "yes" "yes;no")
  1139. if(WOLFSSL_EXTENDED_MASTER)
  1140. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_EXTENDED_MASTER")
  1141. endif()
  1142. if(NOT WOLFSSL_ARC4)
  1143. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RC4")
  1144. else()
  1145. # turn off ARC4 if leanpsk or leantls on
  1146. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1147. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RC4")
  1148. override_cache(WOLFSSL_ARC4 "no")
  1149. endif()
  1150. endif()
  1151. # TODO: - TLS extensions
  1152. # - Early data handshake
  1153. # - wolfSSH options
  1154. # - SCEP
  1155. # - Secure remote password
  1156. # - Indefinite length encoded messages
  1157. # - Small stack cache
  1158. # - Small stack
  1159. # - Valgrind
  1160. # - Test certs
  1161. # - I/O pool example
  1162. # - Certificate service
  1163. # - wolfSSL JNI
  1164. # - lighttpd/lighty
  1165. # - Asio
  1166. # - Apache HTTPD
  1167. set(WOLFSSL_PKCS7_HELP_STRING "Enable PKCS7 (default: disabled)")
  1168. add_option(WOLFSSL_PKCS7 ${WOLFSSL_PKCS7_HELP_STRING} "no" "yes;no")
  1169. set(WOLFSSL_TPM_HELP_STRING "Enable wolfTPM options (default: disabled)")
  1170. add_option(WOLFSSL_TPM ${WOLFSSL_TPM_HELP_STRING} "no" "yes;no")
  1171. set(WOLFSSL_AESKEYWRAP_HELP_STRING "Enable AES key wrap support (default: disabled)")
  1172. add_option(WOLFSSL_AESKEYWRAP ${WOLFSSL_AESKEYWRAP_HELP_STRING} "no" "yes;no")
  1173. set(WOLFSSL_X963KDF_HELP_STRING "Enable X9.63 KDF support (default: disabled)")
  1174. add_option(WOLFSSL_X963KDF ${WOLFSSL_X963KDF_HELP_STRING} "no" "yes;no")
  1175. # Encrypt-then-mac
  1176. add_option("WOLFSSL_ENC_THEN_MAC"
  1177. "Enable Encryptr-Then-Mac extension (default: enabled)"
  1178. "yes" "yes;no")
  1179. if(WOLFSSL_APACHE_HTTPD)
  1180. override_cache(WOLFSSL_ENC_THEN_MAC "no")
  1181. endif()
  1182. if(WOLFSSL_TLSX)
  1183. override_cache(WOLFSSL_ENC_THEN_MAC "yes")
  1184. endif()
  1185. if(WOLFSSL_SNIFFER)
  1186. override_cache(WOLFSSL_ENC_THEN_MAC "no")
  1187. endif()
  1188. # stunnel Support
  1189. # TODO: rest of stunnel support
  1190. add_option("WOLFSSL_STUNNEL"
  1191. "Enable stunnel (default: disabled)"
  1192. "no" "yes;no")
  1193. if(WOLFSSL_ENC_THEN_MAC)
  1194. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ENCRYPT_THEN_MAC")
  1195. endif()
  1196. if(NOT WOLFSSL_PSK AND
  1197. NOT WOLFSSL_LEAN_PSK AND
  1198. NOT WOLFSSL_STUNNEL)
  1199. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PSK")
  1200. endif()
  1201. # MD4
  1202. set(WOLFSSL_MD4_HELP_STRING "Enable MD4 (default: disabled)")
  1203. add_option("WOLFSSL_MD4" ${WOLFSSL_MD4_HELP_STRING} "no" "yes;no")
  1204. if(NOT WOLFSSL_MD4)
  1205. # turn on MD4 if using stunnel
  1206. if(WOLFSSL_STUNNEL OR WOLFSSL_WPAS)
  1207. override_cache(WOLFSSL_MD4 "yes")
  1208. else()
  1209. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD4")
  1210. endif()
  1211. endif()
  1212. # Encrypted keys
  1213. add_option("WOLFSSL_ENCKEYS"
  1214. "Enable PEM encrypted key support (default: disabled)"
  1215. "no" "yes;no")
  1216. if(NOT WOLFSSL_ENCKEYS)
  1217. if(WOLFSSL_OPENSSLEXTRA OR
  1218. WOLFSSL_WEBSERVER OR
  1219. WOLFSSL_WPAS)
  1220. # opensslextra, webserver, and WPAS needs enckeys
  1221. override_cache(WOLFSSL_ENCKEYS "yes")
  1222. endif()
  1223. endif()
  1224. if(WOLFSSL_ENCKEYS)
  1225. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_ENCRYPTED_KEYS")
  1226. endif()
  1227. # PKCS#12
  1228. set(WOLFSSL_PKCS12_HELP_STRING "Enable pkcs12 (default: enabled)")
  1229. add_option("WOLFSSL_PKCS12" ${WOLFSSL_PKCS12_HELP_STRING} "yes" "yes;no")
  1230. if(NOT WOLFSSL_ASN)
  1231. override_cache(WOLFSSL_PKCS12 "no")
  1232. endif()
  1233. if(NOT WOLFSSL_PKCS12)
  1234. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PKCS12")
  1235. endif()
  1236. # PWDBASED has to come after certservice since we want it on w/o explicit on
  1237. # PWDBASED
  1238. add_option("WOLFSSL_PWDBASED"
  1239. "Enable PWDBASED (default: disabled)"
  1240. "no" "yes;no")
  1241. if(NOT WOLFSSL_PWDBASED)
  1242. if(WOLFSSL_OPENSSLEXTRA OR
  1243. WOLFSSL_OPENSSLALL OR
  1244. WOLFSSL_WEBSERVER OR
  1245. WOLFSSL_ENC_KEYS OR
  1246. WOLFSSL_PKCS12)
  1247. # opensslextra, opensslall, webserver, and enckeys needs pwdbased
  1248. override_cache(WOLFSSL_PWDBASED "yes")
  1249. else()
  1250. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PWDBASED")
  1251. endif()
  1252. endif()
  1253. # TODO: - SCRYPT
  1254. # - wolfCrypt only
  1255. # fastmath
  1256. add_option("WOLFSSL_FAST_MATH"
  1257. "Enable fast math ops (default: disabled)"
  1258. "no" "yes;no")
  1259. if(WOLFSSL_FAST_MATH)
  1260. # turn off fastmath if leanpsk on or asn off (w/o DH and ECC)
  1261. if(WOLFSSL_LEAN_PSK OR NOT WOLFSSL_ASN)
  1262. if(NOT WOLFSSL_DH AND
  1263. NOT WOLFSSL_ECC AND
  1264. NOT WOLFSSL_RSA)
  1265. override_cache(WOLFSSL_FAST_MATH "no")
  1266. else()
  1267. list(APPEND WOLFSSL_DEFINITIONS "-DUSE_FAST_MATH")
  1268. set(WOLFSSL_SLOWMATH "no")
  1269. endif()
  1270. else()
  1271. list(APPEND WOLFSSL_DEFINITIONS "-DUSE_FAST_MATH")
  1272. set(WOLFSSL_SLOWMATH "no")
  1273. endif()
  1274. if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  1275. # Have settings.h set FP_MAX_BITS higher if user didn't set directly
  1276. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_X86_64_BUILD")
  1277. endif()
  1278. endif()
  1279. # TODO: - Fast huge math
  1280. if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  1281. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_X86_64_BUILD")
  1282. endif()
  1283. # SP math all
  1284. add_option("WOLFSSL_SP_MATH_ALL"
  1285. "Enable Single Precision math implementation for full algorithm suite (default: enabled)"
  1286. "yes" "yes;no")
  1287. # Enable examples, used to disable examples
  1288. if(WOLFSSL_LINUX_KM)
  1289. set(EXAMPLES_DEFAULT "no")
  1290. else()
  1291. set(EXAMPLES_DEFAULT "yes")
  1292. endif()
  1293. add_option("WOLFSSL_EXAMPLES"
  1294. "Enable examples (default: enabled)"
  1295. ${EXAMPLES_DEFAULT} "yes;no")
  1296. if(NOT WOLFSSL_FILESYSTEM OR
  1297. NOT WOLFSSL_INLINE OR
  1298. WOLFSSL_CRYPT_ONLY)
  1299. override_cache(WOLFSSL_EXAMPLES "no")
  1300. endif()
  1301. # Enable wolfCrypt test and benchmark
  1302. if(WOLFSSL_LINUX_KM)
  1303. set(CRYPT_TESTS_DEFAULT "no")
  1304. else()
  1305. set(CRYPT_TESTS_DEFAULT "yes")
  1306. endif()
  1307. add_option("WOLFSSL_CRYPT_TESTS"
  1308. "Enable Crypt Bench/Test (default: enabled)"
  1309. ${CRYPT_TESTS_DEFAULT} "yes;no")
  1310. add_option("WOLFSSL_CRYPT_TESTS_LIBS"
  1311. "Build static libraries from the wolfCrypt test and benchmark sources (default: disabled)"
  1312. "no" "yes;no")
  1313. add_option("WOLFSSL_CRYPT_TESTS_HELP"
  1314. "Add help text to wolfCrypt test (default: disabled)"
  1315. "no" "yes;no")
  1316. # TODO: - LIBZ
  1317. # - PKCS#11
  1318. # - Cavium
  1319. # - Cavium V
  1320. # - Cavium Octeon
  1321. # - Intel QuickAssist
  1322. # - SP ASM (and other SP logic)
  1323. # - Fast RSA
  1324. # - Static memory use
  1325. # - Microchip API
  1326. # - Asynchronous crypto
  1327. # Asynchronous threading
  1328. add_option("WOLFSSL_ASYNC_THREADS"
  1329. "Enable Asynchronous Threading (default: enabled)"
  1330. "yes" "yes;no")
  1331. if(WOLFSSL_ASYNC_CRYPT AND WOLFSSL_ASYNC_THREADS)
  1332. if(CMAKE_USE_PTHREADS_INIT)
  1333. override_cache(WOLFSSL_ASYNC_THREADS "yes")
  1334. else()
  1335. override_cache(WOLFSSL_ASYNC_THREADS "no")
  1336. endif()
  1337. else()
  1338. override_cache(WOLFSSL_ASYNC_THREADS "no")
  1339. endif()
  1340. if(WOLFSSL_ASYNC_THREADS)
  1341. list(APPEND WOLFSSL_LINK_LIBS Threads::Threads)
  1342. list(APPEND WOLFSSL_DEFINITIONS "-D_GNU_SOURCE")
  1343. else()
  1344. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_ASYNC_THREADING")
  1345. endif()
  1346. # TODO: - cryptodev
  1347. # - Session export
  1348. add_option("WOLFSSL_CRYPTOCB"
  1349. "Enable crypto callbacks (default: disabled)"
  1350. "no" "yes;no")
  1351. add_option("WOLFSSL_OLD_NAMES"
  1352. "Keep backwards compat with old names (default: enabled)"
  1353. "yes" "yes;no")
  1354. if(NOT WOLFSSL_OLD_NAMES AND NOT WOLFSSL_OPENSSL_COEXIST)
  1355. list(APPEND WOLFSSL_DEFINITIONS
  1356. "-DNO_OLD_RNGNAME"
  1357. "-DNO_OLD_WC_NAMES"
  1358. "-DNO_OLD_SSL_NAMES"
  1359. "-DNO_OLD_SHA_NAMES")
  1360. endif()
  1361. # TODO: - Memory tests
  1362. # - Hash flags
  1363. # Support for enabling setting default DH parameters
  1364. add_option("WOLFSSL_DH_DEFAULT_PARAMS"
  1365. "Enables option for default dh parameters (default: disabled)"
  1366. "no" "yes;no")
  1367. if(WOLFSSL_DH_DEFAULT_PARAMS OR NOT WOLFSSL_QT)
  1368. override_cache(WOLFSSL_DH_DEFAULT_PARAMS "yes")
  1369. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_DH_DEFAULT_PARAMS")
  1370. endif()
  1371. if(NOT WOLFSSL_DES3)
  1372. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3")
  1373. else()
  1374. # turn off DES3 if leanpsk or leantls on
  1375. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1376. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3")
  1377. override_cache(WOLFSSL_DES3 "no")
  1378. endif()
  1379. endif()
  1380. add_option("WOLFSSL_USER_SETTINGS"
  1381. "Use your own user_settings.h and do not add Makefile CFLAGS (default: disabled)"
  1382. "no" "yes;no")
  1383. add_option("WOLFSSL_OPTFLAGS"
  1384. "Enable default optimization CFLAGS for the compiler (default: enabled)"
  1385. "yes" "yes;no")
  1386. add_option("WOLFSSL_SYS_CA_CERTS"
  1387. "Enable ability to load CA certs from OS (default: enabled)"
  1388. "yes" "yes;no")
  1389. if(WOLFSSL_SYS_CA_CERTS)
  1390. if(NOT WOLFSSL_FILESYSTEM)
  1391. message(FATAL_ERROR "Cannot use system CA certs without a filesystem.")
  1392. else()
  1393. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SYS_CA_CERTS")
  1394. endif()
  1395. endif()
  1396. # FLAGS operations
  1397. if(WOLFSSL_AESCCM)
  1398. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_AESCCM")
  1399. endif()
  1400. if(WOLFSSL_AESOFB)
  1401. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_OFB" "-DWOLFSSL_AES_DIRECT")
  1402. endif()
  1403. if(WOLFSSL_TPM)
  1404. override_cache(WOLFSSL_KEYGEN "yes")
  1405. override_cache(WOLFSSL_CERTGEN "yes")
  1406. override_cache(WOLFSSL_CRYPTOCB "yes")
  1407. override_cache(WOLFSSL_CERTREQ "yes")
  1408. override_cache(WOLFSSL_CERTEXT "yes")
  1409. override_cache(WOLFSSL_PKCS7 "yes")
  1410. override_cache(WOLFSSL_AESCFB "yes")
  1411. endif()
  1412. if(WOLFSSL_AESCFB)
  1413. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_CFB")
  1414. endif()
  1415. if(WOLFSSL_PKCS7)
  1416. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_PKCS7")
  1417. override_cache(WOLFSSL_AESKEYWRAP "yes")
  1418. # Enable prereqs if not already enabled
  1419. if(WOLFSSL_ECC)
  1420. override_cache(WOLFSSL_X963KDF "yes")
  1421. endif()
  1422. endif()
  1423. if(WOLFSSL_X963KDF)
  1424. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_X963_KDF")
  1425. endif()
  1426. if(WOLFSSL_AESKEYWRAP)
  1427. list(APPEND WOLFSSL_DEFINITIONS
  1428. "-DHAVE_AES_KEYWRAP"
  1429. "-DWOLFSSL_AES_DIRECT"
  1430. )
  1431. endif()
  1432. if(WOLFSSL_KEYGEN)
  1433. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_KEY_GEN")
  1434. endif()
  1435. if(WOLFSSL_CERTGEN)
  1436. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_GEN")
  1437. endif()
  1438. if(WOLFSSL_CERTREQ)
  1439. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_REQ")
  1440. endif()
  1441. if(WOLFSSL_CERTEXT)
  1442. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_EXT")
  1443. endif()
  1444. if(WOLFSSL_CERTGENCACHE)
  1445. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_GEN_CACHE")
  1446. endif()
  1447. if(WOLFSSL_CRYPTOCB)
  1448. list(APPEND WOLFSSL_DEFINITIONS "-DWOLF_CRYPTO_CB")
  1449. endif()
  1450. if(WOLFSSL_OCSPSTAPLING)
  1451. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CERTIFICATE_STATUS_REQUEST" "-DHAVE_TLS_EXTENSIONS")
  1452. override_cache(WOLFSSL_OCSP "yes")
  1453. endif()
  1454. if(WOLFSSL_OCSPSTAPLING_V2)
  1455. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CERTIFICATE_STATUS_REQUEST_V2" "-DHAVE_TLS_EXTENSIONS")
  1456. override_cache(WOLFSSL_OCSP "yes")
  1457. endif()
  1458. # must be below OCSP stapling options to allow override
  1459. if (WOLFSSL_OCSP)
  1460. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_OCSP")
  1461. endif()
  1462. if (WOLFSSL_CRL STREQUAL "yes")
  1463. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CRL")
  1464. elseif(WOLFSSL_CRL STREQUAL "io")
  1465. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CRL" "-DHAVE_CRL_IO")
  1466. endif()
  1467. if (WOLFSSL_SNI)
  1468. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_TLS_EXTENSIONS" "-DHAVE_SNI")
  1469. endif()
  1470. if (WOLFSSL_TLSX)
  1471. list(APPEND WOLFSSL_DEFINITIONS
  1472. "-DHAVE_TLS_EXTENSIONS"
  1473. "-DHAVE_SNI"
  1474. "-DHAVE_MAX_FRAGMENT"
  1475. "-DHAVE_TRUNCATED_HMAC"
  1476. "-DHAVE_ALPN"
  1477. "-DHAVE_TRUSTED_CA")
  1478. if (WOLFSSL_ECC OR WOLFSSL_CURVE25519 OR WOLFSSL_CURVE448 OR WOLFSSL_TLS13)
  1479. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_SUPPORTED_CURVES")
  1480. endif()
  1481. endif()
  1482. # Generates the BUILD_* flags. These control what source files are included in
  1483. # the library. A series of AM_CONDITIONALs handle this in configure.ac.
  1484. generate_build_flags()
  1485. # TODO: - Bit of logic after optimization flags option (above)
  1486. # - Check for build-type conflicts section
  1487. # USER SETTINGS
  1488. if(WOLFSSL_USER_SETTINGS)
  1489. # Replace all options and just use WOLFSSL_USER_SETTINGS
  1490. set(WOLFSSL_DEFINITIONS "-DWOLFSSL_USER_SETTINGS")
  1491. # Create user_settings_asm.h for use in assembly files (e.g. .S files).
  1492. execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/user_settings_asm.sh
  1493. "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}"
  1494. RESULT_VARIABLE USER_SETTINGS_ASM_RET)
  1495. if (NOT USER_SETTINGS_ASM_RET EQUAL 0)
  1496. message(FATAL_ERROR "${CMAKE_CURRENT_SOURCE_DIR}/scripts/user_settings_asm.sh failed.")
  1497. endif()
  1498. endif()
  1499. # TODO: Applying definitions to everything like this, rather than
  1500. # individual targets, is discouraged in CMake.
  1501. add_definitions(${WOLFSSL_DEFINITIONS})
  1502. add_option("WOLFSSL_CONFIG_H"
  1503. "Enable generation of config.h and define HAVE_CONFIG_H (default: enabled)"
  1504. "yes" "yes;no")
  1505. if(WOLFSSL_CONFIG_H)
  1506. add_definitions("-DHAVE_CONFIG_H")
  1507. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.in"
  1508. "${CMAKE_CURRENT_BINARY_DIR}/config.h" )
  1509. set(abs_top_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
  1510. set(abs_top_builddir ${CMAKE_CURRENT_BINARY_DIR})
  1511. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test_paths.h.in"
  1512. "${CMAKE_CURRENT_BINARY_DIR}/wolfcrypt/test/test_paths.h" )
  1513. endif()
  1514. # Suppress some warnings about separate compilation, inlining
  1515. add_definitions("-DWOLFSSL_IGNORE_FILE_WARN")
  1516. # Generate user options header
  1517. message("Generating user options header...")
  1518. if (${CMAKE_DISABLE_SOURCE_CHANGES})
  1519. set(WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT "${CMAKE_DISABLE_SOURCE_CHANGES}")
  1520. else()
  1521. set(WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT "no")
  1522. endif()
  1523. add_option("WOLFSSL_BUILD_OUT_OF_TREE"
  1524. "Don't generate files in the source tree (default: ${WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT})"
  1525. "${WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT}" "yes;no")
  1526. if (${WOLFSSL_BUILD_OUT_OF_TREE})
  1527. set(WOLFSSL_OUTPUT_BASE ${CMAKE_CURRENT_BINARY_DIR})
  1528. else()
  1529. set(WOLFSSL_OUTPUT_BASE ${CMAKE_CURRENT_SOURCE_DIR})
  1530. endif()
  1531. set(OPTION_FILE "${WOLFSSL_OUTPUT_BASE}/wolfssl/options.h")
  1532. set(CYASSL_OPTION_FILE "${WOLFSSL_OUTPUT_BASE}/cyassl/options.h")
  1533. file(REMOVE ${OPTION_FILE})
  1534. file(APPEND ${OPTION_FILE} "/* wolfssl options.h\n")
  1535. file(APPEND ${OPTION_FILE} " * generated from configure options\n")
  1536. file(APPEND ${OPTION_FILE} " *\n")
  1537. file(APPEND ${OPTION_FILE} " * Copyright (C) 2006-2020 wolfSSL Inc.\n")
  1538. file(APPEND ${OPTION_FILE} " *\n")
  1539. file(APPEND ${OPTION_FILE} " * This file is part of wolfSSL. (formerly known as CyaSSL)\n")
  1540. file(APPEND ${OPTION_FILE} " *\n")
  1541. file(APPEND ${OPTION_FILE} " */\n\n")
  1542. file(APPEND ${OPTION_FILE} "#ifndef WOLFSSL_OPTIONS_H\n")
  1543. file(APPEND ${OPTION_FILE} "#define WOLFSSL_OPTIONS_H\n\n\n")
  1544. file(APPEND ${OPTION_FILE} "#ifdef __cplusplus\n")
  1545. file(APPEND ${OPTION_FILE} "extern \"C\" {\n")
  1546. file(APPEND ${OPTION_FILE} "#endif\n\n")
  1547. add_to_options_file("${WOLFSSL_DEFINITIONS}" "${OPTION_FILE}")
  1548. # CMAKE_C_FLAGS is just a string of space-separated flags to pass to the C
  1549. # compiler. We need to replace those spaces with semicolons in order to treat it
  1550. # as a CMake list.
  1551. string(REPLACE " " ";" CMAKE_C_FLAGS_LIST "${CMAKE_C_FLAGS}")
  1552. add_to_options_file("${CMAKE_C_FLAGS_LIST}" "${OPTION_FILE}")
  1553. file(APPEND ${OPTION_FILE} "\n#ifdef __cplusplus\n")
  1554. file(APPEND ${OPTION_FILE} "}\n")
  1555. file(APPEND ${OPTION_FILE} "#endif\n\n\n")
  1556. file(APPEND ${OPTION_FILE} "#endif /* WOLFSSL_OPTIONS_H */\n\n")
  1557. # backwards compatibility for those who have included options or version
  1558. file(REMOVE ${CYASSL_OPTION_FILE})
  1559. file(APPEND ${CYASSL_OPTION_FILE} "/* cyassl options.h\n")
  1560. file(APPEND ${CYASSL_OPTION_FILE} " * generated from wolfssl/options.h\n")
  1561. file(APPEND ${CYASSL_OPTION_FILE} " */\n")
  1562. file(READ ${OPTION_FILE} OPTION_FILE_CONTENTS)
  1563. file(APPEND ${CYASSL_OPTION_FILE} ${OPTION_FILE_CONTENTS})
  1564. ####################################################
  1565. # Library Target
  1566. ####################################################
  1567. # TODO: - Build shared/static libs based on enables. Check CMake
  1568. # global flag BUILD_SHARED_LIBS.
  1569. option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON)
  1570. set(LIB_SOURCES "")
  1571. # Generates a list of sources to include in the library.
  1572. # Corresponds to the instances of "src_libwolfssl_la_SOURCES += ..."
  1573. # in the *.am files.
  1574. generate_lib_src_list("${LIB_SOURCES}")
  1575. add_library(wolfssl ${LIB_SOURCES})
  1576. set_target_properties(wolfssl
  1577. PROPERTIES
  1578. SOVERSION ${LIBTOOL_SO_VERSION}
  1579. VERSION ${LIBTOOL_FULL_VERSION}
  1580. )
  1581. target_compile_definitions(wolfssl PRIVATE "BUILDING_WOLFSSL")
  1582. if(${BUILD_SHARED_LIBS})
  1583. target_compile_definitions(wolfssl PUBLIC "WOLFSSL_DLL")
  1584. endif()
  1585. ####################################################
  1586. # Include Directories
  1587. ####################################################
  1588. target_include_directories(wolfssl
  1589. PUBLIC
  1590. $<INSTALL_INTERFACE:include>
  1591. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  1592. $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  1593. ${WOLFSSL_INCLUDE_DIRS}
  1594. )
  1595. ####################################################
  1596. # Link Libraries
  1597. ####################################################
  1598. target_link_libraries(wolfssl PUBLIC ${WOLFSSL_LINK_LIBS})
  1599. if(WIN32)
  1600. # For Windows link ws2_32
  1601. target_link_libraries(wolfssl PUBLIC
  1602. $<$<PLATFORM_ID:Windows>:ws2_32>)
  1603. elseif(APPLE)
  1604. target_link_libraries(wolfssl PUBLIC
  1605. ${CORE_FOUNDATION_FRAMEWORK}
  1606. ${SECURITY_FRAMEWORK})
  1607. else()
  1608. # DH requires math (m) library
  1609. target_link_libraries(wolfssl
  1610. PUBLIC
  1611. m)
  1612. endif()
  1613. ####################################################
  1614. # Tests and Examples
  1615. ####################################################
  1616. if(WOLFSSL_EXAMPLES)
  1617. # Build wolfSSL client example
  1618. add_executable(client
  1619. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  1620. target_link_libraries(client wolfssl)
  1621. set_property(TARGET client
  1622. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1623. ${WOLFSSL_OUTPUT_BASE}/examples/client)
  1624. # Build wolfSSL server example
  1625. add_executable(server
  1626. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c)
  1627. target_link_libraries(server wolfssl)
  1628. set_property(TARGET server
  1629. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1630. ${WOLFSSL_OUTPUT_BASE}/examples/server)
  1631. # Build echo client example
  1632. add_executable(echoclient
  1633. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c)
  1634. target_include_directories(echoclient PRIVATE
  1635. ${CMAKE_CURRENT_BINARY_DIR})
  1636. target_link_libraries(echoclient wolfssl)
  1637. set_property(TARGET echoclient
  1638. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1639. ${WOLFSSL_OUTPUT_BASE}/examples/echoclient)
  1640. # Build echo server example
  1641. add_executable(echoserver
  1642. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c)
  1643. target_include_directories(echoserver PRIVATE
  1644. ${CMAKE_CURRENT_BINARY_DIR})
  1645. target_link_libraries(echoserver wolfssl)
  1646. set_property(TARGET echoserver
  1647. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1648. ${WOLFSSL_OUTPUT_BASE}/examples/echoserver)
  1649. if(NOT WIN32)
  1650. # Build TLS benchmark example
  1651. add_executable(tls_bench
  1652. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c)
  1653. target_link_libraries(tls_bench wolfssl)
  1654. target_link_libraries(tls_bench Threads::Threads)
  1655. set_property(TARGET tls_bench
  1656. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1657. ${WOLFSSL_OUTPUT_BASE}/examples/benchmark)
  1658. endif()
  1659. # Build unit tests
  1660. add_executable(unit_test
  1661. tests/api.c
  1662. tests/hash.c
  1663. tests/srp.c
  1664. tests/suites.c
  1665. tests/w64wrapper.c
  1666. tests/unit.c
  1667. examples/server/server.c
  1668. examples/client/client.c)
  1669. target_include_directories(unit_test PRIVATE
  1670. ${CMAKE_CURRENT_BINARY_DIR})
  1671. target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER")
  1672. target_link_libraries(unit_test wolfssl)
  1673. target_link_libraries(unit_test Threads::Threads)
  1674. set_property(TARGET unit_test
  1675. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1676. ${WOLFSSL_OUTPUT_BASE}/tests/)
  1677. set_property(TARGET unit_test
  1678. PROPERTY RUNTIME_OUTPUT_NAME
  1679. unit.test)
  1680. endif()
  1681. if(WOLFSSL_CRYPT_TESTS)
  1682. if(WOLFSSL_CRYPT_TESTS_LIBS)
  1683. # Build wolfCrypt test as a library. This will compile test.c and make
  1684. # its functions available as a CMake target that other CMake targets can
  1685. # pull in, in addition to producing the library itself. Note that this
  1686. # feature is not enabled by default, and the API of this library and
  1687. # wofcryptbench_lib should NOT be treated as stable.
  1688. add_library(wolfcrypttest_lib
  1689. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  1690. set_target_properties(wolfcrypttest_lib PROPERTIES OUTPUT_NAME "wolfcrypttest")
  1691. target_link_libraries(wolfcrypttest_lib wolfssl)
  1692. target_compile_options(wolfcrypttest_lib PRIVATE "-DNO_MAIN_DRIVER")
  1693. if(WOLFSSL_CRYPT_TESTS_HELP)
  1694. target_compile_options(wolfcrypttest_lib PRIVATE "-DHAVE_WOLFCRYPT_TEST_OPTIONS")
  1695. endif()
  1696. # Make another library for the wolfCrypt benchmark code.
  1697. add_library(wolfcryptbench_lib
  1698. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  1699. set_target_properties(wolfcryptbench_lib PROPERTIES OUTPUT_NAME "wolfcryptbench")
  1700. target_link_libraries(wolfcryptbench_lib wolfssl)
  1701. target_compile_options(wolfcryptbench_lib PRIVATE "-DNO_MAIN_DRIVER")
  1702. endif()
  1703. # Build wolfCrypt test executable.
  1704. add_executable(wolfcrypttest
  1705. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  1706. target_link_libraries(wolfcrypttest wolfssl)
  1707. set_property(TARGET wolfcrypttest
  1708. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1709. ${WOLFSSL_OUTPUT_BASE}/wolfcrypt/test)
  1710. set_property(TARGET wolfcrypttest
  1711. PROPERTY RUNTIME_OUTPUT_NAME
  1712. testwolfcrypt)
  1713. if(WOLFSSL_CRYPT_TESTS_HELP)
  1714. target_compile_options(wolfcrypttest PRIVATE "-DHAVE_WOLFCRYPT_TEST_OPTIONS")
  1715. endif()
  1716. # Build wolfCrypt benchmark executable.
  1717. add_executable(wolfcryptbench
  1718. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  1719. target_include_directories(wolfcryptbench PRIVATE
  1720. ${CMAKE_CURRENT_BINARY_DIR})
  1721. target_link_libraries(wolfcryptbench wolfssl)
  1722. set_property(TARGET wolfcryptbench
  1723. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1724. ${WOLFSSL_OUTPUT_BASE}/wolfcrypt/benchmark)
  1725. set_property(TARGET wolfcryptbench
  1726. PROPERTY RUNTIME_OUTPUT_NAME
  1727. benchmark)
  1728. endif()
  1729. ####################################################
  1730. # Installation
  1731. ####################################################
  1732. include(GNUInstallDirs)
  1733. set(HEADER_EXCLUDE
  1734. "internal.h"
  1735. "cyassl/ctaocrypt/port"
  1736. "wolfssl/wolfcrypt/port/nrf51.h"
  1737. "wolfssl/wolfcrypt/port/arm"
  1738. "wolfssl/wolfcrypt/port/cypress"
  1739. "wolfssl/wolfcrypt/port/Espressif"
  1740. "wolfssl/wolfcrypt/port/iotsafe"
  1741. "wolfssl/wolfcrypt/port/nxp"
  1742. "wolfssl/wolfcrypt/port/pic"
  1743. "wolfssl/wolfcrypt/port/Renesas"
  1744. "wolfssl/wolfcrypt/port/silabs"
  1745. "wolfssl/wolfcrypt/port/st"
  1746. "wolfssl/wolfcrypt/port/ti"
  1747. "wolfssl/wolfcrypt/port/xilinx"
  1748. )
  1749. # TODO: add support for the various ports
  1750. # For distro build don't install options.h.
  1751. # It depends on the architecture and conflicts with Multi-Arch.
  1752. if(BUILD_DISTRO)
  1753. list(APPEND HEADER_EXCLUDE
  1754. "options.h")
  1755. endif()
  1756. if(NOT BUILD_CRYPTOAUTHLIB)
  1757. list(APPEND HEADER_EXCLUDE
  1758. "wolfssl/wolfcrypt/port/atmel")
  1759. endif()
  1760. if(NOT BUILD_AFALG)
  1761. list(APPEND HEADER_EXCLUDE
  1762. "wolfssl/wolfcrypt/port/af_alg")
  1763. endif()
  1764. if(NOT BUILD_KCAPI)
  1765. list(APPEND HEADER_EXCLUDE
  1766. "wolfssl/wolfcrypt/port/kcapi"
  1767. )
  1768. endif()
  1769. if(NOT BUILD_DEVCRYPTO)
  1770. list(APPEND HEADER_EXCLUDE
  1771. "wolfssl/wolfcrypt/port/devcrypto")
  1772. endif()
  1773. if(NOT BUILD_ASYNCCRYPT)
  1774. list(APPEND HEADER_EXCLUDE
  1775. "wolfssl/wolfcrypt/async.h")
  1776. endif()
  1777. if(NOT BUILD_PKCS11)
  1778. list(APPEND HEADER_EXCLUDE
  1779. "wolfssl/wolfcrypt/wc_pkcs11.h"
  1780. "wolfssl/wolfcrypt/pkcs11.h"
  1781. )
  1782. endif()
  1783. if(NOT BUILD_CAVIUM AND NOT BUILD_OCTEON_SYNC)
  1784. list(APPEND HEADER_EXCLUDE
  1785. "wolfssl/wolfcrypt/port/cavium")
  1786. else()
  1787. if(NOT BUILD_CAVIUM)
  1788. list(APPEND HEADER_EXCLUDE
  1789. "wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h")
  1790. endif()
  1791. if(NOT BUILD_OCTEON_SYNC)
  1792. list(APPEND HEADER_EXCLUDE
  1793. "wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h"
  1794. )
  1795. endif()
  1796. endif()
  1797. if(NOT BUILD_INTEL_QA AND NOT BUILD_INTEL_QA_SYNC)
  1798. list(APPEND HEADER_EXCLUDE
  1799. "wolfssl/wolfcrypt/port/intel")
  1800. else()
  1801. if(NOT BUILD_INTEL_QA)
  1802. list(APPEND HEADER_EXCLUDE
  1803. "wolfssl/wolfcrypt/port/intel/quickassist.h"
  1804. "wolfssl/wolfcrypt/port/intel/quickassist_mem.h"
  1805. )
  1806. endif()
  1807. if(NOT BUILD_INTEL_QA_SYNC)
  1808. list(APPEND HEADER_EXCLUDE
  1809. "wolfssl/wolfcrypt/port/intel/quickassist_sync.h")
  1810. endif()
  1811. endif()
  1812. if(NOT BUILD_SP)
  1813. list(APPEND HEADER_EXCLUDE
  1814. "wolfssl/wolfcrypt/sp.h")
  1815. endif()
  1816. if(NOT BUILD_SP_INT)
  1817. list(APPEND HEADER_EXCLUDE
  1818. "wolfssl/wolfcrypt/sp_int.h")
  1819. endif()
  1820. if(NOT BUILD_SELFTEST)
  1821. list(APPEND HEADER_EXCLUDE
  1822. "wolfssl/wolfcrypt/selftest.h")
  1823. endif()
  1824. if(NOT BUILD_FIPS OR BUILD_FIPS_V1)
  1825. list(APPEND HEADER_EXCLUDE
  1826. "wolfssl/wolfcrypt/fips.h")
  1827. endif()
  1828. if(NOT BUILD_QNXCAAM)
  1829. list(APPEND HEADER_EXCLUDE
  1830. "wolfssl/wolfcrypt/port/caam"
  1831. )
  1832. endif()
  1833. list(JOIN HEADER_EXCLUDE "|" EXCLUDED_HEADERS_REGEX)
  1834. string(PREPEND EXCLUDED_HEADERS_REGEX "(")
  1835. string(APPEND EXCLUDED_HEADERS_REGEX ")")
  1836. set(INSTALLED_EXAMPLES
  1837. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c
  1838. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-server.c
  1839. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-client-dtls.c
  1840. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-client.c
  1841. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-server-dtls.c
  1842. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c
  1843. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c
  1844. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c
  1845. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  1846. # Install the library
  1847. install(TARGETS wolfssl
  1848. EXPORT wolfssl-targets
  1849. LIBRARY DESTINATION lib
  1850. ARCHIVE DESTINATION lib
  1851. RUNTIME DESTINATION bin
  1852. )
  1853. # Install the headers
  1854. install(DIRECTORY ${WOLFSSL_OUTPUT_BASE}/wolfssl/
  1855. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wolfssl
  1856. FILES_MATCHING PATTERN "*.h"
  1857. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  1858. install(DIRECTORY ${WOLFSSL_OUTPUT_BASE}/cyassl/
  1859. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cyassl
  1860. FILES_MATCHING PATTERN "*.h"
  1861. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  1862. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/
  1863. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wolfssl
  1864. FILES_MATCHING PATTERN "*.h"
  1865. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  1866. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cyassl/
  1867. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cyassl
  1868. FILES_MATCHING PATTERN "*.h"
  1869. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  1870. # Install the examples
  1871. install(FILES ${INSTALLED_EXAMPLES}
  1872. DESTINATION ${CMAKE_INSTALL_DOCDIR}/example)
  1873. # Install README.txt and taoCert.txt
  1874. install(FILES
  1875. ${CMAKE_CURRENT_SOURCE_DIR}/doc/README.txt
  1876. ${CMAKE_CURRENT_SOURCE_DIR}/certs/taoCert.txt
  1877. DESTINATION ${CMAKE_INSTALL_DOCDIR})
  1878. # Install the export set
  1879. install(EXPORT wolfssl-targets
  1880. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wolfssl
  1881. FILE wolfssl-config.cmake)
  1882. # TODO: Distro build + rules for what to include in the distro.
  1883. # See various include.am files.
  1884. set(prefix ${CMAKE_INSTALL_PREFIX})
  1885. set(exec_prefix "\${prefix}")
  1886. set(libdir "\${exec_prefix}/lib")
  1887. set(includedir "\${prefix}/include")
  1888. set(VERSION ${PROJECT_VERSION})
  1889. configure_file(support/wolfssl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc @ONLY)
  1890. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc
  1891. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)