CMakeLists.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. # CMakeList.txt
  2. #
  3. # Copyright (C) 2006-2020 wolfSSL Inc.
  4. #
  5. # This file is part of wolfSSL. (formerly known as CyaSSL)
  6. #
  7. # Usage:
  8. # $ mkdir build
  9. # $ cd build
  10. # $ cmake ..
  11. # $ cmake --build .
  12. # To build library only and not build examples and test apps use:
  13. # $ cmake .. -DBUILD_TESTS=NO
  14. # To build with debugging use:
  15. # $ cmake .. -DCMAKE_BUILD_TYPE=Debug
  16. ####################################################
  17. # Project
  18. ####################################################
  19. cmake_minimum_required(VERSION 3.0)
  20. project(wolfssl)
  21. ####################################################
  22. # Dependencies
  23. ####################################################
  24. find_package(Threads)
  25. ####################################################
  26. # Compiler
  27. ####################################################
  28. # Let CMake choose default compiler
  29. if(APPLE)
  30. # Silence ranlib warning "has no symbols"
  31. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  32. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  33. set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  34. set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  35. endif()
  36. ####################################################
  37. # Cross Compile Example
  38. ####################################################
  39. #set(CMAKE_SYSTEM_NAME Linux)
  40. #set(CMAKE_SYSTEM_PROCESSOR arm)
  41. #set(CMAKE_C_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc")
  42. #set(CMAKE_CXX_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-g++")
  43. #set(CMAKE_SYSROOT "/opt/arm-linux-musleabihf-cross/arm-linux-musleabihf/")
  44. # Example for setting CFLAGS
  45. #set(CMAKE_C_FLAGS "-std=gnu89 ${CMAKE_C_FLAGS}")
  46. # Example for map file and custom linker script
  47. #set(CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=output.map -T\"${CMAKE_CURRENT_SOURCE_DIR}/linker.ld\"")
  48. ####################################################
  49. # Build Options
  50. ####################################################
  51. option(BUILD_TESTS "Build test applications" YES)
  52. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h")
  53. # Copy generated ./options.h
  54. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h
  55. ${CMAKE_CURRENT_SOURCE_DIR}/user_settings.h)
  56. else()
  57. # Use template
  58. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h.in
  59. ${CMAKE_CURRENT_SOURCE_DIR}/user_settings.h)
  60. endif()
  61. add_definitions(-DWOLFSSL_USER_SETTINGS)
  62. add_definitions(-DWOLFSSL_IGNORE_FILE_WARN)
  63. if(CMAKE_USE_PTHREADS_INIT)
  64. add_definitions(-DHAVE_PTHREAD)
  65. endif()
  66. ####################################################
  67. # Library Target
  68. ####################################################
  69. add_library(wolfssl
  70. src/bio.c
  71. src/crl.c
  72. src/internal.c
  73. src/keys.c
  74. src/ocsp.c
  75. src/sniffer.c
  76. src/ssl.c
  77. src/tls.c
  78. src/tls13.c
  79. src/wolfio.c
  80. wolfcrypt/src/aes.c
  81. wolfcrypt/src/arc4.c
  82. wolfcrypt/src/asm.c
  83. wolfcrypt/src/asn.c
  84. wolfcrypt/src/async.c
  85. wolfcrypt/src/blake2b.c
  86. wolfcrypt/src/blake2s.c
  87. wolfcrypt/src/camellia.c
  88. wolfcrypt/src/chacha.c
  89. wolfcrypt/src/chacha20_poly1305.c
  90. wolfcrypt/src/cmac.c
  91. wolfcrypt/src/coding.c
  92. wolfcrypt/src/compress.c
  93. wolfcrypt/src/cpuid.c
  94. wolfcrypt/src/cryptocb.c
  95. wolfcrypt/src/curve25519.c
  96. wolfcrypt/src/curve448.c
  97. wolfcrypt/src/des3.c
  98. wolfcrypt/src/dh.c
  99. wolfcrypt/src/dsa.c
  100. wolfcrypt/src/ecc.c
  101. wolfcrypt/src/ecc_fp.c
  102. wolfcrypt/src/ed25519.c
  103. wolfcrypt/src/ed448.c
  104. wolfcrypt/src/error.c
  105. wolfcrypt/src/evp.c
  106. wolfcrypt/src/fe_448.c
  107. wolfcrypt/src/fe_low_mem.c
  108. wolfcrypt/src/fe_operations.c
  109. wolfcrypt/src/fips.c
  110. wolfcrypt/src/fips_test.c
  111. wolfcrypt/src/ge_448.c
  112. wolfcrypt/src/ge_low_mem.c
  113. wolfcrypt/src/ge_operations.c
  114. wolfcrypt/src/hash.c
  115. wolfcrypt/src/hc128.c
  116. wolfcrypt/src/hmac.c
  117. wolfcrypt/src/idea.c
  118. wolfcrypt/src/integer.c
  119. wolfcrypt/src/logging.c
  120. wolfcrypt/src/md2.c
  121. wolfcrypt/src/md4.c
  122. wolfcrypt/src/md5.c
  123. wolfcrypt/src/memory.c
  124. wolfcrypt/src/misc.c
  125. wolfcrypt/src/pkcs12.c
  126. wolfcrypt/src/pkcs7.c
  127. wolfcrypt/src/poly1305.c
  128. wolfcrypt/src/pwdbased.c
  129. wolfcrypt/src/rabbit.c
  130. wolfcrypt/src/random.c
  131. wolfcrypt/src/ripemd.c
  132. wolfcrypt/src/rsa.c
  133. wolfcrypt/src/selftest.c
  134. wolfcrypt/src/sha.c
  135. wolfcrypt/src/sha256.c
  136. wolfcrypt/src/sha3.c
  137. wolfcrypt/src/sha512.c
  138. wolfcrypt/src/signature.c
  139. wolfcrypt/src/sp_arm32.c
  140. wolfcrypt/src/sp_arm64.c
  141. wolfcrypt/src/sp_armthumb.c
  142. wolfcrypt/src/sp_c32.c
  143. wolfcrypt/src/sp_c64.c
  144. wolfcrypt/src/sp_cortexm.c
  145. wolfcrypt/src/sp_dsp32.c
  146. wolfcrypt/src/sp_int.c
  147. wolfcrypt/src/sp_x86_64.c
  148. wolfcrypt/src/srp.c
  149. wolfcrypt/src/tfm.c
  150. wolfcrypt/src/wc_dsp.c
  151. wolfcrypt/src/wc_encrypt.c
  152. wolfcrypt/src/wc_pkcs11.c
  153. wolfcrypt/src/wc_port.c
  154. wolfcrypt/src/wolfcrypt_first.c
  155. wolfcrypt/src/wolfcrypt_last.c
  156. wolfcrypt/src/wolfevent.c
  157. wolfcrypt/src/wolfmath.c
  158. )
  159. ####################################################
  160. # Include Directories
  161. ####################################################
  162. target_include_directories(wolfssl
  163. PUBLIC
  164. $<INSTALL_INTERFACE:wolfssl>
  165. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/wolfssl>
  166. ${CMAKE_CURRENT_SOURCE_DIR}/. # Needed for user_settings.h to be visible
  167. )
  168. ####################################################
  169. # Link Libraries
  170. ####################################################
  171. if(WIN32)
  172. # For Windows link ws2_32
  173. target_link_libraries(wolfssl PUBLIC $<$<PLATFORM_ID:Windows>:ws2_32>)
  174. else()
  175. # DH requires math (m) library
  176. target_link_libraries(wolfssl PUBLIC m)
  177. endif()
  178. ####################################################
  179. # Tests and Examples
  180. ####################################################
  181. # Optionally build example and test applications
  182. if(BUILD_TESTS)
  183. # Build wolfCrypt test
  184. add_executable(wolfcrypttest
  185. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  186. target_link_libraries(wolfcrypttest wolfssl)
  187. # Build wolfCrypt benchmark
  188. add_executable(wolfcryptbench
  189. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  190. target_link_libraries(wolfcryptbench wolfssl)
  191. # Build wolfSSL Client example
  192. add_executable(client
  193. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  194. target_link_libraries(client wolfssl)
  195. # Build wolfSSL Server example
  196. add_executable(server
  197. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c)
  198. target_link_libraries(server wolfssl)
  199. # Build Echo Client Example
  200. add_executable(echoclient
  201. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c)
  202. target_link_libraries(echoclient wolfssl)
  203. # Build Echo Server Example
  204. add_executable(echoserver
  205. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c)
  206. target_link_libraries(echoserver wolfssl)
  207. # Build TLS benchmark example
  208. add_executable(tls_bench
  209. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c)
  210. target_link_libraries(tls_bench wolfssl)
  211. target_link_libraries(tls_bench Threads::Threads)
  212. # Build Unit Tests
  213. add_executable(unit_test
  214. tests/api.c
  215. tests/hash.c
  216. tests/srp.c
  217. tests/suites.c
  218. tests/unit.c
  219. examples/server/server.c
  220. examples/client/client.c
  221. )
  222. target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER")
  223. target_link_libraries(unit_test wolfssl)
  224. target_link_libraries(unit_test Threads::Threads)
  225. endif()
  226. # TODO: Add install() for library, headers and test applications