Commit af231735 authored by Dominik Charousset's avatar Dominik Charousset

Fix handling of CMake target properties

parent 6188521e
...@@ -64,48 +64,44 @@ else() ...@@ -64,48 +64,44 @@ else()
find_package(CAF COMPONENTS core test REQUIRED) find_package(CAF COMPONENTS core test REQUIRED)
endif() endif()
# -- base target to propagate dependencies and flags --------------------------- # -- sanity checks -------------------------------------------------------------
add_library(caf-incubator-project INTERFACE) if(MSVC AND CAF_INC_SANITIZERS)
message(FATAL_ERROR "Sanitizer builds are currently not supported on MSVC")
endif()
# -- compiler setup ------------------------------------------------------------ # -- compiler setup ------------------------------------------------------------
if(MSVC) function(caf_incubator_set_default_properties)
foreach(target ${ARGN})
if(MSVC)
# Disable 4275 and 4251 (warnings regarding C++ classes at ABI boundaries). # Disable 4275 and 4251 (warnings regarding C++ classes at ABI boundaries).
target_compile_options(caf-incubator-project INTERFACE /wd4275 /wd4251) target_compile_options(${target} PRIVATE /wd4275 /wd4251)
if(CAF_INC_SANITIZERS) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
message(FATAL_ERROR "Sanitizer builds are currently not supported on MSVC")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# Flags for both compilers. # Flags for both compilers.
target_compile_options(caf-incubator-project INTERFACE target_compile_options(${target} PRIVATE
-ftemplate-depth=512 -ftemplate-backtrace-limit=0 -ftemplate-depth=512 -ftemplate-backtrace-limit=0
-Wall -Wextra -pedantic) -Wall -Wextra -pedantic)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Flags for Clang only. # Flags for Clang only.
target_compile_options(caf-incubator-project INTERFACE -Wdocumentation) target_compile_options(${target} PRIVATE -Wdocumentation)
else() else()
# Flags for GCC only. # Flags for GCC only.
target_compile_options(caf-incubator-project INTERFACE target_compile_options(${target} PRIVATE
-Wno-missing-field-initializers) -Wno-missing-field-initializers)
endif() endif()
endif() endif()
if(CAF_INC_SANITIZERS)
if(CAF_INC_SANITIZERS) target_compile_options(${target} PRIVATE
target_compile_options(caf-incubator-project INTERFACE
-fsanitize=${CAF_INC_SANITIZERS} -fsanitize=${CAF_INC_SANITIZERS}
-fno-omit-frame-pointer) -fno-omit-frame-pointer)
target_link_libraries(caf-incubator-project INTERFACE target_link_libraries(${target} PRIVATE
-fsanitize=${CAF_INC_SANITIZERS} -fsanitize=${CAF_INC_SANITIZERS}
-fno-omit-frame-pointer) -fno-omit-frame-pointer)
endif() endif()
endforeach()
if(NOT TARGET Threads::Threads) endfunction()
find_package(Threads REQUIRED)
endif()
target_link_libraries(caf-incubator-project INTERFACE Threads::Threads)
# -- unit testing setup / caf_add_test_suites function ------------------------ # -- unit testing setup / caf_add_test_suites function ------------------------
......
...@@ -147,9 +147,12 @@ if(CAF_core_FOUND AND NOT TARGET CAF::core) ...@@ -147,9 +147,12 @@ if(CAF_core_FOUND AND NOT TARGET CAF::core)
else() else()
set(caf_core_include_dirs "${CAF_INCLUDE_DIR_CORE}") set(caf_core_include_dirs "${CAF_INCLUDE_DIR_CORE}")
endif() endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set_target_properties(CAF::core PROPERTIES set_target_properties(CAF::core PROPERTIES
IMPORTED_LOCATION "${CAF_LIBRARY_CORE}" IMPORTED_LOCATION "${CAF_LIBRARY_CORE}"
INTERFACE_INCLUDE_DIRECTORIES "${caf_core_include_dirs}") INTERFACE_INCLUDE_DIRECTORIES "${caf_core_include_dirs}"
INTERFACE_LINK_LIBRARIES "Threads::Threads")
endif() endif()
if(CAF_io_FOUND AND NOT TARGET CAF::io) if(CAF_io_FOUND AND NOT TARGET CAF::io)
add_library(CAF::io UNKNOWN IMPORTED) add_library(CAF::io UNKNOWN IMPORTED)
...@@ -159,18 +162,17 @@ if(CAF_io_FOUND AND NOT TARGET CAF::io) ...@@ -159,18 +162,17 @@ if(CAF_io_FOUND AND NOT TARGET CAF::io)
INTERFACE_LINK_LIBRARIES "CAF::core") INTERFACE_LINK_LIBRARIES "CAF::core")
endif() endif()
if(CAF_openssl_FOUND AND NOT TARGET CAF::openssl) if(CAF_openssl_FOUND AND NOT TARGET CAF::openssl)
if(BUILD_SHARED_LIBS)
find_package(OpenSSL REQUIRED)
else()
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
endif()
add_library(CAF::openssl UNKNOWN IMPORTED) add_library(CAF::openssl UNKNOWN IMPORTED)
set_target_properties(CAF::openssl PROPERTIES set_target_properties(CAF::openssl PROPERTIES
IMPORTED_LOCATION "${CAF_LIBRARY_OPENSSL}" IMPORTED_LOCATION "${CAF_LIBRARY_OPENSSL}"
INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_OPENSSL}" INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_OPENSSL}"
INTERFACE_LINK_LIBRARIES "CAF::core;CAF::io") INTERFACE_LINK_LIBRARIES "CAF::core;CAF::io;OpenSSL::SSL;OpenSSL::Crypto")
if(NOT BUILD_SHARED_LIBS)
include(CMakeFindDependencyMacro)
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_dependency(OpenSSL)
set_property(TARGET CAF::openssl APPEND PROPERTY
INTERFACE_LINK_LIBRARIES "OpenSSL::SSL")
endif()
endif() endif()
if(CAF_test_FOUND AND NOT TARGET CAF::test) if(CAF_test_FOUND AND NOT TARGET CAF::test)
add_library(CAF::test INTERFACE IMPORTED) add_library(CAF::test INTERFACE IMPORTED)
......
...@@ -32,6 +32,8 @@ endif() ...@@ -32,6 +32,8 @@ endif()
add_executable(caf-bb-test test/bb-test.cpp) add_executable(caf-bb-test test/bb-test.cpp)
caf_incubator_set_default_properties(caf-bb-test)
target_include_directories(caf-bb-test PRIVATE target_include_directories(caf-bb-test PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/test") "${CMAKE_CURRENT_SOURCE_DIR}/test")
......
...@@ -17,17 +17,17 @@ caf_incubator_add_enum_consistency_check("caf/net/operation.hpp" ...@@ -17,17 +17,17 @@ caf_incubator_add_enum_consistency_check("caf/net/operation.hpp"
function(caf_net_set_default_properties) function(caf_net_set_default_properties)
foreach(target ${ARGN}) foreach(target ${ARGN})
caf_incubator_set_default_properties(${target})
# Make sure we find our headers plus the the generated export header. # Make sure we find our headers plus the the generated export header.
target_include_directories(${target} PRIVATE target_include_directories(${target} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_BINARY_DIR}") "${CMAKE_BINARY_DIR}")
target_compile_definitions(${target} PRIVATE libcaf_net_EXPORTS) target_compile_definitions(${target} PRIVATE libcaf_net_EXPORTS)
# Force -fPIC on UNIX systems.
if(BUILD_SHARED_LIBS AND UNIX)
target_compile_options(${target} PRIVATE -fPIC)
endif()
# Pull in public dependencies. # Pull in public dependencies.
target_link_libraries(${target} PUBLIC CAF::core) target_link_libraries(${target} PUBLIC CAF::core)
if(MSVC)
target_link_libraries(${target} PUBLIC ws2_32 iphlpapi)
endif()
endforeach() endforeach()
endfunction() endfunction()
...@@ -74,6 +74,8 @@ generate_export_header(libcaf_net ...@@ -74,6 +74,8 @@ generate_export_header(libcaf_net
EXPORT_MACRO_NAME CAF_NET_EXPORT EXPORT_MACRO_NAME CAF_NET_EXPORT
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/caf/detail/net_export.hpp") EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/caf/detail/net_export.hpp")
set_property(TARGET PROPERTY libcaf_net_obj POSITION_INDEPENDENT_CODE ON)
caf_net_set_default_properties(libcaf_net_obj libcaf_net) caf_net_set_default_properties(libcaf_net_obj libcaf_net)
target_include_directories(libcaf_net INTERFACE target_include_directories(libcaf_net INTERFACE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment