CMakeLists.txt 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  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.2)
  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.0.1 LANGUAGES C)
  28. # shared library versioning
  29. # increment if interfaces have been added, removed or changed
  30. set(LIBTOOL_CURRENT 27)
  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 3)
  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. include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/functions.cmake)
  41. ####################################################
  42. # Compiler
  43. ####################################################
  44. # Let CMake choose default compiler
  45. # TODO: See gl_VISIBILITY in visibility.m4. Need to perform
  46. # the same checks.
  47. # TODO: Turn on warnings.
  48. if(APPLE)
  49. # Silence ranlib warning "has no symbols"
  50. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  51. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  52. set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  53. set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  54. endif()
  55. include(CheckIncludeFile)
  56. check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
  57. check_include_file("fcntl.h" HAVE_FCNTL_H)
  58. check_include_file("limits.h" HAVE_LIMITS_H)
  59. check_include_file("netdb.h" HAVE_NETDB_H)
  60. check_include_file("netinet/in.h" HAVE_NETINET_IN_H)
  61. check_include_file("stddef.h" HAVE_STDDEF_H)
  62. check_include_file("time.h" HAVE_TIME_H)
  63. check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  64. check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H)
  65. check_include_file("sys/time.h" HAVE_SYS_TIME_H)
  66. check_include_file("errno.h" HAVE_ERRNO_H)
  67. check_include_file("dlfcn.h" HAVE_DLFCN_H)
  68. check_include_file("inttypes.h" HAVE_INTTYPES_H)
  69. check_include_file("memory.h" HAVE_MEMORY_H)
  70. check_include_file("stdint.h" HAVE_STDINT_H)
  71. check_include_file("stdlib.h" HAVE_STDLIB_H)
  72. check_include_file("string.h" HAVE_STRING_H)
  73. check_include_file("strings.h" HAVE_STRINGS_H)
  74. check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
  75. check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
  76. check_include_file("unistd.h" HAVE_UNISTD_H)
  77. include(CheckFunctionExists)
  78. # TODO: Also check if these functions are declared by the
  79. # expected headers. See comments around
  80. # AC_CHECK_FUNCS/AC_CHECK_DECLS in configure.ac.
  81. check_function_exists("gethostbyname" HAVE_GETHOSTBYNAME)
  82. check_function_exists("getaddrinfo" HAVE_GETADDRINFO)
  83. check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY)
  84. check_function_exists("gmtime_r" HAVE_GMTIME_R)
  85. check_function_exists("inet_ntoa" HAVE_INET_NTOA)
  86. check_function_exists("memset" HAVE_MEMSET)
  87. check_function_exists("socket" HAVE_SOCKET)
  88. check_function_exists("strftime" HAVE_STRFTIME)
  89. include(CheckTypeSize)
  90. check_type_size("__uint128_t" __UINT128_T)
  91. check_type_size("long long" SIZEOF_LONG_LONG)
  92. check_type_size("long" SIZEOF_LONG)
  93. check_type_size("time_t" SIZEOF_TIME_T)
  94. # By default, HAVE___UINT128_T gets defined as TRUE,
  95. # but we want it as 1.
  96. if(HAVE___UINT128_T)
  97. set(HAVE___UINT128_T "1" CACHE INTERNAL "Result of TRY_COMPILE" FORCE)
  98. endif()
  99. include(TestBigEndian)
  100. test_big_endian(WORDS_BIGENDIAN)
  101. # Thread local storage
  102. include(CheckCSourceCompiles)
  103. set(TLS_KEYWORDS "__thread" "__declspec(thread)")
  104. foreach(TLS_KEYWORD IN LISTS TLS_KEYWORDS)
  105. set(TLS_CODE "#include <stdlib.h>
  106. static void foo(void) {
  107. static ${TLS_KEYWORD} int bar\;
  108. exit(1)\;
  109. }
  110. int main() {
  111. return 0\;
  112. }"
  113. )
  114. check_c_source_compiles(${TLS_CODE} THREAD_LS_ON)
  115. if(THREAD_LS_ON)
  116. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_THREAD_LS")
  117. break()
  118. else()
  119. # THREAD_LS_ON is cached after each call to
  120. # check_c_source_compiles, and the function
  121. # won't run subsequent times if the variable
  122. # is in the cache. To make it run again, we
  123. # need to remove the variable from the cache.
  124. unset(THREAD_LS_ON CACHE)
  125. endif()
  126. endforeach()
  127. # TODO: AX_PTHREAD does a lot. Need to implement the
  128. # rest of its logic.
  129. find_package(Threads)
  130. ####################################################
  131. # Cross Compile Example
  132. ####################################################
  133. #set(CMAKE_SYSTEM_NAME Linux)
  134. #set(CMAKE_SYSTEM_PROCESSOR arm)
  135. #set(CMAKE_C_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc")
  136. #set(CMAKE_CXX_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-g++")
  137. #set(CMAKE_SYSROOT "/opt/arm-linux-musleabihf-cross/arm-linux-musleabihf/")
  138. # Example for setting CFLAGS
  139. #set(CMAKE_C_FLAGS "-std=gnu89 ${CMAKE_C_FLAGS}")
  140. # Example for map file and custom linker script
  141. #set(CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=output.map -T\"${CMAKE_CURRENT_SOURCE_DIR}/linker.ld\"")
  142. ####################################################
  143. # Build Options
  144. ####################################################
  145. # TODO: - Debug
  146. # - FIPS
  147. # - Distro
  148. # - Linux Kernel Module
  149. # - Single precision math
  150. # - Enable all
  151. # - Enable all crypto
  152. # - 32-bit mode
  153. # - 16-bit mode
  154. # For reproducible build, gate out from the build anything that might
  155. # introduce semantically frivolous jitter, maximizing chance of
  156. # identical object files.
  157. set(WOLFSSL_REPRODUCIBLE_BUILD_HELP_STRING "Enable maximally reproducible build (default: disabled)")
  158. add_option("WOLFSSL_REPRODUCIBLE_BUILD" ${WOLFSSL_REPRODUCIBLE_BUILD_HELP_STRING} "no" "yes;no")
  159. if(WOLFSSL_REPRODUCIBLE_BUILD)
  160. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
  161. set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
  162. set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
  163. endif()
  164. # Support for disabling all ASM
  165. set(WOLFSSL_ASM_HELP_STRING "Enables option for assembly (default: enabled)")
  166. add_option("WOLFSSL_ASM" ${WOLFSSL_ASM_HELP_STRING} "yes" "yes;no")
  167. if(NOT WOLFSSL_ASM)
  168. list(APPEND WOLFSSL_DEFINITIONS
  169. "-DTFM_NO_ASM"
  170. "-DWOLFSSL_NO_ASM")
  171. endif()
  172. # Single threaded
  173. set(WOLFSSL_SINGLE_THREADED_HELP_STRING "Enable wolfSSL single threaded (default: disabled)")
  174. add_option("WOLFSSL_SINGLE_THREADED" ${WOLFSSL_SINGLE_THREADED_HELP_STRING} "no" "yes;no")
  175. # TODO: Logic here isn't complete, yet (see AX_PTHREAD)
  176. if(NOT WOLFSSL_SINGLE_THREADED)
  177. if(CMAKE_USE_PTHREADS_INIT)
  178. list(APPEND WOLFSSL_LINK_LIBS Threads::Threads)
  179. list(APPEND WOLFSSL_DEFINITIONS
  180. "-DHAVE_PTHREAD"
  181. "-D_POSIX_THREADS")
  182. endif()
  183. endif()
  184. # TODO: - DTLS
  185. # - TLS v1.3 Draft 18
  186. # TLS v1.3
  187. set(WOLFSSL_TLS13_HELP_STRING "Enable wolfSSL TLS v1.3 (default: enabled)")
  188. add_option("WOLFSSL_TLS13" ${WOLFSSL_TLS13_HELP_STRING} "yes" "yes;no")
  189. if("${FIPS_VERSION}" STREQUAL "v1")
  190. override_cache(WOLFSSL_TLS13 "no")
  191. endif()
  192. # TODO: Post-handshake authentication
  193. # Hello retry request cookie
  194. # RNG
  195. set(WOLFSSL_RNG_HELP_STRING "Enable compiling and using RNG (default: enabled)")
  196. add_option("WOLFSSL_RNG" ${WOLFSSL_RNG_HELP_STRING} "yes" "yes;no")
  197. if(NOT WOLFSSL_RNG)
  198. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_RNG")
  199. endif()
  200. # TODO: - DTLS-SCTP
  201. # - DTLS multicast
  202. # - OpenSSH
  203. # - OpenVPN
  204. # - Nginx
  205. # - HAProxy
  206. # - wpa_supplicant
  207. # - Fortress
  208. # - libwebsockets
  209. # - IP alternative name
  210. # - Qt
  211. # - SSL bump
  212. # - sniffer
  213. # - Signal
  214. # - OpenSSL coexist
  215. # - OpenSSL compatibility all
  216. # - OpenSSL compatibility extra
  217. # - Max strength
  218. # Harden, enable Timing Resistance and Blinding by default
  219. set(WOLFSSL_HARDEN_HELP_STRING "Enable Hardened build, Enables Timing Resistance and Blinding (default: enabled)")
  220. add_option("WOLFSSL_HARDEN" ${WOLFSSL_HARDEN_HELP_STRING} "yes" "yes;no")
  221. if(WOLFSSL_HARDEN)
  222. list(APPEND WOLFSSL_DEFINITIONS "-DTFM_TIMING_RESISTANT" "-DECC_TIMING_RESISTANT")
  223. if(WOLFSSL_RNG)
  224. list(APPEND WOLFSSL_DEFINITIONS "-DWC_RSA_BLINDING")
  225. endif()
  226. else()
  227. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HARDEN")
  228. endif()
  229. set(WOLFSSL_OPENSSLEXTRA_HELP_STRING "Enable extra OpenSSL API, size+ (default: disabled)")
  230. add_option(WOLFSSL_OPENSSLEXTRA ${WOLFSSL_OPENSSLEXTRA_HELP_STRING} "no" "yes;no")
  231. if (WOLFSSL_OPENSSLEXTRA AND NOT WOLFSSL_OPENSSLCOEXIST)
  232. list(APPEND WOLFSSL_DEFINITIONS
  233. "-DOPENSSL_EXTRA"
  234. "-DWOLFSSL_ALWAYS_VERIFY_CB"
  235. "-DWOLFSSL_VERIFY_CB_ALL_CERTS"
  236. "-DWOLFSSL_EXTRA_ALERTS"
  237. "-DHAVE_EXT_CACHE"
  238. "-DWOLFSSL_FORCE_CACHE_ON_TICKET")
  239. endif()
  240. # TODO: - IPv6 test apps
  241. set(WOLFSSL_SLOW_MATH "yes")
  242. # TODO: - Lean PSK
  243. # - Lean TLS
  244. # - Low resource
  245. # - Titan cache
  246. # - Huge cache
  247. # - Big cache
  248. # - Small cache
  249. # - Persistent session cache
  250. # - Persistent cert cache
  251. # - Write duplicate
  252. # - Atomic user record layer
  253. # - Public key callbacks
  254. # - Microchip/Atmel CryptoAuthLib
  255. # AES-CBC
  256. set(WOLFSSL_AESCBC_HELP_STRING "Enable wolfSSL AES-CBC support (default: enabled)")
  257. add_option("WOLFSSL_AESCBC" ${WOLFSSL_AESCBC_HELP_STRING} "yes" "yes;no")
  258. if(NOT WOLFSSL_AESCBC)
  259. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES_CBC")
  260. endif()
  261. # AES-GCM
  262. set(WOLFSSL_AESGCM_HELP_STRING "Enable wolfSSL AES-GCM support (default: enabled)")
  263. add_option("WOLFSSL_AESGCM" ${WOLFSSL_AESGCM_HELP_STRING} "yes" "yes;no;table;small;word32")
  264. # leanpsk and leantls don't need gcm
  265. if(WOLFSSL_LEAN_PSK OR (WOLFSSL_LEAN_TLS AND NOT WOLFSSL_TLS13))
  266. override_cache(WOLFSSL_AESGCM "no")
  267. endif()
  268. if(WOLFSSL_AESGCM)
  269. if("${WOLFSSL_AESGCM}" STREQUAL "word32")
  270. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_WORD32")
  271. override_cache(WOLFSSL_AESGCM "yes")
  272. endif()
  273. if(("${WOLFSSL_AESGCM}" STREQUAL "small") OR WOLFSSL_LOW_RESOURCE)
  274. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_SMALL")
  275. override_cache(WOLFSSL_AESGCM "yes")
  276. endif()
  277. if("${WOLFSSL_AESGCM}" STREQUAL "table")
  278. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_TABLE")
  279. override_cache(WOLFSSL_AESGCM "yes")
  280. endif()
  281. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_AESGCM")
  282. endif()
  283. # TODO: - AES-CCM
  284. # - AES-CTR
  285. # - AES-OFB
  286. # - AES-CFB
  287. # - AES-ARM
  288. # - Xilinx hardened crypto
  289. # - Intel AES-NI
  290. # - Intel ASM
  291. # - Intel RDRAND
  292. # - Linux af_alg
  293. # - Linux dev crpyto calls
  294. # - Camellia
  295. # - MD2
  296. # - NULL cipher
  297. # - RIPEMD
  298. # - BLAKE2
  299. # SHA224
  300. set(SHA224_DEFAULT "no")
  301. if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR
  302. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  303. if(NOT WOLFSSL_AFALG AND NOT WOLFSSL_DEVCRYPTO AND
  304. (NOT WOLFSSL_FIPS OR ("${FIPS_VERSION}" STREQUAL "v2")))
  305. set(SHA224_DEFAULT "yes")
  306. endif()
  307. endif()
  308. set(WOLFSSL_SHA224_HELP_STRING "Enable wolfSSL SHA-224 support (default: enabled on x86_64/aarch64)")
  309. add_option("WOLFSSL_SHA224" ${WOLFSSL_SHA224_HELP_STRING} ${SHA224_DEFAULT} "yes;no")
  310. # SHA3
  311. set(SHA3_DEFAULT "no")
  312. if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR
  313. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  314. if(NOT WOLFSSL_FIPS OR ("${FIPS_VERSION}" STREQUAL "v2"))
  315. set(SHA3_DEFAULT "yes")
  316. endif()
  317. endif()
  318. set(WOLFSSL_SHA3_HELP_STRING "Enable wolfSSL SHA-3 support (default: enabled on x86_64/aarch64)")
  319. add_option("WOLFSSL_SHA3" ${WOLFSSL_SHA3_HELP_STRING} ${SHA3_DEFAULT} "yes;no;small")
  320. # SHAKE256
  321. set(WOLFSSL_SHAKE256_HELP_STRING "Enable wolfSSL SHAKE256 support (default: enabled on x86_64/aarch64)")
  322. add_option("WOLFSSL_SHAKE256" ${WOLFSSL_SHAKE256_HELP_STRING} "no" "yes;no;small")
  323. # SHA512
  324. set(WOLFSSL_SHA512_HELP_STRING "Enable wolfSSL SHA-512 support (default: enabled)")
  325. add_option("WOLFSSL_SHA512" ${WOLFSSL_SHA512_HELP_STRING} "yes" "yes;no")
  326. # options that don't require sha512
  327. if(WOLFSSL_LEAN_PSK OR
  328. WOLFSSL_LEAN_TLS OR
  329. WOLFSSL_32BIT OR
  330. WOLFSSL_16BIT)
  331. override_cache(WOLFSSL_SHA512 "no")
  332. endif()
  333. # options that require sha512
  334. if(WOLFSSL_OPENSSH OR
  335. WOLFSSL_WPAS OR
  336. WOLFSSL_FORTRESS)
  337. override_cache(WOLFSSL_SHA512 "yes")
  338. endif()
  339. if(WOLFSSL_SHA512)
  340. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA512")
  341. endif()
  342. # SHA384
  343. set(WOLFSSL_SHA384_HELP_STRING "Enable wolfSSL SHA-384 support (default: enabled)")
  344. add_option("WOLFSSL_SHA384" ${WOLFSSL_SHA384_HELP_STRING} "yes" "yes;no")
  345. # options that don't require sha384
  346. if(WOLFSSL_LEAN_PSK OR
  347. WOLFSSL_LEAN_TLS OR
  348. WOLFSSL_32BIT OR
  349. WOLFSSL_16BIT)
  350. override_cache(WOLFSSL_SHA384 "no")
  351. endif()
  352. # options that require sha384
  353. if(WOLFSSL_OPENSSH OR
  354. WOLFSSL_WPAS OR
  355. WOLFSSL_FORTRESS)
  356. override_cache(WOLFSSL_SHA384 "yes")
  357. endif()
  358. if(WOLFSSL_SHA384)
  359. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA384")
  360. endif()
  361. # TODO: - Session certs
  362. # - Key generation
  363. # - Cert generation
  364. # - Cert request generation
  365. # - Cert request extension
  366. # - Decoded cert cache
  367. # - SEP
  368. # HKDF
  369. set(WOLFSSL_HKDF_HELP_STRING "Enable HKDF (HMAC-KDF) support (default: disabled)")
  370. add_option("WOLFSSL_HKDF" ${WOLFSSL_HKDF_HELP_STRING} "no" "yes;no")
  371. if(WOLFSSL_TLS13)
  372. override_cache(WOLFSSL_HKDF "yes")
  373. endif()
  374. if(WOLFSSL_HKDF)
  375. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HKDF")
  376. endif()
  377. # TODO: - X9.63 KDF
  378. # DSA
  379. set(WOLFSSL_DSA_HELP_STRING "Enable DSA (default: disabled)")
  380. add_option("WOLFSSL_DSA" ${WOLFSSL_DSA_HELP_STRING} "no" "yes;no")
  381. if(NOT WOLFSSL_DSA AND NOT WOLFSSL_OPENSSH)
  382. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DSA")
  383. endif()
  384. # ECC Shamir
  385. set(WOLFSSL_ECCSHAMIR_HELP_STRING "Enable ECC Shamir (default: enabled)")
  386. add_option("WOLFSSL_ECCSHAMIR" ${WOLFSSL_ECCSHAMIR_HELP_STRING} "yes" "yes;no")
  387. # ECC
  388. set(WOLFSSL_ECC_HELP_STRING "Enable ECC (default: enabled)")
  389. add_option("WOLFSSL_ECC" ${WOLFSSL_ECC_HELP_STRING} "yes" "yes;no;nonblock")
  390. # lean psk doesn't need ecc
  391. if(WOLFSSL_LEAN_PSK)
  392. override_cache(WOLFSSL_ECC "no")
  393. endif()
  394. if(WOLFSSL_OPENSSH OR
  395. WOLFSSL_NGINX OR
  396. WOLFSSL_SIGNAL)
  397. override_cache(WOLFSSL_ECC "yes")
  398. endif()
  399. if(WOLFSSL_ECC)
  400. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ECC" "-DTFM_ECC256")
  401. if(WOLFSSL_ECCSHAMIR AND NOT WOLFSSL_LOW_RESOURCE)
  402. list(APPEND WOLFSSL_DEFINITIONS "-DECC_SHAMIR")
  403. endif()
  404. if("${WOLFSSL_ECC}" STREQUAL "nonblock")
  405. list(APPEND WOLFSSL_DEFINITIONS "-DWC_ECC_NONBLOCK")
  406. endif()
  407. endif()
  408. # TODO: - ECC custom curves
  409. # - Compressed key
  410. # - FP ECC, fixed point cache ECC
  411. # - ECC encrypt
  412. # - PSK
  413. # - Single PSK identity
  414. # CURVE25519
  415. set(WOLFSSL_CURVE25519_SMALL "no")
  416. set(WOLFSSL_CURVE25519_HELP_STRING "Enable Curve25519 (default: disabled)")
  417. add_option("WOLFSSL_CURVE25519" ${WOLFSSL_CURVE25519_HELP_STRING} "no" "yes;no;small;no128bit")
  418. if(WOLFSSL_OPENSSH)
  419. override_cache(WOLFSSL_CURVE25519 "yes")
  420. endif()
  421. if(WOLFSSL_CURVE25519)
  422. if("${WOLFSSL_CURVE25519}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  423. list(APPEND WOLFSSL_DEFINITIONS "-DCURVE25519_SMALL")
  424. set(WOLFSSL_CURVE25519_SMALL "yes")
  425. endif()
  426. if("${WOLFSSL_CURVE25519}" STREQUAL "no128bit" OR WOLFSSL_32BIT)
  427. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CURVED25519_128BIT")
  428. endif()
  429. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CURVE25519")
  430. set(WOLFSSL_FEMATH "yes")
  431. endif()
  432. # ED25519
  433. set(WOLFSSL_ED25519_SMALL "no")
  434. set(WOLFSSL_ED25519_HELP_STRING "Enable ED25519 (default: disabled)")
  435. add_option("WOLFSSL_ED25519" ${WOLFSSL_ED25519_HELP_STRING} "no" "yes;no")
  436. if(WOLFSSL_OPENSSH)
  437. override_cache(WOLFSSL_ED25519 "yes")
  438. endif()
  439. if(WOLFSSL_ED25519 AND NOT WOLFSSL_32BIT)
  440. if("${WOLFSSL_ED25519}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  441. list(APPEND WOLFSSL_DEFINITIONS "-DED25519_SMALL")
  442. set(WOLFSSL_ED25519_SMALL "yes")
  443. set(WOLFSSL_CURVE25519_SMALL "yes")
  444. endif()
  445. if(NOT WOLFSSL_SHA512)
  446. message(FATAL_ERROR "cannot enable ed25519 without enabling sha512.")
  447. endif()
  448. set(WOLFSSL_FEMATH "yes")
  449. set(WOLFSSL_GEMATH "yes")
  450. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ED25519")
  451. endif()
  452. # CURVE448
  453. set(WOLFSSL_CURVE448_SMALL "no")
  454. set(WOLFSSL_CURVE448_HELP_STRING "Enable Curve448 (default: disabled)")
  455. add_option("WOLFSSL_CURVE448" ${WOLFSSL_CURVE448_HELP_STRING} "no" "yes;no;small")
  456. if(WOLFSSL_CURVE448)
  457. if("${WOLFSSL_CURVE448}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  458. list(APPEND WOLFSSL_DEFINITIONS "-DCURVE448_SMALL")
  459. set(WOLFSSL_CURVE448_SMALL "yes")
  460. endif()
  461. if("${WOLFSSL_CURVE448}" STREQUAL "no128bit" OR WOLFSSL_32BIT)
  462. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CURVED448_128BIT")
  463. endif()
  464. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CURVE448")
  465. set(WOLFSSL_FE448 "yes")
  466. endif()
  467. # ED448
  468. set(WOLFSSL_ED448_SMALL "no")
  469. set(WOLFSSL_ED448_HELP_STRING "Enable ED448 (default: disabled)")
  470. add_option("WOLFSSL_ED448" ${WOLFSSL_ED448_HELP_STRING} "no" "yes;no;small")
  471. if(WOLFSSL_ED448 AND NOT WOLFSSL_32BIT)
  472. if("${WOLFSSL_ED448}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  473. list(APPEND WOLFSSL_DEFINITIONS "-DED448_SMALL")
  474. set(WOLFSSL_ED448_SMALL "yes")
  475. set(WOLFSSL_CURVE448_SMALL "yes")
  476. endif()
  477. if(NOT WOLFSSL_SHA512)
  478. message(FATAL_ERROR "cannot enable ed448 without enabling sha512.")
  479. endif()
  480. set(WOLFSSL_FE448 "yes")
  481. set(WOLFSSL_GE448 "yes")
  482. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ED448")
  483. # EdDSA448 requires SHAKE256 which requires SHA-3
  484. override_cache(WOLFSSL_SHAKE256 "yes")
  485. endif()
  486. # Error strings
  487. set(WOLFSSL_ERROR_STRINGS_HELP_STRING "Enable error strings table (default: enabled)")
  488. add_option("WOLFSSL_ERROR_STRINGS" ${WOLFSSL_ERROR_STRINGS_HELP_STRING} "yes" "yes;no")
  489. if(NOT WOLFSSL_ERROR_STRINGS)
  490. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_STRINGS")
  491. else()
  492. # turn off error strings if leanpsk or leantls o
  493. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  494. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_STRINGS")
  495. override_cache(WOLFSSL_ERROR_STRINGS "no")
  496. endif()
  497. endif()
  498. # Error queue
  499. set(WOLFSSL_ERROR_QUEUE_HELP_STRING "Enables adding nodes to error queue when compiled with OPENSSL_EXTRA (default: enabled)")
  500. add_option("WOLFSSL_ERROR_QUEUE" ${WOLFSSL_ERROR_QUEUE_HELP_STRING} "yes" "yes;no")
  501. if(NOT WOLFSSL_ERROR_QUEUE)
  502. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_QUEUE")
  503. endif()
  504. # Old TLS
  505. set(WOLFSSL_OLD_TLS_HELP_STRING "Enable old TLS versions < 1.2 (default: enabled)")
  506. add_option("WOLFSSL_OLD_TLS" ${WOLFSSL_OLD_TLS_HELP_STRING} "yes" "yes;no")
  507. if(NOT WOLFSSL_OLD_TLS)
  508. list(APPEND WOLFSSL_DEFINITIONS "-DNO_OLD_TLS")
  509. else()
  510. # turn off old if leanpsk or leantls on
  511. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  512. list(APPEND WOLFSSL_DEFINITIONS "-DNO_OLD_TLS")
  513. override_cache(WOLFSSL_OLD_TLS "no")
  514. endif()
  515. endif()
  516. # TLSv1.2
  517. set(WOLFSSL_TLSV12_HELP_STRING "Enable TLS versions 1.2 (default: enabled)")
  518. add_option("WOLFSSL_TLSV12" ${WOLFSSL_TLSV12_HELP_STRING} "yes" "yes;no")
  519. if(NOT WOLFSSL_TLSV12)
  520. list(APPEND WOLFSSL_DEFINITIONS
  521. "-DWOLFSSL_NO_TLS12"
  522. "-DNO_OLD_TLS")
  523. endif()
  524. # TODO: - TLSv1.0
  525. # - SSLv3
  526. # - Stack size
  527. # - Stack size verbose
  528. # Memory
  529. set(WOLFSSL_MEMORY_HELP_STRING "Enable memory callbacks (default: enabled)")
  530. add_option("WOLFSSL_MEMORY" ${WOLFSSL_MEMORY_HELP_STRING} "yes" "yes;no")
  531. if(NOT WOLFSSL_MEMORY)
  532. list(APPEND WOLFSSL_DEFINITIONS "-DNO_WOLFSSL_MEMORY")
  533. else()
  534. # turn off memory cb if leanpsk or leantls on
  535. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  536. # but don't turn on NO_WOLFSSL_MEMORY because using own
  537. override_cache(WOLFSSL_MEMORY "no")
  538. endif()
  539. endif()
  540. # TODO: - Track memory
  541. # - Memory log
  542. # - Stack log
  543. # RSA
  544. set(WOLFSSL_RSA_HELP_STRING "Enable RSA (default: enabled)")
  545. add_option("WOLFSSL_RSA" ${WOLFSSL_RSA_HELP_STRING} "yes" "yes;no")
  546. if(NOT WOLFSSL_RSA)
  547. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RSA")
  548. else()
  549. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  550. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RSA")
  551. override_cache(WOLFSSL_RSA "no")
  552. endif()
  553. endif()
  554. # OAEP
  555. set(WOLFSSL_OAEP_HELP_STRING "Enable RSA OAEP (default: enabled)")
  556. add_option("WOLFSSL_OAEP" ${WOLFSSL_OAEP_HELP_STRING} "yes" "yes;no")
  557. if(NOT WOLFSSL_OAEP)
  558. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_RSA_OAEP")
  559. endif()
  560. # TODO: - RSA public only
  561. # - RSA verify inline only
  562. # RSA-PSS
  563. set(WOLFSSL_RSA_PSS_HELP_STRING "Enable RSA-PSS (default: disabled)")
  564. add_option("WOLFSSL_RSA_PSS" ${WOLFSSL_RSA_PSS_HELP_STRING} "no" "yes;no")
  565. if(NOT WOLFSSL_RSA)
  566. override_cache(WOLFSSL_RSA_PSS "no")
  567. else()
  568. if(WOLFSSL_TLS13)
  569. override_cache(WOLFSSL_RSA_PSS "yes")
  570. endif()
  571. endif()
  572. if(WOLFSSL_RSA_PSS)
  573. list(APPEND WOLFSSL_DEFINITIONS "-DWC_RSA_PSS")
  574. endif()
  575. # DH
  576. set(WOLFSSL_DH_HELP_STRING "Enable DH (default: enabled)")
  577. add_option("WOLFSSL_DH" ${WOLFSSL_DH_HELP_STRING} "yes" "yes;no")
  578. if(WOLFSSL_OPENSSH)
  579. override_cache(WOLFSSL_DH "yes")
  580. endif()
  581. if(NOT WOLFSSL_DH)
  582. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DH")
  583. else()
  584. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  585. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DH")
  586. override_cache(WOLFSSL_DH "no")
  587. endif()
  588. endif()
  589. # TODO: - Anonymous
  590. # ASN
  591. # turn off asn, which means no certs, no rsa, no dsa, no ecc,
  592. # and no big int (unless dh is on)
  593. set(WOLFSSL_ASN_HELP_STRING "Enable ASN (default: enabled)")
  594. add_option("WOLFSSL_ASN" ${WOLFSSL_ASN_HELP_STRING} "yes" "yes;no")
  595. if(NOT WOLFSSL_ASN)
  596. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ASN" "-DNO_CERTS")
  597. if(NOT WOLFSSL_DH AND NOT WOLFSSL_ECC)
  598. # DH and ECC need bigint
  599. list(APPEND WOLFSSL_DEFINITIONS "-DNO_BIG_INT")
  600. endif()
  601. else()
  602. # turn off ASN if leanpsk on
  603. if(WOLFSSL_LEAN_PSK)
  604. list(APPEND WOLFSSL_DEFINITIONS
  605. "-DNO_ASN"
  606. "-DNO_CERTS"
  607. "-DNO_BIG_INT")
  608. override_cache(WOLFSSL_ASN "no")
  609. else()
  610. if("${WOLFSSL_ASN}" STREQUAL "nocrypt")
  611. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ASN_CRYPT")
  612. # TODO: verify that this is correct
  613. override_cache(WOLFSSL_PWDBASED "no")
  614. endif()
  615. endif()
  616. endif()
  617. if(WOLFSSL_RSA AND NOT WOLFSSL_RSA_VFY AND NOT WOLFSSL_ASN)
  618. message(FATAL_ERROR "please disable rsa if disabling asn.")
  619. endif()
  620. if(WOLFSSL_DSA AND NOT WOLFSSL_ASN)
  621. message(FATAL_ERROR "please disable dsa if disabling asn.")
  622. endif()
  623. # DH and ECC need bigint
  624. if(NOT WOLFSSL_ASN AND
  625. NOT WOLFSSL_DH AND
  626. NOT WOLFSSL_ECC AND
  627. NOT WOLFSSL_RSA)
  628. override_cache(WOLFSSL_FAST_MATH "no")
  629. set(WOLFSSL_SLOWMATH "no")
  630. endif()
  631. # AES
  632. set(WOLFSSL_AES_HELP_STRING "Enable AES (default: enabled)")
  633. add_option("WOLFSSL_AES" ${WOLFSSL_AES_HELP_STRING} "yes" "yes;no")
  634. if(NOT WOLFSSL_AES)
  635. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
  636. if(WOLFSSL_FORTRESS)
  637. message(FATAL_ERROR "fortress requires aes")
  638. endif()
  639. if(WOLFSSL_ECC_ENCRYPT)
  640. message(FATAL_ERROR "cannot enable eccencrypt and hkdf without aes.")
  641. endif()
  642. if(WOLFSSL_AESGCM)
  643. message(FATAL_ERROR "AESGCM requires AES.")
  644. endif()
  645. if(WOLFSSL_AESCCM)
  646. message(FATAL_ERROR "AESCCM requires AES.")
  647. endif()
  648. if(WOLFSSL_AESCTR)
  649. message(FATAL_ERROR "AESCTR requires AES.")
  650. endif()
  651. else()
  652. if(WOLFSSL_LEAN_PSK)
  653. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
  654. override_cache(WOLFSSL_AES "no")
  655. endif()
  656. endif()
  657. # Coding
  658. set(WOLFSSL_CODING_HELP_STRING "Enable coding base 16/64 (default: enabled)")
  659. add_option("WOLFSSL_CODING" ${WOLFSSL_CODING_HELP_STRING} "yes" "yes;no")
  660. if(NOT WOLFSSL_CODING)
  661. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CODING")
  662. else()
  663. # turn off CODING if leanpsk on
  664. if(WOLFSSL_LEAN_PSK)
  665. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CODING")
  666. override_cache(WOLFSSL_CODING "no")
  667. endif()
  668. endif()
  669. # Base64
  670. set(BASE64_ENCODE_DEFAULT "no")
  671. if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  672. set(BASE64_ENCODE_DEFAULT "yes")
  673. endif()
  674. set(WOLFSSL_BASE64_ENCODE_HELP_STRING "Enable Base64 encoding (default: enabled on x86_64)")
  675. add_option("WOLFSSL_BASE64_ENCODE" ${WOLFSSL_BASE64_ENCODE_HELP_STRING} ${BASE64_ENCODE_DEFAULT} "yes;no")
  676. if(WOLFSSL_BASE64_ENCODE)
  677. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_BASE64_ENCODE")
  678. endif()
  679. # TODO: - Base16
  680. # DES3
  681. set(WOLFSSL_DES3_HELP_STRING "Enable DES3 (default: disabled)")
  682. add_option("WOLFSSL_DES3" ${WOLFSSL_DES3_HELP_STRING} "no" "yes;no")
  683. if(WOLFSSL_OPENSSH OR
  684. WOLFSSL_QT OR
  685. WOLFSSL_OPENVPN OR
  686. WOLFSSL_WPAS)
  687. override_cache(WOLFSSL_DES3 "yes")
  688. endif()
  689. # TODO: - IDEA
  690. # ARC4
  691. set(WOLFSSL_ARC4_HELP_STRING "Enable ARC4 (default: disabled)")
  692. add_option("WOLFSSL_ARC4" ${WOLFSSL_ARC4_HELP_STRING} "no" "yes;no")
  693. if(WOLFSSL_OPENSSH OR WOLFSSL_WPAS)
  694. override_cache(WOLFSSL_ARC4 "yes")
  695. endif()
  696. if(NOT WOLFSSL_ARC4)
  697. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RC4")
  698. else()
  699. # turn off ARC4 if leanpsk or leantls on
  700. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  701. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RC4")
  702. override_cache(WOLFSSL_ARC4 "no")
  703. endif()
  704. endif()
  705. # MD5
  706. set(WOLFSSL_MD5_HELP_STRING "Enable MD5 (default: enabled)")
  707. add_option("WOLFSSL_MD5" ${WOLFSSL_MD5_HELP_STRING} "yes" "yes;no")
  708. if(NOT WOLFSSL_MD5)
  709. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD5" "-DNO_OLD_TLS")
  710. else()
  711. # turn off MD5 if leanpsk or leantls on
  712. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  713. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD5" "-DNO_OLD_TLS")
  714. override_cache(WOLFSSL_MD5 "no")
  715. endif()
  716. endif()
  717. # SHA
  718. set(WOLFSSL_SHA_HELP_STRING "Enable SHA (default: enabled)")
  719. add_option("WOLFSSL_SHA" ${WOLFSSL_SHA_HELP_STRING} "yes" "yes;no")
  720. if(NOT WOLFSSL_SHA)
  721. list(APPEND WOLFSSL_DEFINITIONS "-DNO_SHA" "-DNO_OLD_TLS")
  722. else()
  723. # turn off SHA if leanpsk or leantls on
  724. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  725. list(APPEND WOLFSSL_DEFINITIONS "-DNO_SHA" "-DNO_OLD_TLS")
  726. override_cache(WOLFSSL_SHA "no")
  727. endif()
  728. endif()
  729. # TODO: - CMAC
  730. # - AES-XTS
  731. # - Web server
  732. # - Web client
  733. # HC128
  734. set(WOLFSSL_HC128_HELP_STRING "Enable HC-128 (default: disabled)")
  735. add_option("WOLFSSL_HC128" ${WOLFSSL_HC128_HELP_STRING} "no" "yes;no")
  736. if(NOT WOLFSSL_HC128)
  737. list(APPEND WOLFSSL_DEFINITIONS "-DNO_HC128")
  738. else()
  739. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HC128")
  740. endif()
  741. # RABBIT
  742. if(NOT WOLFSSL_RABBIT)
  743. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RABBIT")
  744. else()
  745. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_RABBIT")
  746. endif()
  747. # TODO: - RC2
  748. # - FIPS, again (there's more logic for FIPS after RABBIT in configure.ac)
  749. # - Selftest
  750. # SHA224
  751. if(WOLFSSL_SHA224)
  752. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA224")
  753. endif()
  754. # SHA3
  755. if("${WOLFSSL_SHA3}" STREQUAL "small")
  756. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA3_SMALL")
  757. override_cache(WOLFSSL_SHA3 "yes")
  758. endif()
  759. if(WOLFSSL_SHA3 AND NOT WOLFSSL_32BIT)
  760. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA3")
  761. endif()
  762. # SHAKE256
  763. if(NOT WOLFSSL_SHAKE256)
  764. override_cache(WOLFSSL_SHAKE256 ${WOLFSSL_SHA3})
  765. endif()
  766. if(WOLFSSL_SHAKE256)
  767. if(NOT WOLFSSL_32BIT)
  768. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHAKE256")
  769. if(NOT WOLFSSL_SHA3)
  770. message(FATAL_ERROR "Must have SHA-3 enabled: --enable-sha3")
  771. endif()
  772. endif()
  773. endif()
  774. # POLY1305
  775. set(POLY1305_DEFAULT "yes")
  776. if(WOLFSSL_FIPS)
  777. set(POLY1305_DEFAULT "no")
  778. endif()
  779. set(WOLFSSL_POLY1305_HELP_STRING "Enable wolfSSL POLY1305 support (default: enabled)")
  780. add_option("WOLFSSL_POLY1305" ${WOLFSSL_POLY1305_HELP_STRING} ${POLY1305_DEFAULT} "yes;no")
  781. # leanpsk and leantls don't need poly1305
  782. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  783. override_cache(WOLFSSL_POLY1305 "no")
  784. endif()
  785. if(WOLFSSL_POLY1305)
  786. list(APPEND WOLFSSL_DEFINITIONS
  787. "-DHAVE_POLY1305"
  788. "-DHAVE_ONE_TIME_AUTH")
  789. endif()
  790. # CHACHA
  791. set(CHACHA_DEFAULT "yes")
  792. if(WOLFSSL_FIPS)
  793. set(CHACHA_DEFAULT "no")
  794. endif()
  795. set(WOLFSSL_CHACHA_HELP_STRING "Enable CHACHA (default: enabled). Use `=noasm` to disable ASM AVX/AVX2 speedups")
  796. add_option("WOLFSSL_CHACHA" ${WOLFSSL_CHACHA_HELP_STRING} ${CHACHA_DEFAULT} "yes;no;noasm")
  797. # leanpsk and leantls don't need chacha
  798. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  799. override_cache(WOLFSSL_CHACHA "no")
  800. endif()
  801. if(("${WOLFSSL_CHACHA}" STREQUAL "noasm") OR NOT WOLFSSL_ASM)
  802. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CHACHA_ASM")
  803. endif()
  804. if(NOT ("${WOLFSSL_CHACHA}" STREQUAL "noasm") AND WOLFSSL_CHACHA)
  805. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CHACHA")
  806. endif()
  807. # TODO: - XCHACHA
  808. # Hash DRBG
  809. set(WOLFSSL_HASH_DRBG_HELP_STRING "Enable Hash DRBG support (default: enabled)")
  810. add_option("WOLFSSL_HASH_DRBG" ${WOLFSSL_HASH_DRBG_HELP_STRING} "yes" "yes;no")
  811. if(WOLFSSL_HASH_DRBG)
  812. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HASHDRBG")
  813. else()
  814. # turn on Hash DRBG if FIPS is on
  815. if(WOLFSSL_FIPS)
  816. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HASHDRBG")
  817. override_cache(WOLFSSL_HASH_DRBG "yes")
  818. else()
  819. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HASHDRBG")
  820. endif()
  821. endif()
  822. # Filesystem
  823. if(WOLFSSL_LINUX_KM)
  824. set(FILESYSTEM_DEFAULT "no")
  825. else()
  826. set(FILESYSTEM_DEFAULT "yes")
  827. endif()
  828. set(WOLFSSL_FILESYSTEM_HELP_STRING "Enable Filesystem support (default: enabled)")
  829. add_option("WOLFSSL_FILESYSTEM" ${WOLFSSL_FILESYSTEM_HELP_STRING} ${FILESYSTEM_DEFAULT} "yes;no")
  830. if(NOT WOLFSSL_FILESYSTEM)
  831. list(APPEND WOLFSSL_DEFINITIONS "-DNO_FILESYSTEM")
  832. else()
  833. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  834. list(APPEND WOLFSSL_DEFINITIONS "-DNO_FILESYSTEM")
  835. override_cache(WOLFSSL_FILESYSTEM "no")
  836. endif()
  837. endif()
  838. # Inline function support
  839. set(WOLFSSL_INLINE_HELP_STRING "Enable inline functions (default: enabled)")
  840. add_option("WOLFSSL_INLINE" ${WOLFSSL_INLINE_HELP_STRING} "yes" "yes;no")
  841. if(NOT WOLFSSL_INLINE)
  842. list(APPEND WOLFSSL_DEFINITIONS "-DNO_INLINE")
  843. endif()
  844. # TODO: - OCSP
  845. # - OCSP stapling
  846. # - OCSP stapling v2
  847. # - CRL
  848. # - CRL monitor
  849. # - User crypto
  850. # - Whitewood netRandom client library
  851. # - SNI
  852. # - Max fragment length
  853. # - ALPN
  854. # - Trusted CA indication
  855. # - Truncated HMAC
  856. # - Renegotiation indication
  857. # - Secure renegotiation
  858. # - Fallback SCSV
  859. set(WOLFSSL_SNI_HELP_STRING "Enable SNI (default: disabled)")
  860. add_option(WOLFSSL_SNI ${WOLFSSL_SNI_HELP_STRING} "no" "yes;no")
  861. if (WOLFSSL_SNI)
  862. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_TLS_EXTENSIONS" "-DHAVE_SNI")
  863. endif()
  864. set(WOLFSSL_TLSX_HELP_STRING "Enable all TLS Extensions (default: disabled)")
  865. add_option(WOLFSSL_TLSX ${WOLFSSL_TLSX_HELP_STRING} "no" "yes;no")
  866. if (WOLFSSL_TLSX)
  867. list(APPEND WOLFSSL_DEFINITIONS
  868. "-DHAVE_TLS_EXTENSIONS"
  869. "-DHAVE_SNI"
  870. "-DHAVE_MAX_FRAGMENT"
  871. "-DHAVE_TRUNCATED_HMAC"
  872. "-DHAVE_ALPN"
  873. "-DHAVE_TRUSTED_CA")
  874. if (WOLFSSL_ECC OR WOLFSSL_CURVE25519 OR WOLFSSL_CURVE448 OR WOLFSSL_TLS13)
  875. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_SUPPORTED_CURVES")
  876. endif()
  877. endif()
  878. # Supported elliptic curves extensions
  879. set(WOLFSSL_SUPPORTED_CURVES_HELP_STRING "Enable Supported Elliptic Curves (default: enabled)")
  880. add_option("WOLFSSL_SUPPORTED_CURVES" ${WOLFSSL_SUPPORTED_CURVES_HELP_STRING} "yes" "yes;no")
  881. if(WOLFSSL_SUPPORTED_CURVES)
  882. if(NOT WOLFSSL_ECC AND NOT WOLFSSL_CURVE25519 AND NOT WOLFSSL_CURVE448)
  883. override_cache(WOLFSSL_SUPPORTED_CURVES "no")
  884. else()
  885. list(APPEND WOLFSSL_DEFINITIONS
  886. "-DHAVE_TLS_EXTENSIONS"
  887. "-DHAVE_SUPPORTED_CURVES")
  888. endif()
  889. endif()
  890. # Diffie-Hellman
  891. if(WOLFSSL_DH)
  892. if(WOLFSSL_TLS13 OR WOLFSSL_SUPPORTED_CURVES)
  893. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_FFDHE_2048")
  894. endif()
  895. endif()
  896. # TODO: - FFDHE params only
  897. # TLS 1.3 Requires either ECC or (RSA/DH), or CURVE25519/ED25519 or CURVE448/ED448
  898. if (NOT WOLFSSL_ECC AND
  899. (NOT WOLFSSL_RSA OR NOT WOLFSSL_DH) AND
  900. (NOT WOLFSSL_CURVE25519 OR NOT WOLFSSL_ED25519) AND
  901. (NOT WOLFSSL_CURVE448 AND NOT WOLFSSL_ED448))
  902. override_cache(WOLFSSL_TLS13 "no")
  903. endif()
  904. if (WOLFSSL_TLS13)
  905. list(APPEND WOLFSSL_DEFINITIONS
  906. "-DWOLFSSL_TLS13"
  907. "-DHAVE_TLS_EXTENSIONS"
  908. "-DHAVE_SUPPORTED_CURVES")
  909. endif()
  910. # Session Ticket Extension
  911. set(WOLFSSL_SESSION_TICKET_HELP_STRING "Enable Session Ticket (default: disabled)")
  912. add_option("WOLFSSL_SESSION_TICKET" ${WOLFSSL_SESSION_TICKET_HELP_STRING} "no" "yes;no")
  913. if(WOLFSSL_NGINX OR WOLFSSL_WPAS OR WOLFSSL_HAPROXY OR WOLFSSL_LIGHTY)
  914. override_cache(WOLFSSL_SESSION_TICKET "yes")
  915. endif()
  916. if(WOLFSSL_SESSION_TICKET)
  917. list(APPEND WOLFSSL_DEFINITIONS
  918. "-DHAVE_TLS_EXTENSIONS"
  919. "-DHAVE_SESSION_TICKET")
  920. endif()
  921. # Extended master secret extension
  922. set(WOLFSSL_EXTENDED_MASTER_HELP_STRING "Enable Extended Master Secret (default: enabled)")
  923. add_option("WOLFSSL_EXTENDED_MASTER" ${WOLFSSL_EXTENDED_MASTER_HELP_STRING} "yes" "yes;no")
  924. if(WOLFSSL_EXTENDED_MASTER)
  925. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_EXTENDED_MASTER")
  926. endif()
  927. # TODO: - TLS extensions
  928. # - Early data handshake
  929. # - PKCS7
  930. # - wolfSSH options
  931. # - SCEP
  932. # - Secure remote password
  933. # - Indefinite length encoded messages
  934. # - Small stack cache
  935. # - Small stack
  936. # - Valgrind
  937. # - Test certs
  938. # - I/O pool example
  939. # - Certificate service
  940. # - wolfSSL JNI
  941. # - lighttpd/lighty
  942. # - Asio
  943. # - Apache HTTPD
  944. # Encrypt-then-mac
  945. set(WOLFSSL_ENC_THEN_MAC_HELP_STRING "Enable Encryptr-Then-Mac extension (default: enabled)")
  946. add_option("WOLFSSL_ENC_THEN_MAC" ${WOLFSSL_ENC_THEN_MAC_HELP_STRING} "yes" "yes;no")
  947. if(WOLFSSL_APACHE_HTTPD)
  948. override_cache(WOLFSSL_ENC_THEN_MAC "no")
  949. endif()
  950. if(WOLFSSL_TLSX)
  951. override_cache(WOLFSSL_ENC_THEN_MAC "yes")
  952. endif()
  953. if(WOLFSSL_SNIFFER)
  954. override_cache(WOLFSSL_ENC_THEN_MAC "no")
  955. endif()
  956. # stunnel Support
  957. # TODO: rest of stunnel support
  958. set(WOLFSSL_STUNNEL_HELP_STRING "Enable stunnel (default: disabled)")
  959. add_option("WOLFSSL_STUNNEL" ${WOLFSSL_STUNNEL_HELP_STRING} "no" "yes;no")
  960. if(NOT WOLFSSL_PSK AND
  961. NOT WOLFSSL_LEAN_PSK AND
  962. NOT WOLFSSL_STUNNEL)
  963. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PSK")
  964. endif()
  965. if(WOLFSSL_ENC_THEN_MAC)
  966. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ENCRYPT_THEN_MAC")
  967. endif()
  968. # MD4
  969. set(WOLFSSL_MD4_HELP_STRING "Enable MD4 (default: disabled)")
  970. add_option("WOLFSSL_MD4" ${WOLFSSL_MD4_HELP_STRING} "no" "yes;no")
  971. if(NOT WOLFSSL_MD4)
  972. # turn on MD4 if using stunnel
  973. if(WOLFSSL_STUNNEL OR WOLFSSL_WPAS)
  974. override_cache(WOLFSSL_MD4 "yes")
  975. else()
  976. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD4")
  977. endif()
  978. endif()
  979. # TODO: - Encrypted keys
  980. # PWDBASED has to come after certservice since we want it on w/o explicit on
  981. # PWDBASED
  982. set(WOLFSSL_PWDBASED_HELP_STRING "Enable PWDBASED (default: disabled)")
  983. add_option("WOLFSSL_PWDBASED" ${WOLFSSL_PWDBASED_HELP_STRING} "no" "yes;no")
  984. if(NOT WOLFSSL_PWDBASED)
  985. if(WOLFSSL_OPENSSLEXTRA OR
  986. WOLFSSL_OPENSSLALL OR
  987. WOLFSSL_WEBSERVER OR
  988. WOLFSSL_ENC_KEYS)
  989. # opensslextra, opensslall, webserver, and enckeys needs pwdbased
  990. override_cache(WOLFSSL_PWDBASED "yes")
  991. else()
  992. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PWDBASED")
  993. endif()
  994. endif()
  995. # TODO: - SCRYPT
  996. # - wolfCrypt only
  997. # fastmath
  998. set(FASTMATH_DEFAULT "no")
  999. if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR
  1000. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  1001. set(FASTMATH_DEFAULT "yes")
  1002. endif()
  1003. if(WOLFSSL_LINUXKM_DEFAULTS)
  1004. set(FASTMATH_DEFAULT "no")
  1005. endif()
  1006. if(WOLFSSL_SP_MATH)
  1007. set(FASTMATH_DEFAULT "no")
  1008. endif()
  1009. set(WOLFSSL_FAST_MATH_HELP_STRING "Enable fast math ops (default: enabled on x86_64/aarch64)")
  1010. add_option("WOLFSSL_FAST_MATH" ${WOLFSSL_FAST_MATH_HELP_STRING} ${FASTMATH_DEFAULT} "yes;no")
  1011. if(WOLFSSL_FAST_MATH)
  1012. # turn off fastmath if leanpsk on or asn off (w/o DH and ECC)
  1013. if(WOLFSSL_LEAN_PSK OR NOT WOLFSSL_ASN)
  1014. if(NOT WOLFSSL_DH AND
  1015. NOT WOLFSSL_ECC AND
  1016. NOT WOLFSSL_RSA)
  1017. override_cache(WOLFSSL_FAST_MATH "no")
  1018. else()
  1019. list(APPEND WOLFSSL_DEFINITIONS "-DUSE_FAST_MATH")
  1020. set(WOLFSSL_SLOWMATH "no")
  1021. endif()
  1022. else()
  1023. list(APPEND WOLFSSL_DEFINITIONS "-DUSE_FAST_MATH")
  1024. set(WOLFSSL_SLOWMATH "no")
  1025. endif()
  1026. if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  1027. # Have settings.h set FP_MAX_BITS higher if user didn't set directly
  1028. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_X86_64_BUILD")
  1029. endif()
  1030. endif()
  1031. # TODO: - Fast huge math
  1032. # Enable examples, used to disable examples
  1033. if(WOLFSSL_LINUX_KM)
  1034. set(EXAMPLES_DEFAULT "no")
  1035. else()
  1036. set(EXAMPLES_DEFAULT "yes")
  1037. endif()
  1038. set(WOLFSSL_EXAMPLES_HELP_STRING "Enable examples (default: enabled)")
  1039. add_option("WOLFSSL_EXAMPLES" ${WOLFSSL_EXAMPLES_HELP_STRING} ${EXAMPLES_DEFAULT} "yes;no")
  1040. if(NOT WOLFSSL_FILESYSTEM OR
  1041. NOT WOLFSSL_INLINE OR
  1042. WOLFSSL_CRYPT_ONLY)
  1043. override_cache(WOLFSSL_EXAMPLES "no")
  1044. endif()
  1045. # Enable wolfCrypt test and benchmark
  1046. if(WOLFSSL_LINUX_KM)
  1047. set(CRYPT_TESTS_DEFAULT "no")
  1048. else()
  1049. set(CRYPT_TESTS_DEFAULT "yes")
  1050. endif()
  1051. set(WOLFSSL_CRYPT_TESTS_HELP_STRING "Enable Crypt Bench/Test (default: enabled)")
  1052. add_option("WOLFSSL_CRYPT_TESTS" ${WOLFSSL_CRYPT_TESTS_HELP_STRING} ${CRYPT_TESTS_DEFAULT} "yes;no")
  1053. set(WOLFSSL_CRYPT_TESTS_LIBS_HELP_STRING "Build static libraries from the wolfCrypt test and benchmark sources (default: disabled)")
  1054. add_option("WOLFSSL_CRYPT_TESTS_LIBS" ${WOLFSSL_CRYPT_TESTS_LIBS_HELP_STRING} "no" "yes;no")
  1055. # TODO: - LIBZ
  1056. # - PKCS#11
  1057. # - PKCS#12
  1058. # - Cavium
  1059. # - Cavium V
  1060. # - Cavium Octeon
  1061. # - Intel QuickAssist
  1062. # - SP ASM (and other SP logic)
  1063. # - Fast RSA
  1064. # - Static memory use
  1065. # - Microchip API
  1066. # - Asynchronous crypto
  1067. # Asynchronous threading
  1068. set(WOLFSSL_ASYNC_THREADS_HELP_STRING "Enable Asynchronous Threading (default: enabled)")
  1069. add_option("WOLFSSL_ASYNC_THREADS" ${WOLFSSL_ASYNC_THREADS_HELP_STRING} "yes" "yes;no")
  1070. if(WOLFSSL_ASYNC_CRYPT AND WOLFSSL_ASYNC_THREADS)
  1071. if(CMAKE_USE_PTHREADS_INIT)
  1072. override_cache(WOLFSSL_ASYNC_THREADS "yes")
  1073. else()
  1074. override_cache(WOLFSSL_ASYNC_THREADS "no")
  1075. endif()
  1076. else()
  1077. override_cache(WOLFSSL_ASYNC_THREADS "no")
  1078. endif()
  1079. if(WOLFSSL_ASYNC_THREADS)
  1080. list(APPEND WOLFSSL_LINK_LIBS Threads::Threads)
  1081. list(APPEND WOLFSSL_DEFINITIONS "-D_GNU_SOURCE")
  1082. else()
  1083. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_ASYNC_THREADING")
  1084. endif()
  1085. # TODO: - cryptodev
  1086. # - cryptocb
  1087. # - Session export
  1088. # - AES key wrap
  1089. set(WOLFSSL_OLD_NAMES_HELP_STRING "Keep backwards compat with old names (default: enabled)")
  1090. add_option("WOLFSSL_OLD_NAMES" ${WOLFSSL_OLD_NAMES_HELP_STRING} "yes" "yes;no")
  1091. if(NOT WOLFSSL_OLD_NAMES AND NOT WOLFSSL_OPENSSL_COEXIST)
  1092. list(APPEND WOLFSSL_DEFINITIONS
  1093. "-DNO_OLD_RNGNAME"
  1094. "-DNO_OLD_WC_NAMES"
  1095. "-DNO_OLD_SSL_NAMES"
  1096. "-DNO_OLD_SHA_NAMES")
  1097. endif()
  1098. # TODO: - Memory tests
  1099. # - Hash flags
  1100. # Support for enabling setting default DH parameters
  1101. set(WOLFSSL_DH_DEFAULT_PARAMS_HELP_STRING "Enables option for default dh parameters (default: disabled)")
  1102. add_option("WOLFSSL_DH_DEFAULT_PARAMS" ${WOLFSSL_DH_DEFAULT_PARAMS_HELP_STRING} "no" "yes;no")
  1103. if(WOLFSSL_DH_DEFAULT_PARAMS OR NOT WOLFSSL_QT)
  1104. override_cache(WOLFSSL_DH_DEFAULT_PARAMS "yes")
  1105. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_DH_DEFAULT_PARAMS")
  1106. endif()
  1107. if(NOT WOLFSSL_DES3)
  1108. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3")
  1109. else()
  1110. # turn off DES3 if leanpsk or leantls on
  1111. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1112. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3")
  1113. override_cache(WOLFSSL_DES3 "no")
  1114. endif()
  1115. endif()
  1116. set(WOLFSSL_USER_SETTINGS_HELP_STRING "Use your own user_settings.h and do not add Makefile CFLAGS (default: disabled)")
  1117. add_option("WOLFSSL_USER_SETTINGS" ${WOLFSSL_USER_SETTINGS_HELP_STRING} "no" "yes;no")
  1118. set(WOLFSSL_OPTFLAGS_HELP_STRING "Enable default optimization CFLAGS for the compiler (default: enabled)")
  1119. add_option("WOLFSSL_OPTFLAGS" ${WOLFSSL_OPTFLAGS_HELP_STRING} "yes" "yes;no")
  1120. # Generates the BUILD_* flags. These control what source files are included in
  1121. # the library. A series of AM_CONDITIONALs handle this in configure.ac.
  1122. generate_build_flags()
  1123. # TODO: - Bit of logic after optimization flags option (above)
  1124. # - Check for build-type conflicts section
  1125. # USER SETTINGS
  1126. if(WOLFSSL_USER_SETTINGS)
  1127. # Replace all options and just use WOLFSSL_USER_SETTINGS
  1128. set(WOLFSSL_DEFINITIONS "-DWOLFSSL_USER_SETTINGS")
  1129. endif()
  1130. # TODO: Applying definitions to everything like this, rather than
  1131. # individual targets, is discouraged in CMake.
  1132. add_definitions(${WOLFSSL_DEFINITIONS})
  1133. set(WOLFSSL_CONFIG_H_HELP_STRING "Enable generation of config.h and define HAVE_CONFIG_H (default: enabled)")
  1134. add_option("WOLFSSL_CONFIG_H" ${WOLFSSL_CONFIG_H_HELP_STRING} "yes" "yes;no")
  1135. if(WOLFSSL_CONFIG_H)
  1136. add_definitions("-DHAVE_CONFIG_H")
  1137. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.in"
  1138. "${CMAKE_CURRENT_BINARY_DIR}/config.h" )
  1139. set(abs_top_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
  1140. set(abs_top_builddir ${CMAKE_CURRENT_BINARY_DIR})
  1141. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test_paths.h.in"
  1142. "${CMAKE_CURRENT_BINARY_DIR}/wolfcrypt/test/test_paths.h" )
  1143. endif()
  1144. # Suppress some warnings about separate compilation, inlining
  1145. add_definitions("-DWOLFSSL_IGNORE_FILE_WARN")
  1146. # Generate user options header
  1147. message("Generating user options header...")
  1148. set(OPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h")
  1149. file(REMOVE ${OPTION_FILE})
  1150. file(APPEND ${OPTION_FILE} "/* wolfssl options.h\n")
  1151. file(APPEND ${OPTION_FILE} " * generated from configure options\n")
  1152. file(APPEND ${OPTION_FILE} " *\n")
  1153. file(APPEND ${OPTION_FILE} " * Copyright (C) 2006-2020 wolfSSL Inc.\n")
  1154. file(APPEND ${OPTION_FILE} " *\n")
  1155. file(APPEND ${OPTION_FILE} " * This file is part of wolfSSL. (formerly known as CyaSSL)\n")
  1156. file(APPEND ${OPTION_FILE} " *\n")
  1157. file(APPEND ${OPTION_FILE} " */\n\n")
  1158. file(APPEND ${OPTION_FILE} "#ifndef WOLFSSL_OPTIONS_H\n")
  1159. file(APPEND ${OPTION_FILE} "#define WOLFSSL_OPTIONS_H\n\n\n")
  1160. file(APPEND ${OPTION_FILE} "#ifdef __cplusplus\n")
  1161. file(APPEND ${OPTION_FILE} "extern \"C\" {\n")
  1162. file(APPEND ${OPTION_FILE} "#endif\n\n")
  1163. add_to_options_file("${WOLFSSL_DEFINITIONS}" "${OPTION_FILE}")
  1164. # CMAKE_C_FLAGS is just a string of space-separated flags to pass to the C
  1165. # compiler. We need to replace those spaces with semicolons in order to treat it
  1166. # as a CMake list.
  1167. string(REPLACE " " ";" CMAKE_C_FLAGS_LIST "${CMAKE_C_FLAGS}")
  1168. add_to_options_file("${CMAKE_C_FLAGS_LIST}" "${OPTION_FILE}")
  1169. file(APPEND ${OPTION_FILE} "\n#ifdef __cplusplus\n")
  1170. file(APPEND ${OPTION_FILE} "}\n")
  1171. file(APPEND ${OPTION_FILE} "#endif\n\n\n")
  1172. file(APPEND ${OPTION_FILE} "#endif /* WOLFSSL_OPTIONS_H */\n\n")
  1173. # backwards compatibility for those who have included options or version
  1174. set(CYASSL_OPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cyassl/options.h")
  1175. file(REMOVE ${CYASSL_OPTION_FILE})
  1176. file(APPEND ${CYASSL_OPTION_FILE} "/* cyassl options.h\n")
  1177. file(APPEND ${CYASSL_OPTION_FILE} " * generated from wolfssl/options.h\n")
  1178. file(APPEND ${CYASSL_OPTION_FILE} " */\n")
  1179. file(READ ${OPTION_FILE} OPTION_FILE_CONTENTS)
  1180. file(APPEND ${CYASSL_OPTION_FILE} ${OPTION_FILE_CONTENTS})
  1181. ####################################################
  1182. # Library Target
  1183. ####################################################
  1184. # TODO: - Build shared/static libs based on enables. Check CMake
  1185. # global flag BUILD_SHARED_LIBS.
  1186. set(LIB_SOURCES "")
  1187. # Generates a list of sources to include in the library.
  1188. # Corresponds to the instances of "src_libwolfssl_la_SOURCES += ..."
  1189. # in the *.am files.
  1190. generate_lib_src_list("${LIB_SOURCES}")
  1191. add_library(wolfssl ${LIB_SOURCES})
  1192. set_target_properties(wolfssl
  1193. PROPERTIES
  1194. SOVERSION ${LIBTOOL_SO_VERSION}
  1195. VERSION ${LIBTOOL_FULL_VERSION}
  1196. )
  1197. target_compile_options(wolfssl PRIVATE "-DBUILDING_WOLFSSL")
  1198. ####################################################
  1199. # Include Directories
  1200. ####################################################
  1201. target_include_directories(wolfssl
  1202. PUBLIC
  1203. $<INSTALL_INTERFACE:wolfssl>
  1204. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  1205. $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  1206. )
  1207. ####################################################
  1208. # Link Libraries
  1209. ####################################################
  1210. target_link_libraries(wolfssl PUBLIC ${WOLFSSL_LINK_LIBS})
  1211. if(WIN32)
  1212. # For Windows link ws2_32
  1213. target_link_libraries(wolfssl PUBLIC
  1214. $<$<PLATFORM_ID:Windows>:ws2_32>)
  1215. else()
  1216. # DH requires math (m) library
  1217. target_link_libraries(wolfssl
  1218. PUBLIC
  1219. m)
  1220. endif()
  1221. ####################################################
  1222. # Tests and Examples
  1223. ####################################################
  1224. if(WOLFSSL_EXAMPLES)
  1225. # Build wolfSSL client example
  1226. add_executable(client
  1227. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  1228. target_link_libraries(client wolfssl)
  1229. set_property(TARGET client
  1230. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1231. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client)
  1232. # Build wolfSSL server example
  1233. add_executable(server
  1234. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c)
  1235. target_link_libraries(server wolfssl)
  1236. set_property(TARGET server
  1237. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1238. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server)
  1239. # Build echo client example
  1240. add_executable(echoclient
  1241. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c)
  1242. target_include_directories(echoclient PRIVATE
  1243. ${CMAKE_CURRENT_BINARY_DIR})
  1244. target_link_libraries(echoclient wolfssl)
  1245. set_property(TARGET echoclient
  1246. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1247. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient)
  1248. # Build echo server example
  1249. add_executable(echoserver
  1250. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c)
  1251. target_include_directories(echoserver PRIVATE
  1252. ${CMAKE_CURRENT_BINARY_DIR})
  1253. target_link_libraries(echoserver wolfssl)
  1254. set_property(TARGET echoserver
  1255. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1256. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver)
  1257. if(NOT WIN32)
  1258. # Build TLS benchmark example
  1259. add_executable(tls_bench
  1260. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c)
  1261. target_link_libraries(tls_bench wolfssl)
  1262. target_link_libraries(tls_bench Threads::Threads)
  1263. set_property(TARGET tls_bench
  1264. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1265. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark)
  1266. endif()
  1267. # Build unit tests
  1268. add_executable(unit_test
  1269. tests/api.c
  1270. tests/hash.c
  1271. tests/srp.c
  1272. tests/suites.c
  1273. tests/unit.c
  1274. examples/server/server.c
  1275. examples/client/client.c)
  1276. target_include_directories(unit_test PRIVATE
  1277. ${CMAKE_CURRENT_BINARY_DIR})
  1278. target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER")
  1279. target_link_libraries(unit_test wolfssl)
  1280. target_link_libraries(unit_test Threads::Threads)
  1281. set_property(TARGET unit_test
  1282. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1283. ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
  1284. set_property(TARGET unit_test
  1285. PROPERTY RUNTIME_OUTPUT_NAME
  1286. unit.test)
  1287. endif()
  1288. if(WOLFSSL_CRYPT_TESTS)
  1289. if(WOLFSSL_CRYPT_TESTS_LIBS)
  1290. # Build wolfCrypt test as a library. This will compile test.c and make
  1291. # its functions available as a CMake target that other CMake targets can
  1292. # pull in, in addition to producing the library itself. Note that this
  1293. # feature is not enabled by default, and the API of this library and
  1294. # wofcryptbench_lib should NOT be treated as stable.
  1295. add_library(wolfcrypttest_lib
  1296. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  1297. set_target_properties(wolfcrypttest_lib PROPERTIES OUTPUT_NAME "wolfcrypttest")
  1298. target_link_libraries(wolfcrypttest_lib wolfssl)
  1299. target_compile_options(wolfcrypttest_lib PRIVATE "-DNO_MAIN_DRIVER")
  1300. # Make another library for the wolfCrypt benchmark code.
  1301. add_library(wolfcryptbench_lib
  1302. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  1303. set_target_properties(wolfcryptbench_lib PROPERTIES OUTPUT_NAME "wolfcryptbench")
  1304. target_link_libraries(wolfcryptbench_lib wolfssl)
  1305. target_compile_options(wolfcryptbench_lib PRIVATE "-DNO_MAIN_DRIVER")
  1306. endif()
  1307. # Build wolfCrypt test executable.
  1308. add_executable(wolfcrypttest
  1309. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  1310. target_link_libraries(wolfcrypttest wolfssl)
  1311. set_property(TARGET wolfcrypttest
  1312. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1313. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test)
  1314. set_property(TARGET wolfcrypttest
  1315. PROPERTY RUNTIME_OUTPUT_NAME
  1316. testwolfcrypt)
  1317. # Build wolfCrypt benchmark executable.
  1318. add_executable(wolfcryptbench
  1319. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  1320. target_include_directories(wolfcryptbench PRIVATE
  1321. ${CMAKE_CURRENT_BINARY_DIR})
  1322. target_link_libraries(wolfcryptbench wolfssl)
  1323. set_property(TARGET wolfcryptbench
  1324. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1325. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark)
  1326. set_property(TARGET wolfcryptbench
  1327. PROPERTY RUNTIME_OUTPUT_NAME
  1328. benchmark)
  1329. endif()
  1330. ####################################################
  1331. # Installation
  1332. ####################################################
  1333. include(GNUInstallDirs)
  1334. set(EXCLUDED_HEADERS_REGEX
  1335. "(internal|\
  1336. options|\
  1337. pic32mz-crypt|\
  1338. ti-hash|\
  1339. ti-ccm|\
  1340. nrf51|\
  1341. ksdk_port|\
  1342. dcp_port|\
  1343. xil-sha3|\
  1344. caam_driver|\
  1345. wolfcaam|\
  1346. wolfcaam_sha|\
  1347. stm32|\
  1348. stsafe|\
  1349. esp32-cry|\
  1350. cryptoCell|\
  1351. renesas-tsip-crypt|\
  1352. psoc6_crypto).h")
  1353. set(INSTALLED_EXAMPLES
  1354. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c
  1355. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-server.c
  1356. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-client-dtls.c
  1357. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-client.c
  1358. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-server-dtls.c
  1359. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c
  1360. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c
  1361. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c
  1362. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  1363. # Install the library
  1364. install(TARGETS wolfssl
  1365. DESTINATION ${CMAKE_INSTALL_LIBDIR}
  1366. EXPORT wolfssl-targets
  1367. LIBRARY)
  1368. # Install the headers
  1369. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/
  1370. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wolfssl
  1371. FILES_MATCHING PATTERN "*.h"
  1372. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  1373. # Install the examples
  1374. install(FILES ${INSTALLED_EXAMPLES}
  1375. DESTINATION ${CMAKE_INSTALL_DOCDIR}/example)
  1376. # Install README.txt and taoCert.txt
  1377. install(FILES
  1378. ${CMAKE_CURRENT_SOURCE_DIR}/doc/README.txt
  1379. ${CMAKE_CURRENT_SOURCE_DIR}/certs/taoCert.txt
  1380. DESTINATION ${CMAKE_INSTALL_DOCDIR}/wolfssl)
  1381. # Install the export set
  1382. install(EXPORT wolfssl-targets
  1383. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wolfssl
  1384. FILE wolfssl-config.cmake)
  1385. # TODO: Distro build + rules for what to include in the distro.
  1386. # See various include.am files.