2
0

CMakeLists.txt 81 KB

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