cmake: add integration tests, run them in CI
Add CMake test project consuming curl via these methods: `FetchContent`, `add_subdirectory()`, `find_package()`. Also: - GHA/distcheck: run these tests in CI. - cmakelint: exclude a warning for calling "wonky-cased" built-in CMake functions, such as `FetchContent_Declare()`. Closes #16126
This commit is contained in:
parent
2b9b3ec579
commit
fb70812437
6
.github/labeler.yml
vendored
6
.github/labeler.yml
vendored
@ -78,7 +78,8 @@ build:
|
|||||||
plan9/**,\
|
plan9/**,\
|
||||||
projects/**,\
|
projects/**,\
|
||||||
winbuild/**,\
|
winbuild/**,\
|
||||||
lib/libcurl.def\
|
lib/libcurl.def,\
|
||||||
|
tests/cmake/**\
|
||||||
}"
|
}"
|
||||||
|
|
||||||
CI:
|
CI:
|
||||||
@ -100,7 +101,8 @@ cmake:
|
|||||||
**/CMakeLists.txt,\
|
**/CMakeLists.txt,\
|
||||||
CMake/**,\
|
CMake/**,\
|
||||||
docs/INSTALL-CMAKE.md,\
|
docs/INSTALL-CMAKE.md,\
|
||||||
lib/curl_config.h.cmake\
|
lib/curl_config.h.cmake,\
|
||||||
|
tests/cmake/**\
|
||||||
}"
|
}"
|
||||||
|
|
||||||
cmdline tool:
|
cmdline tool:
|
||||||
|
|||||||
2
.github/workflows/configure-vs-cmake.yml
vendored
2
.github/workflows/configure-vs-cmake.yml
vendored
@ -13,6 +13,7 @@ name: configure-vs-cmake
|
|||||||
- '**/CMakeLists.txt'
|
- '**/CMakeLists.txt'
|
||||||
- 'CMake/**'
|
- 'CMake/**'
|
||||||
- 'lib/curl_config.h.cmake'
|
- 'lib/curl_config.h.cmake'
|
||||||
|
- 'tests/cmake/**'
|
||||||
- '.github/scripts/cmp-config.pl'
|
- '.github/scripts/cmp-config.pl'
|
||||||
- '.github/workflows/configure-vs-cmake.yml'
|
- '.github/workflows/configure-vs-cmake.yml'
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ name: configure-vs-cmake
|
|||||||
- '**/CMakeLists.txt'
|
- '**/CMakeLists.txt'
|
||||||
- 'CMake/**'
|
- 'CMake/**'
|
||||||
- 'lib/curl_config.h.cmake'
|
- 'lib/curl_config.h.cmake'
|
||||||
|
- 'tests/cmake/**'
|
||||||
- '.github/scripts/cmp-config.pl'
|
- '.github/scripts/cmp-config.pl'
|
||||||
- '.github/workflows/configure-vs-cmake.yml'
|
- '.github/workflows/configure-vs-cmake.yml'
|
||||||
|
|
||||||
|
|||||||
30
.github/workflows/distcheck.yml
vendored
30
.github/workflows/distcheck.yml
vendored
@ -159,3 +159,33 @@ jobs:
|
|||||||
mv curl-9.10.11.tar.gz _verify
|
mv curl-9.10.11.tar.gz _verify
|
||||||
cd _verify
|
cd _verify
|
||||||
../scripts/verify-release curl-9.10.11.tar.gz
|
../scripts/verify-release curl-9.10.11.tar.gz
|
||||||
|
|
||||||
|
cmake-integration:
|
||||||
|
name: 'cmake-integration-on-${{ matrix.image }}'
|
||||||
|
runs-on: ${{ matrix.image }}
|
||||||
|
timeout-minutes: 10
|
||||||
|
env:
|
||||||
|
CC: clang
|
||||||
|
CMAKE_GENERATOR: Ninja
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
image: [ubuntu-latest, macos-latest]
|
||||||
|
steps:
|
||||||
|
- name: 'install prereqs'
|
||||||
|
run: |
|
||||||
|
if [[ '${{ matrix.image }}' = *'ubuntu'* ]]; then
|
||||||
|
sudo apt-get -o Dpkg::Use-Pty=0 install ninja-build libpsl-dev libssl-dev
|
||||||
|
else
|
||||||
|
brew install ninja libpsl openssl
|
||||||
|
fi
|
||||||
|
|
||||||
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: 'via FetchContent'
|
||||||
|
run: ./tests/cmake/test.sh FetchContent
|
||||||
|
- name: 'via add_subdirectory'
|
||||||
|
run: ./tests/cmake/test.sh add_subdirectory
|
||||||
|
- name: 'via find_package'
|
||||||
|
run: ./tests/cmake/test.sh find_package
|
||||||
|
|||||||
@ -47,7 +47,7 @@ function(curl_dumpvars)
|
|||||||
if(_var_advanced)
|
if(_var_advanced)
|
||||||
set(_var_advanced " [adv]")
|
set(_var_advanced " [adv]")
|
||||||
endif()
|
endif()
|
||||||
message("${_var}${_var_type}${_var_advanced} = ${${_var}}")
|
message("${_var}${_var_type}${_var_advanced} = '${${_var}}'")
|
||||||
endforeach()
|
endforeach()
|
||||||
message("::endgroup::")
|
message("::endgroup::")
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|||||||
@ -61,7 +61,10 @@ CMAKE_DIST = \
|
|||||||
CMake/PickyWarnings.cmake \
|
CMake/PickyWarnings.cmake \
|
||||||
CMake/Utilities.cmake \
|
CMake/Utilities.cmake \
|
||||||
CMake/win32-cache.cmake \
|
CMake/win32-cache.cmake \
|
||||||
CMakeLists.txt
|
CMakeLists.txt \
|
||||||
|
tests/cmake/CMakeLists.txt \
|
||||||
|
tests/cmake/test.c \
|
||||||
|
tests/cmake/test.sh
|
||||||
|
|
||||||
VC_DIST = projects/README.md \
|
VC_DIST = projects/README.md \
|
||||||
projects/build-openssl.bat \
|
projects/build-openssl.bat \
|
||||||
|
|||||||
@ -47,4 +47,4 @@
|
|||||||
| xargs \
|
| xargs \
|
||||||
cmakelint \
|
cmakelint \
|
||||||
--spaces=2 --linelength=132 \
|
--spaces=2 --linelength=132 \
|
||||||
--filter=-whitespace/indent,-convention/filename,-package/stdargs
|
--filter=-whitespace/indent,-convention/filename,-package/stdargs,-readability/wonkycase
|
||||||
|
|||||||
85
tests/cmake/CMakeLists.txt
Normal file
85
tests/cmake/CMakeLists.txt
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#***************************************************************************
|
||||||
|
# _ _ ____ _
|
||||||
|
# Project ___| | | | _ \| |
|
||||||
|
# / __| | | | |_) | |
|
||||||
|
# | (__| |_| | _ <| |___
|
||||||
|
# \___|\___/|_| \_\_____|
|
||||||
|
#
|
||||||
|
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
#
|
||||||
|
# This software is licensed as described in the file COPYING, which
|
||||||
|
# you should have received as part of this distribution. The terms
|
||||||
|
# are also available at https://curl.se/docs/copyright.html.
|
||||||
|
#
|
||||||
|
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
# copies of the Software, and permit persons to whom the Software is
|
||||||
|
# furnished to do so, under the terms of the COPYING file.
|
||||||
|
#
|
||||||
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
# KIND, either express or implied.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: curl
|
||||||
|
#
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
|
||||||
|
message(STATUS "Using CMake version ${CMAKE_VERSION}")
|
||||||
|
|
||||||
|
project(test-dependent C)
|
||||||
|
|
||||||
|
option(TEST_INTEGRATION_MODE "Integration mode" "find_package")
|
||||||
|
|
||||||
|
message(STATUS "TEST_INTEGRATION_MODE: ${TEST_INTEGRATION_MODE}")
|
||||||
|
|
||||||
|
if(TEST_INTEGRATION_MODE STREQUAL "FetchContent" AND CMAKE_VERSION VERSION_LESS 3.14)
|
||||||
|
message(FATAL_ERROR "This test requires CMake 3.14 or upper")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TEST_INTEGRATION_MODE STREQUAL "find_package")
|
||||||
|
find_package(CURL REQUIRED CONFIG)
|
||||||
|
find_package(CURL REQUIRED CONFIG) # Double-inclusion test
|
||||||
|
foreach(result_var IN ITEMS
|
||||||
|
CURL_FOUND
|
||||||
|
CURL_SUPPORTS_HTTPS
|
||||||
|
CURL_SUPPORTS_Largefile
|
||||||
|
CURL_VERSION
|
||||||
|
CURL_VERSION_STRING
|
||||||
|
)
|
||||||
|
if(NOT ${result_var})
|
||||||
|
message(FATAL_ERROR "'${result_var}' variable expected, but not set by the CURL package.")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
# Show variables set by find_package()
|
||||||
|
get_cmake_property(_vars VARIABLES)
|
||||||
|
foreach(_var IN ITEMS ${_vars})
|
||||||
|
string(TOUPPER "${_var}" _var_upper)
|
||||||
|
if(_var_upper MATCHES "CURL")
|
||||||
|
get_property(_var_type CACHE ${_var} PROPERTY TYPE)
|
||||||
|
if(_var_type)
|
||||||
|
set(_var_type ":${_var_type}")
|
||||||
|
endif()
|
||||||
|
message("find_package() sets: ${_var}${_var_type} = '${${_var}}'")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
elseif(TEST_INTEGRATION_MODE STREQUAL "add_subdirectory")
|
||||||
|
add_subdirectory(curl)
|
||||||
|
elseif(TEST_INTEGRATION_MODE STREQUAL "FetchContent")
|
||||||
|
include(FetchContent)
|
||||||
|
option(FROM_GIT_REPO "Git URL" "https://github.com/curl/curl.git")
|
||||||
|
option(FROM_GIT_TAG "Git tag" "master")
|
||||||
|
FetchContent_Declare(curl
|
||||||
|
GIT_REPOSITORY "${FROM_GIT_REPO}"
|
||||||
|
GIT_TAG "${FROM_GIT_TAG}"
|
||||||
|
GIT_SHALLOW)
|
||||||
|
FetchContent_MakeAvailable(curl) # Requires CMake 3.14
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Alias for either shared or static library
|
||||||
|
add_executable(test-dependent-selected-ns "test.c")
|
||||||
|
target_link_libraries(test-dependent-selected-ns PRIVATE "CURL::libcurl")
|
||||||
|
|
||||||
|
if(TEST_INTEGRATION_MODE STREQUAL "add_subdirectory" OR
|
||||||
|
TEST_INTEGRATION_MODE STREQUAL "FetchContent")
|
||||||
|
add_executable(test-dependent-selected-bare "test.c")
|
||||||
|
target_link_libraries(test-dependent-selected-bare PRIVATE "libcurl")
|
||||||
|
endif()
|
||||||
31
tests/cmake/test.c
Normal file
31
tests/cmake/test.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "curl/curl.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
printf("curl_version(): |%s|\n", curl_version());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
39
tests/cmake/test.sh
Executable file
39
tests/cmake/test.sh
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Copyright (C) Viktor Szakats
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: curl
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
mode="${1:-all}"
|
||||||
|
|
||||||
|
if [ "${mode}" = 'all' ] || [ "${mode}" = 'FetchContent' ]; then
|
||||||
|
rm -rf bld-fetchcontent
|
||||||
|
cmake -B bld-fetchcontent \
|
||||||
|
-DTEST_INTEGRATION_MODE=FetchContent \
|
||||||
|
-DFROM_GIT_REPO="${PWD}/../.." \
|
||||||
|
-DFROM_GIT_TAG="$(git rev-parse HEAD)"
|
||||||
|
cmake --build bld-fetchcontent
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${mode}" = 'all' ] || [ "${mode}" = 'add_subdirectory' ]; then
|
||||||
|
rm -rf curl; ln -s ../.. curl
|
||||||
|
rm -rf bld-add_subdirectory
|
||||||
|
cmake -B bld-add_subdirectory \
|
||||||
|
-DTEST_INTEGRATION_MODE=add_subdirectory
|
||||||
|
cmake --build bld-add_subdirectory
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${mode}" = 'all' ] || [ "${mode}" = 'find_package' ]; then
|
||||||
|
rm -rf bld-curl
|
||||||
|
cmake ../.. -B bld-curl
|
||||||
|
cmake --build bld-curl
|
||||||
|
cmake --install bld-curl --prefix bld-curl/_pkg
|
||||||
|
rm -rf bld-find_package
|
||||||
|
cmake -B bld-find_package \
|
||||||
|
-DTEST_INTEGRATION_MODE=find_package \
|
||||||
|
-DCMAKE_PREFIX_PATH="${PWD}/bld-curl/_pkg/lib/cmake/CURL"
|
||||||
|
cmake --build bld-find_package
|
||||||
|
fi
|
||||||
Loading…
Reference in New Issue
Block a user