CMakeLists.txt 64 KB

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