CMakeLists.txt 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. cmake_minimum_required(VERSION 3.15)
  2. find_package(Threads REQUIRED)
  3. if (ENABLE_SSL_TESTS)
  4. add_library(test_server STATIC
  5. abstractServer.cpp
  6. httpServer.cpp
  7. httpsServer.cpp)
  8. else ()
  9. add_library(test_server STATIC
  10. abstractServer.cpp
  11. httpServer.cpp)
  12. endif()
  13. if(WIN32)
  14. target_link_libraries(test_server PRIVATE Threads::Threads cpr::cpr GTest::GTest
  15. PUBLIC mongoose ws2_32 wsock32)
  16. else()
  17. target_link_libraries(test_server PRIVATE Threads::Threads cpr::cpr GTest::GTest
  18. PUBLIC mongoose)
  19. endif()
  20. macro(add_cpr_test _TEST_NAME)
  21. add_executable(${_TEST_NAME}_tests ${_TEST_NAME}_tests.cpp)
  22. target_link_libraries(${_TEST_NAME}_tests PRIVATE
  23. test_server
  24. GTest::GTest
  25. cpr::cpr
  26. CURL::libcurl)
  27. add_test(NAME cpr_${_TEST_NAME}_tests COMMAND ${_TEST_NAME}_tests)
  28. # Group under the "tests" project folder in IDEs such as Visual Studio.
  29. set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
  30. if(WIN32 AND BUILD_SHARED_LIBS)
  31. add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:libcurl> $<TARGET_FILE_DIR:${_TEST_NAME}_tests>)
  32. add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cpr> $<TARGET_FILE_DIR:${_TEST_NAME}_tests>)
  33. endif()
  34. endmacro()
  35. add_cpr_test(get)
  36. add_cpr_test(post)
  37. add_cpr_test(session)
  38. add_cpr_test(prepare)
  39. add_cpr_test(async)
  40. if(CPR_BUILD_TESTS_PROXY)
  41. add_cpr_test(proxy)
  42. add_cpr_test(proxy_auth)
  43. endif()
  44. add_cpr_test(head)
  45. add_cpr_test(delete)
  46. add_cpr_test(put)
  47. add_cpr_test(callback)
  48. add_cpr_test(raw_body)
  49. add_cpr_test(options)
  50. add_cpr_test(patch)
  51. add_cpr_test(error)
  52. add_cpr_test(alternating)
  53. add_cpr_test(util)
  54. add_cpr_test(structures)
  55. add_cpr_test(encoded_auth)
  56. add_cpr_test(version)
  57. add_cpr_test(download)
  58. add_cpr_test(interceptor)
  59. add_cpr_test(multiperform)
  60. add_cpr_test(resolve)
  61. if (ENABLE_SSL_TESTS)
  62. add_cpr_test(ssl)
  63. # Install all ssl keys and certs. Explicit copy for each file to prevent issues when copying on Windows.
  64. add_custom_command(TARGET ssl_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:ssl_tests>/data/certificates $<TARGET_FILE_DIR:ssl_tests>/data/keys)
  65. add_custom_command(TARGET ssl_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/data/certificates/client.crt $<TARGET_FILE_DIR:ssl_tests>/data/certificates/client.crt)
  66. add_custom_command(TARGET ssl_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/data/certificates/root-ca.crt $<TARGET_FILE_DIR:ssl_tests>/data/certificates/root-ca.crt)
  67. add_custom_command(TARGET ssl_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/data/certificates/server.crt $<TARGET_FILE_DIR:ssl_tests>/data/certificates/server.crt)
  68. add_custom_command(TARGET ssl_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/data/keys/client.key $<TARGET_FILE_DIR:ssl_tests>/data/keys/client.key)
  69. add_custom_command(TARGET ssl_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/data/keys/root-ca.key $<TARGET_FILE_DIR:ssl_tests>/data/keys/root-ca.key)
  70. add_custom_command(TARGET ssl_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/data/keys/server.key $<TARGET_FILE_DIR:ssl_tests>/data/keys/server.key)
  71. add_custom_command(TARGET ssl_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/data/keys/server.pub $<TARGET_FILE_DIR:ssl_tests>/data/keys/server.pub)
  72. endif()
  73. file(INSTALL data DESTINATION data)