CMakeLists.txt 64 KB

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