mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 11:06:50 +01:00
add internal OpenSSL option to cmake
This commit is contained in:
107
CMakeLists.txt
107
CMakeLists.txt
@@ -6,6 +6,7 @@
|
|||||||
# ENABLE_{COMPONENT}
|
# ENABLE_{COMPONENT}
|
||||||
# ENABLE_TESTS
|
# ENABLE_TESTS
|
||||||
# ENABLE_SAMPLES
|
# ENABLE_SAMPLES
|
||||||
|
# DISABLE_INTERNAL_OPENSSL
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.2.0)
|
cmake_minimum_required(VERSION 3.2.0)
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ set(CMAKE_C_STANDARD 99)
|
|||||||
# top of the build tree rather than in hard-to-find leaf
|
# top of the build tree rather than in hard-to-find leaf
|
||||||
# directories. This simplifies manual testing and the use of the build
|
# directories. This simplifies manual testing and the use of the build
|
||||||
# tree rather than installed Boost libraries.
|
# tree rather than installed Boost libraries.
|
||||||
|
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||||
# Windows DLLs are "runtime" for CMake. Output them to "bin" like the Visual Studio projects do.
|
# Windows DLLs are "runtime" for CMake. Output them to "bin" like the Visual Studio projects do.
|
||||||
@@ -45,30 +47,19 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
|||||||
# Setup C/C++ compiler options
|
# Setup C/C++ compiler options
|
||||||
#################################################################################
|
#################################################################################
|
||||||
|
|
||||||
option(DISABLE_CPP11 "Disable C++11 if available" OFF)
|
|
||||||
option(DISABLE_CPP14 "Disable C++14 if available" OFF)
|
option(DISABLE_CPP14 "Disable C++14 if available" OFF)
|
||||||
|
|
||||||
if (DISABLE_CPP11 OR DISABLE_CPP14)
|
if (DISABLE_CPP14)
|
||||||
add_definitions(-DPOCO_DISABLE_CPP11)
|
add_definitions(-DPOCO_DISABLE_CPP14)
|
||||||
|
|
||||||
if (DISABLE_CPP14)
|
|
||||||
add_definitions(-DPOCO_DISABLE_CPP14)
|
|
||||||
endif()
|
|
||||||
else()
|
else()
|
||||||
# C++11/14 compiler flags
|
# C++14 compiler flags
|
||||||
include(CXX11)
|
include(CXX1x)
|
||||||
check_for_cxx11_compiler(CXX11_COMPILER)
|
check_for_cxx14_compiler(CXX14_COMPILER)
|
||||||
|
|
||||||
# If a C++11 compiler is available, then set the appropriate flags
|
# If a C++14 compiler is available, then set the appropriate flags
|
||||||
if(CXX11_COMPILER)
|
if(CXX14_COMPILER)
|
||||||
enable_cxx11()
|
enable_cxx14()
|
||||||
check_for_cxx14_compiler(CXX14_COMPILER)
|
endif()
|
||||||
|
|
||||||
# If a C++14 compiler is available, then set the appropriate flags
|
|
||||||
if(CXX14_COMPILER)
|
|
||||||
enable_cxx14()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT MSVC_IDE)
|
if(NOT MSVC_IDE)
|
||||||
@@ -82,18 +73,45 @@ if (CMAKE_BUILD_TYPE STREQUAL "")
|
|||||||
set( CMAKE_BUILD_TYPE "RelWithDebInfo" )
|
set( CMAKE_BUILD_TYPE "RelWithDebInfo" )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Include some common macros to simpilfy the Poco CMake files
|
# Include some common macros to simpilfy Poco CMake files
|
||||||
include(PocoMacros)
|
include(PocoMacros)
|
||||||
|
|
||||||
# Allow enabling and disabling components
|
# Allow enabling and disabling components
|
||||||
option(ENABLE_CPPUNIT "Enable the CppUnit" ON)
|
option(ENABLE_CPPUNIT "Enable CppUnit" ON)
|
||||||
option(ENABLE_XML "Enable the XML" ON)
|
option(ENABLE_XML "Enable XML" ON)
|
||||||
option(ENABLE_JSON "Enable the JSON" ON)
|
option(ENABLE_JSON "Enable JSON" ON)
|
||||||
option(ENABLE_MONGODB "Enable MongoDB" ON)
|
option(ENABLE_MONGODB "Enable MongoDB" ON)
|
||||||
option(ENABLE_PDF "Enable PDF" OFF)
|
option(ENABLE_PDF "Enable PDF" OFF)
|
||||||
option(ENABLE_UTIL "Enable Util" ON)
|
option(ENABLE_UTIL "Enable Util" ON)
|
||||||
option(ENABLE_NET "Enable Net" ON)
|
option(ENABLE_NET "Enable Net" ON)
|
||||||
find_package(OpenSSL QUIET)
|
|
||||||
|
# allow disabling of internally built OpenSSL# (see below for details)
|
||||||
|
# if POCO pre-built OpenSSL directory is found, and DISABLE_INTERNAL_OPENSSL=OFF,
|
||||||
|
# the internal OpenSSL build will be used
|
||||||
|
option(DISABLE_INTERNAL_OPENSSL "Disable internal OpensSSL binaries use" OFF)
|
||||||
|
set(USING_INTERNAL_OPENSSL false)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
if((EXISTS "${PROJECT_SOURCE_DIR}\\openssl\\VS_120\\") AND NOT DISABLE_INTERNAL_OPENSSL)
|
||||||
|
set(USING_INTERNAL_OPENSSL true)
|
||||||
|
## windows xcopy does not tolerate forward-slash, must change this
|
||||||
|
STRING(REGEX REPLACE "/" "\\\\" PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
|
||||||
|
set(OPENSSL_ROOT_DIR "${PROJECT_SOURCE_DIR}\\openssl\\VS_120\\")
|
||||||
|
endif()
|
||||||
|
endif(MSVC)
|
||||||
|
|
||||||
|
set(OPENSSL_FOUND false)
|
||||||
|
if(USING_INTERNAL_OPENSSL)
|
||||||
|
message(STATUS "Using OpenSSL from ${OPENSSL_ROOT_DIR}")
|
||||||
|
set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}include\\")
|
||||||
|
set(OPENSSL_FOUND true)
|
||||||
|
else()
|
||||||
|
find_package(OpenSSL QUIET)
|
||||||
|
if(OPENSSL_FOUND)
|
||||||
|
add_definitions( -DPOCO_EXTERNAL_OPENSSL)
|
||||||
|
message(STATUS "Using OpenSSL from ${OPENSSL_ROOT_DIR}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
if(OPENSSL_FOUND)
|
if(OPENSSL_FOUND)
|
||||||
option(ENABLE_NETSSL "Enable NetSSL" ON)
|
option(ENABLE_NETSSL "Enable NetSSL" ON)
|
||||||
option(ENABLE_CRYPTO "Enable Crypto" ON)
|
option(ENABLE_CRYPTO "Enable Crypto" ON)
|
||||||
@@ -120,8 +138,6 @@ option(ENABLE_PAGECOMPILER "Enable PageCompiler" ON)
|
|||||||
option(ENABLE_PAGECOMPILER_FILE2PAGE "Enable File2Page" ON)
|
option(ENABLE_PAGECOMPILER_FILE2PAGE "Enable File2Page" ON)
|
||||||
option(ENABLE_REDIS "Enable Redis" ON)
|
option(ENABLE_REDIS "Enable Redis" ON)
|
||||||
|
|
||||||
option(FORCE_OPENSSL "Force usage of OpenSSL even under windows" OFF)
|
|
||||||
|
|
||||||
option(ENABLE_TESTS
|
option(ENABLE_TESTS
|
||||||
"Set to OFF|ON (default is OFF) to control build of POCO tests" OFF)
|
"Set to OFF|ON (default is OFF) to control build of POCO tests" OFF)
|
||||||
|
|
||||||
@@ -144,14 +160,13 @@ endif()
|
|||||||
|
|
||||||
# Uncomment from next two lines to force static or dynamic library, default is autodetection
|
# Uncomment from next two lines to force static or dynamic library, default is autodetection
|
||||||
if(POCO_STATIC)
|
if(POCO_STATIC)
|
||||||
set(LIB_MODE_DEFINITIONS -DPOCO_STATIC -DPOCO_NO_AUTOMATIC_LIBS)
|
set(LIB_MODE_DEFINITIONS -DPOCO_STATIC)
|
||||||
set(LIB_MODE STATIC)
|
set(LIB_MODE STATIC)
|
||||||
if(POCO_VERBOSE_MESSAGES)
|
if(POCO_VERBOSE_MESSAGES)
|
||||||
message(STATUS "Building static libraries")
|
message(STATUS "Building static libraries")
|
||||||
endif()
|
endif()
|
||||||
else(POCO_STATIC)
|
else(POCO_STATIC)
|
||||||
set(LIB_MODE SHARED)
|
set(LIB_MODE SHARED)
|
||||||
set(LIB_MODE_DEFINITIONS -DPOCO_NO_AUTOMATIC_LIBS)
|
|
||||||
if(POCO_VERBOSE_MESSAGES)
|
if(POCO_VERBOSE_MESSAGES)
|
||||||
message(STATUS "Building dynamic libraries")
|
message(STATUS "Building dynamic libraries")
|
||||||
endif()
|
endif()
|
||||||
@@ -232,25 +247,23 @@ if(WIN32 AND ENABLE_NETSSL_WIN)
|
|||||||
endif(WIN32 AND ENABLE_NETSSL_WIN)
|
endif(WIN32 AND ENABLE_NETSSL_WIN)
|
||||||
|
|
||||||
if(ENABLE_NETSSL OR ENABLE_CRYPTO)
|
if(ENABLE_NETSSL OR ENABLE_CRYPTO)
|
||||||
|
if(NOT OPENSSL_FOUND)
|
||||||
find_package(OpenSSL REQUIRED)
|
find_package(OpenSSL REQUIRED)
|
||||||
if(OPENSSL_FOUND)
|
endif()
|
||||||
if(MSVC)
|
if(OPENSSL_FOUND)
|
||||||
option(OPENSSL_IS_STATIC
|
if(MSVC)
|
||||||
"Set to OFF|ON (default is OFF) if OpenSSL has beenbuild as static libraries" OFF)
|
list(APPEND OPENSSL_LIBRARIES ws2_32 Crypt32)
|
||||||
if(OPENSSL_IS_STATIC)
|
endif()
|
||||||
list(APPEND OPENSSL_LIBRARIES ws2_32 Crypt32)
|
include_directories("${OPENSSL_INCLUDE_DIR}")
|
||||||
endif()
|
if(ENABLE_NETSSL)
|
||||||
endif()
|
add_subdirectory(NetSSL_OpenSSL)
|
||||||
include_directories("${OPENSSL_INCLUDE_DIR}")
|
list(APPEND Poco_COMPONENTS "NetSSL_OpenSSL")
|
||||||
if(ENABLE_NETSSL)
|
endif()
|
||||||
add_subdirectory(NetSSL_OpenSSL)
|
if(ENABLE_CRYPTO)
|
||||||
list(APPEND Poco_COMPONENTS "NetSSL_OpenSSL")
|
add_subdirectory(Crypto)
|
||||||
endif()
|
list(APPEND Poco_COMPONENTS "Crypto")
|
||||||
if(ENABLE_CRYPTO)
|
endif()
|
||||||
add_subdirectory(Crypto)
|
endif(OPENSSL_FOUND)
|
||||||
list(APPEND Poco_COMPONENTS "Crypto")
|
|
||||||
endif()
|
|
||||||
endif(OPENSSL_FOUND)
|
|
||||||
endif(ENABLE_NETSSL OR ENABLE_CRYPTO)
|
endif(ENABLE_NETSSL OR ENABLE_CRYPTO)
|
||||||
|
|
||||||
if(ENABLE_DATA)
|
if(ENABLE_DATA)
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ POCO_SOURCES_AUTO( SRCS ${SRCS_G})
|
|||||||
file(GLOB_RECURSE HDRS_G "include/*.h" )
|
file(GLOB_RECURSE HDRS_G "include/*.h" )
|
||||||
POCO_HEADERS_AUTO( SRCS ${HDRS_G})
|
POCO_HEADERS_AUTO( SRCS ${HDRS_G})
|
||||||
|
|
||||||
#add_definitions(-D_USRDLL)
|
# warning: this must be defined before target, otherwise
|
||||||
|
# the link_directories() directive is ignored
|
||||||
|
include(OpenSSLInternalLib)
|
||||||
|
|
||||||
add_library( "${LIBNAME}" ${LIB_MODE} ${SRCS} )
|
add_library( "${LIBNAME}" ${LIB_MODE} ${SRCS} )
|
||||||
add_library( "${POCO_LIBNAME}" ALIAS "${LIBNAME}")
|
add_library( "${POCO_LIBNAME}" ALIAS "${LIBNAME}")
|
||||||
@@ -20,14 +22,16 @@ set_target_properties( "${LIBNAME}"
|
|||||||
DEFINE_SYMBOL Crypto_EXPORTS
|
DEFINE_SYMBOL Crypto_EXPORTS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
include(OpenSSLInternalLibCopy)
|
||||||
|
|
||||||
target_link_libraries( "${LIBNAME}" Foundation ${OPENSSL_LIBRARIES} )
|
target_link_libraries( "${LIBNAME}" Foundation ${OPENSSL_LIBRARIES} )
|
||||||
target_include_directories( "${LIBNAME}"
|
target_include_directories( "${LIBNAME}"
|
||||||
PUBLIC
|
PUBLIC
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
$<INSTALL_INTERFACE:include>
|
$<INSTALL_INTERFACE:include>
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
${OPENSSL_INCLUDE_DIR}
|
${OPENSSL_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
target_compile_definitions("${LIBNAME}" PUBLIC ${LIB_MODE_DEFINITIONS})
|
target_compile_definitions("${LIBNAME}" PUBLIC ${LIB_MODE_DEFINITIONS})
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ POCO_SOURCES_AUTO( SRCS ${SRCS_G})
|
|||||||
file(GLOB_RECURSE HDRS_G "include/*.h" )
|
file(GLOB_RECURSE HDRS_G "include/*.h" )
|
||||||
POCO_HEADERS_AUTO( SRCS ${HDRS_G})
|
POCO_HEADERS_AUTO( SRCS ${HDRS_G})
|
||||||
|
|
||||||
|
# warning: this must be defined before target, otherwise
|
||||||
|
# the link_directories() directive is ignored
|
||||||
|
include(OpenSSLInternalLib)
|
||||||
|
|
||||||
add_library( "${LIBNAME}" ${LIB_MODE} ${SRCS} )
|
add_library( "${LIBNAME}" ${LIB_MODE} ${SRCS} )
|
||||||
add_library( "${POCO_LIBNAME}" ALIAS "${LIBNAME}")
|
add_library( "${POCO_LIBNAME}" ALIAS "${LIBNAME}")
|
||||||
set_target_properties( "${LIBNAME}"
|
set_target_properties( "${LIBNAME}"
|
||||||
@@ -18,6 +22,8 @@ set_target_properties( "${LIBNAME}"
|
|||||||
DEFINE_SYMBOL NetSSL_EXPORTS
|
DEFINE_SYMBOL NetSSL_EXPORTS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
include(OpenSSLInternalLibCopy)
|
||||||
|
|
||||||
target_link_libraries( "${LIBNAME}" Crypto Net Util Foundation ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} )
|
target_link_libraries( "${LIBNAME}" Crypto Net Util Foundation ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} )
|
||||||
target_include_directories( "${LIBNAME}"
|
target_include_directories( "${LIBNAME}"
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
|||||||
26
cmake/OpenSSLInternalLib.cmake
Normal file
26
cmake/OpenSSLInternalLib.cmake
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# warning: this must be defined before target, otherwise
|
||||||
|
# the link_directories() directive is ignored
|
||||||
|
if(MSVC AND USING_INTERNAL_OPENSSL)
|
||||||
|
message(STATUS "Crypto: using internal OpenSSL from ${OPENSSL_ROOT_DIR}")
|
||||||
|
|
||||||
|
if(POCO_STATIC)
|
||||||
|
set(POCO_WIN_LIB_DIR "lib")
|
||||||
|
else(POCO_STATIC)
|
||||||
|
set(POCO_WIN_LIB_DIR "bin")
|
||||||
|
endif(POCO_STATIC)
|
||||||
|
|
||||||
|
set(WIN_LIB_OUTPUT_DIR "")
|
||||||
|
STRING(REGEX REPLACE "/" "\\\\" WIN_LIB_OUTPUT_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
||||||
|
STRING(REGEX REPLACE "/" "\\\\" WIN_BIN_OUTPUT_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||||
|
|
||||||
|
link_directories(${WIN_LIB_OUTPUT_DIR}\\$(Configuration)\\)
|
||||||
|
|
||||||
|
if(CMAKE_CL_64)
|
||||||
|
set(POCO_WIN_PLATFORM_BITS "64")
|
||||||
|
set(OPENSSL_WIN_PLATFORM_BITS "64")
|
||||||
|
else(CMAKE_CL_64)
|
||||||
|
set(POCO_WIN_PLATFORM_BITS "")
|
||||||
|
set(OPENSSL_WIN_PLATFORM_BITS "32")
|
||||||
|
endif(CMAKE_CL_64)
|
||||||
|
|
||||||
|
endif(MSVC AND USING_INTERNAL_OPENSSL)
|
||||||
7
cmake/OpenSSLInternalLibCopy.cmake
Normal file
7
cmake/OpenSSLInternalLibCopy.cmake
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
if(MSVC AND USING_INTERNAL_OPENSSL)
|
||||||
|
add_custom_command(TARGET "${LIBNAME}" PRE_BUILD
|
||||||
|
COMMAND xcopy /Y /C ${OPENSSL_ROOT_DIR}\\win${OPENSSL_WIN_PLATFORM_BITS}\\${POCO_WIN_LIB_DIR}\\$(Configuration)\\*.dll ${WIN_BIN_OUTPUT_DIR}\\$(Configuration)\\*
|
||||||
|
COMMAND xcopy /Y /C ${OPENSSL_ROOT_DIR}\\win${OPENSSL_WIN_PLATFORM_BITS}\\${POCO_WIN_LIB_DIR}\\$(Configuration)\\*.lib ${WIN_LIB_OUTPUT_DIR}\\$(Configuration)\\*
|
||||||
|
COMMAND xcopy /Y /C ${OPENSSL_ROOT_DIR}\\win${OPENSSL_WIN_PLATFORM_BITS}\\${POCO_WIN_LIB_DIR}\\$(Configuration)\\*.pdb ${WIN_BIN_OUTPUT_DIR}\\$(Configuration)\\*
|
||||||
|
COMMENT "Copying OpenSSL binaries" VERBATIM)
|
||||||
|
endif(MSVC AND USING_INTERNAL_OPENSSL)
|
||||||
Reference in New Issue
Block a user