Update networking layer w/ CURL and emscripten impl
This commit is contained in:
+132
@@ -0,0 +1,132 @@
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# 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-consumer C)
|
||||
|
||||
option(TEST_INTEGRATION_MODE "Integration mode" "find_package")
|
||||
|
||||
message(STATUS "TEST_INTEGRATION_MODE: ${TEST_INTEGRATION_MODE}")
|
||||
|
||||
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")
|
||||
set(BUILD_SHARED_LIBS ON CACHE BOOL "")
|
||||
set(BUILD_STATIC_LIBS ON CACHE BOOL "")
|
||||
add_subdirectory(curl)
|
||||
elseif(TEST_INTEGRATION_MODE STREQUAL "FetchContent")
|
||||
if(CMAKE_VERSION VERSION_LESS 3.14)
|
||||
message(FATAL_ERROR "This test requires CMake 3.14 or upper")
|
||||
endif()
|
||||
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)
|
||||
set(BUILD_SHARED_LIBS ON CACHE BOOL "")
|
||||
set(BUILD_STATIC_LIBS ON CACHE BOOL "")
|
||||
FetchContent_MakeAvailable(curl) # Requires CMake 3.14
|
||||
elseif(TEST_INTEGRATION_MODE STREQUAL "ExternalProject")
|
||||
include(ExternalProject)
|
||||
set(_curl_install_dir "${CMAKE_BINARY_DIR}/curl-external-install")
|
||||
set(_curl_static_lib "${_curl_install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}curl${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
string(REPLACE " " ";" CURL_TEST_OPTS "${CURL_TEST_OPTS}")
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
|
||||
set(_download_extract_timestamp "DOWNLOAD_EXTRACT_TIMESTAMP" "ON")
|
||||
endif()
|
||||
ExternalProject_Add(curl-external
|
||||
URL "${FROM_ARCHIVE}" URL_HASH "SHA256=${FROM_HASH}"
|
||||
${_download_extract_timestamp}
|
||||
PREFIX "${CMAKE_BINARY_DIR}/curl-external"
|
||||
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${_curl_install_dir}" -DBUILD_SHARED_LIBS=OFF -DCURL_USE_LIBPSL=OFF -DCURL_USE_PKGCONFIG=OFF
|
||||
-DCURL_ENABLE_SSL=OFF -DCURL_ENABLE_SSL=OFF -DCURL_DISABLE_LDAP=ON -DCURL_USE_LIBSSH2=OFF -DUSE_NGHTTP2=OFF
|
||||
-DCURL_BROTLI=OFF -DCURL_ZLIB=OFF -DCURL_ZSTD=OFF -DUSE_LIBIDN2=OFF -DENABLE_IPV6=OFF
|
||||
${CURL_TEST_OPTS}
|
||||
BUILD_BYPRODUCTS "${_curl_static_lib}")
|
||||
|
||||
add_executable(test-consumer-static-fetch "test.c")
|
||||
add_dependencies(test-consumer-static-fetch curl-external)
|
||||
if(WIN32)
|
||||
target_compile_definitions(test-consumer-static-fetch PRIVATE "CURL_STATICLIB")
|
||||
list(APPEND _curl_static_lib "ws2_32" "bcrypt")
|
||||
endif()
|
||||
target_include_directories(test-consumer-static-fetch PRIVATE "${_curl_install_dir}/include")
|
||||
target_link_libraries(test-consumer-static-fetch PRIVATE "${_curl_static_lib}")
|
||||
endif()
|
||||
|
||||
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")
|
||||
target_link_libraries(test-consumer-static-ns PRIVATE "CURL::libcurl_static")
|
||||
|
||||
add_executable(test-consumer-shared-ns "test.c")
|
||||
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")
|
||||
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")
|
||||
target_link_libraries(test-consumer-static-bare PRIVATE "libcurl_static")
|
||||
|
||||
add_executable(test-consumer-shared-bare "test.c")
|
||||
target_link_libraries(test-consumer-shared-bare PRIVATE "libcurl_shared")
|
||||
|
||||
add_executable(test-consumer-selected-bare "test.c")
|
||||
target_link_libraries(test-consumer-selected-bare PRIVATE "libcurl")
|
||||
endif()
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* 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(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
printf("libcurl test: |%s|%s|\n", argv[0], curl_version());
|
||||
return 0;
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
#!/bin/sh -x
|
||||
# Copyright (C) Viktor Szakats
|
||||
#
|
||||
# SPDX-License-Identifier: curl
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
|
||||
set -eu
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
mode="${1:-all}"; shift
|
||||
|
||||
cmake_consumer="${TEST_CMAKE_CONSUMER:-cmake}"
|
||||
cmake_provider="${TEST_CMAKE_PROVIDER:-${cmake_consumer}}"
|
||||
|
||||
# 'modern': supports -S/-B (3.13+), --install (3.15+)
|
||||
"${cmake_consumer}" --help | grep -q -- '--install' && cmake_consumer_modern=1
|
||||
"${cmake_provider}" --help | grep -q -- '--install' && cmake_provider_modern=1
|
||||
|
||||
if [ -n "${TEST_CMAKE_GENERATOR:-}" ]; then
|
||||
gen="${TEST_CMAKE_GENERATOR}"
|
||||
elif [ -n "${cmake_consumer_modern:-}" ] && \
|
||||
[ -n "${cmake_provider_modern:-}" ] && \
|
||||
command -v ninja >/dev/null; then
|
||||
gen='Ninja' # 3.17+
|
||||
else
|
||||
gen='Unix Makefiles'
|
||||
fi
|
||||
|
||||
cmake_opts='-DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF -DBUILD_MISC_DOCS=OFF -DENABLE_CURL_MANUAL=OFF'
|
||||
|
||||
src='../..'
|
||||
|
||||
runresults() {
|
||||
set +x
|
||||
for bin in "$1"/test-consumer*; do
|
||||
file "${bin}" || true
|
||||
${TEST_CMAKE_EXE_RUNNER:-} "${bin}" || true
|
||||
done
|
||||
set -x
|
||||
}
|
||||
|
||||
if [ "${mode}" = 'all' ] || [ "${mode}" = 'ExternalProject' ]; then
|
||||
(cd "${src}"; git archive --format=tar HEAD) | gzip > source.tar.gz
|
||||
src="${PWD}/source.tar.gz"
|
||||
sha="$(openssl dgst -sha256 "${src}" | grep -a -i -o -E '[0-9a-f]{64}$')"
|
||||
bldc='bld-externalproject'
|
||||
rm -rf "${bldc}"
|
||||
if [ -n "${cmake_consumer_modern:-}" ]; then # 3.15+
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} -DCURL_TEST_OPTS="${cmake_opts} -DCMAKE_UNITY_BUILD=ON $*" \
|
||||
-DTEST_INTEGRATION_MODE=ExternalProject \
|
||||
-DFROM_ARCHIVE="${src}" -DFROM_HASH="${sha}"
|
||||
"${cmake_consumer}" --build "${bldc}" --verbose
|
||||
else
|
||||
mkdir "${bldc}"; cd "${bldc}"
|
||||
"${cmake_consumer}" .. -G "${gen}" ${TEST_CMAKE_FLAGS:-} -DCURL_TEST_OPTS="${cmake_opts} $*" \
|
||||
-DTEST_INTEGRATION_MODE=ExternalProject \
|
||||
-DFROM_ARCHIVE="${src}" -DFROM_HASH="${sha}"
|
||||
VERBOSE=1 "${cmake_consumer}" --build .
|
||||
cd ..
|
||||
fi
|
||||
runresults "${bldc}"
|
||||
fi
|
||||
|
||||
if [ "${mode}" = 'all' ] || [ "${mode}" = 'FetchContent' ]; then # 3.14+
|
||||
src="${PWD}/${src}"
|
||||
bldc='bld-fetchcontent'
|
||||
rm -rf "${bldc}"
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} "$@" \
|
||||
-DTEST_INTEGRATION_MODE=FetchContent \
|
||||
-DFROM_GIT_REPO="${src}" \
|
||||
-DFROM_GIT_TAG="$(git rev-parse HEAD)"
|
||||
"${cmake_consumer}" --build "${bldc}" --verbose
|
||||
PATH="${bldc}/_deps/curl-build/lib:${PATH}"
|
||||
runresults "${bldc}"
|
||||
fi
|
||||
|
||||
if [ "${mode}" = 'all' ] || [ "${mode}" = 'add_subdirectory' ]; then
|
||||
rm -rf curl
|
||||
if ! ln -s "${src}" curl; then
|
||||
rm -rf curl; mkdir curl; (cd "${src}"; git archive --format=tar HEAD) | tar -x --directory=curl # for MSYS2/Cygwin
|
||||
fi
|
||||
bldc='bld-add_subdirectory'
|
||||
rm -rf "${bldc}"
|
||||
if [ -n "${cmake_consumer_modern:-}" ]; then # 3.15+
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} "$@" \
|
||||
-DTEST_INTEGRATION_MODE=add_subdirectory
|
||||
"${cmake_consumer}" --build "${bldc}" --verbose
|
||||
else
|
||||
mkdir "${bldc}"; cd "${bldc}"
|
||||
# Disable `pkg-config` for CMake <= 3.12. These versions cannot propagate
|
||||
# library directories to the consumer project.
|
||||
"${cmake_consumer}" .. -G "${gen}" ${cmake_opts} -DCURL_USE_PKGCONFIG=OFF ${TEST_CMAKE_FLAGS:-} "$@" \
|
||||
-DTEST_INTEGRATION_MODE=add_subdirectory
|
||||
VERBOSE=1 "${cmake_consumer}" --build .
|
||||
cd ..
|
||||
fi
|
||||
PATH="${bldc}/curl/lib:${PATH}"
|
||||
runresults "${bldc}"
|
||||
fi
|
||||
|
||||
if [ "${mode}" = 'all' ] || [ "${mode}" = 'find_package' ]; then
|
||||
src="${PWD}/${src}"
|
||||
bldp='bld-curl'
|
||||
prefix="${PWD}/${bldp}/_pkg"
|
||||
rm -rf "${bldp}"
|
||||
if [ -n "${cmake_provider_modern:-}" ]; then # 3.15+
|
||||
"${cmake_provider}" -B "${bldp}" -S "${src}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} "$@" \
|
||||
-DBUILD_SHARED_LIBS=ON \
|
||||
-DBUILD_STATIC_LIBS=ON \
|
||||
-DCMAKE_INSTALL_PREFIX="${prefix}"
|
||||
"${cmake_provider}" --build "${bldp}" --verbose
|
||||
"${cmake_provider}" --install "${bldp}"
|
||||
else
|
||||
mkdir "${bldp}"; cd "${bldp}"
|
||||
"${cmake_provider}" "${src}" -G "${gen}" ${cmake_opts} -DCURL_USE_PKGCONFIG=OFF ${TEST_CMAKE_FLAGS:-} "$@" \
|
||||
-DBUILD_SHARED_LIBS=ON \
|
||||
-DBUILD_STATIC_LIBS=ON \
|
||||
-DCMAKE_INSTALL_PREFIX="${prefix}"
|
||||
VERBOSE=1 "${cmake_provider}" --build .
|
||||
make install
|
||||
cd ..
|
||||
fi
|
||||
bldc='bld-find_package'
|
||||
rm -rf "${bldc}"
|
||||
if [ -n "${cmake_consumer_modern:-}" ]; then # 3.15+
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} \
|
||||
-DTEST_INTEGRATION_MODE=find_package \
|
||||
-DCMAKE_PREFIX_PATH="${prefix}/lib/cmake/CURL"
|
||||
"${cmake_consumer}" --build "${bldc}" --verbose
|
||||
else
|
||||
mkdir "${bldc}"; cd "${bldc}"
|
||||
"${cmake_consumer}" .. -G "${gen}" ${TEST_CMAKE_FLAGS:-} \
|
||||
-DTEST_INTEGRATION_MODE=find_package \
|
||||
-DCMAKE_PREFIX_PATH="${prefix}/lib/cmake/CURL"
|
||||
VERBOSE=1 "${cmake_consumer}" --build .
|
||||
cd ..
|
||||
fi
|
||||
PATH="${prefix}/bin:${PATH}"
|
||||
runresults "${bldc}"
|
||||
fi
|
||||
Reference in New Issue
Block a user