CMakeLists.txt 76 KB

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