CMakeLists.txt 76 KB

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