CMakeLists.txt 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. # Get 'LIBTESTPROGS', '*_SOURCES', 'TESTUTIL', 'TSTTRACE', 'WARNLESS', 'MULTIBYTE', 'TIMEDIFF', 'THREADS', 'FIRSTFILES' variables
  25. transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
  26. include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
  27. set_source_files_properties("../../lib/curl_multibyte.c" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
  28. add_custom_command(
  29. OUTPUT "lib1521.c"
  30. COMMAND ${PERL_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl" < "${PROJECT_SOURCE_DIR}/include/curl/curl.h" "lib1521.c"
  31. DEPENDS
  32. "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl"
  33. "${PROJECT_SOURCE_DIR}/include/curl/curl.h"
  34. VERBATIM)
  35. if(CURL_TEST_BUNDLES)
  36. add_custom_command(
  37. OUTPUT "libtest_bundle.c"
  38. COMMAND ${PERL_EXECUTABLE} "${PROJECT_SOURCE_DIR}/tests/mk-bundle.pl" "${CMAKE_CURRENT_SOURCE_DIR}" > "libtest_bundle.c"
  39. DEPENDS
  40. "${PROJECT_SOURCE_DIR}/tests/mk-bundle.pl" ${FIRSTFILES} "lib1521.c"
  41. "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc"
  42. VERBATIM)
  43. set(LIBTESTPROGS "libtests")
  44. set(libtests_SOURCES "libtest_bundle.c")
  45. list(APPEND libtests_SOURCES ${TESTUTIL} ${TSTTRACE})
  46. if(LIB_SELECTED STREQUAL LIB_SHARED)
  47. # These are part of the libcurl static lib. Add them here when linking shared.
  48. list(APPEND libtests_SOURCES ${WARNLESS} ${MULTIBYTE} ${TIMEDIFF} ${THREADS})
  49. endif()
  50. endif()
  51. foreach(_target IN LISTS LIBTESTPROGS)
  52. if(DEFINED ${_target}_SOURCES)
  53. set(_sources ${${_target}_SOURCES})
  54. else()
  55. set(_sources ${nodist_${_target}_SOURCES})
  56. endif()
  57. if(LIB_SELECTED STREQUAL LIB_STATIC)
  58. # These are part of the libcurl static lib. Do not compile/link them again.
  59. list(REMOVE_ITEM _sources ${WARNLESS} ${MULTIBYTE} ${TIMEDIFF} ${THREADS})
  60. endif()
  61. string(TOUPPER ${_target} _upper_target)
  62. set(_target_name "${_target}")
  63. add_executable(${_target_name} EXCLUDE_FROM_ALL ${_sources})
  64. add_dependencies(testdeps ${_target_name})
  65. target_link_libraries(${_target_name} ${LIB_SELECTED} ${CURL_LIBS})
  66. target_include_directories(${_target_name} PRIVATE
  67. "${PROJECT_BINARY_DIR}/lib" # for "curl_config.h"
  68. "${PROJECT_SOURCE_DIR}/lib" # for "curl_setup.h"
  69. "${PROJECT_SOURCE_DIR}/tests/libtest" # to be able to build generated tests
  70. )
  71. if(NOT CURL_TEST_BUNDLES)
  72. set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS ${_upper_target})
  73. endif()
  74. set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_NO_GETADDRINFO_OVERRIDE")
  75. set_target_properties(${_target_name} PROPERTIES
  76. OUTPUT_NAME "${_target}"
  77. PROJECT_LABEL "Test libtest ${_target}")
  78. endforeach()