CMakeLists.txt 62 KB

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