Skip to content

Commit

Permalink
[OpenSSL] refactor openssl ports. (#14308)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neumann-A committed Nov 4, 2020
1 parent c4c0208 commit 63dccf7
Show file tree
Hide file tree
Showing 29 changed files with 418 additions and 548 deletions.
2 changes: 1 addition & 1 deletion ports/openssl-unix/CONTROL
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Source: openssl-unix
Version: 1.1.1h
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.
Description: Deprecated OpenSSL port
Supports: !(windows|uwp)
64 changes: 1 addition & 63 deletions ports/openssl-unix/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,63 +1 @@
if (NOT VCPKG_TARGET_IS_MINGW)
vcpkg_fail_port_install(MESSAGE "${PORT} is only for openssl on Unix-like systems" ON_TARGET "UWP" "Windows")
endif()

if(EXISTS "${CURRENT_INSTALLED_DIR}/include/openssl/ssl.h")
message(FATAL_ERROR "Can't build openssl if libressl/boringssl is installed. Please remove libressl/boringssl, and try install openssl again if you need it.")
endif()


vcpkg_find_acquire_program(PERL)

set(OPENSSL_VERSION 1.1.1h)

vcpkg_download_distfile(OPENSSL_SOURCE_ARCHIVE
URLS "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz" "https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz"
FILENAME "openssl-${OPENSSL_VERSION}.tar.gz"
SHA512 da50fd99325841ed7a4367d9251c771ce505a443a73b327d8a46b2c6a7d2ea99e43551a164efc86f8743b22c2bdb0020bf24a9cbd445e9d68868b2dc1d34033a
)

vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH MASTER_COPY_SOURCE_PATH
ARCHIVE ${OPENSSL_SOURCE_ARCHIVE}
REF ${OPENSSL_VERSION}
)

if(CMAKE_HOST_WIN32)
vcpkg_acquire_msys(MSYS_ROOT PACKAGES make perl)
set(BASH ${MSYS_ROOT}/usr/bin/bash.exe)
set(MAKE ${MSYS_ROOT}/usr/bin/make.exe)
set(PERL ${MSYS_ROOT}/usr/bin/perl.exe)
else()
find_program(MAKE make)
if(NOT MAKE)
message(FATAL_ERROR "Could not find make. Please install it through your package manager.")
endif()
endif()

vcpkg_configure_cmake(
SOURCE_PATH ${CMAKE_CURRENT_LIST_DIR}
PREFER_NINJA
OPTIONS
-DSOURCE_PATH=${MASTER_COPY_SOURCE_PATH}
-DPERL=${PERL}
-DMAKE=${MAKE}
OPTIONS_RELEASE
-DINSTALL_HEADERS=ON
)

vcpkg_install_cmake()

file(GLOB HEADERS ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/*/include/openssl/*.h)
set(RESOLVED_HEADERS)
foreach(HEADER ${HEADERS})
get_filename_component(X "${HEADER}" REALPATH)
list(APPEND RESOLVED_HEADERS "${X}")
endforeach()

file(INSTALL ${RESOLVED_HEADERS} DESTINATION ${CURRENT_PACKAGES_DIR}/include/openssl)
file(INSTALL ${MASTER_COPY_SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(COPY ${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/openssl)
endif()
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
4 changes: 0 additions & 4 deletions ports/openssl-unix/usage

This file was deleted.

3 changes: 1 addition & 2 deletions ports/openssl-uwp/CONTROL
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Source: openssl-uwp
Version: 1.1.1h
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.
Description: Deprecated OpenSSL port
Supports: uwp
178 changes: 1 addition & 177 deletions ports/openssl-uwp/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,177 +1 @@
vcpkg_fail_port_install(MESSAGE "${PORT} is only for Windows Universal Platform" ON_TARGET "Linux" "OSX")

if(EXISTS "${CURRENT_INSTALLED_DIR}/include/openssl/ssl.h")
message(FATAL_ERROR "Can't build openssl if libressl/boringssl is installed. Please remove libressl/boringssl, and try install openssl again if you need it.")
endif()

vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)

vcpkg_find_acquire_program(PERL)
vcpkg_find_acquire_program(JOM)
get_filename_component(JOM_EXE_PATH ${JOM} DIRECTORY)
get_filename_component(PERL_EXE_PATH ${PERL} DIRECTORY)
vcpkg_add_to_path("${PERL_EXE_PATH}")
vcpkg_add_to_path("${JOM_EXE_PATH}")

set(OPENSSL_VERSION 1.1.1h)

vcpkg_download_distfile(ARCHIVE
URLS "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz" "https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz"
FILENAME "openssl-${OPENSSL_VERSION}.tar.gz"
SHA512 da50fd99325841ed7a4367d9251c771ce505a443a73b327d8a46b2c6a7d2ea99e43551a164efc86f8743b22c2bdb0020bf24a9cbd445e9d68868b2dc1d34033a
)

vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH SOURCE_PATH
ARCHIVE ${ARCHIVE}
PATCHES
EnableUWPSupport.patch
)

vcpkg_find_acquire_program(NASM)
get_filename_component(NASM_EXE_PATH ${NASM} DIRECTORY)
vcpkg_add_to_path(PREPEND "${NASM_EXE_PATH}")

vcpkg_find_acquire_program(JOM)

set(CONFIGURE_COMMAND ${PERL} Configure
enable-static-engine
enable-capieng
no-unit-test
no-ssl2
no-asm
no-uplink
no-tests
-utf-8
shared
)

if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
set(OPENSSL_ARCH VC-WIN32-UWP)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
set(OPENSSL_ARCH VC-WIN64A-UWP)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
set(OPENSSL_ARCH VC-WIN32-ARM-UWP)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
set(OPENSSL_ARCH VC-WIN64-ARM-UWP)
else()
message(FATAL_ERROR "Unsupported target architecture: ${VCPKG_TARGET_ARCHITECTURE}")
endif()

set(OPENSSL_MAKEFILE "makefile")

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}/*)
foreach(SOURCE_FILE ${OPENSSL_SOURCE_FILES})
file(COPY ${SOURCE_FILE} DESTINATION "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
endforeach()
message(STATUS "Copying openssl release source files... done")
set(SOURCE_PATH_RELEASE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")

set(OPENSSLDIR_RELEASE ${CURRENT_PACKAGES_DIR})

message(STATUS "Configure ${TARGET_TRIPLET}-rel")
vcpkg_execute_required_process(
COMMAND ${CONFIGURE_COMMAND} ${OPENSSL_ARCH} "--prefix=${OPENSSLDIR_RELEASE}" "--openssldir=${OPENSSLDIR_RELEASE}" -FS
WORKING_DIRECTORY ${SOURCE_PATH_RELEASE}
LOGNAME configure-perl-${TARGET_TRIPLET}-${VCPKG_BUILD_TYPE}-rel
)
message(STATUS "Configure ${TARGET_TRIPLET}-rel done")

message(STATUS "Build ${TARGET_TRIPLET}-rel")
# Openssl's buildsystem has a race condition which will cause JOM to fail at some point.
# This is ok; we just do as much work as we can in parallel first, then follow up with a single-threaded build.
make_directory(${SOURCE_PATH_RELEASE}/inc32/openssl)
execute_process(
COMMAND ${JOM} -k -j $ENV{NUMBER_OF_PROCESSORS} -f ${OPENSSL_MAKEFILE} build_libs
WORKING_DIRECTORY ${SOURCE_PATH_RELEASE}
OUTPUT_FILE ${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-rel-0-out.log
ERROR_FILE ${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-rel-0-err.log
)
vcpkg_execute_required_process(
COMMAND nmake -f ${OPENSSL_MAKEFILE} install_dev
WORKING_DIRECTORY ${SOURCE_PATH_RELEASE}
LOGNAME build-${TARGET_TRIPLET}-rel-1)

message(STATUS "Build ${TARGET_TRIPLET}-rel done")
endif()


if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
# Copy openssl sources.
message(STATUS "Copying openssl debug source files...")
file(GLOB OPENSSL_SOURCE_FILES ${SOURCE_PATH}/*)
foreach(SOURCE_FILE ${OPENSSL_SOURCE_FILES})
file(COPY ${SOURCE_FILE} DESTINATION "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
endforeach()
message(STATUS "Copying openssl debug source files... done")
set(SOURCE_PATH_DEBUG "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")

set(OPENSSLDIR_DEBUG ${CURRENT_PACKAGES_DIR}/debug)

message(STATUS "Configure ${TARGET_TRIPLET}-dbg")
vcpkg_execute_required_process(
COMMAND ${CONFIGURE_COMMAND} debug-${OPENSSL_ARCH} "--prefix=${OPENSSLDIR_DEBUG}" "--openssldir=${OPENSSLDIR_DEBUG}" -FS
WORKING_DIRECTORY ${SOURCE_PATH_DEBUG}
LOGNAME configure-perl-${TARGET_TRIPLET}-${VCPKG_BUILD_TYPE}-dbg
)
message(STATUS "Configure ${TARGET_TRIPLET}-dbg done")

message(STATUS "Build ${TARGET_TRIPLET}-dbg")
make_directory(${SOURCE_PATH_DEBUG}/inc32/openssl)
execute_process(
COMMAND ${JOM} -k -j $ENV{NUMBER_OF_PROCESSORS} -f ${OPENSSL_MAKEFILE} build_libs
WORKING_DIRECTORY ${SOURCE_PATH_DEBUG}
OUTPUT_FILE ${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-dbg-0-out.log
ERROR_FILE ${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-dbg-0-err.log
)
vcpkg_execute_required_process(
COMMAND nmake -f ${OPENSSL_MAKEFILE} install_dev
WORKING_DIRECTORY ${SOURCE_PATH_DEBUG}
LOGNAME build-${TARGET_TRIPLET}-dbg-1)

message(STATUS "Build ${TARGET_TRIPLET}-dbg done")
endif()

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/certs)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/private)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/lib/engines-1_1)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/certs)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/lib/engines-1_1)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/private)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)



file(REMOVE
${CURRENT_PACKAGES_DIR}/bin/openssl.exe
${CURRENT_PACKAGES_DIR}/debug/bin/openssl.exe
${CURRENT_PACKAGES_DIR}/debug/openssl.cnf
${CURRENT_PACKAGES_DIR}/openssl.cnf
${CURRENT_PACKAGES_DIR}/ct_log_list.cnf
${CURRENT_PACKAGES_DIR}/ct_log_list.cnf.dist
${CURRENT_PACKAGES_DIR}/openssl.cnf.dist
${CURRENT_PACKAGES_DIR}/debug/ct_log_list.cnf
${CURRENT_PACKAGES_DIR}/debug/ct_log_list.cnf.dist
${CURRENT_PACKAGES_DIR}/debug/openssl.cnf.dist
)


file(READ "${CURRENT_PACKAGES_DIR}/include/openssl/dtls1.h" _contents)
string(REPLACE "<winsock.h>" "<winsock2.h>" _contents "${_contents}")
file(WRITE "${CURRENT_PACKAGES_DIR}/include/openssl/dtls1.h" "${_contents}")

file(READ "${CURRENT_PACKAGES_DIR}/include/openssl/rand.h" _contents)
string(REPLACE "# include <windows.h>" "#ifndef _WINSOCKAPI_\n#define _WINSOCKAPI_\n#endif\n# include <windows.h>" _contents "${_contents}")
file(WRITE "${CURRENT_PACKAGES_DIR}/include/openssl/rand.h" "${_contents}")

vcpkg_copy_pdbs()

file(COPY ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
4 changes: 0 additions & 4 deletions ports/openssl-uwp/usage

This file was deleted.

2 changes: 1 addition & 1 deletion ports/openssl-windows/CONTROL
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Source: openssl-windows
Version: 1.1.1h
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.
Description: Deprecated OpenSSL port
Supports: windows
13 changes: 0 additions & 13 deletions ports/openssl-windows/ConfigureIncludeQuotesFix.patch

This file was deleted.

25 changes: 0 additions & 25 deletions ports/openssl-windows/EmbedSymbolsInStaticLibsZ7.patch

This file was deleted.

21 changes: 0 additions & 21 deletions ports/openssl-windows/EnableWinARM32.patch

This file was deleted.

16 changes: 0 additions & 16 deletions ports/openssl-windows/EnableWinARM64.patch

This file was deleted.

23 changes: 0 additions & 23 deletions ports/openssl-windows/STRINGIFYPatch.patch

This file was deleted.

Loading

0 comments on commit 63dccf7

Please sign in to comment.