CMakeLists.txt 68 KB

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