CMakeLists.txt 81 KB

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