CMakeLists.txt 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 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.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. # SPDX-License-Identifier: curl
  22. #
  23. ###########################################################################
  24. set(TARGET_LABEL_PREFIX "Test ")
  25. function(setup_test TEST_NAME) # ARGN are the files in the test
  26. if(LIB_SELECTED STREQUAL LIB_STATIC)
  27. # These are part of the libcurl static lib. Do not compile/link them again.
  28. list(REMOVE_ITEM ARGN ${WARNLESS} ${MULTIBYTE} ${TIMEDIFF})
  29. endif()
  30. add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${ARGN})
  31. add_dependencies(testdeps ${TEST_NAME})
  32. string(TOUPPER ${TEST_NAME} UPPER_TEST_NAME)
  33. include_directories(
  34. ${CURL_SOURCE_DIR}/lib # To be able to reach "curl_setup_once.h"
  35. ${CURL_BINARY_DIR}/lib # To be able to reach "curl_config.h"
  36. ${CURL_BINARY_DIR}/include # To be able to reach "curl/curl.h"
  37. ${CURL_SOURCE_DIR}/tests/libtest # To be able to build generated tests
  38. )
  39. if(USE_ARES)
  40. include_directories(${CARES_INCLUDE_DIR})
  41. endif()
  42. target_link_libraries(${TEST_NAME} ${LIB_SELECTED} ${CURL_LIBS})
  43. set_target_properties(${TEST_NAME}
  44. PROPERTIES COMPILE_DEFINITIONS ${UPPER_TEST_NAME})
  45. set_target_properties(${TEST_NAME}
  46. PROPERTIES PROJECT_LABEL "${TARGET_LABEL_PREFIX}${TEST_NAME}")
  47. endfunction()
  48. transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
  49. include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
  50. foreach(TEST_NAME ${noinst_PROGRAMS})
  51. if(DEFINED ${TEST_NAME}_SOURCES)
  52. setup_test(${TEST_NAME} ${${TEST_NAME}_SOURCES})
  53. else()
  54. setup_test(${TEST_NAME} ${nodist_${TEST_NAME}_SOURCES})
  55. endif()
  56. endforeach()
  57. # Allows for hostname override to make tests machine independent.
  58. # TODO this cmake build assumes a shared build, detect static linking here!
  59. if(NOT WIN32)
  60. add_library(hostname MODULE EXCLUDE_FROM_ALL sethostname.c sethostname.h)
  61. add_dependencies(testdeps hostname)
  62. # Output to .libs for compatibility with autotools, the test data expects a
  63. # library at (tests)/libtest/.libs/libhostname.so
  64. set_target_properties(hostname PROPERTIES
  65. LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/.libs)
  66. if(HIDES_CURL_PRIVATE_SYMBOLS)
  67. set_property(TARGET hostname APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
  68. set_property(TARGET hostname APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
  69. endif()
  70. endif()
  71. add_custom_command(
  72. OUTPUT lib1521.c
  73. COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl < ${CURL_SOURCE_DIR}/include/curl/curl.h > lib1521.c
  74. DEPENDS
  75. "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl"
  76. "${CURL_SOURCE_DIR}/include/curl/curl.h"
  77. VERBATIM)