CMakeLists.txt 81 KB

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