mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
cmake: add C++ integration test
Also:
- include code to verify a C++-specific public header regression
reported in 8.19.0-rc2.
- curl/curl.h: mention C++ global namespace in comment.
- GHA/dist: add CI job for C++. Runtime: 15 seconds.
Follow-up to ee9b000438 #20686
Ref: #20682
Closes #20687
This commit is contained in:
parent
ee9b000438
commit
6ad50dc285
3
.github/workflows/distcheck.yml
vendored
3
.github/workflows/distcheck.yml
vendored
@ -316,6 +316,9 @@ jobs:
|
||||
run: ./tests/cmake/test.sh add_subdirectory ${TESTOPTS} -DCURL_USE_OPENSSL=ON
|
||||
- name: 'via find_package'
|
||||
run: ./tests/cmake/test.sh find_package ${TESTOPTS} -DCURL_USE_OPENSSL=ON
|
||||
- name: 'via find_package (C++)'
|
||||
if: ${{ contains(matrix.image, 'ubuntu') }}
|
||||
run: TEST_CMAKE_FLAGS=-DTEST_CPP=ON ./tests/cmake/test.sh find_package ${TESTOPTS} -DCURL_USE_OPENSSL=ON
|
||||
|
||||
- name: 'via ExternalProject (old cmake)'
|
||||
if: ${{ contains(matrix.image, 'ubuntu') }}
|
||||
|
||||
@ -62,6 +62,7 @@ CMAKE_DIST = \
|
||||
CMakeLists.txt \
|
||||
tests/cmake/CMakeLists.txt \
|
||||
tests/cmake/test.c \
|
||||
tests/cmake/test.cpp \
|
||||
tests/cmake/test.sh
|
||||
|
||||
EXTRA_DIST = CHANGES.md COPYING RELEASE-NOTES Dockerfile .clang-tidy.yml .editorconfig $(CMAKE_DIST)
|
||||
|
||||
@ -3329,8 +3329,8 @@ CURL_EXTERN CURLcode curl_easy_ssls_export(CURL *handle,
|
||||
#if defined(__STDC__) && (__STDC__ >= 1)
|
||||
/* This preprocessor magic that replaces a call with the exact same call is
|
||||
only done to make sure application authors pass exactly three arguments
|
||||
to these functions. Use recursive macros to allow reusing these symbols
|
||||
as C++ method names. */
|
||||
to these functions. Use recursive macros to allow using these symbols via
|
||||
the C++ global namespace '::' or reuse them as method names. */
|
||||
#define curl_easy_setopt(handle, opt, param) \
|
||||
curl_easy_setopt(handle, opt, param)
|
||||
#define curl_easy_getinfo(handle, info, arg) \
|
||||
|
||||
@ -25,7 +25,15 @@
|
||||
cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
|
||||
message(STATUS "Using CMake version ${CMAKE_VERSION}")
|
||||
|
||||
project(test-consumer C)
|
||||
option(TEST_CPP "Test C++" OFF)
|
||||
|
||||
if(TEST_CPP)
|
||||
project(test-CPP-consumer CXX)
|
||||
set(_source "test.cpp")
|
||||
else()
|
||||
project(test-C-consumer C)
|
||||
set(_source "test.c")
|
||||
endif()
|
||||
|
||||
option(TEST_INTEGRATION_MODE "Integration mode" "find_package")
|
||||
|
||||
@ -93,7 +101,7 @@ elseif(TEST_INTEGRATION_MODE STREQUAL "ExternalProject")
|
||||
${CURL_TEST_OPTS}
|
||||
BUILD_BYPRODUCTS "${_curl_static_lib}")
|
||||
|
||||
add_executable(test-consumer-static-fetch "test.c")
|
||||
add_executable(test-consumer-static-fetch "${_source}")
|
||||
add_dependencies(test-consumer-static-fetch curl-external)
|
||||
if(WIN32)
|
||||
target_compile_definitions(test-consumer-static-fetch PRIVATE "CURL_STATICLIB")
|
||||
@ -107,26 +115,26 @@ if(TEST_INTEGRATION_MODE STREQUAL "find_package" OR
|
||||
TEST_INTEGRATION_MODE STREQUAL "add_subdirectory" OR
|
||||
TEST_INTEGRATION_MODE STREQUAL "FetchContent")
|
||||
|
||||
add_executable(test-consumer-static-ns "test.c")
|
||||
add_executable(test-consumer-static-ns "${_source}")
|
||||
target_link_libraries(test-consumer-static-ns PRIVATE "CURL::libcurl_static")
|
||||
|
||||
add_executable(test-consumer-shared-ns "test.c")
|
||||
add_executable(test-consumer-shared-ns "${_source}")
|
||||
target_link_libraries(test-consumer-shared-ns PRIVATE "CURL::libcurl_shared")
|
||||
|
||||
# Alias for either shared or static library
|
||||
add_executable(test-consumer-selected-ns "test.c")
|
||||
add_executable(test-consumer-selected-ns "${_source}")
|
||||
target_link_libraries(test-consumer-selected-ns PRIVATE "CURL::libcurl")
|
||||
endif()
|
||||
|
||||
if(TEST_INTEGRATION_MODE STREQUAL "add_subdirectory" OR
|
||||
TEST_INTEGRATION_MODE STREQUAL "FetchContent")
|
||||
|
||||
add_executable(test-consumer-static-bare "test.c")
|
||||
add_executable(test-consumer-static-bare "${_source}")
|
||||
target_link_libraries(test-consumer-static-bare PRIVATE "libcurl_static")
|
||||
|
||||
add_executable(test-consumer-shared-bare "test.c")
|
||||
add_executable(test-consumer-shared-bare "${_source}")
|
||||
target_link_libraries(test-consumer-shared-bare PRIVATE "libcurl_shared")
|
||||
|
||||
add_executable(test-consumer-selected-bare "test.c")
|
||||
add_executable(test-consumer-selected-bare "${_source}")
|
||||
target_link_libraries(test-consumer-selected-bare PRIVATE "libcurl")
|
||||
endif()
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
puts("libcurl test:");
|
||||
puts("libcurl C test:");
|
||||
puts(argv[0]);
|
||||
puts(curl_version());
|
||||
puts("---");
|
||||
|
||||
44
tests/cmake/test.cpp
Normal file
44
tests/cmake/test.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* 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 <iostream>
|
||||
|
||||
class CurlClass {
|
||||
public:
|
||||
void curl_multi_setopt(void *a, int b, long c) {
|
||||
std::cout << curl_version() << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
std::cout << "libcurl C++ test:" << std::endl;
|
||||
std::cout << argv[0] << std::endl;
|
||||
CurlClass mycurl;
|
||||
mycurl.curl_multi_setopt(nullptr, 0, 0);
|
||||
::curl_easy_setopt(nullptr, CURLOPT_URL, "https://example.com/");
|
||||
std::cout << "---" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user