CMakeLists.txt 76 KB

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