Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
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
7 changes: 6 additions & 1 deletion 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 Expand Up @@ -495,6 +498,7 @@ if (BUILD_TESTING)
"${CMAKE_CURRENT_SOURCE_DIR}/src/vcpkg.manifest"
)
target_link_libraries(vcpkg-test PRIVATE vcpkglib)

set_property(TARGET vcpkg-test PROPERTY PDB_NAME "vcpkg-test${VCPKG_PDB_SUFFIX}")
if(ANDROID)
target_link_libraries(vcpkg-test PRIVATE log)
Expand All @@ -504,7 +508,8 @@ if (BUILD_TESTING)

if(CMAKE_VERSION GREATER_EQUAL "3.16")
target_precompile_headers(vcpkg-test REUSE_FROM vcpkglib)
elseif(NOT MSVC)
target_compile_definitions(vcpkg-test PRIVATE CURL_STATICLIB)
elseif(NOT MSVC)
target_compile_options(vcpkg-test PRIVATE -include "${CMAKE_CURRENT_SOURCE_DIR}/include/pch.h")
endif()

Expand Down
65 changes: 65 additions & 0 deletions cmake/FindLibCURL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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)
find_package(CURL REQUIRED)
else()
function(get_libcurl)
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(PICKY_COMPILER 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)
endfunction()
get_libcurl()
if(NOT TARGET CURL::libcurl)
add_library(CURL::libcurl INTERFACE)
target_link_libraries(CURL::libcurl INTERFACE libcurl_static)
target_compile_options(CURL::libcurl INTERFACE CURL_STATICLIB)
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