functions.cmake 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. function(override_cache VAR VAL)
  2. get_property(VAR_STRINGS CACHE ${VAR} PROPERTY STRINGS)
  3. LIST(FIND VAR_STRINGS ${VAL} CK)
  4. if(-1 EQUAL ${CK} AND DEFINED VAR_STRINGS)
  5. message(SEND_ERROR
  6. "\"${VAL}\" is not valid override value for \"${VAR}\"."
  7. " Please select value from \"${VAR_STRINGS}\"\n")
  8. endif()
  9. set_property(CACHE ${VAR} PROPERTY VALUE ${VAL})
  10. endfunction()
  11. function(add_option NAME HELP_STRING DEFAULT VALUES)
  12. if(VALUES STREQUAL "yes;no")
  13. # Set the default value for the option.
  14. set(${NAME} ${DEFAULT} CACHE BOOL ${HELP_STRING})
  15. else()
  16. # Set the default value for the option.
  17. set(${NAME} ${DEFAULT} CACHE STRING ${HELP_STRING})
  18. # Set the list of allowed values for the option.
  19. set_property(CACHE ${NAME} PROPERTY STRINGS ${VALUES})
  20. endif()
  21. if(DEFINED ${NAME})
  22. list(FIND VALUES ${${NAME}} IDX)
  23. #
  24. # If the given value isn't in the list of allowed values for the option,
  25. # reduce it to yes/no according to CMake's "if" logic:
  26. # https://cmake.org/cmake/help/latest/command/if.html#basic-expressions
  27. #
  28. # This has no functional impact; it just makes the settings in
  29. # CMakeCache.txt and cmake-gui easier to read.
  30. #
  31. if (${IDX} EQUAL -1)
  32. if(${${NAME}})
  33. override_cache(${NAME} "yes")
  34. else()
  35. override_cache(${NAME} "no")
  36. endif()
  37. endif()
  38. endif()
  39. endfunction()
  40. function(generate_build_flags)
  41. set(BUILD_DISTRO ${WOLFSSL_DISTRO} PARENT_SCOPE)
  42. set(BUILD_ALL ${WOLFSSL_ALL} PARENT_SCOPE)
  43. if(WOLFSSL_TLS13 OR WOLFSSL_USER_SETTINGS)
  44. set(BUILD_TLS13 "yes" PARENT_SCOPE)
  45. endif()
  46. if(WOLFSSL_DTLS13 OR WOLFSSL_USER_SETTINGS)
  47. set(BUILD_DTLS13 "yes" PARENT_SCOPE)
  48. endif()
  49. if(WOLFSSL_QUIC)
  50. set(BUILD_QUIC "yes" PARENT_SCOPE)
  51. endif()
  52. if(WOLFSSL_RNG OR WOLFSSL_USER_SETTINGS)
  53. set(BUILD_RNG "yes" PARENT_SCOPE)
  54. endif()
  55. if(WOLFSSL_SCTP OR WOLFSSL_USER_SETTINGS)
  56. set(BUILD_SCTP "yes" PARENT_SCOPE)
  57. endif()
  58. if(WOLFSSL_DTLS_CID OR WOLFSSL_USER_SETTINGS OR WOLFSSL_DTLS)
  59. set(BUILD_DTLS_COMMON "yes" PARENT_SCOPE)
  60. endif()
  61. set(BUILD_MCAST ${WOLFSSL_MCAST} PARENT_SCOPE)
  62. set(BUILD_IPV6 ${WOLFSSL_IPV6} PARENT_SCOPE)
  63. set(BUILD_LEAN_PSK ${WOLFSSL_LEAN_PSK} PARENT_SCOPE)
  64. set(BUILD_LEAN_TLS ${WOLFSSL_LEAN_TLS} PARENT_SCOPE)
  65. set(BUILD_LOWMEM ${WOLFSSL_LOWRESOURCE} PARENT_SCOPE)
  66. set(BUILD_PKCALLBACKS ${WOLFSSL_PKCALLBACKS} PARENT_SCOPE)
  67. set(BUILD_CRYPTOAUTHLIB ${WOLFSSL_CRYPTOAUTHLIB} PARENT_SCOPE)
  68. if(WOLFSSL_SNIFFER OR WOLFSSL_USER_SETTINGS)
  69. set(BUILD_SNIFFER "yes" PARENT_SCOPE)
  70. endif()
  71. set(BUILD_SNIFFTEST ${WOLFSSL_SNIFFTEST} PARENT_SCOPE)
  72. if(WOLFSSL_AESGCM OR WOLFSSL_USER_SETTINGS)
  73. set(BUILD_AESGCM "yes" PARENT_SCOPE)
  74. endif()
  75. if(WOLFSSL_AESCCM OR WOLFSSL_USER_SETTINGS)
  76. set(BUILD_AESCCM "yes" PARENT_SCOPE)
  77. endif()
  78. set(BUILD_ARM_ASM ${WOLFSSL_ARM_ASM} PARENT_SCOPE)
  79. set(BUILD_XILINX ${WOLFSSL_XILINX} PARENT_SCOPE)
  80. set(BUILD_AESNI ${WOLFSSL_AESNI} PARENT_SCOPE)
  81. set(BUILD_INTEL_ASM ${WOLFSSL_INTEL_ASM} PARENT_SCOPE)
  82. set(BUILD_AFALG ${WOLFSSL_AFALG} PARENT_SCOPE)
  83. set(BUILD_DEVCRYPTO ${WOLFSSL_DEVCRYPTO} PARENT_SCOPE)
  84. if(WOLFSSL_CAMELLIA OR WOLFSSL_USER_SETTINGS)
  85. set(BUILD_CAMELLIA "yes" PARENT_SCOPE)
  86. endif()
  87. if(WOLFSSL_MD2 OR WOLFSSL_USER_SETTINGS)
  88. set(BUILD_MD2 "yes" PARENT_SCOPE)
  89. endif()
  90. if(WOLFSSL_RIPEMD OR WOLFSSL_USER_SETTINGS)
  91. set(BUILD_RIPEMD "yes" PARENT_SCOPE)
  92. endif()
  93. if(WOLFSSL_BLAKE2 OR WOLFSSL_USER_SETTINGS)
  94. set(BUILD_BLAKE2 "yes" PARENT_SCOPE)
  95. endif()
  96. if(WOLFSSL_BLAKE2S OR WOLFSSL_USER_SETTINGS)
  97. set(BUILD_BLAKE2S "yes" PARENT_SCOPE)
  98. endif()
  99. if(WOLFSSL_SHA512 OR WOLFSSL_SHA384 OR WOLFSSL_USER_SETTINGS)
  100. set(BUILD_SHA512 "yes" PARENT_SCOPE)
  101. endif()
  102. if(WOLFSSL_DSA OR WOLFSSL_USER_SETTINGS)
  103. set(BUILD_DSA "yes" PARENT_SCOPE)
  104. endif()
  105. if(WOLFSSL_ECC OR WOLFSSL_USER_SETTINGS)
  106. set(BUILD_ECC "yes" PARENT_SCOPE)
  107. endif()
  108. if(WOLFSSL_ED25519 OR WOLFSSL_USER_SETTINGS)
  109. set(BUILD_ED25519 "yes" PARENT_SCOPE)
  110. endif()
  111. set(BUILD_ED25519_SMALL ${WOLFSSL_ED25519_SMALL} PARENT_SCOPE)
  112. if(WOLFSSL_FEMATH OR WOLFSSL_USER_SETTINGS)
  113. set(BUILD_FEMATH "yes" PARENT_SCOPE)
  114. endif()
  115. if(WOLFSSL_GEMATH OR WOLFSSL_USER_SETTINGS)
  116. set(BUILD_GEMATH "yes" PARENT_SCOPE)
  117. endif()
  118. if(WOLFSSL_CURVE25519 OR WOLFSSL_USER_SETTINGS)
  119. set(BUILD_CURVE25519 "yes" PARENT_SCOPE)
  120. endif()
  121. set(BUILD_CURVE25519_SMALL ${WOLFSSL_CURVE25519_SMALL} PARENT_SCOPE)
  122. if(WOLFSSL_ED448 OR WOLFSSL_USER_SETTINGS)
  123. set(BUILD_ED448 "yes" PARENT_SCOPE)
  124. endif()
  125. set(BUILD_ED448_SMALL ${WOLFSSL_ED448_SMALL} PARENT_SCOPE)
  126. if(WOLFSSL_FE448 OR WOLFSSL_USER_SETTINGS)
  127. set(BUILD_FE448 "yes" PARENT_SCOPE)
  128. endif()
  129. if(WOLFSSL_GE448 OR WOLFSSL_USER_SETTINGS)
  130. set(BUILD_GE448 "yes" PARENT_SCOPE)
  131. endif()
  132. if(WOLFSSL_CURVE448 OR WOLFSSL_USER_SETTINGS)
  133. set(BUILD_CURVE448 "yes" PARENT_SCOPE)
  134. endif()
  135. if(WOLFSSL_CURVE448_SMALL OR WOLFSSL_USER_SETTINGS)
  136. set(BUILD_CURVE448_SMALL "yes" PARENT_SCOPE)
  137. endif()
  138. if(WOLFSSL_MEMORY OR WOLFSSL_USER_SETTINGS)
  139. set(BUILD_MEMORY "yes" PARENT_SCOPE)
  140. endif()
  141. if(WOLFSSL_RSA OR WOLFSSL_USER_SETTINGS)
  142. set(BUILD_RSA "yes" PARENT_SCOPE)
  143. endif()
  144. if(WOLFSSL_DH OR WOLFSSL_USER_SETTINGS)
  145. set(BUILD_DH "yes" PARENT_SCOPE)
  146. endif()
  147. if(WOLFSSL_ASN OR WOLFSSL_USER_SETTINGS)
  148. set(BUILD_ASN "yes" PARENT_SCOPE)
  149. endif()
  150. if(WOLFSSL_AES OR WOLFSSL_USER_SETTINGS)
  151. set(BUILD_AES "yes" PARENT_SCOPE)
  152. endif()
  153. if(WOLFSSL_CODING OR WOLFSSL_USER_SETTINGS)
  154. set(BUILD_CODING "yes" PARENT_SCOPE)
  155. endif()
  156. if(WOLFSSL_ARC4 OR WOLFSSL_USER_SETTINGS)
  157. set(BUILD_RC4 "yes" PARENT_SCOPE)
  158. endif()
  159. if(WOLFSSL_MD5 OR WOLFSSL_USER_SETTINGS)
  160. set(BUILD_MD5 "yes" PARENT_SCOPE)
  161. endif()
  162. if(WOLFSSL_SHA OR WOLFSSL_USER_SETTINGS)
  163. set(BUILD_SHA "yes" PARENT_SCOPE)
  164. endif()
  165. set(BUILD_FIPS ${WOLFSSL_FIPS} PARENT_SCOPE)
  166. if("${FIPS_VERSION}" STREQUAL "v1")
  167. set(BUILD_FIPS_V1 "yes" PARENT_SCOPE)
  168. endif()
  169. if("${FIPS_VERSION}" STREQUAL "v2")
  170. set(BUILD_FIPS_V2 "yes" PARENT_SCOPE)
  171. endif()
  172. if("${FIPS_VERSION}" STREQUAL "rand")
  173. set(BUILD_FIPS_RAND "yes" PARENT_SCOPE)
  174. endif()
  175. if("${FIPS_VERSION}" STREQUAL "v5")
  176. set(BUILD_FIPS_V5 "yes" PARENT_SCOPE)
  177. endif()
  178. set(BUILD_FIPS_READY ${FIPS_READY} PARENT_SCOPE)
  179. if(WOLFSSL_CMAC OR WOLFSSL_USER_SETTINGS)
  180. set(BUILD_CMAC "yes" PARENT_SCOPE)
  181. endif()
  182. set(BUILD_SELFTEST ${WOLFSSL_SELFTEST} PARENT_SCOPE)
  183. if(WOLFSSL_SHA224 OR WOLFSSL_USER_SETTINGS)
  184. set(BUILD_SHA224 "yes" PARENT_SCOPE)
  185. endif()
  186. if(WOLFSSL_SHA3 OR WOLFSSL_USER_SETTINGS)
  187. set(BUILD_SHA3 "yes" PARENT_SCOPE)
  188. endif()
  189. if(WOLFSSL_POLY1305 OR WOLFSSL_USER_SETTINGS)
  190. set(BUILD_POLY1305 "yes" PARENT_SCOPE)
  191. endif()
  192. if(WOLFSSL_CHACHA OR WOLFSSL_USER_SETTINGS)
  193. set(BUILD_CHACHA "yes" PARENT_SCOPE)
  194. endif()
  195. if(WOLFSSL_XCHACHA OR WOLFSSL_USER_SETTINGS)
  196. set(BUILD_XCHACHA "yes" PARENT_SCOPE)
  197. endif()
  198. if(WOLFSSL_OQS OR WOLFSSL_USER_SETTINGS)
  199. set(BUILD_FALCON "yes" PARENT_SCOPE)
  200. set(BUILD_SPHINCS "yes" PARENT_SCOPE)
  201. set(BUILD_DILITHIUM "yes" PARENT_SCOPE)
  202. set(BUILD_EXT_KYBER "yes" PARENT_SCOPE)
  203. set(BUILD_OQS_HELPER "yes" PARENT_SCOPE)
  204. endif()
  205. if(WOLFSSL_ARIA OR WOLFSSL_USER_SETTINGS)
  206. message(STATUS "ARIA functions.cmake found WOLFSSL_ARIA")
  207. # we cannot actually build, as we only have pre-compiled bin
  208. set(BUILD_ARIA "yes" PARENT_SCOPE)
  209. endif()
  210. set(BUILD_INLINE ${WOLFSSL_INLINE} PARENT_SCOPE)
  211. if(WOLFSSL_OCSP OR WOLFSSL_USER_SETTINGS)
  212. set(BUILD_OCSP "yes" PARENT_SCOPE)
  213. endif()
  214. set(BUILD_OCSP_STAPLING ${WOLFSSL_OCSPSTAPLING} PARENT_SCOPE)
  215. set(BUILD_OCSP_STAPLING_V2 ${WOLFSSL_OCSPSTAPLING_V2} PARENT_SCOPE)
  216. if(WOLFSSL_CRL OR WOLFSSL_USER_SETTINGS)
  217. set(BUILD_CRL "yes" PARENT_SCOPE)
  218. endif()
  219. if(WOLFSSL_CRL_MONITOR)
  220. set(BUILD_CRL_MONITOR "yes" PARENT_SCOPE)
  221. endif()
  222. set(BUILD_QUIC ${WOLFSSL_QUIC} PARENT_SCOPE)
  223. set(BUILD_WNR ${WOLFSSL_WNR} PARENT_SCOPE)
  224. if(WOLFSSL_SRP OR WOLFSSL_USER_SETTINGS)
  225. set(BUILD_SRP "yes" PARENT_SCOPE)
  226. endif()
  227. set(USE_VALGRIND ${WOLFSSL_VALGRIND})
  228. if(WOLFSSL_MD4 OR WOLFSSL_USER_SETTINGS)
  229. set(BUILD_MD4 "yes" PARENT_SCOPE)
  230. endif()
  231. if(WOLFSSL_PWDBASED OR WOLFSSL_USER_SETTINGS)
  232. set(BUILD_PWDBASED "yes" PARENT_SCOPE)
  233. endif()
  234. if(WOLFSSL_SCRYPT OR WOLFSSL_USER_SETTINGS)
  235. set(BUILD_SCRYPT "yes" PARENT_SCOPE)
  236. endif()
  237. if(WOLFSSL_CRYPT_ONLY AND NOT WOLFSSL_OPENSSL_EXTRA)
  238. set(BUILD_CRYPTONLY "yes" PARENT_SCOPE)
  239. endif()
  240. if(WOLFSSL_FAST_MATH OR WOLFSSL_USER_SETTINGS)
  241. set(BUILD_FAST_MATH "yes" PARENT_SCOPE)
  242. endif()
  243. if(WOLFSSL_SLOW_MATH OR WOLFSSL_USER_SETTINGS)
  244. set(BUILD_SLOW_MATH "yes" PARENT_SCOPE)
  245. endif()
  246. if(WOLFSSL_EXAMPLES AND NOT WOLFSSL_LEAN_TLS)
  247. set(BUILD_EXAMPLE_SERVERS "yes" PARENT_SCOPE)
  248. endif()
  249. set(BUILD_EXAMPLE_CLIENTS ${WOLFSSL_EXAMPLES} PARENT_SCOPE)
  250. set(BUILD_TESTS ${WOLFSSL_EXAMPLES} PARENT_SCOPE)
  251. if(NOT WOLFSSL_SINGLETHREADED AND WOLFSSL_EXAMPLES AND NOT WOLFSSL_LEAN_TLS)
  252. set(BUILD_THREADED_EXAMPLES "yes" PARENT_SCOPE)
  253. endif()
  254. set(BUILD_WOLFCRYPT_TESTS ${WOLFSSL_CRYPT_TESTS} PARENT_SCOPE)
  255. set(BUILD_LIBZ ${WOLFSSL_LIBZ} PARENT_SCOPE)
  256. if(WOLFSSL_PKCS11 OR WOLFSSL_USER_SETTINGS)
  257. set(BUILD_PKCS11 "yes" PARENT_SCOPE)
  258. endif()
  259. if(WOLFSSL_PKCS12 OR WOLFSSL_USER_SETTINGS)
  260. set(BUILD_PKCS12 "yes" PARENT_SCOPE)
  261. endif()
  262. set(BUILD_CAVIUM ${WOLFSSL_CAVIUM} PARENT_SCOPE)
  263. set(BUILD_CAVIUM_V ${WOLFSSL_CAVIUM_V} PARENT_SCOPE)
  264. set(BUILD_OCTEON_SYNC ${WOLFSSL_OCTEON_SYNC} PARENT_SCOPE)
  265. set(BUILD_INTEL_QA ${WOLFSSL_INTEL_QA} PARENT_SCOPE)
  266. set(BUILD_INTEL_QA_SYNC ${WOLFSSL_INTEL_QA_SYNC} PARENT_SCOPE)
  267. if(WOLFSSL_SP OR WOLFSSL_USER_SETTINGS)
  268. set(BUILD_SP "yes" PARENT_SCOPE)
  269. endif()
  270. if((WOLFSSL_SP AND NOT WOLFSSL_SP_ASM) OR WOLFSSL_USER_SETTINGS)
  271. set(BUILD_SP_C "yes" PARENT_SCOPE)
  272. endif()
  273. if(WOLFSSL_SP_ARM64_ASM OR WOLFSSL_USER_SETTINGS)
  274. set(BUILD_SP_ARM64 "yes" PARENT_SCOPE)
  275. endif()
  276. if(WOLFSSL_SP_ARM32_ASM OR WOLFSSL_USER_SETTINGS)
  277. set(BUILD_SP_ARM32 "yes" PARENT_SCOPE)
  278. endif()
  279. if(WOLFSSL_SP_ARM_THUMB_ASM OR WOLFSSL_USER_SETTINGS)
  280. set(BUILD_SP_ARM_THUMB "yes" PARENT_SCOPE)
  281. endif()
  282. if(WOLFSSL_SP_ARM_CORTEX_ASM OR WOLFSSL_USER_SETTINGS)
  283. set(BUILD_SP_ARM_CORTEX "yes" PARENT_SCOPE)
  284. endif()
  285. if(WOLFSSL_X86_64_BUILD AND (WOLFSSL_SP_X86_64_ASM OR WOLFSSL_USER_SETTINGS))
  286. set(BUILD_SP_X86_64 "yes" PARENT_SCOPE)
  287. endif()
  288. if(WOLFSSL_SP_MATH OR WOLFSSL_SP_MATH_ALL OR WOLFSSL_USER_SETTINGS)
  289. set(BUILD_SP_INT "yes" PARENT_SCOPE)
  290. endif()
  291. set(BUILD_MCAPI ${WOLFSSL_MCAPI} PARENT_SCOPE)
  292. set(BUILD_ASYNCCRYPT ${WOLFSSL_ASYNCCRYPT} PARENT_SCOPE)
  293. set(BUILD_WOLFEVENT ${WOLFSSL_ASYNCCRYPT} PARENT_SCOPE)
  294. if(WOLFSSL_CRYPTOCB OR WOLFSSL_USER_SETTINGS)
  295. set(BUILD_CRYPTOCB "yes" PARENT_SCOPE)
  296. endif()
  297. set(BUILD_PSK ${WOLFSSL_PSK} PARENT_SCOPE)
  298. set(BUILD_TRUST_PEER_CERT ${WOLFSSL_TRUSTED_PEER_CERT} PARENT_SCOPE)
  299. set(BUILD_PKI ${WOLFSSL_PKI} PARENT_SCOPE)
  300. if(WOLFSSL_DES3 OR WOLFSSL_USER_SETTINGS)
  301. set(BUILD_DES3 "yes" PARENT_SCOPE)
  302. endif()
  303. if(WOLFSSL_PKCS7 OR WOLFSSL_USER_SETTINGS)
  304. set(BUILD_PKCS7 "yes" PARENT_SCOPE)
  305. endif()
  306. set(BUILD_HASHFLAGS ${WOLFSSL_HASHFLAGS} PARENT_SCOPE)
  307. set(BUILD_LINUX_KM ${WOLFSSL_LINUX_KM} PARENT_SCOPE)
  308. set(BUILD_NO_LIBRARY ${WOLFSSL_NO_LIBRARY} PARENT_SCOPE)
  309. if(WOLFSSL_DEBUG OR WOLFSSL_STACK_SIZE)
  310. set(BUILD_DEBUG "yes" PARENT_SCOPE)
  311. endif()
  312. set(BUILD_RC2 ${WOLFSSL_RC2} PARENT_SCOPE)
  313. if(WOLFSSL_CAAM)
  314. set(BUILD_CAAM "yes" PARENT_SCOPE)
  315. endif()
  316. if(WOLFSSL_HPKE OR WOLFSSL_USER_SETTINGS)
  317. set(BUILD_HPKE "yes" PARENT_SCOPE)
  318. endif()
  319. set(BUILD_FLAGS_GENERATED "yes" PARENT_SCOPE)
  320. endfunction()
  321. function(generate_lib_src_list LIB_SOURCES)
  322. if(NOT BUILD_FLAGS_GENERATED)
  323. message(FATAL_ERROR "Cannot call generate_lib_src_list without calling generate_build_flags first.")
  324. endif()
  325. # Corresponds to src/include.am
  326. if(BUILD_FIPS)
  327. if(BUILD_FIPS_V2)
  328. # FIPSv2 first file
  329. list(APPEND LIB_SOURCES wolfcrypt/src/wolfcrypt_first.c)
  330. list(APPEND LIB_SOURCES
  331. wolfcrypt/src/hmac.c
  332. wolfcrypt/src/random.c
  333. wolfcrypt/src/sha256.c)
  334. if(BUILD_RSA)
  335. list(APPEND LIB_SOURCES wolfcrypt/src/rsa.c)
  336. endif()
  337. if(BUILD_ECC)
  338. list(APPEND LIB_SOURCES wolfcrypt/src/ecc.c)
  339. endif()
  340. if(BUILD_AES)
  341. list(APPEND LIB_SOURCES wolfcrypt/src/aes.c)
  342. if(BUILD_ARMASM AND BUILD_FIPS_READY)
  343. list(APPEND LIB_SOURCES wolfcrypt/src/port/arm/armv8-aes.c)
  344. endif()
  345. endif()
  346. if(BUILD_AESNI)
  347. list(APPEND LIB_SOURCES wolfcrypt/src/aes_asm.S)
  348. if(BUILD_INTELASM)
  349. list(APPEND LIB_SOURCES wolfcrypt/src/aes_gcm_asm.S)
  350. endif()
  351. endif()
  352. if(BUILD_DES3)
  353. list(APPEND LIB_SOURCES wolfcrypt/src/des3.c)
  354. endif()
  355. if(BUILD_SHA)
  356. list(APPEND LIB_SOURCES wolfcrypt/src/sha.c)
  357. endif()
  358. if(BUILD_ARMASM AND BUILD_FIPS_READY)
  359. list(APPEND LIB_SOURCES wolfcrypt/src/port/arm/armv8-sha256.c)
  360. endif()
  361. if(BUILD_INTELASM)
  362. list(APPEND LIB_SOURCES wolfcrypt/src/sha256_asm.S)
  363. endif()
  364. if(BUILD_SHA512)
  365. list(APPEND LIB_SOURCES wolfcrypt/src/sha512.c)
  366. if(BUILD_ARMASM AND BUILD_FIPS_READY)
  367. list(APPEND LIB_SOURCES
  368. wolfcrypt/src/port/arm/armv8-sha512.c
  369. wolfcrypt/src/port/arm/armv8-sha512-asm.S
  370. wolfcrypt/src/port/arm/armv8-32-sha512-asm.S)
  371. endif()
  372. if(BUILD_INTELASM)
  373. list(APPEND LIB_SOURCES wolfcrypt/src/sha512_asm.S)
  374. endif()
  375. endif()
  376. if(BUILD_SHA3)
  377. list(APPEND LIB_SOURCES wolfcrypt/src/sha3.c)
  378. endif()
  379. if(BUILD_DH)
  380. list(APPEND LIB_SOURCES wolfcrypt/src/dh.c)
  381. endif()
  382. if(BUILD_CMAC)
  383. list(APPEND LIB_SOURCES wolfcrypt/src/cmac.c)
  384. endif()
  385. list(APPEND LIB_SOURCES
  386. wolfcrypt/src/fips.c
  387. wolfcrypt/src/fips_test.c)
  388. # fips last file
  389. list(APPEND LIB_SOURCES wolfcrypt/src/wolfcrypt_last.c)
  390. endif()
  391. if(BUILD_FIPS_V5)
  392. list(APPEND LIB_SOURCES wolfcrypt/src/wolfcrypt_first.c)
  393. list(APPEND LIB_SOURCES
  394. wolfcrypt/src/hmac.c
  395. wolfcrypt/src/random.c
  396. wolfcrypt/src/sha256.c)
  397. list(APPEND LIB_SOURCES
  398. wolfcrypt/src/kdf.c)
  399. if(BUILD_RSA)
  400. list(APPEND LIB_SOURCES wolfcrypt/src/rsa.c)
  401. endif()
  402. endif()
  403. if(BUILD_FIPS_RAND)
  404. list(APPEND LIB_SOURCES
  405. wolfcrypt/src/wolfcrypt_first.c
  406. wolfcrypt/src/hmac.c
  407. wolfcrypt/src/random.c
  408. wolfcrypt/src/sha256.c
  409. wolfcrypt/src/sha256_asm.S
  410. wolfcrypt/src/fips.c
  411. wolfcrypt/src/fips_test.c
  412. wolfcrypt/src/wolfcrypt_last.c)
  413. endif()
  414. endif()
  415. # For wolfRand, exclude everything else.
  416. if(NOT BUILD_FIPS_RAND)
  417. # For FIPSV2, exclude the wolfCrypt files included above.
  418. # For wolfRand, exclude just a couple files.
  419. # For old FIPS, keep the wolfCrypt versions of the
  420. # CtaoCrypt files included above.
  421. if(NOT BUILD_FIPS_V2)
  422. list(APPEND LIB_SOURCES wolfcrypt/src/hmac.c)
  423. endif()
  424. # CAVP self test
  425. if(BUILD_SELFTEST)
  426. list(APPEND LIB_SOURCES wolfcrypt/src/selftest.c)
  427. endif()
  428. endif()
  429. list(APPEND LIB_SOURCES
  430. wolfcrypt/src/hash.c
  431. wolfcrypt/src/cpuid.c)
  432. if(NOT BUILD_FIPS_RAND)
  433. if(NOT BUILD_FIPS_V5)
  434. list(APPEND LIB_SOURCES wolfcrypt/src/kdf.c)
  435. endif()
  436. if(NOT BUILD_FIPS_V2 AND BUILD_RNG)
  437. list(APPEND LIB_SOURCES wolfcrypt/src/random.c)
  438. endif()
  439. if(NOT BUILD_FIPS_V2)
  440. if(BUILD_ARMASM)
  441. list(APPEND LIB_SOURCES wolfcrypt/src/port/arm/armv8-sha256.c)
  442. else()
  443. list(APPEND LIB_SOURCES wolfcrypt/src/sha256.c)
  444. if(BUILD_INTELASM)
  445. list(APPEND LIB_SOURCES wolfcrypt/src/sha256_asm.S)
  446. endif()
  447. endif()
  448. endif()
  449. if(BUILD_AFALG)
  450. list(APPEND LIB_SOURCES wolfcrypt/src/port/af_alg/afalg_hash.c)
  451. endif()
  452. if(BUILD_WOLFEVENT)
  453. list(APPEND LIB_SOURCES wolfcrypt/src/wolfevent.c)
  454. endif()
  455. if(BUILD_ASYNCCRYPT)
  456. list(APPEND LIB_SOURCES wolfcrypt/src/async.c)
  457. endif()
  458. if(BUILD_RSA)
  459. if(NOT BUILD_FIPS_V2)
  460. list(APPEND LIB_SOURCES wolfcrypt/src/rsa.c)
  461. endif()
  462. endif()
  463. if(BUILD_SP)
  464. if(BUILD_SP_C)
  465. list(APPEND LIB_SOURCES
  466. wolfcrypt/src/sp_c32.c
  467. wolfcrypt/src/sp_c64.c)
  468. endif()
  469. if(BUILD_SP_X86_64)
  470. list(APPEND LIB_SOURCES wolfcrypt/src/sp_x86_64.c)
  471. if(WOLFSSL_X86_64_BUILD_ASM)
  472. list(APPEND LIB_SOURCES wolfcrypt/src/sp_x86_64_asm.S)
  473. endif()
  474. endif()
  475. if(NOT BUILD_FIPS_V2 AND BUILD_SP_ARM32)
  476. list(APPEND LIB_SOURCES wolfcrypt/src/sp_arm32.c)
  477. endif()
  478. if(BUILD_SP_ARM_THUMB)
  479. list(APPEND LIB_SOURCES wolfcrypt/src/sp_armthumb.c)
  480. endif()
  481. if(BUILD_SP_ARM64)
  482. list(APPEND LIB_SOURCES wolfcrypt/src/sp_arm64.c)
  483. endif()
  484. if(BUILD_SP_ARM_CORTEX)
  485. list(APPEND LIB_SOURCES wolfcrypt/src/sp_cortexm.c)
  486. endif()
  487. endif()
  488. if(BUILD_SP_INT)
  489. list(APPEND LIB_SOURCES wolfcrypt/src/sp_int.c)
  490. endif()
  491. if(NOT BUILD_FIPS_V2)
  492. if(BUILD_AES)
  493. list(APPEND LIB_SOURCES wolfcrypt/src/aes.c)
  494. if(BUILD_ARMASM)
  495. list(APPEND LIB_SOURCES wolfcrypt/src/port/arm/armv8-aes.c)
  496. endif()
  497. if(BUILD_AFALG)
  498. list(APPEND LIB_SOURCES wolfcrypt/src/port/af_alg/afalg_aes.c)
  499. endif()
  500. endif()
  501. endif()
  502. if(NOT BUILD_FIPS_V2 AND BUILD_CMAC)
  503. list(APPEND LIB_SOURCES wolfcrypt/src/cmac.c)
  504. endif()
  505. if(NOT BUILD_FIPS_V2 AND BUILD_DES3)
  506. list(APPEND LIB_SOURCES wolfcrypt/src/des3.c)
  507. endif()
  508. if(NOT BUILD_FIPS_V2 AND BUILD_SHA)
  509. list(APPEND LIB_SOURCES wolfcrypt/src/sha.c)
  510. endif()
  511. if(NOT BUILD_FIPS_V2 AND BUILD_SHA512)
  512. if(BUILD_ARMASM)
  513. list(APPEND LIB_SOURCES
  514. wolfcrypt/src/port/arm/armv8-sha512.c
  515. wolfcrypt/src/port/arm/armv8-sha512-asm.S
  516. wolfcrypt/src/port/arm/armv8-32-sha512-asm.S)
  517. else()
  518. list(APPEND LIB_SOURCES wolfcrypt/src/sha512.c)
  519. if(BUILD_INTELASM)
  520. list(APPEND LIB_SOURCES wolfcrypt/src/sha512_asm.S)
  521. endif()
  522. endif()
  523. endif()
  524. if(NOT BUILD_FIPS_V2 AND BUILD_SHA3)
  525. list(APPEND LIB_SOURCES wolfcrypt/src/sha3.c)
  526. endif()
  527. endif()
  528. list(APPEND LIB_SOURCES
  529. wolfcrypt/src/logging.c
  530. wolfcrypt/src/wc_port.c
  531. wolfcrypt/src/error.c)
  532. if(BUILD_OQS_HELPER)
  533. list(APPEND LIB_SOURCES
  534. wolfcrypt/src/port/liboqs/liboqs.c)
  535. endif()
  536. if(BUILD_ARIA)
  537. list(APPEND LIB_SOURCES
  538. wolfcrypt/src/port/aria/aria-crypt.c
  539. wolfcrypt/src/port/aria/aria-cryptocb.c)
  540. endif()
  541. if(NOT BUILD_FIPS_RAND)
  542. list(APPEND LIB_SOURCES
  543. wolfcrypt/src/wc_encrypt.c
  544. wolfcrypt/src/signature.c
  545. wolfcrypt/src/wolfmath.c)
  546. endif()
  547. if(BUILD_MEMORY)
  548. list(APPEND LIB_SOURCES wolfcrypt/src/memory.c)
  549. endif()
  550. if(NOT BUILD_FIPS_RAND)
  551. if(NOT BUILD_FIPS_V2 AND BUILD_DH)
  552. list(APPEND LIB_SOURCES wolfcrypt/src/dh.c)
  553. endif()
  554. if(BUILD_ASN)
  555. list(APPEND LIB_SOURCES wolfcrypt/src/asn.c)
  556. endif()
  557. endif()
  558. if(BUILD_CODING)
  559. list(APPEND LIB_SOURCES wolfcrypt/src/coding.c)
  560. endif()
  561. if(NOT BUILD_FIPS_RAND)
  562. if(BUILD_POLY1305)
  563. if(BUILD_ARMASM)
  564. list(APPEND LIB_SOURCES wolfcrypt/src/port/arm/armv8-poly1305.c)
  565. endif()
  566. list(APPEND LIB_SOURCES wolfcrypt/src/poly1305.c)
  567. if(BUILD_INTELASM)
  568. list(APPEND LIB_SOURCES wolfcrypt/src/poly1305_asm.S)
  569. endif()
  570. endif()
  571. if(BUILD_RC4)
  572. list(APPEND LIB_SOURCES wolfcrypt/src/arc4.c)
  573. endif()
  574. if(BUILD_MD4)
  575. list(APPEND LIB_SOURCES wolfcrypt/src/md4.c)
  576. endif()
  577. if(BUILD_MD5)
  578. list(APPEND LIB_SOURCES wolfcrypt/src/md5.c)
  579. endif()
  580. if(BUILD_PWDBASED)
  581. list(APPEND LIB_SOURCES
  582. wolfcrypt/src/pwdbased.c
  583. wolfcrypt/src/pkcs12.c)
  584. endif()
  585. if(BUILD_DSA)
  586. list(APPEND LIB_SOURCES wolfcrypt/src/dsa.c)
  587. endif()
  588. if(NOT BUILD_FIPS_V2 AND BUILD_AESNI)
  589. list(APPEND LIB_SOURCES
  590. wolfcrypt/src/aes_asm.S
  591. wolfcrypt/src/aes_gcm_asm.S)
  592. endif()
  593. if(BUILD_CAMELLIA)
  594. list(APPEND LIB_SOURCES wolfcrypt/src/camellia.c)
  595. endif()
  596. if(BUILD_MD2)
  597. list(APPEND LIB_SOURCES wolfcrypt/src/md2.c)
  598. endif()
  599. if(BUILD_RIPEMD)
  600. list(APPEND LIB_SOURCES wolfcrypt/src/ripemd.c)
  601. endif()
  602. if(BUILD_BLAKE2)
  603. list(APPEND LIB_SOURCES wolfcrypt/src/blake2b.c)
  604. endif()
  605. if(BUILD_BLAKE2S)
  606. list(APPEND LIB_SOURCES wolfcrypt/src/blake2s.c)
  607. endif()
  608. if(BUILD_CHACHA)
  609. if(BUILD_ARMASM)
  610. list(APPEND LIB_SOURCES wolfcrypt/src/port/arm/armv8-chacha.c)
  611. else()
  612. list(APPEND LIB_SOURCES wolfcrypt/src/chacha.c)
  613. if(BUILD_INTELASM)
  614. list(APPEND LIB_SOURCES wolfcrypt/src/chacha_asm.S)
  615. endif()
  616. endif()
  617. if(BUILD_POLY1305)
  618. list(APPEND LIB_SOURCES wolfcrypt/src/chacha20_poly1305.c)
  619. endif()
  620. endif()
  621. if(NOT BUILD_INLINE)
  622. list(APPEND LIB_SOURCES wolfcrypt/src/misc.c)
  623. endif()
  624. if(BUILD_FAST_MATH)
  625. list(APPEND LIB_SOURCES wolfcrypt/src/tfm.c)
  626. endif()
  627. if(BUILD_SLOW_MATH)
  628. list(APPEND LIB_SOURCES wolfcrypt/src/integer.c)
  629. endif()
  630. if(NOT BUILD_FIPS_V2 AND BUILD_ECC)
  631. list(APPEND LIB_SOURCES wolfcrypt/src/ecc.c)
  632. endif()
  633. if(BUILD_CURVE25519)
  634. list(APPEND LIB_SOURCES wolfcrypt/src/curve25519.c)
  635. endif()
  636. if(BUILD_ED25519)
  637. list(APPEND LIB_SOURCES wolfcrypt/src/ed25519.c)
  638. endif()
  639. if(BUILD_FEMATH)
  640. if(BUILD_CURVE25519_SMALL)
  641. list(APPEND LIB_SOURCES wolfcrypt/src/fe_low_mem.c)
  642. else()
  643. if(BUILD_INTELASM)
  644. list(APPEND LIB_SOURCES wolfcrypt/src/fe_x25519_asm.S)
  645. else()
  646. if(BUILD_ARMASM)
  647. list(APPEND LIB_SOURCES
  648. wolfcrypt/src/port/arm/armv8-32-curve25519.S
  649. wolfcrypt/src/port/arm/armv8-curve25519.S)
  650. else()
  651. list(APPEND LIB_SOURCES wolfcrypt/src/fe_operations.c)
  652. endif()
  653. endif()
  654. endif()
  655. endif()
  656. if(BUILD_GEMATH)
  657. if(BUILD_ED25519_SMALL)
  658. list(APPEND LIB_SOURCES wolfcrypt/src/ge_low_mem.c)
  659. else()
  660. list(APPEND LIB_SOURCES wolfcrypt/src/ge_operations.c)
  661. if(NOT BUILD_FEMATH)
  662. if(BUILD_INTELASM)
  663. list(APPEND LIB_SOURCES wolfcrypt/src/fe_x25519_asm.S)
  664. else()
  665. if(BUILD_ARMASM)
  666. list(APPEND LIB_SOURCES wolfcrypt/src/port/arm/armv8-curve25519.S)
  667. else()
  668. list(APPEND LIB_SOURCES wolfcrypt/src/fe_operations.c)
  669. endif()
  670. endif()
  671. endif()
  672. endif()
  673. endif()
  674. if(BUILD_CURVE448)
  675. list(APPEND LIB_SOURCES wolfcrypt/src/curve448.c)
  676. endif()
  677. if(BUILD_ED448)
  678. list(APPEND LIB_SOURCES wolfcrypt/src/ed448.c)
  679. endif()
  680. if(BUILD_FE448)
  681. list(APPEND LIB_SOURCES wolfcrypt/src/fe_448.c)
  682. endif()
  683. if(BUILD_GE448)
  684. list(APPEND LIB_SOURCES wolfcrypt/src/ge_448.c)
  685. if(NOT BUILD_FE448)
  686. list(APPEND LIB_SOURCES wolfcrypt/src/fe_448.c)
  687. endif()
  688. endif()
  689. if(BUILD_FALCON)
  690. list(APPEND LIB_SOURCES wolfcrypt/src/falcon.c)
  691. endif()
  692. if(BUILD_SPHINCS)
  693. list(APPEND LIB_SOURCES wolfcrypt/src/sphincs.c)
  694. endif()
  695. if(BUILD_DILITHIUM)
  696. list(APPEND LIB_SOURCES wolfcrypt/src/dilithium.c)
  697. endif()
  698. if(BUILD_EXT_KYBER)
  699. list(APPEND LIB_SOURCES wolfcrypt/src/ext_kyber.c)
  700. endif()
  701. if(BUILD_LIBZ)
  702. list(APPEND LIB_SOURCES wolfcrypt/src/compress.c)
  703. endif()
  704. if(BUILD_PKCS7)
  705. list(APPEND LIB_SOURCES wolfcrypt/src/pkcs7.c)
  706. endif()
  707. if(BUILD_SRP)
  708. list(APPEND LIB_SOURCES wolfcrypt/src/srp.c)
  709. endif()
  710. if(BUILD_AFALG)
  711. list(APPEND LIB_SOURCES wolfcrypt/src/port/af_alg/wc_afalg.c)
  712. endif()
  713. if(NOT BUILD_CRYPTONLY)
  714. # ssl files
  715. list(APPEND LIB_SOURCES
  716. src/internal.c
  717. src/wolfio.c
  718. src/keys.c
  719. src/ssl.c
  720. src/ocsp.c
  721. src/tls.c)
  722. if(BUILD_TLS13)
  723. list(APPEND LIB_SOURCES src/tls13.c)
  724. endif()
  725. if(BUILD_DTLS13)
  726. list(APPEND LIB_SOURCES src/dtls13.c)
  727. endif()
  728. if(BUILD_QUIC)
  729. list(APPEND LIB_SOURCES src/quic.c)
  730. endif()
  731. if(BUILD_OCSP)
  732. list(APPEND LIB_SOURCES src/ocsp.c)
  733. endif()
  734. if(BUILD_CRL)
  735. list(APPEND LIB_SOURCES src/crl.c)
  736. endif()
  737. if(BUILD_SNIFFER)
  738. list(APPEND LIB_SOURCES src/sniffer.c)
  739. endif()
  740. if(BUILD_DTLS_COMMON)
  741. list(APPEND LIB_SOURCES src/dtls.c)
  742. endif()
  743. if(BUILD_QUIC)
  744. list(APPEND LIB_SOURCES src/quic.c)
  745. endif()
  746. endif()
  747. endif()
  748. # Corresponds to wolfcrypt/src/include.am
  749. if(BUILD_CRYPTOCB)
  750. list(APPEND LIB_SOURCES wolfcrypt/src/cryptocb.c)
  751. endif()
  752. if(BUILD_PKCS11)
  753. list(APPEND LIB_SOURCES wolfcrypt/src/wc_pkcs11.c)
  754. endif()
  755. if(BUILD_DEVCRYPTO)
  756. list(APPEND LIB_SOURCES
  757. wolfcrypt/src/port/devcrypto/devcrypto_hash.c
  758. wolfcrypt/src/port/devcrypto/devcrypto_aes.c
  759. wolfcrypt/src/port/devcrypto/wc_devcrypto.c)
  760. endif()
  761. if(BUILD_CAVIUM)
  762. list(APPEND LIB_SOURCES wolfcrypt/src/port/cavium/cavium_nitrox.c)
  763. endif()
  764. if(BUILD_OCTEON_SYNC)
  765. list(APPEND LIB_SOURCES wolfcrypt/src/port/cavium/cavium_octeon_sync.c)
  766. endif()
  767. if(BUILD_INTEL_QA)
  768. list(APPEND LIB_SOURCES
  769. wolfcrypt/src/port/intel/quickassist.c
  770. wolfcrypt/src/port/intel/quickassist_mem.c)
  771. endif()
  772. if(BUILD_INTEL_QA_SYNC)
  773. list(APPEND LIB_SOURCES wolfcrypt/src/port/intel/quickassist_sync.c)
  774. endif()
  775. if(BUILD_CRYPTOAUTHLIB)
  776. list(APPEND LIB_SOURCES wolfcrypt/src/port/atmel/atmel.c)
  777. endif()
  778. if(BUILD_CAAM)
  779. list(APPEND LIB_SOURCES
  780. wolfcrypt/src/port/caam/wolfcaam_init.c
  781. wolfcrypt/src/port/caam/wolfcaam_qnx.c
  782. wolfcrypt/src/port/caam/wolfcaam_seco.c
  783. wolfcrypt/src/port/caam/wolfcaam_fsl_nxp.c
  784. wolfcrypt/src/port/caam/wolfcaam_x25519.c
  785. wolfcrypt/src/port/caam/wolfcaam_ecdsa.c
  786. wolfcrypt/src/port/caam/wolfcaam_cmac.c
  787. wolfcrypt/src/port/caam/wolfcaam_aes.c
  788. wolfcrypt/src/port/caam/wolfcaam_hash.c
  789. wolfcrypt/src/port/caam/wolfcaam_rsa.c
  790. wolfcrypt/src/port/caam/wolfcaam_hmac.c)
  791. endif()
  792. if(BUILD_HPKE)
  793. list(APPEND LIB_SOURCES wolfcrypt/src/hpke.c)
  794. endif()
  795. set(LIB_SOURCES ${LIB_SOURCES} PARENT_SCOPE)
  796. endfunction()
  797. function(add_to_options_file DEFINITIONS OPTION_FILE)
  798. list(REMOVE_DUPLICATES DEFINITIONS)
  799. foreach(DEF IN LISTS DEFINITIONS)
  800. if(DEF MATCHES "^-D")
  801. if(DEF MATCHES "^-D(N)?DEBUG(=.+)?")
  802. message("not outputting (N)DEBUG to ${OPTION_FILE}")
  803. endif()
  804. # allow user to ignore system options
  805. if(DEF MATCHES "^-D_.*")
  806. file(APPEND ${OPTION_FILE} "#ifndef WOLFSSL_OPTIONS_IGNORE_SYS\n")
  807. endif()
  808. string(REGEX REPLACE "^-D" "" DEF_NO_PREFIX ${DEF})
  809. string(REGEX REPLACE "=.*$" "" DEF_NO_EQUAL_NO_VAL ${DEF_NO_PREFIX})
  810. string(REPLACE "=" " " DEF_NO_EQUAL ${DEF_NO_PREFIX})
  811. file(APPEND ${OPTION_FILE} "#undef ${DEF_NO_EQUAL_NO_VAL}\n")
  812. file(APPEND ${OPTION_FILE} "#define ${DEF_NO_EQUAL}\n")
  813. if(DEF MATCHES "^-D_.*")
  814. file(APPEND ${OPTION_FILE} "#endif\n")
  815. endif()
  816. file(APPEND ${OPTION_FILE} "\n")
  817. endif()
  818. endforeach()
  819. endfunction()
  820. # Function: set_wolfssl_definitions
  821. # Parameter: SEARCH_VALUE The string to search for. (e.g. "WOLFSSL_SHA3")
  822. # Returns: RESULT
  823. #
  824. # Searches WOLFSSL_DEFINITIONS for SEARCH_VALUE
  825. # Returns RESULT = 1 (true) if the search value is found
  826. #
  827. # Ensures setting is only added once and prints status messages.
  828. #
  829. # Also sets a parent (global in cmake file) variable by the same name to 1.
  830. #
  831. # See also get_wolfssl_definitions() for query-only.
  832. #
  833. function(set_wolfssl_definitions SEARCH_VALUE RESULT)
  834. if (${SEARCH_VALUE} STREQUAL "")
  835. message(FATAL_ERROR "Function set_wolfssl_definitions cannot have blank SEARCH_VALUE")
  836. endif()
  837. list(FIND WOLFSSL_DEFINITIONS "${SEARCH_VALUE}" pos)
  838. string(SUBSTRING "${SEARCH_VALUE}" 0 2 PREFIX_VALUE)
  839. if ("${PREFIX_VALUE}" STREQUAL "-D")
  840. message(FATAL_ERROR "Do not specify the -D prefix in set_wolfssl_definitions")
  841. endif()
  842. if(${pos} EQUAL -1)
  843. message(STATUS "${SEARCH_VALUE} not found in WOLFSSL_DEFINITIONS.")
  844. message(STATUS "Enabling ${SEARCH_VALUE}")
  845. list(APPEND WOLFSSL_DEFINITIONS "-D${SEARCH_VALUE}")
  846. set(${SEARCH_VALUE} 1 PARENT_SCOPE)
  847. # override_cache("${SEARCH_VALUE}" "yes") # Need to check that value is settable
  848. set(${RESULT} 1 PARENT_SCOPE)
  849. message(STATUS "Enabling ${SEARCH_VALUE} - success")
  850. else()
  851. message(STATUS "${SEARCH_VALUE} found in WOLFSSL_DEFINITIONS.")
  852. set(${RESULT} 0 PARENT_SCOPE)
  853. endif()
  854. endfunction()
  855. # Function: get_wolfssl_definitions
  856. # Parameter: SEARCH_VALUE The string to search for. (e.g. "WOLFSSL_SHA3")
  857. # Returns: RESULT
  858. #
  859. # Searches WOLFSSL_DEFINITIONS for SEARCH_VALUE
  860. # Returns RESULT = 1 (true) if the search value is found
  861. #
  862. # Unlike set_wolfssl_definitions(), this function only queries the WOLFSSL_DEFINITIONS.
  863. #
  864. function(get_wolfssl_definitions SEARCH_VALUE RESULT)
  865. if (${SEARCH_VALUE} STREQUAL "")
  866. message(FATAL_ERROR "Function get_wolfssl_definitions cannot have blank SEARCH_VALUE")
  867. endif()
  868. list(FIND WOLFSSL_DEFINITIONS "${SEARCH_VALUE}" pos)
  869. string(SUBSTRING "${SEARCH_VALUE}" 0 2 PREFIX_VALUE)
  870. if ("${PREFIX_VALUE}" STREQUAL "-D")
  871. message(FATAL_ERROR "Do not specify the -D prefix in get_wolfssl_definitions")
  872. endif()
  873. if(${pos} EQUAL -1)
  874. message(STATUS "${SEARCH_VALUE} not found in WOLFSSL_DEFINITIONS.")
  875. else()
  876. message(STATUS "${SEARCH_VALUE} found in WOLFSSL_DEFINITIONS.")
  877. endif()
  878. endfunction()