CMake merge from devel to 1.10 to use embedded OpenSSL for Windows (#2767)

* Add  embedded openssl for windows
* Add windows fix for OpenSSL #2708
* Fix CppUnit lib prefix with Poco
This commit is contained in:
Joerg-Christian Boehme 2019-09-02 11:48:01 +02:00 committed by GitHub
parent ef516fa767
commit b9fa82b08b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 145 additions and 40 deletions

View File

@ -69,6 +69,36 @@ endif()
# Include some common macros to simpilfy the Poco CMake files
include(PocoMacros)
option(POCO_STATIC
"Set to OFF|ON (default is OFF) to control build of POCO as STATIC library" OFF)
if(POCO_STATIC)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
else()
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
endif()
if(MSVC)
option(POCO_MT
"Set to OFF|ON (default is OFF) to control build of POCO as /MT instead of /MD" OFF)
option(ENABLE_MSVC_MP
"Set to OFF|ON (default is OFF) to control parallel build of POCO with MSVC" OFF)
# allow disabling of internally built OpenSSL# (see below for details)
# if POCO pre-built OpenSSL directory is found, and POCO_DISABLE_INTERNAL_OPENSSL=OFF,
# the internal OpenSSL build will be used
option(POCO_DISABLE_INTERNAL_OPENSSL "Disable internal OpensSSL binaries use" OFF)
if((NOT POCO_DISABLE_INTERNAL_OPENSSL) AND (ENABLE_NETSSL OR ENABLE_CRYPTO OR (ENABLE_DATA_MYSQL AND MINGW)))
include(UseEmbeddedOpenSSL)
endif()
endif()
option(ENABLE_NETSSL_WIN "Enable NetSSL Windows" OFF)
option(FORCE_OPENSSL "Force usage of OpenSSL even under windows" OFF)
if(ENABLE_CRYPTO OR ENABLE_NETSSL OR ENABLE_JWT)
find_package(OpenSSL REQUIRED)
else()
@ -155,7 +185,7 @@ option(ENABLE_REDIS "Enable Redis" ON)
option(ENABLE_PDF "Enable PDF" OFF)
option(ENABLE_UTIL "Enable Util" ON)
option(ENABLE_NET "Enable Net" ON)
option(ENABLE_NETSSL_WIN "Enable NetSSL Windows" OFF)
option(ENABLE_SEVENZIP "Enable SevenZip" OFF)
option(ENABLE_ZIP "Enable Zip" ON)
option(ENABLE_CPPPARSER "Enable C++ parser" OFF)
@ -163,31 +193,12 @@ option(ENABLE_POCODOC "Enable Poco Documentation Generator" OFF)
option(ENABLE_PAGECOMPILER "Enable PageCompiler" ON)
option(ENABLE_PAGECOMPILER_FILE2PAGE "Enable File2Page" ON)
option(FORCE_OPENSSL "Force usage of OpenSSL even under windows" OFF)
option(ENABLE_TESTS
"Set to OFF|ON (default is OFF) to control build of POCO tests & samples" OFF)
option(POCO_STATIC
"Set to OFF|ON (default is OFF) to control build of POCO as STATIC library" OFF)
if(POCO_STATIC)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
else()
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
endif()
option(POCO_UNBUNDLED
"Set to OFF|ON (default is OFF) to control linking dependencies as external" OFF)
if(MSVC)
option(POCO_MT
"Set to OFF|ON (default is OFF) to control build of POCO as /MT instead of /MD" OFF)
option(ENABLE_MSVC_MP
"Set to OFF|ON (default is OFF) to control parallel build of POCO with MSVC" OFF)
endif()
if(ENABLE_TESTS)
option(ENABLE_LONG_RUNNING_TESTS "Enable long running test" ON)
include(CTest)
@ -271,11 +282,6 @@ if(ENABLE_NET AND ENABLE_TESTS)
set(ENABLE_UTIL ON CACHE BOOL "Enable Util" FORCE)
endif()
if(ENABLE_JWT)
set(ENABLE_CRYPTO ON CACHE BOOL "Enable Crypto" FORCE)
set(ENABLE_JSON ON CACHE BOOL "Enable JSON" FORCE)
endif()
if(ENABLE_PDF)
set(ENABLE_UTIL ON CACHE BOOL "Enable Util" FORCE)
set(ENABLE_XML ON CACHE BOOL "Enable XML" FORCE)
@ -297,6 +303,11 @@ if(ENABLE_UTIL AND ENABLE_TESTS)
set(ENABLE_XML ON CACHE BOOL "Enable XML" FORCE)
endif()
if(ENABLE_JWT)
set(ENABLE_CRYPTO ON CACHE BOOL "Enable Crypto" FORCE)
set(ENABLE_JSON ON CACHE BOOL "Enable JSON" FORCE)
endif()
add_subdirectory(Foundation)
if(ENABLE_ENCODINGS)
add_subdirectory(Encodings)
@ -323,11 +334,6 @@ if(ENABLE_NET)
list(APPEND Poco_COMPONENTS "Net")
endif()
if(EXISTS ${PROJECT_SOURCE_DIR}/JWT AND ENABLE_JWT)
add_subdirectory(JWT)
list(APPEND Poco_COMPONENTS "JWT")
endif()
if(EXISTS ${PROJECT_SOURCE_DIR}/MongoDB AND ENABLE_MONGODB)
add_subdirectory(MongoDB)
list(APPEND Poco_COMPONENTS "MongoDB")
@ -343,6 +349,10 @@ if(EXISTS ${PROJECT_SOURCE_DIR}/PDF AND ENABLE_PDF)
list(APPEND Poco_COMPONENTS "PDF")
endif()
if(EXISTS ${PROJECT_SOURCE_DIR}/JWT AND ENABLE_JWT)
add_subdirectory(JWT)
list(APPEND Poco_COMPONENTS "JWT")
endif()
#NetSSL

View File

@ -7,16 +7,20 @@ file(GLOB_RECURSE HDRS_G "include/*.h" )
POCO_HEADERS_AUTO( SRCS ${HDRS_G})
add_library(CppUnit ${SRCS})
add_library(Poco::CppUnit ALIAS CppUnit)
set_target_properties(CppUnit
PROPERTIES
VERSION "1" SOVERSION "1"
DEFINE_SYMBOL CppUnit_EXPORTS)
target_link_libraries(CppUnit Poco::Foundation)
OUTPUT_NAME PocoCppUnit
DEFINE_SYMBOL CppUnit_EXPORTS
)
target_link_libraries(CppUnit PUBLIC Poco::Foundation)
target_include_directories(CppUnit
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
if(NOT BUILD_SHARED_LIBS)
@ -24,7 +28,11 @@ if(NOT BUILD_SHARED_LIBS)
PUBLIC
POCO_STATIC
)
elseif(MINGW)
target_compile_definitions(CppUnit
PUBLIC
_DLL)
endif()
if (WIN32)
target_compile_definitions(CppUnit PRIVATE _CRT_SECURE_NO_WARNINGS)
endif (WIN32)
POCO_INSTALL(CppUnit)

View File

@ -26,11 +26,15 @@ target_include_directories(Crypto
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
if(MSVC AND OPENSSL_USE_STATIC_LIBS)
if(MSVC AND POCO_DISABLE_INTERNAL_OPENSSL)
target_compile_definitions(Crypto PUBLIC POCO_EXTERNAL_OPENSSL)
if(OPENSSL_USE_STATIC_LIBS)
target_link_libraries(Crypto PUBLIC ws2_32.lib Crypt32.lib)
endif()
endif()
POCO_INSTALL(Crypto)

View File

@ -21,7 +21,7 @@ set_target_properties( NetSSL
DEFINE_SYMBOL NetSSL_EXPORTS
)
target_link_libraries(NetSSL PUBLIC Poco::Crypto Poco::Net Poco::Util)
target_link_libraries(NetSSL PUBLIC Poco::Crypto Poco::Util Poco::Net)
target_include_directories(NetSSL
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@ -29,6 +29,10 @@ target_include_directories(NetSSL
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
)
if(MSVC AND POCO_DISABLE_INTERNAL_OPENSSL AND OPENSSL_USE_STATIC_LIBS)
target_link_libraries(NetSSL PUBLIC ws2_32.lib Crypt32.lib)
endif()
POCO_INSTALL(NetSSL)
POCO_GENERATE_PACKAGE(NetSSL)

View File

@ -0,0 +1,79 @@
macro(copy_shared_ossl_lib path)
if(NOT EXISTS "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()
file(GLOB OSSL_LIB_LIST LIST_DIRECTORIES false "${path}/*")
foreach(OSSL_LIB_FILE ${OSSL_LIB_LIST})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${OSSL_LIB_FILE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
if(POCO_VERBOSE_MESSAGES)
message(STATUS "Copying embedded OpenSSL library from ${OSSL_LIB_FILE} to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
endif()
endforeach()
endmacro()
macro(copy_static_ossl_lib path)
if(NOT EXISTS "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
endif()
file(GLOB OSSL_LIB_LIST LIST_DIRECTORIES false "${path}/*")
foreach(OSSL_LIB_FILE ${OSSL_LIB_LIST})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${OSSL_LIB_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
if(POCO_VERBOSE_MESSAGES)
message(STATUS "Copying embedded OpenSSL library from ${OSSL_LIB_FILE} to ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
endif()
endforeach()
endmacro()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/openssl/build")
message(STATUS "Use internal OpenSSL binaries but ${PROJECT_SOURCE_DIR}/openssl/build doesn't exists. Try to checkout ...")
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --remote openssl
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE EXITCODE)
if(NOT "${EXITCODE}" STREQUAL "0")
message(FATAL_ERROR "Checkout ${PROJECT_SOURCE_DIR}/openssl FAILED!")
endif()
endif()
if( "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" )
set(_OPENSSL_MSVC_ARCH_SUFFIX "64")
else()
set(_OPENSSL_MSVC_ARCH_SUFFIX "32")
endif()
if(BUILD_SHARED_LIBS)
option(OPENSSL_MSVC_STATIC_RT "Set ON to choose the MT version of the openssl lib" OFF)
option(OPENSSL_USE_STATIC_LIBS "Set ON to look for static openssl libraries" OFF)
else()
option(OPENSSL_MSVC_STATIC_RT "Set ON to choose the MT version of the openssl lib" ON)
option(OPENSSL_USE_STATIC_LIBS "Set ON to look for static openssl libraries" ON)
endif()
set(OPENSSL_ROOT_DIR "${PROJECT_SOURCE_DIR}/openssl/build")
if(OPENSSL_USE_STATIC_LIBS)
if(POCO_VERBOSE_MESSAGES)
message(STATUS "Use internal OpenSSL static binaries from ${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/lib")
endif()
list(APPEND CMAKE_LIBRARY_PATH
"${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/lib/debug"
"${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/lib/release")
copy_static_ossl_lib("${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/lib/debug")
copy_static_ossl_lib("${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/lib/release")
else()
if(POCO_VERBOSE_MESSAGES)
message(STATUS "Use internal OpenSSL shared binaries from ${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/bin")
endif()
list(APPEND CMAKE_LIBRARY_PATH
"${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/bin/debug"
"${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/bin/release")
copy_shared_ossl_lib("${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/bin/debug")
copy_shared_ossl_lib("${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/bin/release")
foreach(_OSSL_PATH "${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/bin/debug" "${OPENSSL_ROOT_DIR}/win${_OPENSSL_MSVC_ARCH_SUFFIX}/bin/release")
string(REPLACE "/" "\\" _OSSL_WIN_PATH ${_OSSL_PATH})
string(APPEND OPENSSL_PATH ${_OSSL_WIN_PATH} "\;")
endforeach()
set(INTERNAL_OPENSSL_PATH "PATH=%PATH%\;${OPENSSL_PATH}")
endif()