Improve ssl and nih in cmake:

- provide better override handling for ssl dir
- include build type in nih cache for single config
  to avoid cmake cache collision
This commit is contained in:
Mike Ellery
2018-08-13 09:04:20 -07:00
committed by Nik Bougalis
parent ab6163e989
commit 8a4951947d
2 changed files with 50 additions and 29 deletions

View File

@@ -27,20 +27,20 @@ find_dependency (Boost 1.67
#[=========================================================[ #[=========================================================[
OpenSSL OpenSSL
#]=========================================================] #]=========================================================]
if (APPLE AND NOT DEFINED ENV{OPENSSL_ROOT_DIR}) if (NOT DEFINED OPENSSL_ROOT_DIR)
find_program (HOMEBREW brew) if (DEFINED ENV{OPENSSL_ROOT})
if (NOT HOMEBREW STREQUAL "HOMEBREW-NOTFOUND") set (OPENSSL_ROOT_DIR $ENV{OPENSSL_ROOT})
execute_process (COMMAND ${HOMEBREW} --prefix openssl elseif (APPLE)
OUTPUT_VARIABLE OPENSSL_ROOT_DIR find_program (homebrew brew)
OUTPUT_STRIP_TRAILING_WHITESPACE) if (homebrew)
execute_process (COMMAND ${homebrew} --prefix openssl
OUTPUT_VARIABLE OPENSSL_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
endif () endif ()
file (TO_CMAKE_PATH "${OPENSSL_ROOT_DIR}" OPENSSL_ROOT_DIR)
endif () endif ()
if ((NOT DEFINED OPENSSL_ROOT) AND (DEFINED ENV{OPENSSL_ROOT}))
set (OPENSSL_ROOT $ENV{OPENSSL_ROOT})
endif ()
file (TO_CMAKE_PATH "${OPENSSL_ROOT}" OPENSSL_ROOT)
if (static OR APPLE OR MSVC) if (static OR APPLE OR MSVC)
set (OPENSSL_USE_STATIC_LIBS ON) set (OPENSSL_USE_STATIC_LIBS ON)
endif () endif ()

View File

@@ -200,6 +200,12 @@ target_compile_definitions (common
INTERFACE INTERFACE
$<$<CONFIG:Debug>:DEBUG _DEBUG> $<$<CONFIG:Debug>:DEBUG _DEBUG>
$<$<AND:$<BOOL:profile>,$<NOT:$<BOOL:assert>>>:NDEBUG>) $<$<AND:$<BOOL:profile>,$<NOT:$<BOOL:assert>>>:NDEBUG>)
# ^^^^ NOTE: CMAKE release builds already have NDEBUG
# defined, so no need to add it explicitly except for
# this special case of (profile ON) and (assert OFF)
# -- presumably this is because we don't want profile
# builds asserting unless asserts were specifically
# requested
if (MSVC) if (MSVC)
# remove existing exception flag since we set it to -EHa # remove existing exception flag since we set it to -EHa
@@ -523,20 +529,25 @@ target_link_libraries (ripple_boost
NIH dep: openssl NIH dep: openssl
#]===================================================================] #]===================================================================]
if (APPLE AND NOT DEFINED ENV{OPENSSL_ROOT_DIR}) #[===============================================[
find_program (HOMEBREW brew) OPENSSL_ROOT_DIR is the only variable that
if (NOT HOMEBREW STREQUAL "HOMEBREW-NOTFOUND") FindOpenSSL honors for locating, so convert any
execute_process (COMMAND ${HOMEBREW} --prefix openssl OPENSSL_ROOT vars to this
OUTPUT_VARIABLE OPENSSL_ROOT_DIR #]===============================================]
OUTPUT_STRIP_TRAILING_WHITESPACE) if (NOT DEFINED OPENSSL_ROOT_DIR)
if (DEFINED ENV{OPENSSL_ROOT})
set (OPENSSL_ROOT_DIR $ENV{OPENSSL_ROOT})
elseif (APPLE)
find_program (homebrew brew)
if (homebrew)
execute_process (COMMAND ${homebrew} --prefix openssl
OUTPUT_VARIABLE OPENSSL_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
endif () endif ()
file (TO_CMAKE_PATH "${OPENSSL_ROOT_DIR}" OPENSSL_ROOT_DIR)
endif () endif ()
if ((NOT DEFINED OPENSSL_ROOT) AND (DEFINED ENV{OPENSSL_ROOT}))
set (OPENSSL_ROOT $ENV{OPENSSL_ROOT})
endif ()
file (TO_CMAKE_PATH "${OPENSSL_ROOT}" OPENSSL_ROOT)
if (static) if (static)
set (OPENSSL_USE_STATIC_LIBS ON) set (OPENSSL_USE_STATIC_LIBS ON)
endif () endif ()
@@ -668,14 +679,24 @@ exclude_if_included (lz4)
#]===================================================================] #]===================================================================]
set (la_root_suffix) set (la_root_suffix)
if (MSVC) if (MSVC)
set(la_root_suffix "_static") set (la_root_suffix "_static")
endif () endif ()
string(REGEX REPLACE "[ \\/%]+" "_" gen_for_path ${CMAKE_GENERATOR}) string (REGEX REPLACE "[ \\/%]+" "_" gen_for_path ${CMAKE_GENERATOR})
string(TOLOWER ${gen_for_path} gen_for_path) string (TOLOWER ${gen_for_path} gen_for_path)
# hack: trying to shorten paths for windows CI (hits 260 MAXPATH easily) # hack: trying to shorten paths for windows CI (hits 260 MAXPATH easily)
string(REPLACE "visual_studio" "vs" gen_for_path ${gen_for_path}) string (REPLACE "visual_studio" "vs" gen_for_path ${gen_for_path})
set (nih_cache_path
${CMAKE_SOURCE_DIR}/.nih_c/${gen_for_path}/${CMAKE_CXX_COMPILER_ID}_${CMAKE_CXX_COMPILER_VERSION})
if (NOT is_multiconfig)
if (CMAKE_BUILD_TYPE STREQUAL Debug)
set (nih_cache_path "${nih_cache_path}/Debug")
else ()
set (nih_cache_path "${nih_cache_path}/Release")
endif ()
endif ()
message (STATUS "NIH-EP cache path: ${nih_cache_path}")
ExternalProject_Add (libarchive ExternalProject_Add (libarchive
PREFIX ${CMAKE_SOURCE_DIR}/.nih_c/${gen_for_path}/${CMAKE_CXX_COMPILER_ID}_${CMAKE_CXX_COMPILER_VERSION} PREFIX ${nih_cache_path}
# TODO: switch back to official repo once they allow ENABLE_WERROR option in # TODO: switch back to official repo once they allow ENABLE_WERROR option in
# mainline -- see https://github.com/libarchive/libarchive/pull/1033 # mainline -- see https://github.com/libarchive/libarchive/pull/1033
#GIT_REPOSITORY https://github.com/libarchive/libarchive.git #GIT_REPOSITORY https://github.com/libarchive/libarchive.git
@@ -689,7 +710,7 @@ ExternalProject_Add (libarchive
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:-DCMAKE_VERBOSE_MAKEFILE=ON> $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:-DCMAKE_VERBOSE_MAKEFILE=ON>
-DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/lz4 -DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/lz4
-DCMAKE_DEBUG_POSTFIX=_d -DCMAKE_DEBUG_POSTFIX=_d
-DCMAKE_BUILD_TYPE=$<IF:$<STREQUAL:${CMAKE_BUILD_TYPE},Debug>,Debug,Release> -DCMAKE_BUILD_TYPE=$<IF:$<CONFIG:Debug>,Debug,Release>
-DENABLE_LZ4=ON -DENABLE_LZ4=ON
-ULZ4_* -ULZ4_*
-DENABLE_WERROR=OFF -DENABLE_WERROR=OFF
@@ -733,7 +754,7 @@ ExternalProject_Add (libarchive
$<$<BOOL:${is_multiconfig}>: $<$<BOOL:${is_multiconfig}>:
COMMAND COMMAND
${CMAKE_COMMAND} -E copy ${CMAKE_COMMAND} -E copy
<BINARY_DIR>/libarchive/$<CONFIG>/${CMAKE_STATIC_LIBRARY_PREFIX}archive${la_root_suffix}$<$<OR:$<CONFIG:Debug>,$<CONFIG:DebugClassic>>:_d>${CMAKE_STATIC_LIBRARY_SUFFIX} <BINARY_DIR>/libarchive/$<CONFIG>/${CMAKE_STATIC_LIBRARY_PREFIX}archive${la_root_suffix}$<$<CONFIG:Debug>:_d>${CMAKE_STATIC_LIBRARY_SUFFIX}
<BINARY_DIR>/libarchive <BINARY_DIR>/libarchive
> >
TEST_COMMAND "" TEST_COMMAND ""