Skip to content

Commit

Permalink
[openssl] Support custom cflags on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0219-msft committed Apr 14, 2022
1 parent 99346bb commit 8f2244c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ports/openssl/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "openssl",
"version": "3.0.2",
"port-version": 2,
"port-version": 3,
"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",
Expand Down
22 changes: 22 additions & 0 deletions ports/openssl/windows/flags.patch
Original file line number Diff line number Diff line change
@@ -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,
29 changes: 26 additions & 3 deletions ports/openssl/windows/portfile.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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}
)

Expand Down Expand Up @@ -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}/*)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -5154,7 +5154,7 @@
},
"openssl": {
"baseline": "3.0.2",
"port-version": 2
"port-version": 3
},
"openssl-unix": {
"baseline": "1.1.1h",
Expand Down
5 changes: 5 additions & 0 deletions versions/o-/openssl.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "b5396eda889fb7bfa247f221132e539671470dd1",
"version": "3.0.2",
"port-version": 3
},
{
"git-tree": "66e7ff434d21a4fc00cab9bbe6167db295ffefd3",
"version": "3.0.2",
Expand Down

0 comments on commit 8f2244c

Please sign in to comment.