CMakeLists.txt 78 KB

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