Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/cmake/CMakeLists.txt
2659 views
1
#***************************************************************************
2
# _ _ ____ _
3
# Project ___| | | | _ \| |
4
# / __| | | | |_) | |
5
# | (__| |_| | _ <| |___
6
# \___|\___/|_| \_\_____|
7
#
8
# Copyright (C) Daniel Stenberg, <[email protected]>, 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 "find_package")
35
find_package(CURL REQUIRED CONFIG)
36
find_package(CURL REQUIRED CONFIG) # Double-inclusion test
37
foreach(_result_var IN ITEMS
38
CURL_FOUND
39
CURL_SUPPORTS_HTTPS
40
CURL_SUPPORTS_Largefile
41
CURL_VERSION
42
CURL_VERSION_STRING
43
)
44
if(NOT ${_result_var})
45
message(FATAL_ERROR "'${_result_var}' variable expected, but not set by the CURL package.")
46
endif()
47
endforeach()
48
# Show variables set by find_package()
49
get_cmake_property(_vars VARIABLES)
50
foreach(_var IN ITEMS ${_vars})
51
string(TOUPPER "${_var}" _var_upper)
52
if(_var_upper MATCHES "CURL")
53
get_property(_var_type CACHE ${_var} PROPERTY TYPE)
54
if(_var_type)
55
set(_var_type ":${_var_type}")
56
endif()
57
message("find_package() sets: ${_var}${_var_type} = '${${_var}}'")
58
endif()
59
endforeach()
60
elseif(TEST_INTEGRATION_MODE STREQUAL "add_subdirectory")
61
set(BUILD_SHARED_LIBS ON CACHE BOOL "")
62
set(BUILD_STATIC_LIBS ON CACHE BOOL "")
63
add_subdirectory(curl)
64
elseif(TEST_INTEGRATION_MODE STREQUAL "FetchContent")
65
if(CMAKE_VERSION VERSION_LESS 3.14)
66
message(FATAL_ERROR "This test requires CMake 3.14 or upper")
67
endif()
68
include(FetchContent)
69
option(FROM_GIT_REPO "Git URL" "https://github.com/curl/curl.git")
70
option(FROM_GIT_TAG "Git tag" "master")
71
FetchContent_Declare(curl
72
GIT_REPOSITORY "${FROM_GIT_REPO}"
73
GIT_TAG "${FROM_GIT_TAG}"
74
GIT_SHALLOW)
75
set(BUILD_SHARED_LIBS ON CACHE BOOL "")
76
set(BUILD_STATIC_LIBS ON CACHE BOOL "")
77
FetchContent_MakeAvailable(curl) # Requires CMake 3.14
78
elseif(TEST_INTEGRATION_MODE STREQUAL "ExternalProject")
79
include(ExternalProject)
80
set(_curl_install_dir "${CMAKE_BINARY_DIR}/curl-external-install")
81
set(_curl_static_lib "${_curl_install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}curl${CMAKE_STATIC_LIBRARY_SUFFIX}")
82
string(REPLACE " " ";" CURL_TEST_OPTS "${CURL_TEST_OPTS}")
83
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
84
set(_download_extract_timestamp "DOWNLOAD_EXTRACT_TIMESTAMP" "ON")
85
endif()
86
ExternalProject_Add(curl-external
87
URL "${FROM_ARCHIVE}" URL_HASH "SHA256=${FROM_HASH}"
88
${_download_extract_timestamp}
89
PREFIX "${CMAKE_BINARY_DIR}/curl-external"
90
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${_curl_install_dir}" -DBUILD_SHARED_LIBS=OFF -DCURL_USE_LIBPSL=OFF -DCURL_USE_PKGCONFIG=OFF
91
-DCURL_ENABLE_SSL=OFF -DCURL_ENABLE_SSL=OFF -DCURL_DISABLE_LDAP=ON -DCURL_USE_LIBSSH2=OFF -DUSE_NGHTTP2=OFF
92
-DCURL_BROTLI=OFF -DCURL_ZLIB=OFF -DCURL_ZSTD=OFF -DUSE_LIBIDN2=OFF -DENABLE_IPV6=OFF
93
${CURL_TEST_OPTS}
94
BUILD_BYPRODUCTS "${_curl_static_lib}")
95
96
add_executable(test-consumer-static-fetch "test.c")
97
add_dependencies(test-consumer-static-fetch curl-external)
98
if(WIN32)
99
target_compile_definitions(test-consumer-static-fetch PRIVATE "CURL_STATICLIB")
100
list(APPEND _curl_static_lib "ws2_32" "bcrypt")
101
endif()
102
target_include_directories(test-consumer-static-fetch PRIVATE "${_curl_install_dir}/include")
103
target_link_libraries(test-consumer-static-fetch PRIVATE "${_curl_static_lib}")
104
endif()
105
106
if(TEST_INTEGRATION_MODE STREQUAL "find_package" OR
107
TEST_INTEGRATION_MODE STREQUAL "add_subdirectory" OR
108
TEST_INTEGRATION_MODE STREQUAL "FetchContent")
109
110
add_executable(test-consumer-static-ns "test.c")
111
target_link_libraries(test-consumer-static-ns PRIVATE "CURL::libcurl_static")
112
113
add_executable(test-consumer-shared-ns "test.c")
114
target_link_libraries(test-consumer-shared-ns PRIVATE "CURL::libcurl_shared")
115
116
# Alias for either shared or static library
117
add_executable(test-consumer-selected-ns "test.c")
118
target_link_libraries(test-consumer-selected-ns PRIVATE "CURL::libcurl")
119
endif()
120
121
if(TEST_INTEGRATION_MODE STREQUAL "add_subdirectory" OR
122
TEST_INTEGRATION_MODE STREQUAL "FetchContent")
123
124
add_executable(test-consumer-static-bare "test.c")
125
target_link_libraries(test-consumer-static-bare PRIVATE "libcurl_static")
126
127
add_executable(test-consumer-shared-bare "test.c")
128
target_link_libraries(test-consumer-shared-bare PRIVATE "libcurl_shared")
129
130
add_executable(test-consumer-selected-bare "test.c")
131
target_link_libraries(test-consumer-selected-bare PRIVATE "libcurl")
132
endif()
133
134