From 61058871a9d0a671539b35f73c7fde8ac88d9014 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Tue, 17 May 2022 16:52:27 -0700 Subject: [PATCH] [openssl] Support custom cflags on Windows (#24133) * [openssl] Support custom cflags on Windows * [openssl] Add vcpkg-cmake-get-vars dependency * [openssl] Record version Co-authored-by: Billy Robert O'Neal --- ports/openssl/vcpkg.json | 10 ++++++++++ ports/openssl/windows/flags.patch | 22 +++++++++++++++++++++ ports/openssl/windows/portfile.cmake | 29 +++++++++++++++++++++++++--- versions/baseline.json | 2 +- versions/o-/openssl.json | 5 +++++ 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 ports/openssl/windows/flags.patch diff --git a/ports/openssl/vcpkg.json b/ports/openssl/vcpkg.json index 008c3fa130..a0619265e1 100644 --- a/ports/openssl/vcpkg.json +++ b/ports/openssl/vcpkg.json @@ -1,6 +1,7 @@ { "name": "openssl", "version": "3.0.3", + "port-version": 1, "description": "OpenSSL is an open source project that provides a robust, commercial-grade, and full-featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. It is also a general-purpose cryptography library.", "homepage": "https://www.openssl.org", "license": "Apache-2.0", @@ -8,6 +9,15 @@ { "name": "vcpkg-cmake", "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + }, + { + "name": "vcpkg-cmake-get-vars", + "host": true, + "platform": "windows & !mingw & !uwp" } ] } diff --git a/ports/openssl/windows/flags.patch b/ports/openssl/windows/flags.patch new file mode 100644 index 0000000000..90f0e89107 --- /dev/null +++ b/ports/openssl/windows/flags.patch @@ -0,0 +1,22 @@ +diff --git a/Configure b/Configure +index faf57b1..690a9b8 100644 +--- a/Configure ++++ b/Configure +@@ -556,7 +556,7 @@ my $list_separator_re = + # (we supported those before the change to "make variable" support. + my %user = ( + AR => env('AR'), +- ARFLAGS => [], ++ ARFLAGS => [ env('ARFLAGS') || () ], + AS => undef, + ASFLAGS => [], + CC => env('CC'), +@@ -569,7 +569,7 @@ my %user = ( + CPPINCLUDES => [], # Alternative for -I + CROSS_COMPILE => env('CROSS_COMPILE'), + HASHBANGPERL=> env('HASHBANGPERL') || env('PERL'), +- LD => undef, ++ LD => env('LD'), + LDFLAGS => [ env('LDFLAGS') || () ], # -L, -Wl, + LDLIBS => [ env('LDLIBS') || () ], # -l + MT => undef, diff --git a/ports/openssl/windows/portfile.cmake b/ports/openssl/windows/portfile.cmake index 5cd4873002..f4f346e184 100644 --- a/ports/openssl/windows/portfile.cmake +++ b/ports/openssl/windows/portfile.cmake @@ -1,6 +1,7 @@ vcpkg_extract_source_archive_ex( OUT_SOURCE_PATH SOURCE_PATH ARCHIVE ${ARCHIVE} + PATCHES "${CMAKE_CURRENT_LIST_DIR}/flags.patch" ) vcpkg_find_acquire_program(NASM) @@ -10,16 +11,29 @@ vcpkg_add_to_path(PREPEND "${NASM_EXE_PATH}") vcpkg_find_acquire_program(JOM) set(OPENSSL_SHARED no-shared) -if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) +if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") set(OPENSSL_SHARED shared) endif() +vcpkg_cmake_get_vars(cmake_vars_file) +include("${cmake_vars_file}") + +set(ENV{CC} "${VCPKG_DETECTED_CMAKE_C_COMPILER}") +set(ENV{CXX} "${VCPKG_DETECTED_CMAKE_CXX_COMPILER}") +set(ENV{AR} "${VCPKG_DETECTED_CMAKE_AR}") +set(ENV{LD} "${VCPKG_DETECTED_CMAKE_LINKER}") + +# OpenSSL's buildsystem hardcodes certain PDB manipulations, so we cannot use Z7 +string(REGEX REPLACE "(^| )-Z7($| )" " " VCPKG_COMBINED_C_FLAGS_RELEASE "${VCPKG_COMBINED_C_FLAGS_RELEASE}") +string(REGEX REPLACE "(^| )-Z7($| )" " " VCPKG_COMBINED_C_FLAGS_DEBUG "${VCPKG_COMBINED_C_FLAGS_DEBUG}") +string(REGEX REPLACE "(^| )-Z7($| )" " " VCPKG_COMBINED_CXX_FLAGS_RELEASE "${VCPKG_COMBINED_CXX_FLAGS_RELEASE}") +string(REGEX REPLACE "(^| )-Z7($| )" " " VCPKG_COMBINED_CXX_FLAGS_DEBUG "${VCPKG_COMBINED_CXX_FLAGS_DEBUG}") + set(CONFIGURE_OPTIONS enable-static-engine enable-capieng no-ssl2 no-tests - -utf-8 ${OPENSSL_SHARED} ) @@ -51,7 +65,6 @@ file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg") if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") - # Copy openssl sources. message(STATUS "Copying openssl release source files...") file(GLOB OPENSSL_SOURCE_FILES ${SOURCE_PATH}/*) @@ -63,6 +76,11 @@ if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") set(OPENSSLDIR_RELEASE ${CURRENT_PACKAGES_DIR}) + set(ENV{CFLAGS} "${VCPKG_COMBINED_C_FLAGS_RELEASE}") + set(ENV{CXXFLAGS} "${VCPKG_COMBINED_CXX_FLAGS_RELEASE}") + set(ENV{LDFLAGS} "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_RELEASE}") + set(ENV{ARFLAGS} "${VCPKG_COMBINED_STATIC_LINKER_FLAGS_RELEASE}") + message(STATUS "Configure ${TARGET_TRIPLET}-rel") vcpkg_execute_required_process( COMMAND ${CONFIGURE_COMMAND} ${OPENSSL_ARCH} "--prefix=${OPENSSLDIR_RELEASE}" "--openssldir=${OPENSSLDIR_RELEASE}" -FS @@ -102,6 +120,11 @@ if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") set(OPENSSLDIR_DEBUG ${CURRENT_PACKAGES_DIR}/debug) + set(ENV{CFLAGS} "${VCPKG_COMBINED_C_FLAGS_DEBUG}") + set(ENV{CXXFLAGS} "${VCPKG_COMBINED_CXX_FLAGS_DEBUG}") + set(ENV{LDFLAGS} "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_DEBUG}") + set(ENV{ARFLAGS} "${VCPKG_COMBINED_STATIC_LINKER_FLAGS_DEBUG}") + message(STATUS "Configure ${TARGET_TRIPLET}-dbg") vcpkg_execute_required_process( COMMAND ${CONFIGURE_COMMAND} debug-${OPENSSL_ARCH} "--prefix=${OPENSSLDIR_DEBUG}" "--openssldir=${OPENSSLDIR_DEBUG}" -FS diff --git a/versions/baseline.json b/versions/baseline.json index 3a15b5e832..5c78dcc9f7 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -5178,7 +5178,7 @@ }, "openssl": { "baseline": "3.0.3", - "port-version": 0 + "port-version": 1 }, "openssl-unix": { "baseline": "1.1.1h", diff --git a/versions/o-/openssl.json b/versions/o-/openssl.json index 14d19fb958..93f7b62b5c 100644 --- a/versions/o-/openssl.json +++ b/versions/o-/openssl.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "1ac5c972c2c6c9af050334b2f7a41de1253c6a5e", + "version": "3.0.3", + "port-version": 1 + }, { "git-tree": "973408910bc03c5a350f502080548a0d1ac68352", "version": "3.0.3",