From 47f01b7e029ab6a393bae50b6886ec37c506c986 Mon Sep 17 00:00:00 2001 From: "ssf.developer" Date: Tue, 9 Jun 2015 10:26:23 +0200 Subject: [PATCH] Fixed #1: missing CMake scripts --- .gitignore | 4 +- cmake/external/boost/build/CMakeLists.txt | 147 ++++++++ cmake/external/boost/build/boost_build.cmake | 244 ++++++++++++ cmake/external/openssl/build/CMakeLists.txt | 100 +++++ .../openssl/build/openssl_build.cmake | 350 ++++++++++++++++++ 5 files changed, 843 insertions(+), 2 deletions(-) create mode 100644 cmake/external/boost/build/CMakeLists.txt create mode 100644 cmake/external/boost/build/boost_build.cmake create mode 100644 cmake/external/openssl/build/CMakeLists.txt create mode 100644 cmake/external/openssl/build/openssl_build.cmake diff --git a/.gitignore b/.gitignore index c56afbe5..df58d9de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -build -build64 \ No newline at end of file +./build +./build64 \ No newline at end of file diff --git a/cmake/external/boost/build/CMakeLists.txt b/cmake/external/boost/build/CMakeLists.txt new file mode 100644 index 00000000..54bab88b --- /dev/null +++ b/cmake/external/boost/build/CMakeLists.txt @@ -0,0 +1,147 @@ +# This CMakeLists wraps the Boost build scripts in order to allow compilation +# in a separate build tree. +# +# Expected CMake variables are: +# +# MODULES_SEARCH_PATH : Search path for cmake-common modules +# BOOST_SOURCE_DIR : The absolute path to the Boost's source tree +# BOOST_NO_COMPONENTS : Boolean flag if no components has to be built +# BOOST_COMPONENTS : List of components to build +# BOOST_EXTRA_FLAGS : List of extra raw flags to provide to package +# low level build engine +# BOOST_FLAGS : List of flags to configure Boost's build +# RUNTIME_STATIC : Flag to request static link with runtime +# STATIC : Flag to request compilation of a staic library +# +cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) + +include(ExternalPackageHelpers) +include(HelpersArguments) +include(EnhancedList) +include(boost_build) + +# ============================================================================== +# ======================= D e f i n e f u n c t i o n s ====================== +# ============================================================================== + +# ------------------------------------------------------------------------------ +# Prepare the build context for the BOOST package +macro(_boost_setup_build_context) + # Parse given flags + if(BOOST_FLAGS) + parse_arguments("BOOST" + "STATIC;RUNTIME_STATIC" + "" + "" + "" + ${BOOST_FLAGS} + ) + endif() + + # Prepare build base flags and build directory suffix + unset(_base_build_flags) + unset(_build_dir_suffix) + + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + list(APPEND _build_dir_suffix x64) + else() + list(APPEND _build_dir_suffix x86) + endif() + + if(BOOST_STATIC) + list(APPEND _base_build_flags STATIC) + list(APPEND _build_dir_suffix ST) + else() + list(APPEND _build_dir_suffix SH) + endif() + + if(BOOST_RUNTIME_STATIC) + list(APPEND _base_build_flags RUNTIME_STATIC) + list(APPEND _build_dir_suffix RS) + endif() + + list_join(_build_dir_suffix "_" _build_dir_suffix) + string(TOLOWER "${_build_dir_suffix}" _build_dir_suffix) + + # Set-up some directories + set(BOOST_BUILD_BASE_DIR + "${CMAKE_CURRENT_BINARY_DIR}/build/${_build_dir_suffix}" + ) + + set(BOOST_INSTALL_DIR + "${CMAKE_CURRENT_BINARY_DIR}/stage/${_build_dir_suffix}" + ) + + external_setup_build_context(Boost "${_build_dir_suffix}") +endmacro() + + +# ============================================================================== +# ==================== C o r e I m p l e m e n t a t i o n =================== +# ============================================================================== + +_boost_setup_build_context() + +if(Boost_DEBUG) + external_debug("Build context status:") + foreach(_var NEED_BUILD NO_COMPONENTS EXTRA_FLAGS COMPONENTS + STATIC RUNTIME_STATIC INSTALL_DIR BUILD_BASE_DIR) + external_debug(" BOOST_${_var} : ${BOOST_${_var}}") + endforeach() +endif() + +if(BOOST_NEED_BUILD) + # Determine what modes the Boost has to be compiled in + if(CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) + set(_build_modes "dbg" "rel") + elseif(CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$") + set(_build_modes "dbg") + else() + set(_build_modes "rel") + endif() + + file(MAKE_DIRECTORY "${BOOST_INSTALL_DIR}") + foreach(_mode IN LISTS _build_modes) + # Set build flags + unset(_build_flags) + unset(_lib_mode) + + if(BOOST_NO_COMPONENTS) + list(APPEND _build_flags "NO_LIB") + endif() + + if(_base_build_flags) + list(APPEND _build_flags "${_base_build_flags}") + list(APPEND _lib_mode "${_base_build_flags}") + else() + list(APPEND _lib_mode "SHARED") + endif() + + if(_mode STREQUAL "dbg") + list(APPEND _build_flags "DEBUG") + list(APPEND _lib_mode "DEBUG") + else() + list(APPEND _lib_mode "RELEASE") + endif() + + if(Boost_DEBUG) + external_debug("_build_flags: '${_build_flags}'") + endif() + + # Start the build session + list_join(_lib_mode "/" _lib_mode) + external_log("Building Libraries in mode ${_lib_mode}") + boost_build( + NO_LOG + "${_build_flags}" + SOURCE_DIR "${BOOST_SOURCE_DIR}" + INSTALL_DIR "${BOOST_INSTALL_DIR}" + BUILD_DIR "${BOOST_BUILD_BASE_DIR}/${_mode}" + COMPONENTS ${BOOST_COMPONENTS} + EXTRA_FLAGS "${BOOST_EXTRA_FLAGS}" + ) + endforeach() + + external_teardown_build_context(Boost "${_build_dir_suffix}") + +endif() diff --git a/cmake/external/boost/build/boost_build.cmake b/cmake/external/boost/build/boost_build.cmake new file mode 100644 index 00000000..90bd60f4 --- /dev/null +++ b/cmake/external/boost/build/boost_build.cmake @@ -0,0 +1,244 @@ +# This CMAKE script should be included from parent wishing to build BOOST +# libraries. +# +# Valid options are: +# DEBUG # Flag to compile library in debug mode +# STATIC # Flag to compile library in static mode +# RUNTIME_STATIC # Flag to link with platform's static runtime +# SOURCE_DIR # Path to package's source tree +# INSTALL_DIR # Destination where to store built libraries +# BUILD_DIR # Destination where to build libraries +# COMPONENTS # List of names of the components to build +# EXTRA_FLAGS # List of raw flags to provide to boost's scripts +# +# Example: +# include(boost_build) +# +# boost_build( +# SOURCE_DIR "path/to/the/package/source/tree" +# COMPONENTS +# chrono +# filesystem +# iostreams +# EXTRA_FLAGS +# -sNO_BZIP2=1 +# ) +# +if(__H_BOOST_BUILD_INCLUDED) + return() +endif() +set(__H_BOOST_BUILD_INCLUDED TRUE) + +cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) + +include(ExternalPackageHelpers) +include(HelpersArguments) +include(SystemTools) +include(ProcessorCount) + +# ============================================================================== +# ======================= D e f i n e f u n c t i o n s ====================== +# ============================================================================== + +# ------------------------------------------------------------------------------ +# Initializes the environment that will be needed to build the BOOST package +macro(boost_build_initialization) + # Parse arguments + parse_arguments("BOOST_BUILD" + "NO_LIB;NO_LOG;DEBUG;STATIC;RUNTIME_STATIC" + "SOURCE_DIR;INSTALL_DIR;BUILD_DIR" + "COMPONENTS;EXTRA_FLAGS" + "" + ${ARGN} + ) + + if(NOT BOOST_BUILD_BUILD_DIR) + set(BOOST_BUILD_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/boost") + endif() + + if(NOT BOOST_BUILD_INSTALL_DIR) + set(BOOST_BUILD_INSTALL_DIR "${BOOST_BUILD_BUILD_DIR}/stage") + endif() + + if(Boost_DEBUG) + set(Boost_DEBUG NO_LOG DEBUG) + else() + unset(Boost_DEBUG) + endif() + + set(BOOST_BOOTSTRAP "${BOOST_BUILD_SOURCE_DIR}/bootstrap") + set(BOOST_BUILDER "${BOOST_BUILD_SOURCE_DIR}/bjam") + if(NOT BOOST_BUILD_NO_LOG) + set(BOOST_BUILDER_LOG LOG "${BOOST_BUILD_BUILD_DIR}/boost_builder.log") + else() + set(BOOST_BUILDER_LOG NO_LOG) + endif() + + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(BOOST_BUILDER "${BOOST_BUILDER}.exe") + set(BOOST_BOOTSTRAP "${BOOST_BOOTSTRAP}.bat") + else() + set(BOOST_BOOTSTRAP "${BOOST_BOOTSTRAP}.sh") + endif() + + # Set-up toolset name and associated ABI flags flags + unset(cxx_flags) + unset(link_flags) + string(TOLOWER "${CMAKE_CXX_COMPILER_ID}" toolset_name) + if ("${toolset_name}" STREQUAL "clang") + set(cxx_flags "cxxflags=-std=c++11 -stdlib=libc++") + set(link_flags "linkflags=-stdlib=libc++") + elseif ("${toolset_name}" STREQUAL "gnu") + set(toolset_name "gcc") + string(REGEX REPLACE + "([0-9]+)(\\.([0-9]+))?.*" + "gcc\\1\\3" + toolset_version + "${CMAKE_CXX_COMPILER_VERSION}" + ) + set(cxx_flags "cxxflags=-std=c++11") + elseif("${toolset_name}" STREQUAL "msvc") + else() + external_error("COMPILER '${CMAKE_CXX_COMPILER_ID}' NOT HANDLED") + endif() + + unset(_arch_cfg) + list(APPEND _arch_cfg "architecture=x86") + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + list(APPEND _arch_cfg "address-model=64") + else() + list(APPEND _arch_cfg "address-model=32") + endif() + + ProcessorCount(_processors_count) + if(_processors_count) + set(_processors_count "-j${_processors_count}") + else() + unset(_processors_count) + endif() + + # Compile BOOST's build tool + if(NOT EXISTS "${BOOST_BUILDER}") + external_log("Compiling Boost's builder") + unset(_tmp) + if(NOT "$ENV{CC}" STREQUAL "") + set(_tmp "ENV" "CC=") + endif() + system_execute( + ${Boost_DEBUG} + "${BOOST_BUILDER_LOG}" + WORKING_DIR "${BOOST_BUILD_SOURCE_DIR}" + COMMAND "${BOOST_BOOTSTRAP}" + ${_tmp} + ) + + # Test we successfully built builder + if(NOT EXISTS "${BOOST_BUILDER}") + if(EXISTS "${BOOST_BUILD_SOURCE_DIR}/bootstrap.log") + file(STRINGS "${BOOST_BUILD_SOURCE_DIR}/bootstrap.log" _tmp) + external_log("===[ ${BOOST_BUILD_SOURCE_DIR}/bootstrap.log ] ===\n") + foreach(_line IN LISTS _tmp) + external_log("${_line}") + endforeach() + external_log("===") + endif() + external_error("Cannot compile Boost's builder.") + endif() + endif() + + # Compute list of possible components + execute_process( + OUTPUT_VARIABLE _boost_libraries + WORKING_DIRECTORY "${BOOST_BUILD_SOURCE_DIR}" + COMMAND "${BOOST_BUILDER}" "--show-libraries" + ) + string(REGEX REPLACE "(^[^:]+:[\t ]*\n|[\t ]+)" "" + _boost_libraries "${_boost_libraries}") + string(REGEX REPLACE "-([^\n]*)\n+" "\\1;" + _boost_libraries "${_boost_libraries}") + string(REGEX REPLACE ";+$" "" + _boost_libraries "${_boost_libraries}") + + # Create BOOST's headers tree in case of Boost Modular repo + if(NOT EXISTS "${BOOST_BUILD_SOURCE_DIR}/boost") + external_log("Create Boost's headers tree") + system_execute( + ${Boost_DEBUG} + "${BOOST_BUILDER_LOG}" + WORKING_DIR "${BOOST_BUILD_SOURCE_DIR}" + COMMAND "${BOOST_BUILDER}" + ARGS headers + ) + endif() +endmacro() + +# ------------------------------------------------------------------------------ +# Build the BOOST package from the given source path +function(boost_build) + + # Prepare BOOST context + boost_build_initialization("${ARGN}") + + # Prepare build options + if(BOOST_BUILD_NO_LIB) + # No libraries to compile... + return() + endif() + + set(_build_options + "${cxx_flags}" + "${link_flags}" + "${_arch_cfg}" + "toolset=${toolset_name}" + "${_processors_count}" + "-q" + "--hash" + --debug-configuration + --layout=versioned + stage + "--stagedir=${BOOST_BUILD_INSTALL_DIR}" + "--build-dir=${BOOST_BUILD_BUILD_DIR}" + ) + + if(NOT BOOST_BUILD_DEBUG) + list(APPEND _build_options variant=release optimization=space) + else() + list(APPEND _build_options variant=debug) + endif() + + unset(_skipped) + list_join(_boost_libraries "|" _filter) + foreach(_component ${BOOST_BUILD_COMPONENTS}) + if("${_component}" MATCHES "^(${_filter})$") + list(APPEND _build_options "--with-${_component}") + else() + list(APPEND _skipped "${_component}") + endif() + endforeach() + if(_skipped) + list_join(_skipped ", " _skipped) + external_log("Skipping implicit libraries: ${_skipped}") + endif() + + if(BOOST_BUILD_EXTRA_FLAGS) + list(APPEND _build_options "${BOOST_BUILD_EXTRA_FLAGS}") + endif() + + if(NOT BOOST_BUILD_STATIC) + list(APPEND _build_options link=shared runtime-link=shared) + elseif(NOT BOOST_BUILD_RUNTIME_STATIC) + list(APPEND _build_options link=static runtime-link=shared) + else() + list(APPEND _build_options link=static runtime-link=static) + endif() + + # Compile BOOST libraries + system_execute( + ${Boost_DEBUG} + "${BOOST_BUILDER_LOG}" + WORKING_DIR "${BOOST_BUILD_SOURCE_DIR}" + COMMAND "${BOOST_BUILDER}" + ARGS "${_build_options}" + ) +endfunction() + diff --git a/cmake/external/openssl/build/CMakeLists.txt b/cmake/external/openssl/build/CMakeLists.txt new file mode 100644 index 00000000..97868390 --- /dev/null +++ b/cmake/external/openssl/build/CMakeLists.txt @@ -0,0 +1,100 @@ +# This CMakeLists wraps the OpenSSL build scripts in order to allow compilation +# in a separate build tree. +# +# Expected CMake variables are: +# +# MODULES_SEARCH_PATH : Search path for cmake-common modules +# OPENSSL_SOURCE_DIR : The absolute path to the OpenSSL's source tree +# OPENSSL_EXTRA_FLAGS : Extra flags to provide to OpenSSL's +# configuration script +# OPENSSL_FLAGS : List of flags to configure OpenSSL's build +# RUNTIME_STATIC : Flag to request static link with run-time +# +cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) + +include(ExternalPackageHelpers) +include(HelpersArguments) +include(EnhancedList) +include(openssl_build) + +# ============================================================================== +# ======================= D e f i n e f u n c t i o n s ====================== +# ============================================================================== + +# ------------------------------------------------------------------------------ +# Prepare the build context for the OpenSSL package +macro(_openssl_setup_build_context) + # Parse given flags + if(OPENSSL_FLAGS) + parse_arguments("OPENSSL" + "RUNTIME_STATIC;STATIC" + "" + "" + "" + ${OPENSSL_FLAGS} + ) + endif() + + # Prepare build base flags and build directory suffix + unset(_base_build_flags) + unset(_build_dir_suffix) + + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + list(APPEND _build_dir_suffix x64) + else() + list(APPEND _build_dir_suffix x86) + endif() + + if(OPENSSL_STATIC) + list(APPEND _base_build_flags STATIC) + list(APPEND _build_dir_suffix st) + else() + list(APPEND _build_dir_suffix sh) + endif() + + if(OPENSSL_RUNTIME_STATIC) + list(APPEND _base_build_flags RUNTIME_STATIC) + list(APPEND _build_dir_suffix rs) + endif() + + list_join(_build_dir_suffix "_" _build_dir_suffix) + string(TOLOWER "${_build_dir_suffix}" _build_dir_suffix) + + # Set-up some directories + set(OPENSSL_BUILD_DIR + "${CMAKE_CURRENT_BINARY_DIR}/build/${_build_dir_suffix}" + ) + + set(OPENSSL_INSTALL_DIR + "${CMAKE_CURRENT_BINARY_DIR}/stage/${_build_dir_suffix}" + ) + + external_setup_build_context(OpenSSL "${_build_dir_suffix}") +endmacro() + +# ------------------------------------------------------------------------------ +# ============================================================================== +# ==================== C o r e I m p l e m e n t a t i o n =================== +# ============================================================================== + +# Prepare build context +_openssl_setup_build_context() + +# Check if package has already been built +if(OPENSSL_NEED_BUILD) + if(OPENSSL_RUNTIME_STATIC) + external_log("[Embedding static runtime]") + endif() + + # Launch build process + openssl_build( + ${_base_build_flags} + SOURCE_DIR "${OPENSSL_SOURCE_DIR}" + INSTALL_DIR "${OPENSSL_INSTALL_DIR}" + BUILD_DIR "${OPENSSL_BUILD_DIR}" + EXTRA_FLAGS "${OPENSSL_EXTRA_FLAGS}" + ) + + external_teardown_build_context(OpenSSL "${_build_dir_suffix}") +endif() + diff --git a/cmake/external/openssl/build/openssl_build.cmake b/cmake/external/openssl/build/openssl_build.cmake new file mode 100644 index 00000000..9d1151ef --- /dev/null +++ b/cmake/external/openssl/build/openssl_build.cmake @@ -0,0 +1,350 @@ +# This CMAKE script should be included from parent wishing to build OpenSSL +# library. +# +# openssl_build( +# RUNTIME_STATIC # Link against static runtime +# STATIC # Build only static libraries +# SOURCE_DIR # Path to package's source tree +# BUILD_DIR # Working directory where package should be built +# INSTALL_DIR # Destination where to store built libraries +# EXTRA_FLAGS # OpenSSL's specific configuration flags +# ) +# +# Example: +# include(openssl_build) +# +# openssl_build( +# SOURCE_DIR "path/to/the/openssl/source/tree" +# DESTINATION_DIR "path/where/to/store/built/libraries" +# ) +# +if(__H_OPENSSL_BUILD_INCLUDED) + return() +endif() +set(__H_OPENSSL_BUILD_INCLUDED TRUE) + +cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) + +include(ExternalPackageHelpers) +include(FindPerl) +include(HelpersArguments) +include(MultiList) +include(FileEdit) +include(SystemTools) + + +# ============================================================================== +# ======================= D e f i n e f u n c t i o n s ====================== +# ============================================================================== + +# ------------------------------------------------------------------------------ +# Set-up the environment for Unix platforms +# +# Usage: +# openssl_build_setup_unix( +# out_setup_rules # output variable where set-up rules will be stored +# platform # targeted platform +# [extra_args] # Additional arguments for configuration +# ) +# +macro(openssl_build_setup_unix out_setup_rules platform) + # This set-up rule runs the Configure with all configuration options + multi_list(APPEND ${out_setup_rules} + EXEC "${PERL_EXECUTABLE}" ./Configure ${platform} ${ARGN} + LOG "${OPENSSL_CONFIG_LOG}" + ) + + # This next rule is to build the package + multi_list(APPEND ${out_setup_rules} EXEC make all) + + # Finally, this last rule is to install package in case a destination + # has been provided + if(OPENSSL_BUILD_INSTALL_DIR) + multi_list(APPEND ${out_setup_rules} EXEC make install_sw) + endif() +endmacro() + +# ------------------------------------------------------------------------------ +# Set-up the environment for Darwin +# +# Usage: +# openssl_build_setup_darwin( +# out_setup_rules # output variable where set-up rules will be stored +# [extra_args] # Additional arguments for configuration +# ) +# +macro(openssl_build_setup_darwin out_setup_rules) + openssl_build_setup_unix(${out_setup_rules} darwin64-x86_64-cc ${ARGN}) +endmacro() + +# ------------------------------------------------------------------------------ +# Set-up the environment for Linux +# +# Usage: +# openssl_build_setup_linux( +# out_setup_rules # output variable where set-up rules will be stored +# [extra_args] # Additional arguments for configuration +# ) +# +macro(openssl_build_setup_linux out_setup_rules) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + openssl_build_setup_unix(${out_setup_rules} linux-x86_64 ${ARGN}) + else() + openssl_build_setup_unix(${out_setup_rules} linux-elf ${ARGN}) + endif() +endmacro() + +# ------------------------------------------------------------------------------ +# Patches some generated files for the Windows environment +function(openssl_build_patch_windows) + # Find generated Makefile files (i.e. "*.mak") on windows platform + file(GLOB _files "${OPENSSL_BUILD_SOURCE_DIR}/ms/*.mak") + + # Define common path rules + unset(_rules) + list(APPEND _rules + # Remove /Zi and /Fd from *CFLAG and ASM variables + RULE "(^ASM|CFLAG)[\t ]*=" "[\t ]*/(Zi|Fd[^\t ]+)" "" + # Remove option /debug from *LFLAGS variables + RULE "LFLAGS[\t ]*=" "[\t ]*/debug" "" + ) + + if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) + list(APPEND _rules + # Add option /safeseh to *LFLAGS and ASM variables + RULE "(^ASM|LFLAGS)[\t ]*=" "(.+)[\t ]*$" "\\1 -safeseh" + ) + endif() + + list(APPEND _rules + # Add option /dynamicbase to *LFLAGS + RULE "LFLAGS[\t ]*=" "(.+)[\t ]*$" "\\1 /dynamicbase" + ) + + # Define runtime specific rules + if(NOT OPENSSL_BUILD_RUNTIME_STATIC) + list(APPEND _rules + # Replace /MT to /MD from CFLAG + RULE "^CFLAG[\t ]*=" "([\t ]*/M)T([d\t ]|$)" "\\1D\\2" + ) + endif() + + # Patch all the generated Makefile files + file_edit( + MERGE_SPLIT + FILE ${_files} + ${_rules} + ) +endfunction() + +# ------------------------------------------------------------------------------ +# Set-up the environment for windows +# +# Usage: +# openssl_build_setup_unix( +# out_setup_rules # output variable where set-up rules will be stored +# [extra_args] # Additional arguments for configuration +# ) +# +macro(openssl_build_setup_windows out_setup_rules) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + multi_list(APPEND ${out_setup_rules} + WRAP "${PERL_EXECUTABLE}" + ARGS "${OPENSSL_SOURCE_DIR}/Configure" VC-WIN64A ${ARGN} + LOG "${OPENSSL_CONFIG_LOG}" + ) + multi_list(APPEND ${out_setup_rules} + WRAP "${OPENSSL_SOURCE_DIR}/ms/do_win64a.bat" + ) + else() + multi_list(APPEND ${out_setup_rules} + WRAP "${PERL_EXECUTABLE}" + ARGS "${OPENSSL_SOURCE_DIR}/Configure" VC-WIN32 ${ARGN} + LOG "${OPENSSL_CONFIG_LOG}" + ) + multi_list(APPEND ${out_setup_rules} + WRAP "${OPENSSL_SOURCE_DIR}/ms/do_nasm.bat" + ) + endif() + + multi_list(APPEND ${out_setup_rules} + EVAL "openssl_build_patch_windows()" + ) + + multi_list(APPEND ${out_setup_rules} + EVAL + "file(MAKE_DIRECTORY \"${OPENSSL_BUILD_BUILD_DIR}/tmp/lib\")" + "file(MAKE_DIRECTORY \"${OPENSSL_BUILD_BUILD_DIR}/tmp/dll\")" + "file(MAKE_DIRECTORY \"${OPENSSL_BUILD_INSTALL_DIR}/lib\")" + "file(MAKE_DIRECTORY \"${OPENSSL_BUILD_INSTALL_DIR}/dll\")" + "file(MAKE_DIRECTORY \"${OPENSSL_BUILD_INSTALL_DIR}/include/openssl\")" + ) + + multi_list(APPEND ${out_setup_rules} + WRAP nmake + ARGS /nologo /f "${OPENSSL_SOURCE_DIR}/ms/nt.mak" + ARGS "OUT_D=${OPENSSL_BUILD_INSTALL_DIR}/lib" + ARGS "TMP_D=${OPENSSL_BUILD_BUILD_DIR}/tmp/lib" + ARGS "INC_D=${OPENSSL_BUILD_INSTALL_DIR}/include" + ARGS "INCO_D=${OPENSSL_BUILD_INSTALL_DIR}/include/openssl" + ARGS headers lib + ) + + multi_list(APPEND ${out_setup_rules} + WRAP nmake + ARGS /nologo /f "${OPENSSL_SOURCE_DIR}/ms/ntdll.mak" + ARGS "OUT_D=${OPENSSL_BUILD_INSTALL_DIR}/dll" + ARGS "TMP_D=${OPENSSL_BUILD_BUILD_DIR}/tmp/dll" + ARGS "INC_D=${OPENSSL_BUILD_INSTALL_DIR}/include" + ARGS "INCO_D=${OPENSSL_BUILD_INSTALL_DIR}/include/openssl" + ARGS headers lib + ) +endmacro() + +# ------------------------------------------------------------------------------ +# Initializes the environment that will be needed to build the OPENSSL package +macro(openssl_build_initialization) + + # Parse arguments + parse_arguments("OPENSSL_BUILD" + "RUNTIME_STATIC;STATIC" + "SOURCE_DIR;INSTALL_DIR;BUILD_DIR" + "EXTRA_FLAGS" + "" + ${ARGN} + ) + + if(OpenSSL_DEBUG) + set(OpenSSL_DEBUG NO_LOG DEBUG) + else() + unset(OpenSSL_DEBUG) + endif() + + # Ensure perl runtime is accessible + if(NOT PERL_FOUND) + external_error( + "No perl interpreter found. " + "Please ensure perl is available from system before running " + "this script" + ) + endif() + + # Set path to log file + if(NOT OPENSSL_BUILD_BUILD_DIR) + set(OPENSSL_BUILD_LOG "${CMAKE_BINARY_DIR}/openssl_build.log") + set(OPENSSL_CONFIG_LOG "${CMAKE_BINARY_DIR}/openssl_configure.log") + else() + set(OPENSSL_BUILD_LOG "${OPENSSL_BUILD_BUILD_DIR}/build.log") + set(OPENSSL_CONFIG_LOG "${OPENSSL_BUILD_BUILD_DIR}/configure.log") + endif() + + # Check source directory + if(NOT IS_DIRECTORY "${OPENSSL_BUILD_SOURCE_DIR}" + OR NOT EXISTS "${OPENSSL_BUILD_SOURCE_DIR}/openssl.spec") + external_error("Source path to OpenSSL package not defined or invalid") + endif() + + # Create working directories + foreach(_tmp "${OPENSSL_BUILD_BUILD_DIR}" "${OPENSSL_BUILD_INSTALL_DIR}") + if(_tmp AND NOT IS_DIRECTORY "${_tmp}") + file(MAKE_DIRECTORY "${_tmp}") + endif() + endforeach() + unset(_tmp) + + # Retrieve OS name + unset(os_name) + if(NOT CMAKE_SYSTEM_NAME MATCHES "^(Darwin|Linux|Windows)$") + external_error("OS '${CMAKE_SYSTEM_NAME}' NOT HANDLED") + endif() + + string(TOLOWER "${CMAKE_SYSTEM_NAME}" os_name) + +endmacro() + +# ------------------------------------------------------------------------------ +# Build the OpenSSL command lines to compile package +macro(openssl_build_compilation_scripts out_setup_rules) + # Compute compilation rules + if(os_name STREQUAL "darwin") + openssl_build_setup_darwin(${out_setup_rules} ${ARGN}) + elseif(os_name STREQUAL "linux") + openssl_build_setup_linux(${out_setup_rules} ${ARGN}) + elseif(os_name STREQUAL "windows") + openssl_build_setup_windows(${out_setup_rules} ${ARGN}) + else() + external_error("COMPILATION FOR OS '${os_name}'NOT HANDLED") + endif() +endmacro() + +# ------------------------------------------------------------------------------ +function(openssl_run) + parse_arguments("RUN" + "" + "" + "EXEC;EVAL;WRAP" + "" + ${ARGN} + ) + + # Ensure that NO unparsed arguments has been found + if(RUN_ARGN) + message(FATAL_ERROR "Unparsed arguments found:\n${RUN_ARGN}") + endif() + + if(RUN_EVAL) + # Proceed to the EVAL (if any) + system_eval(${RUN_EVAL}) + elseif(RUN_EXEC) + # Proceed to the EXEC + system_execute( + COMMAND ${RUN_EXEC} + WORKING_DIR "${OPENSSL_BUILD_SOURCE_DIR}" + ${OpenSSL_DEBUG} + ) + else() + # Proceed to the wrapped execution + external_execute( + COMMAND ${RUN_WRAP} + WORKING_DIR "${OPENSSL_BUILD_SOURCE_DIR}" + ${OpenSSL_DEBUG} + ) + endif() +endfunction() + +# ------------------------------------------------------------------------------ +# Build the OpenSSL package from the given source path +function(openssl_build) + + # Prepare OpenSSL context + openssl_build_initialization("${ARGN}") + + # Set-up list of configuration options + unset(base_configure_options) + if(OPENSSL_BUILD_STATIC) + list(APPEND base_configure_options "no-shared") + else() + list(APPEND base_configure_options "shared") + endif() + + # Complete configure options + if(OPENSSL_BUILD_INSTALL_DIR) + list(APPEND base_configure_options + "--prefix=${OPENSSL_BUILD_INSTALL_DIR}" + ) + endif() + + if(OPENSSL_EXTRA_FLAGS) + list(APPEND base_configure_options "${OPENSSL_EXTRA_FLAGS}") + endif() + + # Generate configure and build scripts + unset(config_scripts) + openssl_build_compilation_scripts(config_scripts ${base_configure_options}) + + # Configure and build OpenSSL + foreach(_command ${config_scripts}) + openssl_run(${_command}) + endforeach() +endfunction() +