CMakeLists.txt 78 KB

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