CMakeLists.txt 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.haxx.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. ###########################################################################
  22. set(TARGET_LABEL_PREFIX "Test ")
  23. function(setup_test TEST_NAME) # ARGN are the files in the test
  24. add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${ARGN})
  25. add_dependencies(testdeps ${TEST_NAME})
  26. string(TOUPPER ${TEST_NAME} UPPER_TEST_NAME)
  27. include_directories(
  28. ${CURL_SOURCE_DIR}/lib # To be able to reach "curl_setup_once.h"
  29. ${CURL_BINARY_DIR}/lib # To be able to reach "curl_config.h"
  30. ${CURL_BINARY_DIR}/include # To be able to reach "curl/curl.h"
  31. ${CURL_SOURCE_DIR}/tests/libtest # To be able to build generated tests
  32. )
  33. if(USE_ARES)
  34. include_directories(${CARES_INCLUDE_DIR})
  35. endif()
  36. target_link_libraries(${TEST_NAME} libcurl ${CURL_LIBS})
  37. set_target_properties(${TEST_NAME}
  38. PROPERTIES COMPILE_DEFINITIONS ${UPPER_TEST_NAME})
  39. set_target_properties(${TEST_NAME}
  40. PROPERTIES PROJECT_LABEL "${TARGET_LABEL_PREFIX}${TEST_NAME}")
  41. endfunction()
  42. transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
  43. include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
  44. foreach(TEST_NAME ${noinst_PROGRAMS})
  45. if(DEFINED ${TEST_NAME}_SOURCES)
  46. setup_test(${TEST_NAME} ${${TEST_NAME}_SOURCES})
  47. else()
  48. setup_test(${TEST_NAME} ${nodist_${TEST_NAME}_SOURCES})
  49. endif()
  50. endforeach()
  51. # Allows for hostname override to make tests machine independent.
  52. # TODO this cmake build assumes a shared build, detect static linking here!
  53. if(NOT WIN32)
  54. add_library(hostname MODULE EXCLUDE_FROM_ALL sethostname.c sethostname.h)
  55. add_dependencies(testdeps hostname)
  56. # Output to .libs for compatibility with autotools, the test data expects a
  57. # library at (tests)/libtest/.libs/libhostname.so
  58. set_target_properties(hostname PROPERTIES
  59. LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/.libs)
  60. if(HIDES_CURL_PRIVATE_SYMBOLS)
  61. set_property(TARGET hostname APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
  62. set_property(TARGET hostname APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
  63. endif()
  64. endif()
  65. add_custom_command(
  66. OUTPUT lib1521.c
  67. COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl < ${CURL_SOURCE_DIR}/include/curl/curl.h > lib1521.c
  68. DEPENDS
  69. "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl"
  70. "${CURL_SOURCE_DIR}/include/curl/curl.h"
  71. VERBATIM)
  72. set_property(TARGET chkdecimalpoint
  73. APPEND PROPERTY COMPILE_DEFINITIONS "CURLX_NO_MEMORY_CALLBACKS;CURL_STATICLIB")