CMakeLists.txt 73 KB

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