CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. cmake_minimum_required (VERSION 2.6)
  17. ####################################################
  18. # Project
  19. ####################################################
  20. project(wolfssl)
  21. find_package (Threads)
  22. ####################################################
  23. # Compiler
  24. ####################################################
  25. # Let CMake choose default compiler
  26. if(APPLE)
  27. # Silence ranlib warning "has no symbols"
  28. SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  29. SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  30. SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  31. SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  32. endif()
  33. ####################################################
  34. # Cross Compile Example
  35. ####################################################
  36. #set(CMAKE_SYSTEM_NAME Linux)
  37. #set(CMAKE_SYSTEM_PROCESSOR arm)
  38. #set(CMAKE_C_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc")
  39. #set(CMAKE_CXX_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-g++")
  40. #set(CMAKE_SYSROOT "/opt/arm-linux-musleabihf-cross/arm-linux-musleabihf/")
  41. # Example for setting CFLAGS
  42. #set(CMAKE_C_FLAGS "-std=gnu89 ${CMAKE_C_FLAGS}")
  43. # Example for map file and custom linker script
  44. #set(CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=output.map -T\"${CMAKE_CURRENT_SOURCE_DIR}/linker.ld\"")
  45. ####################################################
  46. # Build Options
  47. ####################################################
  48. SET(BUILD_TESTS YES CACHE BOOL "Build test applications")
  49. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h")
  50. # Copy generated ./options.h
  51. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h
  52. ${CMAKE_CURRENT_BINARY_DIR}/user_settings.h)
  53. else()
  54. # Use template
  55. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h.in
  56. ${CMAKE_CURRENT_BINARY_DIR}/user_settings.h)
  57. endif()
  58. add_definitions(-DWOLFSSL_USER_SETTINGS)
  59. add_definitions(-DWOLFSSL_IGNORE_FILE_WARN)
  60. if(CMAKE_HAVE_PTHREAD_H)
  61. add_definitions(-DHAVE_PTHREAD)
  62. endif()
  63. ####################################################
  64. # Source Files
  65. ####################################################
  66. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.)
  67. include_directories(${CMAKE_CURRENT_BINARY_DIR}/.)
  68. file(GLOB LIB_SOURCE_FILES
  69. ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c
  70. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/src/*.c)
  71. file(GLOB TEST_SOURCE_FILES
  72. ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.c
  73. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c
  74. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  75. ####################################################
  76. # Output Files
  77. ####################################################
  78. # Build wolfssl library
  79. add_library(wolfssl ${LIB_SOURCE_FILES})
  80. if(WIN32)
  81. # For Windows link ws2_32
  82. target_link_libraries(wolfssl PUBLIC $<$<PLATFORM_ID:Windows>:ws2_32>)
  83. else()
  84. # DH requires math (m) library
  85. target_link_libraries(wolfssl PUBLIC m)
  86. endif()
  87. # Optionally build example and test applications
  88. if(BUILD_TESTS)
  89. # Build wolfCrypt test
  90. add_executable(wolfcrypttest
  91. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
  92. target_link_libraries(wolfcrypttest wolfssl)
  93. # Build wolfCrypt benchmark
  94. add_executable(wolfcryptbench
  95. ${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
  96. target_link_libraries(wolfcryptbench wolfssl)
  97. # Build wolfSSL Client example
  98. add_executable(client
  99. ${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
  100. target_link_libraries(client wolfssl)
  101. # Build wolfSSL Server example
  102. add_executable(server
  103. ${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c)
  104. target_link_libraries(server wolfssl)
  105. # Build Echo Client Example
  106. add_executable(echoclient
  107. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoclient/echoclient.c)
  108. target_link_libraries(echoclient wolfssl)
  109. # Build Echo Server Example
  110. add_executable(echoserver
  111. ${CMAKE_CURRENT_SOURCE_DIR}/examples/echoserver/echoserver.c)
  112. target_link_libraries(echoserver wolfssl)
  113. # Build TLS benchmark example
  114. add_executable(tls_bench
  115. ${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c)
  116. target_link_libraries(tls_bench wolfssl)
  117. target_link_libraries(tls_bench Threads::Threads)
  118. # Build Unit Tests
  119. add_executable(unit_test
  120. ${TEST_SOURCE_FILES})
  121. set_target_properties( unit_test PROPERTIES COMPILE_FLAGS "-DNO_MAIN_DRIVER" )
  122. target_link_libraries(unit_test wolfssl)
  123. target_link_libraries(unit_test Threads::Threads)
  124. endif()
  125. # TODO: Add install() for library, headers and test applications