vcpkg/ports/openssl-windows/portfile.cmake
Sofapriester e09594e429
[openssl-windows] Added feature option to build openssl with no-pinshared flag (#12056)
* [openssl-windows] Added feature option to build openssl with no-pinshared flag

* Fix review findings from @NancyLi1013

* Try a CI test re-run

* Changed fix to idea from @ras0219-msft

* Remove options from message

As suggested by @ras0219.

Co-authored-by: ras0219 <533828+ras0219@users.noreply.github.com>

* Update ports/openssl-windows/CONTROL

Co-authored-by: Stefan Strauss <stefan.strauss@avira.com>
Co-authored-by: ras0219 <533828+ras0219@users.noreply.github.com>
Co-authored-by: NancyLi1013 <46708020+NancyLi1013@users.noreply.github.com>
2020-08-14 09:51:10 -07:00

193 lines
7.5 KiB
CMake

vcpkg_fail_port_install(MESSAGE "${PORT} is only for Windows Desktop" ON_TARGET "UWP" "Linux" "OSX")
if(EXISTS "${CURRENT_INSTALLED_DIR}/include/openssl/ssl.h")
message(WARNING "Can't build openssl if libressl is installed. Please remove libressl, and try install openssl again if you need it. Build will continue but there might be problems since libressl is only a subset of openssl")
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
return()
endif()
vcpkg_find_acquire_program(PERL)
set(OPENSSL_VERSION 1.1.1g)
get_filename_component(PERL_EXE_PATH ${PERL} DIRECTORY)
vcpkg_add_to_path("${PERL_EXE_PATH}")
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 01e3d0b1bceeed8fb066f542ef5480862001556e0f612e017442330bbd7e5faee228b2de3513d7fc347446b7f217e27de1003dc9d7214d5833b97593f3ec25ab
)
vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH SOURCE_PATH
ARCHIVE ${ARCHIVE}
)
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(OPENSSL_SHARED no-shared)
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
set(OPENSSL_SHARED shared)
endif()
set(CONFIGURE_OPTIONS
enable-static-engine
enable-capieng
no-ssl2
no-tests
-utf-8
${OPENSSL_SHARED}
)
if(DEFINED OPENSSL_USE_NOPINSHARED)
set(CONFIGURE_OPTIONS ${CONFIGURE_OPTIONS} no-pinshared)
endif()
set(CONFIGURE_COMMAND ${PERL} Configure ${CONFIGURE_OPTIONS})
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
set(OPENSSL_ARCH VC-WIN32)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
set(OPENSSL_ARCH VC-WIN64A)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
set(OPENSSL_ARCH VC-WIN32-ARM)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
set(OPENSSL_ARCH VC-WIN64-ARM)
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}
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_sw install_ssldirs
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}
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_sw install_ssldirs
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}/ct_log_list.cnf
${CURRENT_PACKAGES_DIR}/ct_log_list.cnf.dist
${CURRENT_PACKAGES_DIR}/openssl.cnf.dist
${CURRENT_PACKAGES_DIR}/debug/bin/openssl.exe
${CURRENT_PACKAGES_DIR}/debug/ct_log_list.cnf
${CURRENT_PACKAGES_DIR}/debug/ct_log_list.cnf.dist
${CURRENT_PACKAGES_DIR}/debug/openssl.cnf
${CURRENT_PACKAGES_DIR}/debug/openssl.cnf.dist
)
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/tools/openssl/)
file(RENAME ${CURRENT_PACKAGES_DIR}/bin/openssl.exe ${CURRENT_PACKAGES_DIR}/tools/openssl/openssl.exe)
file(RENAME ${CURRENT_PACKAGES_DIR}/openssl.cnf ${CURRENT_PACKAGES_DIR}/tools/openssl/openssl.cnf)
vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/openssl)
if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
# They should be empty, only the exes deleted above were in these directories
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/bin/)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin/)
endif()
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/openssl/dtls1.h"
"<winsock.h>"
"<winsock2.h>"
)
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/openssl/rand.h"
"# include <windows.h>"
"#ifndef _WINSOCKAPI_\n#define _WINSOCKAPI_\n#endif\n# include <windows.h>"
)
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)