CMakeLists.txt 76 KB

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