CMakeLists.txt 68 KB

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