CMakeLists.txt 68 KB

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