CMakeLists.txt 61 KB

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