CMakeLists.txt 65 KB

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