Skip to content

Commit

Permalink
[openssl] Split openssl into multiple ports per platform
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0219-msft committed Jul 17, 2018
1 parent c2f96eb commit b4422a1
Show file tree
Hide file tree
Showing 23 changed files with 302 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ if(CMAKE_SYSROOT AND CMAKE_C_COMPILE_OPTIONS_SYSROOT)
set(CFLAGS "${CFLAGS} ${CMAKE_C_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}")
endif()

string(REGEX REPLACE "^ " "" CFLAGS "${CFLAGS}")

file(TO_NATIVE_PATH ENV_PATH "${COMPILER_ROOT};$ENV{PATH}")
set(ENV{ANDROID_DEV} "${CMAKE_SYSROOT}/usr")
set(ENV{CC} "${CMAKE_C_COMPILER}")
Expand Down
3 changes: 3 additions & 0 deletions ports/openssl-unix/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Source: openssl-unix
Version: 1.0.2o
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.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,37 +1,61 @@
if(CMAKE_HOST_WIN32)
vcpkg_acquire_msys(MSYS_ROOT PACKAGES make)
set(BASH ${MSYS_ROOT}/usr/bin/bash.exe)
set(MAKE ${MSYS_ROOT}/usr/bin/make.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/openssl 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()
if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" OR NOT VCPKG_CMAKE_SYSTEM_NAME)
message(FATAL_ERROR "This port is only for openssl on Unix-like systems")
endif()

include(vcpkg_common_functions)
set(OPENSSL_VERSION 1.0.2o)
set(MASTER_COPY_SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/openssl-${OPENSSL_VERSION})

vcpkg_find_acquire_program(PERL)

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

vcpkg_extract_source_archive(${OPENSSL_SOURCE_ARCHIVE})
vcpkg_apply_patches(
SOURCE_PATH ${MASTER_COPY_SOURCE_PATH}
PATCHES ${CMAKE_CURRENT_LIST_DIR}/ConfigureIncludeQuotesFix.patch
${CMAKE_CURRENT_LIST_DIR}/STRINGIFYPatch.patch
${CMAKE_CURRENT_LIST_DIR}/EmbedSymbolsInStaticLibsZ7.patch
)

if(CMAKE_HOST_WIN32)
vcpkg_acquire_msys(MSYS_ROOT PACKAGES make)
set(BASH ${MSYS_ROOT}/usr/bin/bash.exe)
set(MAKE ${MSYS_ROOT}/usr/bin/make.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/openssl-unix 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()
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions ports/openssl-uwp/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Source: openssl-uwp
Version: 1.0.2l-winrt
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.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# Common Ambient Variables:
# VCPKG_ROOT_DIR = <C:\path\to\current\vcpkg>
# TARGET_TRIPLET is the current triplet (x86-windows, etc)
# PORT is the current port name (zlib, etc)
# CURRENT_BUILDTREES_DIR = ${VCPKG_ROOT_DIR}\buildtrees\${PORT}
# CURRENT_PACKAGES_DIR = ${VCPKG_ROOT_DIR}\packages\${PORT}_${TARGET_TRIPLET}
#

if (VCPKG_LIBRARY_LINKAGE STREQUAL static)
set(VCPKG_LIBRARY_LINKAGE dynamic)
message("Static building not supported yet")
Expand Down Expand Up @@ -94,6 +86,5 @@ file(INSTALL
${SOURCE_PATH}/out32dll/ssleay32.lib
DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)

file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/openssl RENAME copyright)

file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
file(COPY ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})
4 changes: 4 additions & 0 deletions ports/openssl-uwp/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The package openssl is compatible with built-in CMake targets:

find_package(OpenSSL REQUIRED)
target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)
3 changes: 3 additions & 0 deletions ports/openssl-windows/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Source: openssl-windows
Version: 1.0.2o
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.
13 changes: 13 additions & 0 deletions ports/openssl-windows/ConfigureIncludeQuotesFix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/Configure b/Configure
index c98107a..77ad9d3 100644
--- a/Configure
+++ b/Configure
@@ -972,7 +972,7 @@ PROCESS_ARGS:
}
elsif (/^--with-zlib-include=(.*)$/)
{
- $withargs{"zlib-include"}="-I$1";
+ $withargs{"zlib-include"}="-I\"$1\"";
}
elsif (/^--with-fipsdir=(.*)$/)
{
25 changes: 25 additions & 0 deletions ports/openssl-windows/EmbedSymbolsInStaticLibsZ7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/util/pl/VC-32.pl b/util/pl/VC-32.pl
index dba96cb..5722f6e 100644
--- a/util/pl/VC-32.pl
+++ b/util/pl/VC-32.pl
@@ -154,9 +154,17 @@ else
$cflags=$opt_cflags.$base_cflags;
}

-# generate symbols.pdb unconditionally
-$app_cflag.=" /Zi /Fd\$(TMP_D)/app";
-$lib_cflag.=" /Zi /Fd\$(TMP_D)/lib";
+# generate symbols.pdb when building dlls and embed symbols when building static libs
+if ($shlib)
+ {
+ $app_cflag.=" /Zi /Fd\$(TMP_D)/app.pdb";
+ $lib_cflag.=" /Zi /Fd\$(TMP_D)/lib.pdb";
+ }
+else
+ {
+ $app_cflag.=" /Z7";
+ $lib_cflag.=" /Z7";
+ }
$lflags.=" /debug";

$obj='.obj';
23 changes: 23 additions & 0 deletions ports/openssl-windows/STRINGIFYPatch.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/crypto/cversion.c b/crypto/cversion.c
index bfff699..17b7912 100644
--- a/crypto/cversion.c
+++ b/crypto/cversion.c
@@ -56,6 +56,9 @@
* [including the GNU Public Licence.]
*/

+#define STRINGIFY2(x) #x
+#define STRINGIFY(x) STRINGIFY2(x)
+
#include "cryptlib.h"

#ifndef NO_WINDOWS_BRAINDEATH
@@ -79,7 +82,7 @@ const char *SSLeay_version(int t)
}
if (t == SSLEAY_CFLAGS) {
#ifdef CFLAGS
- return (CFLAGS);
+ return STRINGIFY(CFLAGS);
#else
return ("compiler: information not available");
#endif
157 changes: 157 additions & 0 deletions ports/openssl-windows/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
if(VCPKG_CMAKE_SYSTEM_NAME)
message(FATAL_ERROR "This port is only for building openssl on Windows Desktop")
endif()

include(vcpkg_common_functions)
set(OPENSSL_VERSION 1.0.2o)
set(MASTER_COPY_SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/openssl-${OPENSSL_VERSION})

vcpkg_find_acquire_program(PERL)

get_filename_component(PERL_EXE_PATH ${PERL} DIRECTORY)
set(ENV{PATH} "$ENV{PATH};${PERL_EXE_PATH}")

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

vcpkg_extract_source_archive(${OPENSSL_SOURCE_ARCHIVE})
vcpkg_apply_patches(
SOURCE_PATH ${MASTER_COPY_SOURCE_PATH}
PATCHES ${CMAKE_CURRENT_LIST_DIR}/ConfigureIncludeQuotesFix.patch
${CMAKE_CURRENT_LIST_DIR}/STRINGIFYPatch.patch
${CMAKE_CURRENT_LIST_DIR}/EmbedSymbolsInStaticLibsZ7.patch
)

vcpkg_find_acquire_program(NASM)
get_filename_component(NASM_EXE_PATH ${NASM} DIRECTORY)
set(ENV{PATH} "${NASM_EXE_PATH};$ENV{PATH}")

vcpkg_find_acquire_program(JOM)

set(CONFIGURE_COMMAND ${PERL} Configure
enable-static-engine
enable-capieng
no-ssl2
-utf-8
)

if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
set(OPENSSL_ARCH VC-WIN32)
set(OPENSSL_DO "ms\\do_nasm.bat")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
set(OPENSSL_ARCH VC-WIN64A)
set(OPENSSL_DO "ms\\do_win64a.bat")
else()
message(FATAL_ERROR "Unsupported target architecture: ${VCPKG_TARGET_ARCHITECTURE}")
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
set(OPENSSL_MAKEFILE "ms\\ntdll.mak")
else()
set(OPENSSL_MAKEFILE "ms\\nt.mak")
endif()

file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)


file(COPY ${MASTER_COPY_SOURCE_PATH} DESTINATION ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
set(SOURCE_PATH_RELEASE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/openssl-${OPENSSL_VERSION})
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}-${CMAKE_BUILD_TYPE}-rel
)
vcpkg_execute_required_process(
COMMAND ${OPENSSL_DO}
WORKING_DIRECTORY ${SOURCE_PATH_RELEASE}
LOGNAME configure-do-${TARGET_TRIPLET}-${CMAKE_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
WORKING_DIRECTORY ${SOURCE_PATH_RELEASE}
LOGNAME build-${TARGET_TRIPLET}-rel-1)

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


message(STATUS "Configure ${TARGET_TRIPLET}-dbg")
file(COPY ${MASTER_COPY_SOURCE_PATH} DESTINATION ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)
set(SOURCE_PATH_DEBUG ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/openssl-${OPENSSL_VERSION})
set(OPENSSLDIR_DEBUG ${CURRENT_PACKAGES_DIR}/debug)

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}-${CMAKE_BUILD_TYPE}-dbg
)
vcpkg_execute_required_process(
COMMAND ${OPENSSL_DO}
WORKING_DIRECTORY ${SOURCE_PATH_DEBUG}
LOGNAME configure-do-${TARGET_TRIPLET}-${CMAKE_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
WORKING_DIRECTORY ${SOURCE_PATH_DEBUG}
LOGNAME build-${TARGET_TRIPLET}-dbg-1)

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


file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE
${CURRENT_PACKAGES_DIR}/debug/bin/openssl.exe
${CURRENT_PACKAGES_DIR}/debug/openssl.cnf
${CURRENT_PACKAGES_DIR}/openssl.cnf
)

file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/tools/openssl/)
file(RENAME ${CURRENT_PACKAGES_DIR}/bin/openssl.exe ${CURRENT_PACKAGES_DIR}/tools/openssl/openssl.exe)

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()

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 ${MASTER_COPY_SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
4 changes: 4 additions & 0 deletions ports/openssl-windows/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The package openssl is compatible with built-in CMake targets:

find_package(OpenSSL REQUIRED)
target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)
3 changes: 2 additions & 1 deletion ports/openssl/CONTROL
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Source: openssl
Version: 1.0.2o-3
Version: 0
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.
Build-Depends: openssl-windows (windows), openssl-uwp (uwp), openssl-unix (!uwp&!windows)
Loading

0 comments on commit b4422a1

Please sign in to comment.