Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add and link libcurl #1422

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ set(TEST_SCRIPT_ASSET_CACHE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/test-script

find_package(fmt REQUIRED)
find_package(CMakeRC REQUIRED)
find_package(LibCURL REQUIRED)

# === Target: locale-resources ===

Expand Down Expand Up @@ -223,6 +224,8 @@ target_compile_definitions(vcpkglib PUBLIC
_FILE_OFFSET_BITS=64
)

target_link_libraries(vcpkglib PRIVATE CURL::libcurl)

if(VCPKG_STANDALONE_BUNDLE_SHA)
target_compile_definitions(vcpkglib PUBLIC
"VCPKG_STANDALONE_BUNDLE_SHA=${VCPKG_STANDALONE_BUNDLE_SHA}"
Expand Down
62 changes: 62 additions & 0 deletions cmake/FindLibCURL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
option(VCPKG_DEPENDENCY_EXTERNAL_LIBCURL "Use an external version of the libcurl library" OFF)

# This option exists to allow the URI to be replaced with a Microsoft-internal URI in official
# builds which have restricted internet access; see azure-pipelines/signing.yml
# Note that the SHA512 is the same, so vcpkg-tool contributors need not be concerned that we built
# with different content.
if(NOT VCPKG_LIBCURL_URL)
set(VCPKG_LIBCURL_URL "https://github.com/curl/curl/archive/refs/tags/curl-8_8_0.tar.gz")
endif()

if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()

include(FetchContent)
FetchContent_Declare(
LibCURL
URL "${VCPKG_LIBCURL_URL}"
URL_HASH "SHA512=e66cbf9bd3ae7b9b031475210b80b883b6a133042fbbc7cf2413f399d1b38aa54ab7322626abd3c6f1af56e0d540221f618aa903bd6b463ac8324f2c4e92dfa8"
)

if(NOT LibCURL_FIND_REQUIRED)
message(FATAL_ERROR "LibCURL must be REQUIRED")
endif()

if(VCPKG_DEPENDENCY_EXTERNAL_FMT)
Neumann-A marked this conversation as resolved.
Show resolved Hide resolved
find_package(CURL REQUIRED)
else()
block()
Neumann-A marked this conversation as resolved.
Show resolved Hide resolved
set(BUILD_SHARED_LIBS OFF)
set(BUILD_STATIC_LIBS ON)
set(BUILD_CURL_EXE OFF)
set(CURL_DISABLE_INSTALL OFF)
#set(CURL_STATIC_CRT ON)
set(ENABLE_UNICODE ON)
set(CURL_ENABLE_EXPORT_TARGET OFF)
set(BUILD_LIBCURL_DOCS OFF)
set(BUILD_MISC_DOCS OFF)
set(ENABLE_CURL_MANUAL OFF)
set(CMAKE_DISABLE_FIND_PACKAGE_Perl ON)
set(CMAKE_DISABLE_FIND_PACKAGE_ZLIB ON)
set(CMAKE_DISABLE_FIND_PACKAGE_LibPSL ON)
set(CMAKE_DISABLE_FIND_PACKAGE_LibSSH2 ON)
if(MSVC) # This is in block() so no need to backup the variables
string(APPEND CMAKE_C_FLAGS " /wd6101")
string(APPEND CMAKE_C_FLAGS " /wd6011")
string(APPEND CMAKE_C_FLAGS " /wd6054")
string(APPEND CMAKE_C_FLAGS " /wd6240")
string(APPEND CMAKE_C_FLAGS " /wd6239")
string(APPEND CMAKE_C_FLAGS " /wd6323")
string(APPEND CMAKE_C_FLAGS " /wd6387")
string(APPEND CMAKE_C_FLAGS " /wd28182")
string(APPEND CMAKE_C_FLAGS " /wd28183")
string(APPEND CMAKE_C_FLAGS " /wd28251")
endif()
FetchContent_MakeAvailable(LibCURL)
endblock()
if(NOT TARGET CURL::libcurl)
add_library(CURL::libcurl INTERFACE)
target_link_libraries(CURL::libcurl PUBLIC libcurl_static)
endif()
endif()
11 changes: 11 additions & 0 deletions include/vcpkg/base/curl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#ifdef _MSC_VER
#pragma warning(push) // Save current warning state
#pragma warning(disable : 6101) // Disable specific warning (e.g., warning 4996)
#endif

#include <curl/curl.h>

#ifdef _MSC_VER
#pragma warning(pop)
#endif
2 changes: 2 additions & 0 deletions src/vcpkg/base/downloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vcpkg/base/system.process.h>
#include <vcpkg/base/system.proxy.h>
#include <vcpkg/base/util.h>
#include <vcpkg/base/curl.h>

#include <vcpkg/commands.version.h>

Expand Down Expand Up @@ -379,6 +380,7 @@ namespace vcpkg
{
#define GUID_MARKER "5ec47b8e-6776-4d70-b9b3-ac2a57bc0a1c"
static constexpr StringLiteral guid_marker = GUID_MARKER;
// TODO: Replace with libcurl code.
Command prefix_cmd{"curl"};
if (!prefixArgs.empty())
{
Expand Down
2 changes: 2 additions & 0 deletions src/vcpkg/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vcpkg/base/system.mac.h>
#include <vcpkg/base/system.process.h>
#include <vcpkg/base/uuid.h>
#include <vcpkg/base/curl.h>

#include <vcpkg/commands.version.h>
#include <vcpkg/metrics.h>
Expand Down Expand Up @@ -606,6 +607,7 @@ namespace vcpkg
builder.string_arg(vcpkg_metrics_txt_path);
cmd_execute_background(builder);
#else
// TODO: replace with libcurl code
cmd_execute_background(Command("curl")
.string_arg("https://dc.services.visualstudio.com/v2/track")
.string_arg("--max-time")
Expand Down
Loading