CMakeLists.txt 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291
  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.6.0 LANGUAGES C ASM)
  28. # shared library versioning
  29. # increment if interfaces have been added, removed or changed
  30. set(LIBTOOL_CURRENT 39)
  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 4)
  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;const")
  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. if("${WOLFSSL_DH}" STREQUAL "const")
  787. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_DH_CONST")
  788. set(WOLFSSL_DH_CONST "yes")
  789. endif()
  790. # TODO: - Anonymous
  791. # ASN
  792. # turn off asn, which means no certs, no rsa, no dsa, no ecc,
  793. # and no big int (unless dh is on)
  794. add_option("WOLFSSL_ASN"
  795. "Enable ASN (default: enabled)"
  796. "yes" "yes;no")
  797. if(NOT WOLFSSL_ASN)
  798. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ASN" "-DNO_CERTS")
  799. if(NOT WOLFSSL_DH AND NOT WOLFSSL_ECC)
  800. # DH and ECC need bigint
  801. list(APPEND WOLFSSL_DEFINITIONS "-DNO_BIG_INT")
  802. endif()
  803. else()
  804. # turn off ASN if leanpsk on
  805. if(WOLFSSL_LEAN_PSK)
  806. list(APPEND WOLFSSL_DEFINITIONS
  807. "-DNO_ASN"
  808. "-DNO_CERTS"
  809. "-DNO_BIG_INT")
  810. override_cache(WOLFSSL_ASN "no")
  811. else()
  812. if("${WOLFSSL_ASN}" STREQUAL "nocrypt")
  813. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ASN_CRYPT")
  814. # TODO: verify that this is correct
  815. override_cache(WOLFSSL_PWDBASED "no")
  816. endif()
  817. endif()
  818. endif()
  819. if(WOLFSSL_RSA AND NOT WOLFSSL_RSA_VFY AND NOT WOLFSSL_ASN)
  820. message(FATAL_ERROR "please disable rsa if disabling asn.")
  821. endif()
  822. if(WOLFSSL_DSA AND NOT WOLFSSL_ASN)
  823. message(FATAL_ERROR "please disable dsa if disabling asn.")
  824. endif()
  825. # DH and ECC need bigint
  826. if(NOT WOLFSSL_ASN AND
  827. NOT WOLFSSL_DH AND
  828. NOT WOLFSSL_ECC AND
  829. NOT WOLFSSL_RSA)
  830. override_cache(WOLFSSL_FAST_MATH "no")
  831. set(WOLFSSL_SLOWMATH "no")
  832. endif()
  833. # AES
  834. add_option("WOLFSSL_AES"
  835. "Enable AES (default: enabled)"
  836. "yes" "yes;no")
  837. if(NOT WOLFSSL_AES)
  838. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
  839. if(WOLFSSL_FORTRESS)
  840. message(FATAL_ERROR "fortress requires aes")
  841. endif()
  842. if(WOLFSSL_ECC_ENCRYPT)
  843. message(FATAL_ERROR "cannot enable eccencrypt and hkdf without aes.")
  844. endif()
  845. if(WOLFSSL_AESGCM)
  846. message(FATAL_ERROR "AESGCM requires AES.")
  847. endif()
  848. if(WOLFSSL_AESCCM)
  849. message(FATAL_ERROR "AESCCM requires AES.")
  850. endif()
  851. if(WOLFSSL_AESCTR)
  852. message(FATAL_ERROR "AESCTR requires AES.")
  853. endif()
  854. else()
  855. if(WOLFSSL_LEAN_PSK)
  856. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
  857. override_cache(WOLFSSL_AES "no")
  858. endif()
  859. endif()
  860. # Coding
  861. add_option("WOLFSSL_CODING"
  862. "Enable coding base 16/64 (default: enabled)"
  863. "yes" "yes;no")
  864. if(NOT WOLFSSL_CODING)
  865. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CODING")
  866. else()
  867. # turn off CODING if leanpsk on
  868. if(WOLFSSL_LEAN_PSK)
  869. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CODING")
  870. override_cache(WOLFSSL_CODING "no")
  871. endif()
  872. endif()
  873. # Base64
  874. set(BASE64_ENCODE_DEFAULT "no")
  875. if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  876. set(BASE64_ENCODE_DEFAULT "yes")
  877. endif()
  878. set(WOLFSSL_BASE64_ENCODE_HELP_STRING "Enable Base64 encoding (default: enabled on x86_64)")
  879. add_option("WOLFSSL_BASE64_ENCODE" ${WOLFSSL_BASE64_ENCODE_HELP_STRING} ${BASE64_ENCODE_DEFAULT} "yes;no")
  880. if(WOLFSSL_BASE64_ENCODE)
  881. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_BASE64_ENCODE")
  882. endif()
  883. # TODO: - Base16
  884. # DES3
  885. set(WOLFSSL_DES3_HELP_STRING "Enable DES3 (default: disabled)")
  886. add_option("WOLFSSL_DES3" ${WOLFSSL_DES3_HELP_STRING} "no" "yes;no")
  887. if(WOLFSSL_OPENSSH OR
  888. WOLFSSL_QT OR
  889. WOLFSSL_OPENVPN OR
  890. WOLFSSL_WPAS)
  891. override_cache(WOLFSSL_DES3 "yes")
  892. endif()
  893. # ARC4
  894. set(WOLFSSL_ARC4_HELP_STRING "Enable ARC4 (default: disabled)")
  895. add_option("WOLFSSL_ARC4" ${WOLFSSL_ARC4_HELP_STRING} "no" "yes;no")
  896. if(WOLFSSL_OPENSSH OR WOLFSSL_WPAS)
  897. override_cache(WOLFSSL_ARC4 "yes")
  898. endif()
  899. # MD5
  900. set(WOLFSSL_MD5_HELP_STRING "Enable MD5 (default: enabled)")
  901. add_option("WOLFSSL_MD5" ${WOLFSSL_MD5_HELP_STRING} "yes" "yes;no")
  902. if(NOT WOLFSSL_MD5)
  903. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD5" "-DNO_OLD_TLS")
  904. else()
  905. # turn off MD5 if leanpsk or leantls on
  906. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  907. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD5" "-DNO_OLD_TLS")
  908. override_cache(WOLFSSL_MD5 "no")
  909. endif()
  910. endif()
  911. # SHA
  912. add_option("WOLFSSL_SHA"
  913. "Enable SHA (default: enabled)"
  914. "yes" "yes;no")
  915. if(NOT WOLFSSL_SHA)
  916. list(APPEND WOLFSSL_DEFINITIONS "-DNO_SHA" "-DNO_OLD_TLS")
  917. else()
  918. # turn off SHA if leanpsk or leantls on
  919. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  920. list(APPEND WOLFSSL_DEFINITIONS "-DNO_SHA" "-DNO_OLD_TLS")
  921. override_cache(WOLFSSL_SHA "no")
  922. endif()
  923. endif()
  924. # TODO: - AES-XTS
  925. # - Web server
  926. # - Web client
  927. add_option("WOLFSSL_CMAC"
  928. "Enable CMAC (default: disabled)"
  929. "no" "yes;no")
  930. if(WOLFSSL_WPAS OR
  931. WOLFSSL_NTP OR
  932. WOLFSSL_AESSIV)
  933. override_cache(WOLFSSL_CMAC "yes")
  934. endif()
  935. if(WOLFSSL_CMAC)
  936. if (NOT WOLFSSL_AES)
  937. message(FATAL_ERROR "Cannot use CMAC without AES.")
  938. else()
  939. list(APPEND WOLFSSL_DEFINITIONS
  940. "-DWOLFSSL_CMAC"
  941. "-DWOLFSSL_AES_DIRECT")
  942. endif()
  943. endif()
  944. # TODO: - RC2
  945. # - FIPS, again (there's more logic for FIPS in configure.ac)
  946. # - Selftest
  947. # SHA224
  948. if(WOLFSSL_SHA224)
  949. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA224")
  950. endif()
  951. # SHA3
  952. if("${WOLFSSL_SHA3}" STREQUAL "small")
  953. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA3_SMALL")
  954. override_cache(WOLFSSL_SHA3 "yes")
  955. endif()
  956. if(WOLFSSL_SHA3 AND NOT WOLFSSL_32BIT)
  957. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA3")
  958. endif()
  959. # SHAKE256
  960. if(WOLFSSL_SHAKE256)
  961. if(NOT WOLFSSL_32BIT)
  962. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHAKE256")
  963. if(NOT WOLFSSL_SHA3)
  964. message(FATAL_ERROR "Must have SHA-3 enabled: --enable-sha3")
  965. endif()
  966. endif()
  967. else()
  968. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_NO_SHAKE256")
  969. endif()
  970. # SHAKE128
  971. if(WOLFSSL_SHAKE128)
  972. if(NOT WOLFSSL_32BIT)
  973. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHAKE128")
  974. if(NOT WOLFSSL_SHA3)
  975. message(FATAL_ERROR "Must have SHA-3 enabled: --enable-sha3")
  976. endif()
  977. endif()
  978. else()
  979. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_NO_SHAKE128")
  980. endif()
  981. # POLY1305
  982. set(POLY1305_DEFAULT "yes")
  983. if(WOLFSSL_FIPS)
  984. set(POLY1305_DEFAULT "no")
  985. endif()
  986. set(WOLFSSL_POLY1305_HELP_STRING "Enable wolfSSL POLY1305 support (default: enabled)")
  987. add_option("WOLFSSL_POLY1305" ${WOLFSSL_POLY1305_HELP_STRING} ${POLY1305_DEFAULT} "yes;no")
  988. # leanpsk and leantls don't need poly1305
  989. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  990. override_cache(WOLFSSL_POLY1305 "no")
  991. endif()
  992. if(WOLFSSL_POLY1305)
  993. list(APPEND WOLFSSL_DEFINITIONS
  994. "-DHAVE_POLY1305"
  995. "-DHAVE_ONE_TIME_AUTH")
  996. endif()
  997. # CHACHA
  998. set(CHACHA_DEFAULT "yes")
  999. if(WOLFSSL_FIPS)
  1000. set(CHACHA_DEFAULT "no")
  1001. endif()
  1002. add_option("WOLFSSL_CHACHA"
  1003. "Enable CHACHA (default: enabled). Use `=noasm` to disable ASM AVX/AVX2 speedups"
  1004. ${CHACHA_DEFAULT} "yes;no;noasm")
  1005. # leanpsk and leantls don't need chacha
  1006. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1007. override_cache(WOLFSSL_CHACHA "no")
  1008. endif()
  1009. if(("${WOLFSSL_CHACHA}" STREQUAL "noasm") OR NOT WOLFSSL_ASM)
  1010. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CHACHA_ASM")
  1011. endif()
  1012. if(NOT ("${WOLFSSL_CHACHA}" STREQUAL "noasm") AND WOLFSSL_CHACHA)
  1013. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CHACHA")
  1014. endif()
  1015. # TODO: - XCHACHA
  1016. # Hash DRBG
  1017. add_option("WOLFSSL_HASH_DRBG"
  1018. "Enable Hash DRBG support (default: enabled)"
  1019. "yes" "yes;no")
  1020. if(WOLFSSL_HASH_DRBG)
  1021. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HASHDRBG")
  1022. else()
  1023. # turn on Hash DRBG if FIPS is on
  1024. if(WOLFSSL_FIPS)
  1025. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HASHDRBG")
  1026. override_cache(WOLFSSL_HASH_DRBG "yes")
  1027. else()
  1028. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HASHDRBG")
  1029. endif()
  1030. endif()
  1031. # Filesystem
  1032. if(WOLFSSL_LINUX_KM)
  1033. set(FILESYSTEM_DEFAULT "no")
  1034. else()
  1035. set(FILESYSTEM_DEFAULT "yes")
  1036. endif()
  1037. add_option("WOLFSSL_FILESYSTEM"
  1038. "Enable Filesystem support (default: enabled)"
  1039. ${FILESYSTEM_DEFAULT} "yes;no")
  1040. if(NOT WOLFSSL_FILESYSTEM)
  1041. list(APPEND WOLFSSL_DEFINITIONS "-DNO_FILESYSTEM")
  1042. else()
  1043. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1044. list(APPEND WOLFSSL_DEFINITIONS "-DNO_FILESYSTEM")
  1045. override_cache(WOLFSSL_FILESYSTEM "no")
  1046. endif()
  1047. endif()
  1048. # Inline function support
  1049. add_option("WOLFSSL_INLINE"
  1050. "Enable inline functions (default: enabled)"
  1051. "yes" "yes;no")
  1052. if(NOT WOLFSSL_INLINE)
  1053. list(APPEND WOLFSSL_DEFINITIONS "-DNO_INLINE")
  1054. endif()
  1055. # TODO:
  1056. # - CRL monitor
  1057. # - User crypto
  1058. # - Whitewood netRandom client library
  1059. # - SNI
  1060. # - Max fragment length
  1061. # - ALPN
  1062. # - Trusted CA indication
  1063. # - Truncated HMAC
  1064. # - Renegotiation indication
  1065. # - Secure renegotiation
  1066. # - Fallback SCSV
  1067. add_option(WOLFSSL_OCSP "Enable OCSP (default: disabled)" "no" "yes;no")
  1068. add_option(WOLFSSL_OCSPSTAPLING "Enable OCSP Stapling (default: disabled)" "no" "yes;no")
  1069. add_option(WOLFSSL_OCSPSTAPLING_V2 "Enable OCSP Stapling v2 (default: disabled)" "no" "yes;no")
  1070. add_option(WOLFSSL_CRL
  1071. "Enable CRL (Use =io for inline CRL HTTP GET) (default: disabled)"
  1072. "no" "yes;no;io")
  1073. set(WOLFSSL_SNI_HELP_STRING "Enable SNI (default: disabled)")
  1074. add_option(WOLFSSL_SNI ${WOLFSSL_SNI_HELP_STRING} "no" "yes;no")
  1075. set(WOLFSSL_TLSX_HELP_STRING "Enable all TLS Extensions (default: disabled)")
  1076. add_option(WOLFSSL_TLSX ${WOLFSSL_TLSX_HELP_STRING} "no" "yes;no")
  1077. # Supported elliptic curves extensions
  1078. add_option("WOLFSSL_SUPPORTED_CURVES"
  1079. "Enable Supported Elliptic Curves (default: enabled)"
  1080. "yes" "yes;no")
  1081. if(WOLFSSL_SUPPORTED_CURVES)
  1082. if(NOT WOLFSSL_ECC AND NOT WOLFSSL_CURVE25519 AND NOT WOLFSSL_CURVE448)
  1083. override_cache(WOLFSSL_SUPPORTED_CURVES "no")
  1084. else()
  1085. list(APPEND WOLFSSL_DEFINITIONS
  1086. "-DHAVE_TLS_EXTENSIONS"
  1087. "-DHAVE_SUPPORTED_CURVES")
  1088. endif()
  1089. endif()
  1090. # Diffie-Hellman
  1091. if(WOLFSSL_DH)
  1092. if(WOLFSSL_TLS13 OR WOLFSSL_SUPPORTED_CURVES)
  1093. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_FFDHE_2048")
  1094. endif()
  1095. endif()
  1096. # TODO: - FFDHE params only
  1097. # TLS 1.3 Requires either ECC or (RSA/DH), or CURVE25519/ED25519 or CURVE448/ED448
  1098. if (NOT WOLFSSL_ECC AND
  1099. (NOT WOLFSSL_RSA OR NOT WOLFSSL_DH) AND
  1100. (NOT WOLFSSL_CURVE25519 OR NOT WOLFSSL_ED25519) AND
  1101. (NOT WOLFSSL_CURVE448 AND NOT WOLFSSL_ED448))
  1102. override_cache(WOLFSSL_TLS13 "no")
  1103. endif()
  1104. if (WOLFSSL_TLS13)
  1105. list(APPEND WOLFSSL_DEFINITIONS
  1106. "-DHAVE_SUPPORTED_CURVES"
  1107. "-DWOLFSSL_TLS13"
  1108. "-DHAVE_TLS_EXTENSIONS"
  1109. )
  1110. endif()
  1111. # Session Ticket Extension
  1112. add_option("WOLFSSL_SESSION_TICKET"
  1113. "Enable Session Ticket (default: disabled)"
  1114. "no" "yes;no")
  1115. if(WOLFSSL_NGINX OR WOLFSSL_WPAS OR WOLFSSL_HAPROXY OR WOLFSSL_LIGHTY)
  1116. override_cache(WOLFSSL_SESSION_TICKET "yes")
  1117. endif()
  1118. if(WOLFSSL_SESSION_TICKET)
  1119. list(APPEND WOLFSSL_DEFINITIONS
  1120. "-DHAVE_TLS_EXTENSIONS"
  1121. "-DHAVE_SESSION_TICKET")
  1122. endif()
  1123. add_option("WOLFSSL_TICKET_NONCE_MALLOC"
  1124. "Enable dynamic allocation of ticket nonces (default: disabled)"
  1125. "no" "yes;no")
  1126. if(WOLFSSL_TICKET_NONCE_MALLOC)
  1127. list(APPEND WOLFSSL_DEFINITIONS
  1128. "-DWOLFSSL_TICKET_NONCE_MALLOC")
  1129. endif()
  1130. # Extended master secret extension
  1131. add_option("WOLFSSL_EXTENDED_MASTER"
  1132. "Enable Extended Master Secret (default: enabled)"
  1133. "yes" "yes;no")
  1134. if(WOLFSSL_EXTENDED_MASTER)
  1135. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_EXTENDED_MASTER")
  1136. endif()
  1137. if(NOT WOLFSSL_ARC4)
  1138. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RC4")
  1139. else()
  1140. # turn off ARC4 if leanpsk or leantls on
  1141. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1142. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RC4")
  1143. override_cache(WOLFSSL_ARC4 "no")
  1144. endif()
  1145. endif()
  1146. # TODO: - TLS extensions
  1147. # - Early data handshake
  1148. # - wolfSSH options
  1149. # - SCEP
  1150. # - Secure remote password
  1151. # - Indefinite length encoded messages
  1152. # - Small stack cache
  1153. # - Small stack
  1154. # - Valgrind
  1155. # - Test certs
  1156. # - I/O pool example
  1157. # - Certificate service
  1158. # - wolfSSL JNI
  1159. # - lighttpd/lighty
  1160. # - Asio
  1161. # - Apache HTTPD
  1162. set(WOLFSSL_PKCS7_HELP_STRING "Enable PKCS7 (default: disabled)")
  1163. add_option(WOLFSSL_PKCS7 ${WOLFSSL_PKCS7_HELP_STRING} "no" "yes;no")
  1164. set(WOLFSSL_TPM_HELP_STRING "Enable wolfTPM options (default: disabled)")
  1165. add_option(WOLFSSL_TPM ${WOLFSSL_TPM_HELP_STRING} "no" "yes;no")
  1166. set(WOLFSSL_AESKEYWRAP_HELP_STRING "Enable AES key wrap support (default: disabled)")
  1167. add_option(WOLFSSL_AESKEYWRAP ${WOLFSSL_AESKEYWRAP_HELP_STRING} "no" "yes;no")
  1168. set(WOLFSSL_X963KDF_HELP_STRING "Enable X9.63 KDF support (default: disabled)")
  1169. add_option(WOLFSSL_X963KDF ${WOLFSSL_X963KDF_HELP_STRING} "no" "yes;no")
  1170. # Encrypt-then-mac
  1171. add_option("WOLFSSL_ENC_THEN_MAC"
  1172. "Enable Encryptr-Then-Mac extension (default: enabled)"
  1173. "yes" "yes;no")
  1174. if(WOLFSSL_APACHE_HTTPD)
  1175. override_cache(WOLFSSL_ENC_THEN_MAC "no")
  1176. endif()
  1177. if(WOLFSSL_TLSX)
  1178. override_cache(WOLFSSL_ENC_THEN_MAC "yes")
  1179. endif()
  1180. if(WOLFSSL_SNIFFER)
  1181. override_cache(WOLFSSL_ENC_THEN_MAC "no")
  1182. endif()
  1183. # stunnel Support
  1184. # TODO: rest of stunnel support
  1185. add_option("WOLFSSL_STUNNEL"
  1186. "Enable stunnel (default: disabled)"
  1187. "no" "yes;no")
  1188. if(WOLFSSL_ENC_THEN_MAC)
  1189. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ENCRYPT_THEN_MAC")
  1190. endif()
  1191. if(NOT WOLFSSL_PSK AND
  1192. NOT WOLFSSL_LEAN_PSK AND
  1193. NOT WOLFSSL_STUNNEL)
  1194. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PSK")
  1195. endif()
  1196. # MD4
  1197. set(WOLFSSL_MD4_HELP_STRING "Enable MD4 (default: disabled)")
  1198. add_option("WOLFSSL_MD4" ${WOLFSSL_MD4_HELP_STRING} "no" "yes;no")
  1199. if(NOT WOLFSSL_MD4)
  1200. # turn on MD4 if using stunnel
  1201. if(WOLFSSL_STUNNEL OR WOLFSSL_WPAS)
  1202. override_cache(WOLFSSL_MD4 "yes")
  1203. else()
  1204. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD4")
  1205. endif()
  1206. endif()
  1207. # Encrypted keys
  1208. add_option("WOLFSSL_ENCKEYS"
  1209. "Enable PEM encrypted key support (default: disabled)"
  1210. "no" "yes;no")
  1211. if(NOT WOLFSSL_ENCKEYS)
  1212. if(WOLFSSL_OPENSSLEXTRA OR
  1213. WOLFSSL_WEBSERVER OR
  1214. WOLFSSL_WPAS)
  1215. # opensslextra, webserver, and WPAS needs enckeys
  1216. override_cache(WOLFSSL_ENCKEYS "yes")
  1217. endif()
  1218. endif()
  1219. if(WOLFSSL_ENCKEYS)
  1220. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_ENCRYPTED_KEYS")
  1221. endif()
  1222. # PKCS#12
  1223. set(WOLFSSL_PKCS12_HELP_STRING "Enable pkcs12 (default: enabled)")
  1224. add_option("WOLFSSL_PKCS12" ${WOLFSSL_PKCS12_HELP_STRING} "yes" "yes;no")
  1225. if(NOT WOLFSSL_ASN)
  1226. override_cache(WOLFSSL_PKCS12 "no")
  1227. endif()
  1228. if(NOT WOLFSSL_PKCS12)
  1229. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PKCS12")
  1230. endif()
  1231. # PWDBASED has to come after certservice since we want it on w/o explicit on
  1232. # PWDBASED
  1233. add_option("WOLFSSL_PWDBASED"
  1234. "Enable PWDBASED (default: disabled)"
  1235. "no" "yes;no")
  1236. if(NOT WOLFSSL_PWDBASED)
  1237. if(WOLFSSL_OPENSSLEXTRA OR
  1238. WOLFSSL_OPENSSLALL OR
  1239. WOLFSSL_WEBSERVER OR
  1240. WOLFSSL_ENC_KEYS OR
  1241. WOLFSSL_PKCS12)
  1242. # opensslextra, opensslall, webserver, and enckeys needs pwdbased
  1243. override_cache(WOLFSSL_PWDBASED "yes")
  1244. else()
  1245. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PWDBASED")
  1246. endif()
  1247. endif()
  1248. # TODO: - SCRYPT
  1249. # - wolfCrypt only
  1250. # fastmath
  1251. add_option("WOLFSSL_FAST_MATH"
  1252. "Enable fast math ops (default: disabled)"
  1253. "no" "yes;no")
  1254. if(WOLFSSL_FAST_MATH)
  1255. # turn off fastmath if leanpsk on or asn off (w/o DH and ECC)
  1256. if(WOLFSSL_LEAN_PSK OR NOT WOLFSSL_ASN)
  1257. if(NOT WOLFSSL_DH AND
  1258. NOT WOLFSSL_ECC AND
  1259. NOT WOLFSSL_RSA)
  1260. override_cache(WOLFSSL_FAST_MATH "no")
  1261. else()
  1262. list(APPEND WOLFSSL_DEFINITIONS "-DUSE_FAST_MATH")
  1263. set(WOLFSSL_SLOWMATH "no")
  1264. endif()
  1265. else()
  1266. list(APPEND WOLFSSL_DEFINITIONS "-DUSE_FAST_MATH")
  1267. set(WOLFSSL_SLOWMATH "no")
  1268. endif()
  1269. if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  1270. # Have settings.h set FP_MAX_BITS higher if user didn't set directly
  1271. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_X86_64_BUILD")
  1272. endif()
  1273. endif()
  1274. # TODO: - Fast huge math
  1275. if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  1276. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_X86_64_BUILD")
  1277. endif()
  1278. # SP math all
  1279. add_option("WOLFSSL_SP_MATH_ALL"
  1280. "Enable Single Precision math implementation for full algorithm suite (default: enabled)"
  1281. "yes" "yes;no")
  1282. # Enable examples, used to disable examples
  1283. if(WOLFSSL_LINUX_KM)
  1284. set(EXAMPLES_DEFAULT "no")
  1285. else()
  1286. set(EXAMPLES_DEFAULT "yes")
  1287. endif()
  1288. add_option("WOLFSSL_EXAMPLES"
  1289. "Enable examples (default: enabled)"
  1290. ${EXAMPLES_DEFAULT} "yes;no")
  1291. if(NOT WOLFSSL_FILESYSTEM OR
  1292. NOT WOLFSSL_INLINE OR
  1293. WOLFSSL_CRYPT_ONLY)
  1294. override_cache(WOLFSSL_EXAMPLES "no")
  1295. endif()
  1296. # Enable wolfCrypt test and benchmark
  1297. if(WOLFSSL_LINUX_KM)
  1298. set(CRYPT_TESTS_DEFAULT "no")
  1299. else()
  1300. set(CRYPT_TESTS_DEFAULT "yes")
  1301. endif()
  1302. add_option("WOLFSSL_CRYPT_TESTS"
  1303. "Enable Crypt Bench/Test (default: enabled)"
  1304. ${CRYPT_TESTS_DEFAULT} "yes;no")
  1305. add_option("WOLFSSL_CRYPT_TESTS_LIBS"
  1306. "Build static libraries from the wolfCrypt test and benchmark sources (default: disabled)"
  1307. "no" "yes;no")
  1308. add_option("WOLFSSL_CRYPT_TESTS_HELP"
  1309. "Add help text to wolfCrypt test (default: disabled)"
  1310. "no" "yes;no")
  1311. # TODO: - LIBZ
  1312. # - PKCS#11
  1313. # - Cavium
  1314. # - Cavium V
  1315. # - Cavium Octeon
  1316. # - Intel QuickAssist
  1317. # - SP ASM (and other SP logic)
  1318. # - Fast RSA
  1319. # - Static memory use
  1320. # - Microchip API
  1321. # - Asynchronous crypto
  1322. # Asynchronous threading
  1323. add_option("WOLFSSL_ASYNC_THREADS"
  1324. "Enable Asynchronous Threading (default: enabled)"
  1325. "yes" "yes;no")
  1326. if(WOLFSSL_ASYNC_CRYPT AND WOLFSSL_ASYNC_THREADS)
  1327. if(CMAKE_USE_PTHREADS_INIT)
  1328. override_cache(WOLFSSL_ASYNC_THREADS "yes")
  1329. else()
  1330. override_cache(WOLFSSL_ASYNC_THREADS "no")
  1331. endif()
  1332. else()
  1333. override_cache(WOLFSSL_ASYNC_THREADS "no")
  1334. endif()
  1335. if(WOLFSSL_ASYNC_THREADS)
  1336. list(APPEND WOLFSSL_LINK_LIBS Threads::Threads)
  1337. list(APPEND WOLFSSL_DEFINITIONS "-D_GNU_SOURCE")
  1338. else()
  1339. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_ASYNC_THREADING")
  1340. endif()
  1341. # TODO: - cryptodev
  1342. # - Session export
  1343. add_option("WOLFSSL_CRYPTOCB"
  1344. "Enable crypto callbacks (default: disabled)"
  1345. "no" "yes;no")
  1346. add_option("WOLFSSL_OLD_NAMES"
  1347. "Keep backwards compat with old names (default: enabled)"
  1348. "yes" "yes;no")
  1349. if(NOT WOLFSSL_OLD_NAMES AND NOT WOLFSSL_OPENSSL_COEXIST)
  1350. list(APPEND WOLFSSL_DEFINITIONS
  1351. "-DNO_OLD_RNGNAME"
  1352. "-DNO_OLD_WC_NAMES"
  1353. "-DNO_OLD_SSL_NAMES"
  1354. "-DNO_OLD_SHA_NAMES")
  1355. endif()
  1356. # TODO: - Memory tests
  1357. # - Hash flags
  1358. # Support for enabling setting default DH parameters
  1359. add_option("WOLFSSL_DH_DEFAULT_PARAMS"
  1360. "Enables option for default dh parameters (default: disabled)"
  1361. "no" "yes;no")
  1362. if(WOLFSSL_DH_DEFAULT_PARAMS OR NOT WOLFSSL_QT)
  1363. override_cache(WOLFSSL_DH_DEFAULT_PARAMS "yes")
  1364. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_DH_DEFAULT_PARAMS")
  1365. endif()
  1366. if(NOT WOLFSSL_DES3)
  1367. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3")
  1368. else()
  1369. # turn off DES3 if leanpsk or leantls on
  1370. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1371. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3")
  1372. override_cache(WOLFSSL_DES3 "no")
  1373. endif()
  1374. endif()
  1375. add_option("WOLFSSL_USER_SETTINGS"
  1376. "Use your own user_settings.h and do not add Makefile CFLAGS (default: disabled)"
  1377. "no" "yes;no")
  1378. add_option("WOLFSSL_OPTFLAGS"
  1379. "Enable default optimization CFLAGS for the compiler (default: enabled)"
  1380. "yes" "yes;no")
  1381. add_option("WOLFSSL_SYS_CA_CERTS"
  1382. "Enable ability to load CA certs from OS (default: enabled)"
  1383. "yes" "yes;no")
  1384. if(WOLFSSL_SYS_CA_CERTS)
  1385. if(NOT WOLFSSL_FILESYSTEM)
  1386. message("Can't enable system CA certs without a filesystem.")
  1387. override_cache(WOLFSSL_SYS_CA_CERTS "no")
  1388. elseif(APPLE)
  1389. check_include_file("Security/SecTrustSettings.h" HAVE_SECURITY_SECTRUSTSETTINGS_H)
  1390. if(NOT HAVE_SECURITY_SECTRUSTSETTINGS_H)
  1391. message("Can't enable system CA certs without Security/SecTrustSettings.h.")
  1392. override_cache(WOLFSSL_SYS_CA_CERTS "no")
  1393. else()
  1394. find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
  1395. if(NOT CORE_FOUNDATION_FRAMEWORK)
  1396. message("Can't enable system CA certs without CoreFoundation framework.")
  1397. override_cache(WOLFSSL_SYS_CA_CERTS "no")
  1398. else()
  1399. find_library(SECURITY_FRAMEWORK Security)
  1400. if(NOT SECURITY_FRAMEWORK)
  1401. message("Can't enable system CA certs without Security framework.")
  1402. override_cache(WOLFSSL_SYS_CA_CERTS "no")
  1403. endif()
  1404. endif()
  1405. endif()
  1406. endif()
  1407. if(WOLFSSL_SYS_CA_CERTS)
  1408. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SYS_CA_CERTS")
  1409. endif()
  1410. endif()
  1411. # FLAGS operations
  1412. if(WOLFSSL_AESCCM)
  1413. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_AESCCM")
  1414. endif()
  1415. if(WOLFSSL_AESOFB)
  1416. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_OFB" "-DWOLFSSL_AES_DIRECT")
  1417. endif()
  1418. if(WOLFSSL_TPM)
  1419. override_cache(WOLFSSL_KEYGEN "yes")
  1420. override_cache(WOLFSSL_CERTGEN "yes")
  1421. override_cache(WOLFSSL_CRYPTOCB "yes")
  1422. override_cache(WOLFSSL_CERTREQ "yes")
  1423. override_cache(WOLFSSL_CERTEXT "yes")
  1424. override_cache(WOLFSSL_PKCS7 "yes")
  1425. override_cache(WOLFSSL_AESCFB "yes")
  1426. endif()
  1427. if(WOLFSSL_AESCFB)
  1428. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_CFB")
  1429. endif()
  1430. if(WOLFSSL_PKCS7)
  1431. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_PKCS7")
  1432. override_cache(WOLFSSL_AESKEYWRAP "yes")
  1433. # Enable prereqs if not already enabled
  1434. if(WOLFSSL_ECC)
  1435. override_cache(WOLFSSL_X963KDF "yes")
  1436. endif()
  1437. endif()
  1438. if(WOLFSSL_X963KDF)
  1439. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_X963_KDF")
  1440. endif()
  1441. if(WOLFSSL_AESKEYWRAP)
  1442. list(APPEND WOLFSSL_DEFINITIONS
  1443. "-DHAVE_AES_KEYWRAP"
  1444. "-DWOLFSSL_AES_DIRECT"
  1445. )
  1446. endif()
  1447. if(WOLFSSL_KEYGEN)
  1448. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_KEY_GEN")
  1449. endif()
  1450. if(WOLFSSL_CERTGEN)
  1451. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_GEN")
  1452. endif()
  1453. if(WOLFSSL_CERTREQ)
  1454. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_REQ")
  1455. endif()
  1456. if(WOLFSSL_CERTEXT)
  1457. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_EXT")
  1458. endif()
  1459. if(WOLFSSL_CERTGENCACHE)
  1460. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CERT_GEN_CACHE")
  1461. endif()
  1462. if(WOLFSSL_CRYPTOCB)
  1463. list(APPEND WOLFSSL_DEFINITIONS "-DWOLF_CRYPTO_CB")
  1464. endif()
  1465. if(WOLFSSL_OCSPSTAPLING)
  1466. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CERTIFICATE_STATUS_REQUEST" "-DHAVE_TLS_EXTENSIONS")
  1467. override_cache(WOLFSSL_OCSP "yes")
  1468. endif()
  1469. if(WOLFSSL_OCSPSTAPLING_V2)
  1470. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CERTIFICATE_STATUS_REQUEST_V2" "-DHAVE_TLS_EXTENSIONS")
  1471. override_cache(WOLFSSL_OCSP "yes")
  1472. endif()
  1473. # must be below OCSP stapling options to allow override
  1474. if (WOLFSSL_OCSP)
  1475. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_OCSP")
  1476. endif()
  1477. if (WOLFSSL_CRL STREQUAL "yes")
  1478. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CRL")
  1479. elseif(WOLFSSL_CRL STREQUAL "io")
  1480. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CRL" "-DHAVE_CRL_IO")
  1481. endif()
  1482. if (WOLFSSL_SNI)
  1483. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_TLS_EXTENSIONS" "-DHAVE_SNI")
  1484. endif()
  1485. if (WOLFSSL_TLSX)
  1486. list(APPEND WOLFSSL_DEFINITIONS
  1487. "-DHAVE_TLS_EXTENSIONS"
  1488. "-DHAVE_SNI"
  1489. "-DHAVE_MAX_FRAGMENT"
  1490. "-DHAVE_TRUNCATED_HMAC"
  1491. "-DHAVE_ALPN"
  1492. "-DHAVE_TRUSTED_CA")
  1493. if (WOLFSSL_ECC OR WOLFSSL_CURVE25519 OR WOLFSSL_CURVE448 OR WOLFSSL_TLS13)
  1494. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_SUPPORTED_CURVES")
  1495. endif()
  1496. endif()
  1497. add_option("WOLFSSL_CAAM"
  1498. "Enable use of CAAM with NXP (default: disabled)"
  1499. "no" "yes;no")
  1500. if (WOLFSSL_CAAM)
  1501. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_CAAM")
  1502. endif()
  1503. # Generates the BUILD_* flags. These control what source files are included in
  1504. # the library. A series of AM_CONDITIONALs handle this in configure.ac.
  1505. generate_build_flags()
  1506. # TODO: - Bit of logic after optimization flags option (above)
  1507. # - Check for build-type conflicts section
  1508. # USER SETTINGS
  1509. if(WOLFSSL_USER_SETTINGS)
  1510. # Replace all options and just use WOLFSSL_USER_SETTINGS
  1511. set(WOLFSSL_DEFINITIONS "-DWOLFSSL_USER_SETTINGS
  1512. -DWOLFSSL_USER_SETTINGS_ASM")
  1513. # Create user_settings_asm.h for use in assembly files (e.g. .S files).
  1514. execute_process(COMMAND $ENV{SHELL} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/user_settings_asm.sh
  1515. "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}"
  1516. RESULT_VARIABLE USER_SETTINGS_ASM_RET)
  1517. if (NOT USER_SETTINGS_ASM_RET EQUAL 0)
  1518. message(FATAL_ERROR "${CMAKE_CURRENT_SOURCE_DIR}/scripts/user_settings_asm.sh failed.")
  1519. endif()
  1520. endif()
  1521. # TODO: Applying definitions to everything like this, rather than
  1522. # individual targets, is discouraged in CMake.
  1523. add_definitions(${WOLFSSL_DEFINITIONS})
  1524. add_option("WOLFSSL_CONFIG_H"
  1525. "Enable generation of config.h and define HAVE_CONFIG_H (default: enabled)"
  1526. "yes" "yes;no")
  1527. if(WOLFSSL_CONFIG_H)
  1528. add_definitions("-DHAVE_CONFIG_H")
  1529. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.in"
  1530. "${CMAKE_CURRENT_BINARY_DIR}/config.h" )
  1531. set(abs_top_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
  1532. set(abs_top_builddir ${CMAKE_CURRENT_BINARY_DIR})
  1533. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test_paths.h.in"
  1534. "${CMAKE_CURRENT_BINARY_DIR}/wolfcrypt/test/test_paths.h" )
  1535. endif()
  1536. # Suppress some warnings about separate compilation, inlining
  1537. add_definitions("-DWOLFSSL_IGNORE_FILE_WARN")
  1538. # Generate user options header
  1539. message("Generating user options header...")
  1540. if (${CMAKE_DISABLE_SOURCE_CHANGES})
  1541. set(WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT "${CMAKE_DISABLE_SOURCE_CHANGES}")
  1542. else()
  1543. set(WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT "no")
  1544. endif()
  1545. add_option("WOLFSSL_BUILD_OUT_OF_TREE"
  1546. "Don't generate files in the source tree (default: ${WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT})"
  1547. "${WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT}" "yes;no")
  1548. if (${WOLFSSL_BUILD_OUT_OF_TREE})
  1549. set(WOLFSSL_OUTPUT_BASE ${CMAKE_CURRENT_BINARY_DIR})
  1550. else()
  1551. set(WOLFSSL_OUTPUT_BASE ${CMAKE_CURRENT_SOURCE_DIR})
  1552. endif()
  1553. set(OPTION_FILE "${WOLFSSL_OUTPUT_BASE}/wolfssl/options.h")
  1554. set(CYASSL_OPTION_FILE "${WOLFSSL_OUTPUT_BASE}/cyassl/options.h")
  1555. file(REMOVE ${OPTION_FILE})
  1556. file(APPEND ${OPTION_FILE} "/* wolfssl options.h\n")
  1557. file(APPEND ${OPTION_FILE} " * generated from configure options\n")
  1558. file(APPEND ${OPTION_FILE} " *\n")
  1559. file(APPEND ${OPTION_FILE} " * Copyright (C) 2006-2020 wolfSSL Inc.\n")
  1560. file(APPEND ${OPTION_FILE} " *\n")
  1561. file(APPEND ${OPTION_FILE} " * This file is part of wolfSSL. (formerly known as CyaSSL)\n")
  1562. file(APPEND ${OPTION_FILE} " *\n")
  1563. file(APPEND ${OPTION_FILE} " */\n\n")
  1564. file(APPEND ${OPTION_FILE} "#ifndef WOLFSSL_OPTIONS_H\n")
  1565. file(APPEND ${OPTION_FILE} "#define WOLFSSL_OPTIONS_H\n\n\n")
  1566. file(APPEND ${OPTION_FILE} "#ifdef __cplusplus\n")
  1567. file(APPEND ${OPTION_FILE} "extern \"C\" {\n")
  1568. file(APPEND ${OPTION_FILE} "#endif\n\n")
  1569. add_to_options_file("${WOLFSSL_DEFINITIONS}" "${OPTION_FILE}")
  1570. # CMAKE_C_FLAGS is just a string of space-separated flags to pass to the C
  1571. # compiler. We need to replace those spaces with semicolons in order to treat it
  1572. # as a CMake list.
  1573. string(REPLACE " " ";" CMAKE_C_FLAGS_LIST "${CMAKE_C_FLAGS}")
  1574. add_to_options_file("${CMAKE_C_FLAGS_LIST}" "${OPTION_FILE}")
  1575. file(APPEND ${OPTION_FILE} "\n#ifdef __cplusplus\n")
  1576. file(APPEND ${OPTION_FILE} "}\n")
  1577. file(APPEND ${OPTION_FILE} "#endif\n\n\n")
  1578. file(APPEND ${OPTION_FILE} "#endif /* WOLFSSL_OPTIONS_H */\n\n")
  1579. # backwards compatibility for those who have included options or version
  1580. file(REMOVE ${CYASSL_OPTION_FILE})
  1581. file(APPEND ${CYASSL_OPTION_FILE} "/* cyassl options.h\n")
  1582. file(APPEND ${CYASSL_OPTION_FILE} " * generated from wolfssl/options.h\n")
  1583. file(APPEND ${CYASSL_OPTION_FILE} " */\n")
  1584. file(READ ${OPTION_FILE} OPTION_FILE_CONTENTS)
  1585. file(APPEND ${CYASSL_OPTION_FILE} ${OPTION_FILE_CONTENTS})
  1586. ####################################################
  1587. # Library Target
  1588. ####################################################
  1589. # TODO: - Build shared/static libs based on enables. Check CMake
  1590. # global flag BUILD_SHARED_LIBS.
  1591. option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON)
  1592. set(LIB_SOURCES "")
  1593. # Generates a list of sources to include in the library.
  1594. # Corresponds to the instances of "src_libwolfssl_la_SOURCES += ..."
  1595. # in the *.am files.
  1596. generate_lib_src_list("${LIB_SOURCES}")
  1597. add_library(wolfssl ${LIB_SOURCES})
  1598. set_target_properties(wolfssl
  1599. PROPERTIES
  1600. SOVERSION ${LIBTOOL_SO_VERSION}
  1601. VERSION ${LIBTOOL_FULL_VERSION}
  1602. )
  1603. target_compile_definitions(wolfssl PRIVATE "BUILDING_WOLFSSL")
  1604. if(${BUILD_SHARED_LIBS})
  1605. target_compile_definitions(wolfssl PUBLIC "WOLFSSL_DLL")
  1606. endif()
  1607. ####################################################
  1608. # Include Directories
  1609. ####################################################
  1610. target_include_directories(wolfssl
  1611. PUBLIC
  1612. $<INSTALL_INTERFACE:include>
  1613. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  1614. $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  1615. ${WOLFSSL_INCLUDE_DIRS}
  1616. )
  1617. ####################################################
  1618. # Link Libraries
  1619. ####################################################
  1620. target_link_libraries(wolfssl PUBLIC ${WOLFSSL_LINK_LIBS})
  1621. if(WIN32)
  1622. # For Windows link ws2_32
  1623. target_link_libraries(wolfssl PUBLIC
  1624. $<$<PLATFORM_ID:Windows>:ws2_32>)
  1625. elseif(APPLE)
  1626. if(WOLFSSL_SYS_CA_CERTS)
  1627. target_link_libraries(wolfssl PUBLIC
  1628. ${CORE_FOUNDATION_FRAMEWORK}
  1629. ${SECURITY_FRAMEWORK})
  1630. endif()
  1631. else()
  1632. if(WOLFSSL_DH AND NOT WOLFSSL_DH_CONST)
  1633. # DH requires math (m) library
  1634. target_link_libraries(wolfssl
  1635. PUBLIC
  1636. m)
  1637. endif()
  1638. endif()
  1639. ####################################################
  1640. # Tests and Examples
  1641. ####################################################
  1642. if(WOLFSSL_EXAMPLES)
  1643. # Build wolfSSL client example
  1644. add_executable(client
  1645. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  1646. target_link_libraries(client wolfssl)
  1647. set_property(TARGET client
  1648. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1649. ${WOLFSSL_OUTPUT_BASE}/examples/client)
  1650. # Build wolfSSL server example
  1651. add_executable(server
  1652. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c)
  1653. target_link_libraries(server wolfssl)
  1654. set_property(TARGET server
  1655. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1656. ${WOLFSSL_OUTPUT_BASE}/examples/server)
  1657. # Build echo client example
  1658. add_executable(echoclient
  1659. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c)
  1660. target_include_directories(echoclient PRIVATE
  1661. ${CMAKE_CURRENT_BINARY_DIR})
  1662. target_link_libraries(echoclient wolfssl)
  1663. set_property(TARGET echoclient
  1664. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1665. ${WOLFSSL_OUTPUT_BASE}/examples/echoclient)
  1666. # Build echo server example
  1667. add_executable(echoserver
  1668. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c)
  1669. target_include_directories(echoserver PRIVATE
  1670. ${CMAKE_CURRENT_BINARY_DIR})
  1671. target_link_libraries(echoserver wolfssl)
  1672. set_property(TARGET echoserver
  1673. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1674. ${WOLFSSL_OUTPUT_BASE}/examples/echoserver)
  1675. if(NOT WIN32)
  1676. # Build TLS benchmark example
  1677. add_executable(tls_bench
  1678. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c)
  1679. target_link_libraries(tls_bench wolfssl)
  1680. target_link_libraries(tls_bench Threads::Threads)
  1681. set_property(TARGET tls_bench
  1682. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1683. ${WOLFSSL_OUTPUT_BASE}/examples/benchmark)
  1684. endif()
  1685. # Build unit tests
  1686. add_executable(unit_test
  1687. tests/api.c
  1688. tests/hash.c
  1689. tests/srp.c
  1690. tests/suites.c
  1691. tests/w64wrapper.c
  1692. tests/unit.c
  1693. examples/server/server.c
  1694. examples/client/client.c)
  1695. target_include_directories(unit_test PRIVATE
  1696. ${CMAKE_CURRENT_BINARY_DIR})
  1697. target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER")
  1698. target_link_libraries(unit_test wolfssl)
  1699. target_link_libraries(unit_test Threads::Threads)
  1700. set_property(TARGET unit_test
  1701. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1702. ${WOLFSSL_OUTPUT_BASE}/tests/)
  1703. set_property(TARGET unit_test
  1704. PROPERTY RUNTIME_OUTPUT_NAME
  1705. unit.test)
  1706. endif()
  1707. if(WOLFSSL_CRYPT_TESTS)
  1708. if(WOLFSSL_CRYPT_TESTS_LIBS)
  1709. # Build wolfCrypt test as a library. This will compile test.c and make
  1710. # its functions available as a CMake target that other CMake targets can
  1711. # pull in, in addition to producing the library itself. Note that this
  1712. # feature is not enabled by default, and the API of this library and
  1713. # wofcryptbench_lib should NOT be treated as stable.
  1714. add_library(wolfcrypttest_lib
  1715. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  1716. set_target_properties(wolfcrypttest_lib PROPERTIES OUTPUT_NAME "wolfcrypttest")
  1717. target_link_libraries(wolfcrypttest_lib wolfssl)
  1718. target_compile_options(wolfcrypttest_lib PRIVATE "-DNO_MAIN_DRIVER")
  1719. if(WOLFSSL_CRYPT_TESTS_HELP)
  1720. target_compile_options(wolfcrypttest_lib PRIVATE "-DHAVE_WOLFCRYPT_TEST_OPTIONS")
  1721. endif()
  1722. # Make another library for the wolfCrypt benchmark code.
  1723. add_library(wolfcryptbench_lib
  1724. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  1725. set_target_properties(wolfcryptbench_lib PROPERTIES OUTPUT_NAME "wolfcryptbench")
  1726. target_link_libraries(wolfcryptbench_lib wolfssl)
  1727. target_compile_options(wolfcryptbench_lib PRIVATE "-DNO_MAIN_DRIVER")
  1728. endif()
  1729. # Build wolfCrypt test executable.
  1730. add_executable(wolfcrypttest
  1731. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  1732. target_link_libraries(wolfcrypttest wolfssl)
  1733. set_property(TARGET wolfcrypttest
  1734. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1735. ${WOLFSSL_OUTPUT_BASE}/wolfcrypt/test)
  1736. set_property(TARGET wolfcrypttest
  1737. PROPERTY RUNTIME_OUTPUT_NAME
  1738. testwolfcrypt)
  1739. if(WOLFSSL_CRYPT_TESTS_HELP)
  1740. target_compile_options(wolfcrypttest PRIVATE "-DHAVE_WOLFCRYPT_TEST_OPTIONS")
  1741. endif()
  1742. # Build wolfCrypt benchmark executable.
  1743. add_executable(wolfcryptbench
  1744. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  1745. target_include_directories(wolfcryptbench PRIVATE
  1746. ${CMAKE_CURRENT_BINARY_DIR})
  1747. target_link_libraries(wolfcryptbench wolfssl)
  1748. set_property(TARGET wolfcryptbench
  1749. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1750. ${WOLFSSL_OUTPUT_BASE}/wolfcrypt/benchmark)
  1751. set_property(TARGET wolfcryptbench
  1752. PROPERTY RUNTIME_OUTPUT_NAME
  1753. benchmark)
  1754. endif()
  1755. ####################################################
  1756. # Installation
  1757. ####################################################
  1758. include(GNUInstallDirs)
  1759. set(HEADER_EXCLUDE
  1760. "internal.h"
  1761. "cyassl/ctaocrypt/port"
  1762. "wolfssl/wolfcrypt/port/nrf51.h"
  1763. "wolfssl/wolfcrypt/port/arm"
  1764. "wolfssl/wolfcrypt/port/cypress"
  1765. "wolfssl/wolfcrypt/port/Espressif"
  1766. "wolfssl/wolfcrypt/port/iotsafe"
  1767. "wolfssl/wolfcrypt/port/nxp"
  1768. "wolfssl/wolfcrypt/port/pic"
  1769. "wolfssl/wolfcrypt/port/Renesas"
  1770. "wolfssl/wolfcrypt/port/silabs"
  1771. "wolfssl/wolfcrypt/port/st"
  1772. "wolfssl/wolfcrypt/port/ti"
  1773. "wolfssl/wolfcrypt/port/xilinx"
  1774. )
  1775. # TODO: add support for the various ports
  1776. # For distro build don't install options.h.
  1777. # It depends on the architecture and conflicts with Multi-Arch.
  1778. if(BUILD_DISTRO)
  1779. list(APPEND HEADER_EXCLUDE
  1780. "options.h")
  1781. endif()
  1782. if(NOT BUILD_CRYPTOAUTHLIB)
  1783. list(APPEND HEADER_EXCLUDE
  1784. "wolfssl/wolfcrypt/port/atmel")
  1785. endif()
  1786. if(NOT BUILD_AFALG)
  1787. list(APPEND HEADER_EXCLUDE
  1788. "wolfssl/wolfcrypt/port/af_alg")
  1789. endif()
  1790. if(NOT BUILD_KCAPI)
  1791. list(APPEND HEADER_EXCLUDE
  1792. "wolfssl/wolfcrypt/port/kcapi"
  1793. )
  1794. endif()
  1795. if(NOT BUILD_DEVCRYPTO)
  1796. list(APPEND HEADER_EXCLUDE
  1797. "wolfssl/wolfcrypt/port/devcrypto")
  1798. endif()
  1799. if(NOT BUILD_ASYNCCRYPT)
  1800. list(APPEND HEADER_EXCLUDE
  1801. "wolfssl/wolfcrypt/async.h")
  1802. endif()
  1803. if(NOT BUILD_PKCS11)
  1804. list(APPEND HEADER_EXCLUDE
  1805. "wolfssl/wolfcrypt/wc_pkcs11.h"
  1806. "wolfssl/wolfcrypt/pkcs11.h"
  1807. )
  1808. endif()
  1809. if(NOT BUILD_CAVIUM AND NOT BUILD_OCTEON_SYNC)
  1810. list(APPEND HEADER_EXCLUDE
  1811. "wolfssl/wolfcrypt/port/cavium")
  1812. else()
  1813. if(NOT BUILD_CAVIUM)
  1814. list(APPEND HEADER_EXCLUDE
  1815. "wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h")
  1816. endif()
  1817. if(NOT BUILD_OCTEON_SYNC)
  1818. list(APPEND HEADER_EXCLUDE
  1819. "wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h"
  1820. )
  1821. endif()
  1822. endif()
  1823. if(NOT BUILD_INTEL_QA AND NOT BUILD_INTEL_QA_SYNC)
  1824. list(APPEND HEADER_EXCLUDE
  1825. "wolfssl/wolfcrypt/port/intel")
  1826. else()
  1827. if(NOT BUILD_INTEL_QA)
  1828. list(APPEND HEADER_EXCLUDE
  1829. "wolfssl/wolfcrypt/port/intel/quickassist.h"
  1830. "wolfssl/wolfcrypt/port/intel/quickassist_mem.h"
  1831. )
  1832. endif()
  1833. if(NOT BUILD_INTEL_QA_SYNC)
  1834. list(APPEND HEADER_EXCLUDE
  1835. "wolfssl/wolfcrypt/port/intel/quickassist_sync.h")
  1836. endif()
  1837. endif()
  1838. if(NOT BUILD_SP)
  1839. list(APPEND HEADER_EXCLUDE
  1840. "wolfssl/wolfcrypt/sp.h")
  1841. endif()
  1842. if(NOT BUILD_SP_INT)
  1843. list(APPEND HEADER_EXCLUDE
  1844. "wolfssl/wolfcrypt/sp_int.h")
  1845. endif()
  1846. if(NOT BUILD_SELFTEST)
  1847. list(APPEND HEADER_EXCLUDE
  1848. "wolfssl/wolfcrypt/selftest.h")
  1849. endif()
  1850. if(NOT BUILD_FIPS OR BUILD_FIPS_V1)
  1851. list(APPEND HEADER_EXCLUDE
  1852. "wolfssl/wolfcrypt/fips.h")
  1853. endif()
  1854. if(NOT BUILD_QNXCAAM OR BUILD_CAAM)
  1855. list(APPEND HEADER_EXCLUDE
  1856. "wolfssl/wolfcrypt/port/caam"
  1857. )
  1858. endif()
  1859. list(JOIN HEADER_EXCLUDE "|" EXCLUDED_HEADERS_REGEX)
  1860. string(PREPEND EXCLUDED_HEADERS_REGEX "(")
  1861. string(APPEND EXCLUDED_HEADERS_REGEX ")")
  1862. set(INSTALLED_EXAMPLES
  1863. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c
  1864. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-server.c
  1865. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-client-dtls.c
  1866. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-client.c
  1867. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-server-dtls.c
  1868. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c
  1869. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c
  1870. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c
  1871. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  1872. # Install the library
  1873. install(TARGETS wolfssl
  1874. EXPORT wolfssl-targets
  1875. LIBRARY DESTINATION lib
  1876. ARCHIVE DESTINATION lib
  1877. RUNTIME DESTINATION bin
  1878. )
  1879. # Install the headers
  1880. install(DIRECTORY ${WOLFSSL_OUTPUT_BASE}/wolfssl/
  1881. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wolfssl
  1882. FILES_MATCHING PATTERN "*.h"
  1883. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  1884. install(DIRECTORY ${WOLFSSL_OUTPUT_BASE}/cyassl/
  1885. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cyassl
  1886. FILES_MATCHING PATTERN "*.h"
  1887. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  1888. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/
  1889. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wolfssl
  1890. FILES_MATCHING PATTERN "*.h"
  1891. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  1892. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cyassl/
  1893. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cyassl
  1894. FILES_MATCHING PATTERN "*.h"
  1895. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  1896. # Install the examples
  1897. install(FILES ${INSTALLED_EXAMPLES}
  1898. DESTINATION ${CMAKE_INSTALL_DOCDIR}/example)
  1899. # Install README.txt and taoCert.txt
  1900. install(FILES
  1901. ${CMAKE_CURRENT_SOURCE_DIR}/doc/README.txt
  1902. ${CMAKE_CURRENT_SOURCE_DIR}/certs/taoCert.txt
  1903. DESTINATION ${CMAKE_INSTALL_DOCDIR})
  1904. # Install the export set
  1905. install(EXPORT wolfssl-targets
  1906. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wolfssl
  1907. FILE wolfssl-config.cmake)
  1908. # TODO: Distro build + rules for what to include in the distro.
  1909. # See various include.am files.
  1910. set(prefix ${CMAKE_INSTALL_PREFIX})
  1911. set(exec_prefix "\${prefix}")
  1912. set(libdir "\${exec_prefix}/lib")
  1913. set(includedir "\${prefix}/include")
  1914. set(VERSION ${PROJECT_VERSION})
  1915. configure_file(support/wolfssl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc @ONLY)
  1916. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc
  1917. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)