CMakeLists.txt 81 KB

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