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