CMakeLists.txt 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  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.2)
  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 4.7.1 LANGUAGES C)
  28. # shared library versioning
  29. # increment if interfaces have been added, removed or changed
  30. set(LIBTOOL_CURRENT 27)
  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. include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/functions.cmake)
  41. ####################################################
  42. # Compiler
  43. ####################################################
  44. # Let CMake choose default compiler
  45. # TODO: See gl_VISIBILITY in visibility.m4. Need to perform
  46. # the same checks.
  47. # TODO: Turn on warnings.
  48. if(APPLE)
  49. # Silence ranlib warning "has no symbols"
  50. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  51. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  52. set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  53. set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  54. endif()
  55. include(CheckIncludeFile)
  56. check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
  57. check_include_file("fcntl.h" HAVE_FCNTL_H)
  58. check_include_file("limits.h" HAVE_LIMITS_H)
  59. check_include_file("netdb.h" HAVE_NETDB_H)
  60. check_include_file("netinet/in.h" HAVE_NETINET_IN_H)
  61. check_include_file("stddef.h" HAVE_STDDEF_H)
  62. check_include_file("time.h" HAVE_TIME_H)
  63. check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  64. check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H)
  65. check_include_file("sys/time.h" HAVE_SYS_TIME_H)
  66. check_include_file("errno.h" HAVE_ERRNO_H)
  67. check_include_file("dlfcn.h" HAVE_DLFCN_H)
  68. check_include_file("inttypes.h" HAVE_INTTYPES_H)
  69. check_include_file("memory.h" HAVE_MEMORY_H)
  70. check_include_file("stdint.h" HAVE_STDINT_H)
  71. check_include_file("stdlib.h" HAVE_STDLIB_H)
  72. check_include_file("string.h" HAVE_STRING_H)
  73. check_include_file("strings.h" HAVE_STRINGS_H)
  74. check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
  75. check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
  76. check_include_file("unistd.h" HAVE_UNISTD_H)
  77. include(CheckFunctionExists)
  78. # TODO: Also check if these functions are declared by the
  79. # expected headers. See comments around
  80. # AC_CHECK_FUNCS/AC_CHECK_DECLS in configure.ac.
  81. check_function_exists("gethostbyname" HAVE_GETHOSTBYNAME)
  82. check_function_exists("getaddrinfo" HAVE_GETADDRINFO)
  83. check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY)
  84. check_function_exists("gmtime_r" HAVE_GMTIME_R)
  85. check_function_exists("inet_ntoa" HAVE_INET_NTOA)
  86. check_function_exists("memset" HAVE_MEMSET)
  87. check_function_exists("socket" HAVE_SOCKET)
  88. check_function_exists("strftime" HAVE_STRFTIME)
  89. include(CheckTypeSize)
  90. check_type_size("__uint128_t" __UINT128_T)
  91. check_type_size("long long" SIZEOF_LONG_LONG)
  92. check_type_size("long" SIZEOF_LONG)
  93. check_type_size("time_t" SIZEOF_TIME_T)
  94. # By default, HAVE___UINT128_T gets defined as TRUE,
  95. # but we want it as 1.
  96. if(HAVE___UINT128_T)
  97. set(HAVE___UINT128_T "1" CACHE INTERNAL "Result of TRY_COMPILE" FORCE)
  98. endif()
  99. include(TestBigEndian)
  100. test_big_endian(WORDS_BIGENDIAN)
  101. # Thread local storage
  102. include(CheckCSourceCompiles)
  103. set(TLS_KEYWORDS "__thread" "__declspec(thread)")
  104. foreach(TLS_KEYWORD IN LISTS TLS_KEYWORDS)
  105. set(TLS_CODE "#include <stdlib.h>
  106. static void foo(void) {
  107. static ${TLS_KEYWORD} int bar\;
  108. exit(1)\;
  109. }
  110. int main() {
  111. return 0\;
  112. }"
  113. )
  114. check_c_source_compiles(${TLS_CODE} THREAD_LS_ON)
  115. if(THREAD_LS_ON)
  116. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_THREAD_LS")
  117. break()
  118. else()
  119. # THREAD_LS_ON is cached after each call to
  120. # check_c_source_compiles, and the function
  121. # won't run subsequent times if the variable
  122. # is in the cache. To make it run again, we
  123. # need to remove the variable from the cache.
  124. unset(THREAD_LS_ON CACHE)
  125. endif()
  126. endforeach()
  127. # TODO: AX_PTHREAD does a lot. Need to implement the
  128. # rest of its logic.
  129. find_package(Threads)
  130. ####################################################
  131. # Cross Compile Example
  132. ####################################################
  133. #set(CMAKE_SYSTEM_NAME Linux)
  134. #set(CMAKE_SYSTEM_PROCESSOR arm)
  135. #set(CMAKE_C_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc")
  136. #set(CMAKE_CXX_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-g++")
  137. #set(CMAKE_SYSROOT "/opt/arm-linux-musleabihf-cross/arm-linux-musleabihf/")
  138. # Example for setting CFLAGS
  139. #set(CMAKE_C_FLAGS "-std=gnu89 ${CMAKE_C_FLAGS}")
  140. # Example for map file and custom linker script
  141. #set(CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=output.map -T\"${CMAKE_CURRENT_SOURCE_DIR}/linker.ld\"")
  142. ####################################################
  143. # Build Options
  144. ####################################################
  145. # TODO: - Debug
  146. # - FIPS
  147. # - Distro
  148. # - Linux Kernel Module
  149. # - Single precision math
  150. # - Enable all
  151. # - Enable all crypto
  152. # - 32-bit mode
  153. # - 16-bit mode
  154. # Support for disabling all ASM
  155. set(WOLFSSL_ASM_HELP_STRING "Enables option for assembly (default: enabled)")
  156. add_option("WOLFSSL_ASM" ${WOLFSSL_ASM_HELP_STRING} "yes" "yes;no")
  157. if(NOT WOLFSSL_ASM)
  158. list(APPEND WOLFSSL_DEFINITIONS
  159. "-DTFM_NO_ASM"
  160. "-DWOLFSSL_NO_ASM")
  161. endif()
  162. # Single threaded
  163. set(WOLFSSL_SINGLE_THREADED_HELP_STRING "Enable wolfSSL single threaded (default: disabled)")
  164. add_option("WOLFSSL_SINGLE_THREADED" ${WOLFSSL_SINGLE_THREADED_HELP_STRING} "no" "yes;no")
  165. # TODO: Logic here isn't complete, yet (see AX_PTHREAD)
  166. if(NOT WOLFSSL_SINGLE_THREADED)
  167. if(CMAKE_USE_PTHREADS_INIT)
  168. list(APPEND WOLFSSL_LINK_LIBS Threads::Threads)
  169. list(APPEND WOLFSSL_DEFINITIONS
  170. "-DHAVE_PTHREAD"
  171. "-D_POSIX_THREADS")
  172. endif()
  173. endif()
  174. # TODO: - DTLS
  175. # - TLS v1.3 Draft 18
  176. # TLS v1.3
  177. set(WOLFSSL_TLS13_HELP_STRING "Enable wolfSSL TLS v1.3 (default: enabled)")
  178. add_option("WOLFSSL_TLS13" ${WOLFSSL_TLS13_HELP_STRING} "yes" "yes;no")
  179. if("${FIPS_VERSION}" STREQUAL "v1")
  180. override_cache(WOLFSSL_TLS13 "no")
  181. endif()
  182. # TODO: Post-handshake authentication
  183. # Hello retry request cookie
  184. # RNG
  185. set(WOLFSSL_RNG_HELP_STRING "Enable compiling and using RNG (default: enabled)")
  186. add_option("WOLFSSL_RNG" ${WOLFSSL_RNG_HELP_STRING} "yes" "yes;no")
  187. if(NOT WOLFSSL_RNG)
  188. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_RNG")
  189. endif()
  190. # TODO: - DTLS-SCTP
  191. # - DTLS multicast
  192. # - OpenSSH
  193. # - OpenVPN
  194. # - Nginx
  195. # - HAProxy
  196. # - wpa_supplicant
  197. # - Fortress
  198. # - libwebsockets
  199. # - IP alternative name
  200. # - Qt
  201. # - SSL bump
  202. # - sniffer
  203. # - Signal
  204. # - OpenSSL coexist
  205. # - OpenSSL compatibility all
  206. # - OpenSSL compatibility extra
  207. # - Max strength
  208. # Harden, enable Timing Resistance and Blinding by default
  209. set(WOLFSSL_HARDEN_HELP_STRING "Enable Hardened build, Enables Timing Resistance and Blinding (default: enabled)")
  210. add_option("WOLFSSL_HARDEN" ${WOLFSSL_HARDEN_HELP_STRING} "yes" "yes;no")
  211. if(WOLFSSL_HARDEN)
  212. list(APPEND WOLFSSL_DEFINITIONS "-DTFM_TIMING_RESISTANT" "-DECC_TIMING_RESISTANT")
  213. if(WOLFSSL_RNG)
  214. list(APPEND WOLFSSL_DEFINITIONS "-DWC_RSA_BLINDING")
  215. endif()
  216. else()
  217. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HARDEN")
  218. endif()
  219. # TODO: - IPv6 test apps
  220. set(WOLFSSL_SLOW_MATH "yes")
  221. # TODO: - Lean PSK
  222. # - Lean TLS
  223. # - Low resource
  224. # - Titan cache
  225. # - Huge cache
  226. # - Big cache
  227. # - Small cache
  228. # - Persistent session cache
  229. # - Persistent cert cache
  230. # - Write duplicate
  231. # - Atomic user record layer
  232. # - Public key callbacks
  233. # - Microchip/Atmel CryptoAuthLib
  234. # AES-CBC
  235. set(WOLFSSL_AESCBC_HELP_STRING "Enable wolfSSL AES-CBC support (default: enabled)")
  236. add_option("WOLFSSL_AESCBC" ${WOLFSSL_AESCBC_HELP_STRING} "yes" "yes;no")
  237. if(NOT WOLFSSL_AESCBC)
  238. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES_CBC")
  239. endif()
  240. # AES-GCM
  241. set(WOLFSSL_AESGCM_HELP_STRING "Enable wolfSSL AES-GCM support (default: enabled)")
  242. add_option("WOLFSSL_AESGCM" ${WOLFSSL_AESGCM_HELP_STRING} "yes" "yes;no;table;small;word32")
  243. # leanpsk and leantls don't need gcm
  244. if(WOLFSSL_LEAN_PSK OR (WOLFSSL_LEAN_TLS AND NOT WOLFSSL_TLS13))
  245. override_cache(WOLFSSL_AESGCM "no")
  246. endif()
  247. if(WOLFSSL_AESGCM)
  248. if("${WOLFSSL_AESGCM}" STREQUAL "word32")
  249. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_WORD32")
  250. override_cache(WOLFSSL_AESGCM "yes")
  251. endif()
  252. if(("${WOLFSSL_AESGCM}" STREQUAL "small") OR WOLFSSL_LOW_RESOURCE)
  253. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_SMALL")
  254. override_cache(WOLFSSL_AESGCM "yes")
  255. endif()
  256. if("${WOLFSSL_AESGCM}" STREQUAL "table")
  257. list(APPEND WOLFSSL_DEFINITIONS "-DGCM_TABLE")
  258. override_cache(WOLFSSL_AESGCM "yes")
  259. endif()
  260. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_AESGCM")
  261. endif()
  262. # TODO: - AES-CCM
  263. # - AES-CTR
  264. # - AES-OFB
  265. # - AES-CFB
  266. # - AES-ARM
  267. # - Xilinx hardened crypto
  268. # - Intel AES-NI
  269. # - Intel ASM
  270. # - Intel RDRAND
  271. # - Linux af_alg
  272. # - Linux dev crpyto calls
  273. # - Camellia
  274. # - MD2
  275. # - NULL cipher
  276. # - RIPEMD
  277. # - BLAKE2
  278. # SHA224
  279. set(SHA224_DEFAULT "no")
  280. if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR
  281. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  282. if(NOT WOLFSSL_AFALG AND NOT WOLFSSL_DEVCRYPTO AND
  283. (NOT WOLFSSL_FIPS OR ("${FIPS_VERSION}" STREQUAL "v2")))
  284. set(SHA224_DEFAULT "yes")
  285. endif()
  286. endif()
  287. set(WOLFSSL_SHA224_HELP_STRING "Enable wolfSSL SHA-224 support (default: enabled on x86_64/aarch64)")
  288. add_option("WOLFSSL_SHA224" ${WOLFSSL_SHA224_HELP_STRING} ${SHA224_DEFAULT} "yes;no")
  289. # SHA3
  290. set(SHA3_DEFAULT "no")
  291. if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR
  292. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  293. if(NOT WOLFSSL_FIPS OR ("${FIPS_VERSION}" STREQUAL "v2"))
  294. set(SHA3_DEFAULT "yes")
  295. endif()
  296. endif()
  297. set(WOLFSSL_SHA3_HELP_STRING "Enable wolfSSL SHA-3 support (default: enabled on x86_64/aarch64)")
  298. add_option("WOLFSSL_SHA3" ${WOLFSSL_SHA3_HELP_STRING} ${SHA3_DEFAULT} "yes;no;small")
  299. # SHAKE256
  300. set(WOLFSSL_SHAKE256_HELP_STRING "Enable wolfSSL SHAKE256 support (default: enabled on x86_64/aarch64)")
  301. add_option("WOLFSSL_SHAKE256" ${WOLFSSL_SHAKE256_HELP_STRING} "no" "yes;no;small")
  302. # SHA512
  303. set(WOLFSSL_SHA512_HELP_STRING "Enable wolfSSL SHA-512 support (default: enabled)")
  304. add_option("WOLFSSL_SHA512" ${WOLFSSL_SHA512_HELP_STRING} "yes" "yes;no")
  305. # options that don't require sha512
  306. if(WOLFSSL_LEAN_PSK OR
  307. WOLFSSL_LEAN_TLS OR
  308. WOLFSSL_32BIT OR
  309. WOLFSSL_16BIT)
  310. override_cache(WOLFSSL_SHA512 "no")
  311. endif()
  312. # options that require sha512
  313. if(WOLFSSL_OPENSSH OR
  314. WOLFSSL_WPAS OR
  315. WOLFSSL_FORTRESS)
  316. override_cache(WOLFSSL_SHA512 "yes")
  317. endif()
  318. if(WOLFSSL_SHA512)
  319. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA512")
  320. endif()
  321. # SHA384
  322. set(WOLFSSL_SHA384_HELP_STRING "Enable wolfSSL SHA-384 support (default: enabled)")
  323. add_option("WOLFSSL_SHA384" ${WOLFSSL_SHA384_HELP_STRING} "yes" "yes;no")
  324. # options that don't require sha384
  325. if(WOLFSSL_LEAN_PSK OR
  326. WOLFSSL_LEAN_TLS OR
  327. WOLFSSL_32BIT OR
  328. WOLFSSL_16BIT)
  329. override_cache(WOLFSSL_SHA384 "no")
  330. endif()
  331. # options that require sha384
  332. if(WOLFSSL_OPENSSH OR
  333. WOLFSSL_WPAS OR
  334. WOLFSSL_FORTRESS)
  335. override_cache(WOLFSSL_SHA384 "yes")
  336. endif()
  337. if(WOLFSSL_SHA384)
  338. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA384")
  339. endif()
  340. # TODO: - Session certs
  341. # - Key generation
  342. # - Cert generation
  343. # - Cert request generation
  344. # - Cert request extension
  345. # - Decoded cert cache
  346. # - SEP
  347. # HKDF
  348. set(WOLFSSL_HKDF_HELP_STRING "Enable HKDF (HMAC-KDF) support (default: disabled)")
  349. add_option("WOLFSSL_HKDF" ${WOLFSSL_HKDF_HELP_STRING} "no" "yes;no")
  350. if(WOLFSSL_TLS13)
  351. override_cache(WOLFSSL_HKDF "yes")
  352. endif()
  353. if(WOLFSSL_HKDF)
  354. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HKDF")
  355. endif()
  356. # TODO: - X9.63 KDF
  357. # DSA
  358. set(WOLFSSL_DSA_HELP_STRING "Enable DSA (default: disabled)")
  359. add_option("WOLFSSL_DSA" ${WOLFSSL_DSA_HELP_STRING} "no" "yes;no")
  360. if(NOT WOLFSSL_DSA AND NOT WOLFSSL_OPENSSH)
  361. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DSA")
  362. endif()
  363. # ECC Shamir
  364. set(WOLFSSL_ECCSHAMIR_HELP_STRING "Enable ECC Shamir (default: enabled)")
  365. add_option("WOLFSSL_ECCSHAMIR" ${WOLFSSL_ECCSHAMIR_HELP_STRING} "yes" "yes;no")
  366. # ECC
  367. set(WOLFSSL_ECC_HELP_STRING "Enable ECC (default: enabled)")
  368. add_option("WOLFSSL_ECC" ${WOLFSSL_ECC_HELP_STRING} "yes" "yes;no;nonblock")
  369. # lean psk doesn't need ecc
  370. if(WOLFSSL_LEAN_PSK)
  371. override_cache(WOLFSSL_ECC "no")
  372. endif()
  373. if(WOLFSSL_OPENSSH OR
  374. WOLFSSL_NGINX OR
  375. WOLFSSL_SIGNAL)
  376. override_cache(WOLFSSL_ECC "yes")
  377. endif()
  378. if(WOLFSSL_ECC)
  379. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ECC" "-DTFM_ECC256")
  380. if(WOLFSSL_ECCSHAMIR AND NOT WOLFSSL_LOW_RESOURCE)
  381. list(APPEND WOLFSSL_DEFINITIONS "-DECC_SHAMIR")
  382. endif()
  383. if("${WOLFSSL_ECC}" STREQUAL "nonblock")
  384. list(APPEND WOLFSSL_DEFINITIONS "-DWC_ECC_NONBLOCK")
  385. endif()
  386. endif()
  387. # TODO: - ECC custom curves
  388. # - Compressed key
  389. # - FP ECC, fixed point cache ECC
  390. # - ECC encrypt
  391. # - PSK
  392. # - Single PSK identity
  393. # CURVE25519
  394. set(WOLFSSL_CURVE25519_SMALL "no")
  395. set(WOLFSSL_CURVE25519_HELP_STRING "Enable Curve25519 (default: disabled)")
  396. add_option("WOLFSSL_CURVE25519" ${WOLFSSL_CURVE25519_HELP_STRING} "no" "yes;no;small;no128bit")
  397. if(WOLFSSL_OPENSSH)
  398. override_cache(WOLFSSL_CURVE25519 "yes")
  399. endif()
  400. if(WOLFSSL_CURVE25519)
  401. if("${WOLFSSL_CURVE25519}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  402. list(APPEND WOLFSSL_DEFINITIONS "-DCURVE25519_SMALL")
  403. set(WOLFSSL_CURVE25519_SMALL "yes")
  404. endif()
  405. if("${WOLFSSL_CURVE25519}" STREQUAL "no128bit" OR WOLFSSL_32BIT)
  406. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CURVED25519_128BIT")
  407. endif()
  408. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CURVE25519")
  409. set(WOLFSSL_FEMATH "yes")
  410. endif()
  411. # ED25519
  412. set(WOLFSSL_ED25519_SMALL "no")
  413. set(WOLFSSL_ED25519_HELP_STRING "Enable ED25519 (default: disabled)")
  414. add_option("WOLFSSL_ED25519" ${WOLFSSL_ED25519_HELP_STRING} "no" "yes;no")
  415. if(WOLFSSL_OPENSSH)
  416. override_cache(WOLFSSL_ED25519 "yes")
  417. endif()
  418. if(WOLFSSL_ED25519 AND NOT WOLFSSL_32BIT)
  419. if("${WOLFSSL_ED25519}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  420. list(APPEND WOLFSSL_DEFINITIONS "-DED25519_SMALL")
  421. set(WOLFSSL_ED25519_SMALL "yes")
  422. set(WOLFSSL_CURVE25519_SMALL "yes")
  423. endif()
  424. if(NOT WOLFSSL_SHA512)
  425. message(FATAL_ERROR "cannot enable ed25519 without enabling sha512.")
  426. endif()
  427. set(WOLFSSL_FEMATH "yes")
  428. set(WOLFSSL_GEMATH "yes")
  429. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ED25519")
  430. endif()
  431. # CURVE448
  432. set(WOLFSSL_CURVE448_SMALL "no")
  433. set(WOLFSSL_CURVE448_HELP_STRING "Enable Curve448 (default: disabled)")
  434. add_option("WOLFSSL_CURVE448" ${WOLFSSL_CURVE448_HELP_STRING} "no" "yes;no;small")
  435. if(WOLFSSL_CURVE448)
  436. if("${WOLFSSL_CURVE448}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  437. list(APPEND WOLFSSL_DEFINITIONS "-DCURVE448_SMALL")
  438. set(WOLFSSL_CURVE448_SMALL "yes")
  439. endif()
  440. if("${WOLFSSL_CURVE448}" STREQUAL "no128bit" OR WOLFSSL_32BIT)
  441. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CURVED448_128BIT")
  442. endif()
  443. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CURVE448")
  444. set(WOLFSSL_FE448 "yes")
  445. endif()
  446. # ED448
  447. set(WOLFSSL_ED448_SMALL "no")
  448. set(WOLFSSL_ED448_HELP_STRING "Enable ED448 (default: disabled)")
  449. add_option("WOLFSSL_ED448" ${WOLFSSL_ED448_HELP_STRING} "no" "yes;no;small")
  450. if(WOLFSSL_ED448 AND NOT WOLFSSL_32BIT)
  451. if("${WOLFSSL_ED448}" STREQUAL "small" OR WOLFSSL_LOW_RESOURCE)
  452. list(APPEND WOLFSSL_DEFINITIONS "-DED448_SMALL")
  453. set(WOLFSSL_ED448_SMALL "yes")
  454. set(WOLFSSL_CURVE448_SMALL "yes")
  455. endif()
  456. if(NOT WOLFSSL_SHA512)
  457. message(FATAL_ERROR "cannot enable ed448 without enabling sha512.")
  458. endif()
  459. set(WOLFSSL_FE448 "yes")
  460. set(WOLFSSL_GE448 "yes")
  461. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ED448")
  462. # EdDSA448 requires SHAKE256 which requires SHA-3
  463. override_cache(WOLFSSL_SHAKE256 "yes")
  464. endif()
  465. # Error strings
  466. set(WOLFSSL_ERROR_STRINGS_HELP_STRING "Enable error strings table (default: enabled)")
  467. add_option("WOLFSSL_ERROR_STRINGS" ${WOLFSSL_ERROR_STRINGS_HELP_STRING} "yes" "yes;no")
  468. if(NOT WOLFSSL_ERROR_STRINGS)
  469. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_STRINGS")
  470. else()
  471. # turn off error strings if leanpsk or leantls o
  472. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  473. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_STRINGS")
  474. override_cache(WOLFSSL_ERROR_STRINGS "no")
  475. endif()
  476. endif()
  477. # Error queue
  478. set(WOLFSSL_ERROR_QUEUE_HELP_STRING "Enables adding nodes to error queue when compiled with OPENSSL_EXTRA (default: enabled)")
  479. add_option("WOLFSSL_ERROR_QUEUE" ${WOLFSSL_ERROR_QUEUE_HELP_STRING} "yes" "yes;no")
  480. if(NOT WOLFSSL_ERROR_QUEUE)
  481. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ERROR_QUEUE")
  482. endif()
  483. # Old TLS
  484. set(WOLFSSL_OLD_TLS_HELP_STRING "Enable old TLS versions < 1.2 (default: enabled)")
  485. add_option("WOLFSSL_OLD_TLS" ${WOLFSSL_OLD_TLS_HELP_STRING} "yes" "yes;no")
  486. if(NOT WOLFSSL_OLD_TLS)
  487. list(APPEND WOLFSSL_DEFINITIONS "-DNO_OLD_TLS")
  488. else()
  489. # turn off old if leanpsk or leantls on
  490. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  491. list(APPEND WOLFSSL_DEFINITIONS "-DNO_OLD_TLS")
  492. override_cache(WOLFSSL_OLD_TLS "no")
  493. endif()
  494. endif()
  495. # TLSv1.2
  496. set(WOLFSSL_TLSV12_HELP_STRING "Enable TLS versions 1.2 (default: enabled)")
  497. add_option("WOLFSSL_TLSV12" ${WOLFSSL_TLSV12_HELP_STRING} "yes" "yes;no")
  498. if(NOT WOLFSSL_TLSV12)
  499. list(APPEND WOLFSSL_DEFINITIONS
  500. "-DWOLFSSL_NO_TLS12"
  501. "-DNO_OLD_TLS")
  502. endif()
  503. # TODO: - TLSv1.0
  504. # - SSLv3
  505. # - Stack size
  506. # - Stack size verbose
  507. # Memory
  508. set(WOLFSSL_MEMORY_HELP_STRING "Enable memory callbacks (default: enabled)")
  509. add_option("WOLFSSL_MEMORY" ${WOLFSSL_MEMORY_HELP_STRING} "yes" "yes;no")
  510. if(NOT WOLFSSL_MEMORY)
  511. list(APPEND WOLFSSL_DEFINITIONS "-DNO_WOLFSSL_MEMORY")
  512. else()
  513. # turn off memory cb if leanpsk or leantls on
  514. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  515. # but don't turn on NO_WOLFSSL_MEMORY because using own
  516. override_cache(WOLFSSL_MEMORY "no")
  517. endif()
  518. endif()
  519. # TODO: - Track memory
  520. # - Memory log
  521. # - Stack log
  522. # RSA
  523. set(WOLFSSL_RSA_HELP_STRING "Enable RSA (default: enabled)")
  524. add_option("WOLFSSL_RSA" ${WOLFSSL_RSA_HELP_STRING} "yes" "yes;no")
  525. if(NOT WOLFSSL_RSA)
  526. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RSA")
  527. else()
  528. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  529. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RSA")
  530. override_cache(WOLFSSL_RSA "no")
  531. endif()
  532. endif()
  533. # OAEP
  534. set(WOLFSSL_OAEP_HELP_STRING "Enable RSA OAEP (default: enabled)")
  535. add_option("WOLFSSL_OAEP" ${WOLFSSL_OAEP_HELP_STRING} "yes" "yes;no")
  536. if(NOT WOLFSSL_OAEP)
  537. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_RSA_OAEP")
  538. endif()
  539. # TODO: - RSA public only
  540. # - RSA verify inline only
  541. # RSA-PSS
  542. set(WOLFSSL_RSA_PSS_HELP_STRING "Enable RSA-PSS (default: disabled)")
  543. add_option("WOLFSSL_RSA_PSS" ${WOLFSSL_RSA_PSS_HELP_STRING} "no" "yes;no")
  544. if(NOT WOLFSSL_RSA)
  545. override_cache(WOLFSSL_RSA_PSS "no")
  546. else()
  547. if(WOLFSSL_TLS13)
  548. override_cache(WOLFSSL_RSA_PSS "yes")
  549. endif()
  550. endif()
  551. if(WOLFSSL_RSA_PSS)
  552. list(APPEND WOLFSSL_DEFINITIONS "-DWC_RSA_PSS")
  553. endif()
  554. # DH
  555. set(WOLFSSL_DH_HELP_STRING "Enable DH (default: enabled)")
  556. add_option("WOLFSSL_DH" ${WOLFSSL_DH_HELP_STRING} "yes" "yes;no")
  557. if(WOLFSSL_OPENSSH)
  558. override_cache(WOLFSSL_DH "yes")
  559. endif()
  560. if(NOT WOLFSSL_DH)
  561. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DH")
  562. else()
  563. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  564. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DH")
  565. override_cache(WOLFSSL_DH "no")
  566. endif()
  567. endif()
  568. # TODO: - Anonymous
  569. # ASN
  570. # turn off asn, which means no certs, no rsa, no dsa, no ecc,
  571. # and no big int (unless dh is on)
  572. set(WOLFSSL_ASN_HELP_STRING "Enable ASN (default: enabled)")
  573. add_option("WOLFSSL_ASN" ${WOLFSSL_ASN_HELP_STRING} "yes" "yes;no")
  574. if(NOT WOLFSSL_ASN)
  575. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ASN" "-DNO_CERTS")
  576. if(NOT WOLFSSL_DH AND NOT WOLFSSL_ECC)
  577. # DH and ECC need bigint
  578. list(APPEND WOLFSSL_DEFINITIONS "-DNO_BIG_INT")
  579. endif()
  580. else()
  581. # turn off ASN if leanpsk on
  582. if(WOLFSSL_LEAN_PSK)
  583. list(APPEND WOLFSSL_DEFINITIONS
  584. "-DNO_ASN"
  585. "-DNO_CERTS"
  586. "-DNO_BIG_INT")
  587. override_cache(WOLFSSL_ASN "no")
  588. else()
  589. if("${WOLFSSL_ASN}" STREQUAL "nocrypt")
  590. list(APPEND WOLFSSL_DEFINITIONS "-DNO_ASN_CRYPT")
  591. # TODO: verify that this is correct
  592. override_cache(WOLFSSL_PWDBASED "no")
  593. endif()
  594. endif()
  595. endif()
  596. if(WOLFSSL_RSA AND NOT WOLFSSL_RSA_VFY AND NOT WOLFSSL_ASN)
  597. message(FATAL_ERROR "please disable rsa if disabling asn.")
  598. endif()
  599. if(WOLFSSL_DSA AND NOT WOLFSSL_ASN)
  600. message(FATAL_ERROR "please disable dsa if disabling asn.")
  601. endif()
  602. # DH and ECC need bigint
  603. if(NOT WOLFSSL_ASN AND
  604. NOT WOLFSSL_DH AND
  605. NOT WOLFSSL_ECC AND
  606. NOT WOLFSSL_RSA)
  607. override_cache(WOLFSSL_FAST_MATH "no")
  608. set(WOLFSSL_SLOWMATH "no")
  609. endif()
  610. # AES
  611. set(WOLFSSL_AES_HELP_STRING "Enable AES (default: enabled)")
  612. add_option("WOLFSSL_AES" ${WOLFSSL_AES_HELP_STRING} "yes" "yes;no")
  613. if(NOT WOLFSSL_AES)
  614. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
  615. if(WOLFSSL_FORTRESS)
  616. message(FATAL_ERROR "fortress requires aes")
  617. endif()
  618. if(WOLFSSL_ECC_ENCRYPT)
  619. message(FATAL_ERROR "cannot enable eccencrypt and hkdf without aes.")
  620. endif()
  621. if(WOLFSSL_AESGCM)
  622. message(FATAL_ERROR "AESGCM requires AES.")
  623. endif()
  624. if(WOLFSSL_AESCCM)
  625. message(FATAL_ERROR "AESCCM requires AES.")
  626. endif()
  627. if(WOLFSSL_AESCTR)
  628. message(FATAL_ERROR "AESCTR requires AES.")
  629. endif()
  630. else()
  631. if(WOLFSSL_LEAN_PSK)
  632. list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
  633. override_cache(WOLFSSL_AES "no")
  634. endif()
  635. endif()
  636. # Coding
  637. set(WOLFSSL_CODING_HELP_STRING "Enable coding base 16/64 (default: enabled)")
  638. add_option("WOLFSSL_CODING" ${WOLFSSL_CODING_HELP_STRING} "yes" "yes;no")
  639. if(NOT WOLFSSL_CODING)
  640. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CODING")
  641. else()
  642. # turn off CODING if leanpsk on
  643. if(WOLFSSL_LEAN_PSK)
  644. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CODING")
  645. override_cache(WOLFSSL_CODING "no")
  646. endif()
  647. endif()
  648. # Base64
  649. set(BASE64_ENCODE_DEFAULT "no")
  650. if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  651. set(BASE64_ENCODE_DEFAULT "yes")
  652. endif()
  653. set(WOLFSSL_BASE64_ENCODE_HELP_STRING "Enable Base64 encoding (default: enabled on x86_64)")
  654. add_option("WOLFSSL_BASE64_ENCODE" ${WOLFSSL_BASE64_ENCODE_HELP_STRING} ${BASE64_ENCODE_DEFAULT} "yes;no")
  655. if(WOLFSSL_BASE64_ENCODE)
  656. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_BASE64_ENCODE")
  657. endif()
  658. # TODO: - Base16
  659. # DES3
  660. set(WOLFSSL_DES3_HELP_STRING "Enable DES3 (default: disabled)")
  661. add_option("WOLFSSL_DES3" ${WOLFSSL_DES3_HELP_STRING} "no" "yes;no")
  662. if(WOLFSSL_OPENSSH OR
  663. WOLFSSL_QT OR
  664. WOLFSSL_OPENVPN OR
  665. WOLFSSL_WPAS)
  666. override_cache(WOLFSSL_DES3 "yes")
  667. endif()
  668. # TODO: - IDEA
  669. # ARC4
  670. set(WOLFSSL_ARC4_HELP_STRING "Enable ARC4 (default: disabled)")
  671. add_option("WOLFSSL_ARC4" ${WOLFSSL_ARC4_HELP_STRING} "no" "yes;no")
  672. if(WOLFSSL_OPENSSH OR WOLFSSL_WPAS)
  673. override_cache(WOLFSSL_ARC4 "yes")
  674. endif()
  675. if(NOT WOLFSSL_ARC4)
  676. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RC4")
  677. else()
  678. # turn off ARC4 if leanpsk or leantls on
  679. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  680. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RC4")
  681. override_cache(WOLFSSL_ARC4 "no")
  682. endif()
  683. endif()
  684. # MD5
  685. set(WOLFSSL_MD5_HELP_STRING "Enable MD5 (default: enabled)")
  686. add_option("WOLFSSL_MD5" ${WOLFSSL_MD5_HELP_STRING} "yes" "yes;no")
  687. if(NOT WOLFSSL_MD5)
  688. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD5" "-DNO_OLD_TLS")
  689. else()
  690. # turn off MD5 if leanpsk or leantls on
  691. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  692. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD5" "-DNO_OLD_TLS")
  693. override_cache(WOLFSSL_MD5 "no")
  694. endif()
  695. endif()
  696. # SHA
  697. set(WOLFSSL_SHA_HELP_STRING "Enable SHA (default: enabled)")
  698. add_option("WOLFSSL_SHA" ${WOLFSSL_SHA_HELP_STRING} "yes" "yes;no")
  699. if(NOT WOLFSSL_SHA)
  700. list(APPEND WOLFSSL_DEFINITIONS "-DNO_SHA" "-DNO_OLD_TLS")
  701. else()
  702. # turn off SHA if leanpsk or leantls on
  703. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  704. list(APPEND WOLFSSL_DEFINITIONS "-DNO_SHA" "-DNO_OLD_TLS")
  705. override_cache(WOLFSSL_SHA "no")
  706. endif()
  707. endif()
  708. # TODO: - CMAC
  709. # - AES-XTS
  710. # - Web server
  711. # - Web client
  712. # HC128
  713. set(WOLFSSL_HC128_HELP_STRING "Enable HC-128 (default: disabled)")
  714. add_option("WOLFSSL_HC128" ${WOLFSSL_HC128_HELP_STRING} "no" "yes;no")
  715. if(NOT WOLFSSL_HC128)
  716. list(APPEND WOLFSSL_DEFINITIONS "-DNO_HC128")
  717. else()
  718. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HC128")
  719. endif()
  720. # RABBIT
  721. if(NOT WOLFSSL_RABBIT)
  722. list(APPEND WOLFSSL_DEFINITIONS "-DNO_RABBIT")
  723. else()
  724. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_RABBIT")
  725. endif()
  726. # TODO: - RC2
  727. # - FIPS, again (there's more logic for FIPS after RABBIT in configure.ac)
  728. # - Selftest
  729. # SHA224
  730. if(WOLFSSL_SHA224)
  731. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA224")
  732. endif()
  733. # SHA3
  734. if("${WOLFSSL_SHA3}" STREQUAL "small")
  735. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA3_SMALL")
  736. override_cache(WOLFSSL_SHA3 "yes")
  737. endif()
  738. if(WOLFSSL_SHA3 AND NOT WOLFSSL_32BIT)
  739. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHA3")
  740. endif()
  741. # SHAKE256
  742. if(NOT WOLFSSL_SHAKE256)
  743. override_cache(WOLFSSL_SHAKE256 ${WOLFSSL_SHA3})
  744. endif()
  745. if(WOLFSSL_SHAKE256)
  746. if(NOT WOLFSSL_32BIT)
  747. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SHAKE256")
  748. if(NOT WOLFSSL_SHA3)
  749. message(FATAL_ERROR "Must have SHA-3 enabled: --enable-sha3")
  750. endif()
  751. endif()
  752. endif()
  753. # POLY1305
  754. set(POLY1305_DEFAULT "yes")
  755. if(WOLFSSL_FIPS)
  756. set(POLY1305_DEFAULT "no")
  757. endif()
  758. set(WOLFSSL_POLY1305_HELP_STRING "Enable wolfSSL POLY1305 support (default: enabled)")
  759. add_option("WOLFSSL_POLY1305" ${WOLFSSL_POLY1305_HELP_STRING} ${POLY1305_DEFAULT} "yes;no")
  760. # leanpsk and leantls don't need poly1305
  761. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  762. override_cache(WOLFSSL_POLY1305 "no")
  763. endif()
  764. if(WOLFSSL_POLY1305)
  765. list(APPEND WOLFSSL_DEFINITIONS
  766. "-DHAVE_POLY1305"
  767. "-DHAVE_ONE_TIME_AUTH")
  768. endif()
  769. # CHACHA
  770. set(CHACHA_DEFAULT "yes")
  771. if(WOLFSSL_FIPS)
  772. set(CHACHA_DEFAULT "no")
  773. endif()
  774. set(WOLFSSL_CHACHA_HELP_STRING "Enable CHACHA (default: enabled). Use `=noasm` to disable ASM AVX/AVX2 speedups")
  775. add_option("WOLFSSL_CHACHA" ${WOLFSSL_CHACHA_HELP_STRING} ${CHACHA_DEFAULT} "yes;no;noasm")
  776. # leanpsk and leantls don't need chacha
  777. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  778. override_cache(WOLFSSL_CHACHA "no")
  779. endif()
  780. if(("${WOLFSSL_CHACHA}" STREQUAL "noasm") OR NOT WOLFSSL_ASM)
  781. list(APPEND WOLFSSL_DEFINITIONS "-DNO_CHACHA_ASM")
  782. endif()
  783. if(NOT ("${WOLFSSL_CHACHA}" STREQUAL "noasm") AND WOLFSSL_CHACHA)
  784. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CHACHA")
  785. endif()
  786. # TODO: - XCHACHA
  787. # Hash DRBG
  788. set(WOLFSSL_HASH_DRBG_HELP_STRING "Enable Hash DRBG support (default: enabled)")
  789. add_option("WOLFSSL_HASH_DRBG" ${WOLFSSL_HASH_DRBG_HELP_STRING} "yes" "yes;no")
  790. if(WOLFSSL_HASH_DRBG)
  791. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HASHDRBG")
  792. else()
  793. # turn on Hash DRBG if FIPS is on
  794. if(WOLFSSL_FIPS)
  795. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_HASHDRBG")
  796. override_cache(WOLFSSL_HASH_DRBG "yes")
  797. else()
  798. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_HASHDRBG")
  799. endif()
  800. endif()
  801. # Filesystem
  802. if(WOLFSSL_LINUX_KM)
  803. set(FILESYSTEM_DEFAULT "no")
  804. else()
  805. set(FILESYSTEM_DEFAULT "yes")
  806. endif()
  807. set(WOLFSSL_FILESYSTEM_HELP_STRING "Enable Filesystem support (default: enabled)")
  808. add_option("WOLFSSL_FILESYSTEM" ${WOLFSSL_FILESYSTEM_HELP_STRING} ${FILESYSTEM_DEFAULT} "yes;no")
  809. if(NOT WOLFSSL_FILESYSTEM)
  810. list(APPEND WOLFSSL_DEFINITIONS "-DNO_FILESYSTEM")
  811. else()
  812. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  813. list(APPEND WOLFSSL_DEFINITIONS "-DNO_FILESYSTEM")
  814. override_cache(WOLFSSL_FILESYSTEM "no")
  815. endif()
  816. endif()
  817. # Inline function support
  818. set(WOLFSSL_INLINE_HELP_STRING "Enable inline functions (default: enabled)")
  819. add_option("WOLFSSL_INLINE" ${WOLFSSL_INLINE_HELP_STRING} "yes" "yes;no")
  820. if(NOT WOLFSSL_INLINE)
  821. list(APPEND WOLFSSL_DEFINITIONS "-DNO_INLINE")
  822. endif()
  823. # TODO: - OCSP
  824. # - OCSP stapling
  825. # - OCSP stapling v2
  826. # - CRL
  827. # - CRL monitor
  828. # - User crypto
  829. # - NTRU
  830. # - QSH
  831. # - Whitewood netRandom client library
  832. # - SNI
  833. # - Max fragment length
  834. # - ALPN
  835. # - Trusted CA indication
  836. # - Truncated HMAC
  837. # - Renegotiation indication
  838. # - Secure renegotiation
  839. # - Fallback SCSV
  840. # Supported elliptic curves extensions
  841. set(WOLFSSL_SUPPORTED_CURVES_HELP_STRING "Enable Supported Elliptic Curves (default: enabled)")
  842. add_option("WOLFSSL_SUPPORTED_CURVES" ${WOLFSSL_SUPPORTED_CURVES_HELP_STRING} "yes" "yes;no")
  843. if(WOLFSSL_SUPPORTED_CURVES)
  844. if(NOT WOLFSSL_ECC AND NOT WOLFSSL_CURVE25519 AND NOT WOLFSSL_CURVE448)
  845. override_cache(WOLFSSL_SUPPORTED_CURVES "no")
  846. else()
  847. list(APPEND WOLFSSL_DEFINITIONS
  848. "-DHAVE_TLS_EXTENSIONS"
  849. "-DHAVE_SUPPORTED_CURVES")
  850. endif()
  851. endif()
  852. # Diffie-Hellman
  853. if(WOLFSSL_DH)
  854. if(WOLFSSL_TLS13 OR WOLFSSL_SUPPORTED_CURVES)
  855. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_FFDHE_2048")
  856. endif()
  857. endif()
  858. # TODO: - FFDHE params only
  859. # TLS 1.3 Requires either ECC or (RSA/DH), or CURVE25519/ED25519 or CURVE448/ED448
  860. if (NOT WOLFSSL_ECC AND
  861. (NOT WOLFSSL_RSA OR NOT WOLFSSL_DH) AND
  862. (NOT WOLFSSL_CURVE25519 OR NOT WOLFSSL_ED25519) AND
  863. (NOT WOLFSSL_CURVE448 AND NOT WOLFSSL_ED448))
  864. override_cache(WOLFSSL_TLS13 "no")
  865. endif()
  866. if (WOLFSSL_TLS13)
  867. list(APPEND WOLFSSL_DEFINITIONS
  868. "-DWOLFSSL_TLS13"
  869. "-DHAVE_TLS_EXTENSIONS"
  870. "-DHAVE_SUPPORTED_CURVES")
  871. endif()
  872. # TODO: - Session ticket
  873. # Extended master secret extension
  874. set(WOLFSSL_EXTENDED_MASTER_HELP_STRING "Enable Extended Master Secret (default: enabled)")
  875. add_option("WOLFSSL_EXTENDED_MASTER" ${WOLFSSL_EXTENDED_MASTER_HELP_STRING} "yes" "yes;no")
  876. if(WOLFSSL_EXTENDED_MASTER)
  877. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_EXTENDED_MASTER")
  878. endif()
  879. # TODO: - TLS extensions
  880. # - Early data handshake
  881. # - PKCS7
  882. # - wolfSSH options
  883. # - SCEP
  884. # - Secure remote password
  885. # - Indefinite length encoded messages
  886. # - Small stack cache
  887. # - Small stack
  888. # - Valgrind
  889. # - Test certs
  890. # - I/O pool example
  891. # - Certificate service
  892. # - wolfSSL JNI
  893. # - lighttpd/lighty
  894. # - Asio
  895. # - Apache HTTPD
  896. # Encrypt-then-mac
  897. set(WOLFSSL_ENC_THEN_MAC_HELP_STRING "Enable Encryptr-Then-Mac extension (default: enabled)")
  898. add_option("WOLFSSL_ENC_THEN_MAC" ${WOLFSSL_ENC_THEN_MAC_HELP_STRING} "yes" "yes;no")
  899. if(WOLFSSL_APACHE_HTTPD)
  900. override_cache(WOLFSSL_ENC_THEN_MAC "no")
  901. endif()
  902. if(WOLFSSL_TLSX)
  903. override_cache(WOLFSSL_ENC_THEN_MAC "yes")
  904. endif()
  905. if(WOLFSSL_SNIFFER)
  906. override_cache(WOLFSSL_ENC_THEN_MAC "no")
  907. endif()
  908. # stunnel Support
  909. # TODO: rest of stunnel support
  910. set(WOLFSSL_STUNNEL_HELP_STRING "Enable stunnel (default: disabled)")
  911. add_option("WOLFSSL_STUNNEL" ${WOLFSSL_STUNNEL_HELP_STRING} "no" "yes;no")
  912. if(NOT WOLFSSL_PSK AND
  913. NOT WOLFSSL_LEAN_PSK AND
  914. NOT WOLFSSL_STUNNEL)
  915. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PSK")
  916. endif()
  917. if(WOLFSSL_ENC_THEN_MAC)
  918. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ENCRYPT_THEN_MAC")
  919. endif()
  920. # MD4
  921. set(WOLFSSL_MD4_HELP_STRING "Enable MD4 (default: disabled)")
  922. add_option("WOLFSSL_MD4" ${WOLFSSL_MD4_HELP_STRING} "no" "yes;no")
  923. if(NOT WOLFSSL_MD4)
  924. # turn on MD4 if using stunnel
  925. if(WOLFSSL_STUNNEL OR WOLFSSL_WPAS)
  926. override_cache(WOLFSSL_MD4 "yes")
  927. else()
  928. list(APPEND WOLFSSL_DEFINITIONS "-DNO_MD4")
  929. endif()
  930. endif()
  931. # TODO: - Encrypted keys
  932. # PWDBASED has to come after certservice since we want it on w/o explicit on
  933. # PWDBASED
  934. set(WOLFSSL_PWDBASED_HELP_STRING "Enable PWDBASED (default: disabled)")
  935. add_option("WOLFSSL_PWDBASED" ${WOLFSSL_PWDBASED_HELP_STRING} "no" "yes;no")
  936. if(NOT WOLFSSL_PWDBASED)
  937. if(WOLFSSL_OPENSSLEXTRA OR
  938. WOLFSSL_OPENSSLALL OR
  939. WOLFSSL_WEBSERVER OR
  940. WOLFSSL_ENC_KEYS)
  941. # opensslextra, opensslall, webserver, and enckeys needs pwdbased
  942. override_cache(WOLFSSL_PWDBASED "yes")
  943. else()
  944. list(APPEND WOLFSSL_DEFINITIONS "-DNO_PWDBASED")
  945. endif()
  946. endif()
  947. # TODO: - SCRYPT
  948. # - wolfCrypt only
  949. # fastmath
  950. set(FASTMATH_DEFAULT "no")
  951. if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR
  952. ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
  953. set(FASTMATH_DEFAULT "yes")
  954. endif()
  955. if(WOLFSSL_LINUXKM_DEFAULTS)
  956. set(FASTMATH_DEFAULT "no")
  957. endif()
  958. if(WOLFSSL_SP_MATH)
  959. set(FASTMATH_DEFAULT "no")
  960. endif()
  961. set(WOLFSSL_FAST_MATH_HELP_STRING "Enable fast math ops (default: enabled on x86_64/aarch64)")
  962. add_option("WOLFSSL_FAST_MATH" ${WOLFSSL_FAST_MATH_HELP_STRING} ${FASTMATH_DEFAULT} "yes;no")
  963. if(WOLFSSL_FAST_MATH)
  964. # turn off fastmath if leanpsk on or asn off (w/o DH and ECC)
  965. if(WOLFSSL_LEAN_PSK OR NOT WOLFSSL_ASN)
  966. if(NOT WOLFSSL_DH AND
  967. NOT WOLFSSL_ECC AND
  968. NOT WOLFSSL_RSA)
  969. override_cache(WOLFSSL_FAST_MATH "no")
  970. else()
  971. list(APPEND WOLFSSL_DEFINITIONS "-DUSE_FAST_MATH")
  972. set(WOLFSSL_SLOWMATH "no")
  973. endif()
  974. else()
  975. list(APPEND WOLFSSL_DEFINITIONS "-DUSE_FAST_MATH")
  976. set(WOLFSSL_SLOWMATH "no")
  977. endif()
  978. if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  979. # Have settings.h set FP_MAX_BITS higher if user didn't set directly
  980. list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_X86_64_BUILD")
  981. endif()
  982. endif()
  983. # TODO: - Fast huge math
  984. # Enable examples, used to disable examples
  985. if(WOLFSSL_LINUX_KM)
  986. set(EXAMPLES_DEFAULT "no")
  987. else()
  988. set(EXAMPLES_DEFAULT "yes")
  989. endif()
  990. set(WOLFSSL_EXAMPLES_HELP_STRING "Enable examples (default: enabled)")
  991. add_option("WOLFSSL_EXAMPLES" ${WOLFSSL_EXAMPLES_HELP_STRING} ${EXAMPLES_DEFAULT} "yes;no")
  992. if(NOT WOLFSSL_FILESYSTEM OR
  993. NOT WOLFSSL_INLINE OR
  994. WOLFSSL_CRYPT_ONLY)
  995. override_cache(WOLFSSL_EXAMPLES "no")
  996. endif()
  997. # Enable wolfCrypt test and benchmark
  998. if(WOLFSSL_LINUX_KM)
  999. set(CRYPT_TESTS_DEFAULT "no")
  1000. else()
  1001. set(CRYPT_TESTS_DEFAULT "yes")
  1002. endif()
  1003. set(WOLFSSL_CRYPT_TESTS_HELP_STRING "Enable Crypt Bench/Test (default: enabled)")
  1004. add_option("WOLFSSL_CRYPT_TESTS" ${WOLFSSL_CRYPT_TESTS_HELP_STRING} ${CRYPT_TESTS_DEFAULT} "yes;no")
  1005. # TODO: - LIBZ
  1006. # - PKCS#11
  1007. # - PKCS#12
  1008. # - Cavium
  1009. # - Cavium V
  1010. # - Cavium Octeon
  1011. # - Intel QuickAssist
  1012. # - SP ASM (and other SP logic)
  1013. # - Fast RSA
  1014. # - Static memory use
  1015. # - Microchip API
  1016. # - Asynchronous crypto
  1017. # Asynchronous threading
  1018. set(WOLFSSL_ASYNC_THREADS_HELP_STRING "Enable Asynchronous Threading (default: enabled)")
  1019. add_option("WOLFSSL_ASYNC_THREADS" ${WOLFSSL_ASYNC_THREADS_HELP_STRING} "yes" "yes;no")
  1020. if(WOLFSSL_ASYNC_CRYPT AND WOLFSSL_ASYNC_THREADS)
  1021. if(CMAKE_USE_PTHREADS_INIT)
  1022. override_cache(WOLFSSL_ASYNC_THREADS "yes")
  1023. else()
  1024. override_cache(WOLFSSL_ASYNC_THREADS "no")
  1025. endif()
  1026. else()
  1027. override_cache(WOLFSSL_ASYNC_THREADS "no")
  1028. endif()
  1029. if(WOLFSSL_ASYNC_THREADS)
  1030. list(APPEND WOLFSSL_LINK_LIBS Threads::Threads)
  1031. list(APPEND WOLFSSL_DEFINITIONS "-D_GNU_SOURCE")
  1032. else()
  1033. list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_ASYNC_THREADING")
  1034. endif()
  1035. # TODO: - cryptodev
  1036. # - cryptocb
  1037. # - Session export
  1038. # - AES key wrap
  1039. set(WOLFSSL_OLD_NAMES_HELP_STRING "Keep backwards compat with old names (default: enabled)")
  1040. add_option("WOLFSSL_OLD_NAMES" ${WOLFSSL_OLD_NAMES_HELP_STRING} "yes" "yes;no")
  1041. if(NOT WOLFSSL_OLD_NAMES AND NOT WOLFSSL_OPENSSL_COEXIST)
  1042. list(APPEND WOLFSSL_DEFINITIONS
  1043. "-DNO_OLD_RNGNAME"
  1044. "-DNO_OLD_WC_NAMES"
  1045. "-DNO_OLD_SSL_NAMES"
  1046. "-DNO_OLD_SHA_NAMES")
  1047. endif()
  1048. # TODO: - Memory tests
  1049. # - Hash flags
  1050. # Support for enabling setting default DH parameters
  1051. set(WOLFSSL_DH_DEFAULT_PARAMS_HELP_STRING "Enables option for default dh parameters (default: disabled)")
  1052. add_option("WOLFSSL_DH_DEFAULT_PARAMS" ${WOLFSSL_DH_DEFAULT_PARAMS_HELP_STRING} "no" "yes;no")
  1053. if(WOLFSSL_DH_DEFAULT_PARAMS OR NOT WOLFSSL_QT)
  1054. override_cache(WOLFSSL_DH_DEFAULT_PARAMS "yes")
  1055. list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_DH_DEFAULT_PARAMS")
  1056. endif()
  1057. if(NOT WOLFSSL_DES3)
  1058. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3")
  1059. else()
  1060. # turn off DES3 if leanpsk or leantls on
  1061. if(WOLFSSL_LEAN_PSK OR WOLFSSL_LEAN_TLS)
  1062. list(APPEND WOLFSSL_DEFINITIONS "-DNO_DES3")
  1063. override_cache(WOLFSSL_DES3 "no")
  1064. endif()
  1065. endif()
  1066. set(WOLFSSL_USER_SETTINGS_HELP_STRING "Use your own user_settings.h and do not add Makefile CFLAGS (default: disabled)")
  1067. add_option("WOLFSSL_USER_SETTINGS" ${WOLFSSL_USER_SETTINGS_HELP_STRING} "no" "yes;no")
  1068. set(WOLFSSL_OPTFLAGS_HELP_STRING "Enable default optimization CFLAGS for the compiler (default: enabled)")
  1069. add_option("WOLFSSL_OPTFLAGS" ${WOLFSSL_OPTFLAGS_HELP_STRING} "yes" "yes;no")
  1070. # Generates the BUILD_* flags. These control what source files are included in
  1071. # the library. A series of AM_CONDITIONALs handle this in configure.ac.
  1072. generate_build_flags()
  1073. # TODO: - Bit of logic after optimization flags option (above)
  1074. # - Check for build-type conflicts section
  1075. # USER SETTINGS
  1076. if(WOLFSSL_USER_SETTINGS)
  1077. # Replace all options and just use WOLFSSL_USER_SETTINGS
  1078. set(WOLFSSL_DEFINITIONS "-DWOLFSSL_USER_SETTINGS")
  1079. endif()
  1080. # TODO: Applying definitions to everything like this, rather than
  1081. # individual targets, is discouraged in CMake.
  1082. add_definitions(${WOLFSSL_DEFINITIONS})
  1083. set(WOLFSSL_CONFIG_H_HELP_STRING "Enable generation of config.h and define HAVE_CONFIG_H (default: enabled)")
  1084. add_option("WOLFSSL_CONFIG_H" ${WOLFSSL_CONFIG_H_HELP_STRING} "yes" "yes;no")
  1085. if(WOLFSSL_CONFIG_H)
  1086. add_definitions("-DHAVE_CONFIG_H")
  1087. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.in"
  1088. "${CMAKE_CURRENT_BINARY_DIR}/config.h" )
  1089. set(abs_top_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
  1090. set(abs_top_builddir ${CMAKE_CURRENT_BINARY_DIR})
  1091. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test_paths.h.in"
  1092. "${CMAKE_CURRENT_BINARY_DIR}/wolfcrypt/test/test_paths.h" )
  1093. endif()
  1094. # Suppress some warnings about separate compilation, inlining
  1095. add_definitions("-DWOLFSSL_IGNORE_FILE_WARN")
  1096. # Generate user options header
  1097. message("Generating user options header...")
  1098. set(OPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h")
  1099. file(REMOVE ${OPTION_FILE})
  1100. file(APPEND ${OPTION_FILE} "/* wolfssl options.h\n")
  1101. file(APPEND ${OPTION_FILE} " * generated from configure options\n")
  1102. file(APPEND ${OPTION_FILE} " *\n")
  1103. file(APPEND ${OPTION_FILE} " * Copyright (C) 2006-2020 wolfSSL Inc.\n")
  1104. file(APPEND ${OPTION_FILE} " *\n")
  1105. file(APPEND ${OPTION_FILE} " * This file is part of wolfSSL. (formerly known as CyaSSL)\n")
  1106. file(APPEND ${OPTION_FILE} " *\n")
  1107. file(APPEND ${OPTION_FILE} " */\n\n")
  1108. file(APPEND ${OPTION_FILE} "#ifndef WOLFSSL_OPTIONS_H\n")
  1109. file(APPEND ${OPTION_FILE} "#define WOLFSSL_OPTIONS_H\n\n\n")
  1110. file(APPEND ${OPTION_FILE} "#ifdef __cplusplus\n")
  1111. file(APPEND ${OPTION_FILE} "extern \"C\" {\n")
  1112. file(APPEND ${OPTION_FILE} "#endif\n\n")
  1113. foreach(DEF IN LISTS WOLFSSL_DEFINITIONS)
  1114. if(DEF MATCHES "^-D")
  1115. if(DEF MATCHES "^-D(N)?DEBUG(=.+)?")
  1116. message("not outputting (N)DEBUG to ${OPTION_FILE}")
  1117. endif()
  1118. # allow user to ignore system options
  1119. if(DEF MATCHES "^-D_.*")
  1120. file(APPEND ${OPTION_FILE} "#ifndef WOLFSSL_OPTIONS_IGNORE_SYS\n")
  1121. endif()
  1122. string(REGEX REPLACE "^-D" "" DEF_NO_PREFIX ${DEF})
  1123. string(REGEX REPLACE "=.*$" "" DEF_NO_EQUAL_NO_VAL ${DEF_NO_PREFIX})
  1124. string(REPLACE "=" " " DEF_NO_EQUAL ${DEF_NO_PREFIX})
  1125. file(APPEND ${OPTION_FILE} "#undef ${DEF_NO_EQUAL_NO_VAL}\n")
  1126. file(APPEND ${OPTION_FILE} "#define ${DEF_NO_EQUAL}\n")
  1127. if(DEF MATCHES "^-D_.*")
  1128. file(APPEND ${OPTION_FILE} "#endif\n")
  1129. endif()
  1130. file(APPEND ${OPTION_FILE} "\n")
  1131. else()
  1132. message("option w/o begin -D is ${DEF}, not saving to ${OPTION_FILE}")
  1133. endif()
  1134. endforeach()
  1135. file(APPEND ${OPTION_FILE} "\n#ifdef __cplusplus\n")
  1136. file(APPEND ${OPTION_FILE} "}\n")
  1137. file(APPEND ${OPTION_FILE} "#endif\n\n\n")
  1138. file(APPEND ${OPTION_FILE} "#endif /* WOLFSSL_OPTIONS_H */\n\n")
  1139. # backwards compatibility for those who have included options or version
  1140. set(CYASSL_OPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cyassl/options.h")
  1141. file(REMOVE ${CYASSL_OPTION_FILE})
  1142. file(APPEND ${CYASSL_OPTION_FILE} "/* cyassl options.h\n")
  1143. file(APPEND ${CYASSL_OPTION_FILE} " * generated from wolfssl/options.h\n")
  1144. file(APPEND ${CYASSL_OPTION_FILE} " */\n")
  1145. file(READ ${OPTION_FILE} OPTION_FILE_CONTENTS)
  1146. file(APPEND ${CYASSL_OPTION_FILE} ${OPTION_FILE_CONTENTS})
  1147. ####################################################
  1148. # Library Target
  1149. ####################################################
  1150. # TODO: - Build shared/static libs based on enables. Check CMake
  1151. # global flag BUILD_SHARED_LIBS.
  1152. set(LIB_SOURCES "")
  1153. # Generates a list of sources to include in the library.
  1154. # Corresponds to the instances of "src_libwolfssl_la_SOURCES += ..."
  1155. # in the *.am files.
  1156. generate_lib_src_list("${LIB_SOURCES}")
  1157. add_library(wolfssl ${LIB_SOURCES})
  1158. set_target_properties(wolfssl
  1159. PROPERTIES
  1160. SOVERSION ${LIBTOOL_SO_VERSION}
  1161. VERSION ${LIBTOOL_FULL_VERSION}
  1162. )
  1163. ####################################################
  1164. # Include Directories
  1165. ####################################################
  1166. target_include_directories(wolfssl
  1167. PUBLIC
  1168. $<INSTALL_INTERFACE:wolfssl>
  1169. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  1170. $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  1171. )
  1172. ####################################################
  1173. # Link Libraries
  1174. ####################################################
  1175. target_link_libraries(wolfssl PUBLIC ${WOLFSSL_LINK_LIBS})
  1176. if(WIN32)
  1177. # For Windows link ws2_32
  1178. target_link_libraries(wolfssl PUBLIC
  1179. $<$<PLATFORM_ID:Windows>:ws2_32>)
  1180. else()
  1181. # DH requires math (m) library
  1182. target_link_libraries(wolfssl
  1183. PUBLIC
  1184. m)
  1185. endif()
  1186. ####################################################
  1187. # Tests and Examples
  1188. ####################################################
  1189. if(WOLFSSL_EXAMPLES)
  1190. # Build wolfSSL client example
  1191. add_executable(client
  1192. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  1193. target_link_libraries(client wolfssl)
  1194. set_property(TARGET client
  1195. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1196. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client)
  1197. # Build wolfSSL server example
  1198. add_executable(server
  1199. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c)
  1200. target_link_libraries(server wolfssl)
  1201. set_property(TARGET server
  1202. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1203. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server)
  1204. # Build echo client example
  1205. add_executable(echoclient
  1206. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c)
  1207. target_include_directories(echoclient PRIVATE
  1208. ${CMAKE_CURRENT_BINARY_DIR})
  1209. target_link_libraries(echoclient wolfssl)
  1210. set_property(TARGET echoclient
  1211. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1212. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient)
  1213. # Build echo server example
  1214. add_executable(echoserver
  1215. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c)
  1216. target_include_directories(echoserver PRIVATE
  1217. ${CMAKE_CURRENT_BINARY_DIR})
  1218. target_link_libraries(echoserver wolfssl)
  1219. set_property(TARGET echoserver
  1220. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1221. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver)
  1222. if(NOT WIN32)
  1223. # Build TLS benchmark example
  1224. add_executable(tls_bench
  1225. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c)
  1226. target_link_libraries(tls_bench wolfssl)
  1227. target_link_libraries(tls_bench Threads::Threads)
  1228. set_property(TARGET tls_bench
  1229. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1230. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark)
  1231. endif()
  1232. # Build unit tests
  1233. add_executable(unit_test
  1234. tests/api.c
  1235. tests/hash.c
  1236. tests/srp.c
  1237. tests/suites.c
  1238. tests/unit.c
  1239. examples/server/server.c
  1240. examples/client/client.c)
  1241. target_include_directories(unit_test PRIVATE
  1242. ${CMAKE_CURRENT_BINARY_DIR})
  1243. target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER")
  1244. target_link_libraries(unit_test wolfssl)
  1245. target_link_libraries(unit_test Threads::Threads)
  1246. set_property(TARGET unit_test
  1247. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1248. ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
  1249. set_property(TARGET unit_test
  1250. PROPERTY RUNTIME_OUTPUT_NAME
  1251. unit.test)
  1252. endif()
  1253. if(WOLFSSL_CRYPT_TESTS)
  1254. # Build wolfCrypt test
  1255. add_executable(wolfcrypttest
  1256. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  1257. target_link_libraries(wolfcrypttest wolfssl)
  1258. set_property(TARGET wolfcrypttest
  1259. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1260. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test)
  1261. set_property(TARGET wolfcrypttest
  1262. PROPERTY RUNTIME_OUTPUT_NAME
  1263. testwolfcrypt)
  1264. # Build wolfCrypt benchmark
  1265. add_executable(wolfcryptbench
  1266. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  1267. target_include_directories(wolfcryptbench PRIVATE
  1268. ${CMAKE_CURRENT_BINARY_DIR})
  1269. target_link_libraries(wolfcryptbench wolfssl)
  1270. set_property(TARGET wolfcryptbench
  1271. PROPERTY RUNTIME_OUTPUT_DIRECTORY
  1272. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark)
  1273. set_property(TARGET wolfcryptbench
  1274. PROPERTY RUNTIME_OUTPUT_NAME
  1275. benchmark)
  1276. endif()
  1277. ####################################################
  1278. # Installation
  1279. ####################################################
  1280. include(GNUInstallDirs)
  1281. set(EXCLUDED_HEADERS_REGEX
  1282. "(internal|\
  1283. options|\
  1284. pic32mz-crypt|\
  1285. ti-hash|\
  1286. ti-ccm|\
  1287. nrf51|\
  1288. ksdk_port|\
  1289. dcp_port|\
  1290. xil-sha3|\
  1291. caam_driver|\
  1292. wolfcaam|\
  1293. wolfcaam_sha|\
  1294. stm32|\
  1295. stsafe|\
  1296. esp32-cry|\
  1297. cryptoCell|\
  1298. renesas-tsip-crypt|\
  1299. psoc6_crypto).h")
  1300. set(INSTALLED_EXAMPLES
  1301. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c
  1302. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-server.c
  1303. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-client-dtls.c
  1304. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-client.c
  1305. ${CMAKE_CURRENT_SOURCE_DIR}/examples/sctp/sctp-server-dtls.c
  1306. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c
  1307. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c
  1308. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c
  1309. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  1310. # Install the library
  1311. install(TARGETS wolfssl
  1312. DESTINATION ${CMAKE_INSTALL_LIBDIR}
  1313. EXPORT wolfssl-targets
  1314. LIBRARY)
  1315. # Install the headers
  1316. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/
  1317. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wolfssl
  1318. FILES_MATCHING PATTERN "*.h"
  1319. REGEX ${EXCLUDED_HEADERS_REGEX} EXCLUDE)
  1320. # Install the examples
  1321. install(FILES ${INSTALLED_EXAMPLES}
  1322. DESTINATION ${CMAKE_INSTALL_DOCDIR}/example)
  1323. # Install README.txt and taoCert.txt
  1324. install(FILES
  1325. ${CMAKE_CURRENT_SOURCE_DIR}/doc/README.txt
  1326. ${CMAKE_CURRENT_SOURCE_DIR}/certs/taoCert.txt
  1327. DESTINATION ${CMAKE_INSTALL_DOCDIR}/wolfssl)
  1328. # Install the export set
  1329. install(EXPORT wolfssl-targets
  1330. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wolfssl
  1331. FILE wolfssl-config.cmake)
  1332. # TODO: Distro build + rules for what to include in the distro.
  1333. # See various include.am files.