CMakeLists.txt (4168B)
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 cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR) 26 message(STATUS "Using CMake version ${CMAKE_VERSION}") 27 28 project(test-consumer C) 29 30 option(TEST_INTEGRATION_MODE "Integration mode" "find_package") 31 32 message(STATUS "TEST_INTEGRATION_MODE: ${TEST_INTEGRATION_MODE}") 33 34 if(TEST_INTEGRATION_MODE STREQUAL "FetchContent" AND CMAKE_VERSION VERSION_LESS 3.14) 35 message(FATAL_ERROR "This test requires CMake 3.14 or upper") 36 endif() 37 38 if(TEST_INTEGRATION_MODE STREQUAL "ExternalProject") # Broken 39 include(ExternalProject) 40 ExternalProject_Add(libssh2 41 URL "${FROM_ARCHIVE}" URL_HASH "SHA256=${FROM_HASH}" 42 INSTALL_COMMAND "" 43 DOWNLOAD_EXTRACT_TIMESTAMP ON) 44 endif() 45 46 if(TEST_INTEGRATION_MODE STREQUAL "find_package" OR 47 TEST_INTEGRATION_MODE STREQUAL "ExternalProject") 48 find_package(CURL REQUIRED CONFIG) 49 find_package(CURL REQUIRED CONFIG) # Double-inclusion test 50 foreach(_result_var IN ITEMS 51 CURL_FOUND 52 CURL_SUPPORTS_HTTPS 53 CURL_SUPPORTS_Largefile 54 CURL_VERSION 55 CURL_VERSION_STRING 56 ) 57 if(NOT ${_result_var}) 58 message(FATAL_ERROR "'${_result_var}' variable expected, but not set by the CURL package.") 59 endif() 60 endforeach() 61 # Show variables set by find_package() 62 get_cmake_property(_vars VARIABLES) 63 foreach(_var IN ITEMS ${_vars}) 64 string(TOUPPER "${_var}" _var_upper) 65 if(_var_upper MATCHES "CURL") 66 get_property(_var_type CACHE ${_var} PROPERTY TYPE) 67 if(_var_type) 68 set(_var_type ":${_var_type}") 69 endif() 70 message("find_package() sets: ${_var}${_var_type} = '${${_var}}'") 71 endif() 72 endforeach() 73 elseif(TEST_INTEGRATION_MODE STREQUAL "add_subdirectory") 74 set(BUILD_SHARED_LIBS ON CACHE BOOL "") 75 set(BUILD_STATIC_LIBS ON CACHE BOOL "") 76 add_subdirectory(curl) 77 elseif(TEST_INTEGRATION_MODE STREQUAL "FetchContent") 78 include(FetchContent) 79 option(FROM_GIT_REPO "Git URL" "https://github.com/curl/curl.git") 80 option(FROM_GIT_TAG "Git tag" "master") 81 FetchContent_Declare(curl 82 GIT_REPOSITORY "${FROM_GIT_REPO}" 83 GIT_TAG "${FROM_GIT_TAG}" 84 GIT_SHALLOW) 85 set(BUILD_SHARED_LIBS ON CACHE BOOL "") 86 set(BUILD_STATIC_LIBS ON CACHE BOOL "") 87 FetchContent_MakeAvailable(curl) # Requires CMake 3.14 88 endif() 89 90 add_executable(test-consumer-static-ns "test.c") 91 target_link_libraries(test-consumer-static-ns PRIVATE "CURL::libcurl_static") 92 93 add_executable(test-consumer-shared-ns "test.c") 94 target_link_libraries(test-consumer-shared-ns PRIVATE "CURL::libcurl_shared") 95 96 # Alias for either shared or static library 97 add_executable(test-consumer-selected-ns "test.c") 98 target_link_libraries(test-consumer-selected-ns PRIVATE "CURL::libcurl") 99 100 if(TEST_INTEGRATION_MODE STREQUAL "add_subdirectory" OR 101 TEST_INTEGRATION_MODE STREQUAL "FetchContent") 102 103 add_executable(test-consumer-static-bare "test.c") 104 target_link_libraries(test-consumer-static-bare PRIVATE "libcurl_static") 105 106 add_executable(test-consumer-shared-bare "test.c") 107 target_link_libraries(test-consumer-shared-bare PRIVATE "libcurl_shared") 108 109 add_executable(test-consumer-selected-bare "test.c") 110 target_link_libraries(test-consumer-selected-bare PRIVATE "libcurl") 111 endif()