CMakeLists.txt 75 KB

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