Commit 99c43535 authored by Dominik Charousset's avatar Dominik Charousset

Tidy up CMake setup, propagate flags via targets

parent 44c41ad2
cmake_minimum_required(VERSION 3.4 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5...3.18 FATAL_ERROR)
project(CAF CXX)
cmake_policy(PUSH)
cmake_policy(VERSION 3.5...3.18)
# -- includes ------------------------------------------------------------------
include(CMakeDependentOption) # Conditional default values
include(CMakePackageConfigHelpers) # For creating .cmake files
include(CheckCXXSourceCompiles) # For checking whether some C++ features work
include(GNUInstallDirs) # Sets default install paths
include(GenerateExportHeader) # Auto-generates dllexport macros
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(CheckCXXSourceCompiles)
include(GNUInstallDirs)
include(GenerateExportHeader)
# -- override CMake defaults for internal cache entries ------------------------
......@@ -77,67 +80,26 @@ if(MSVC AND CAF_SANITIZERS)
message(FATAL_ERROR "Sanitizer builds are currently not supported on MSVC")
endif()
# -- compiler setup ------------------------------------------------------------
# -- base target setup ---------------------------------------------------------
# Calls target_link_libraries for non-object library targets.
function(caf_target_link_libraries target access)
get_target_property(targetType ${target} TYPE)
if (NOT targetType STREQUAL OBJECT_LIBRARY)
target_link_libraries(${target} ${access} ${ARGN})
else()
# If we can't link against it, at least make sure to pull in INTERFACE
# includes and compiler options.
foreach(arg ${ARGN})
if (TARGET ${arg})
target_include_directories(
${target} PRIVATE
$<TARGET_PROPERTY:${arg},INTERFACE_INCLUDE_DIRECTORIES>)
target_compile_options(
${target} PRIVATE
$<TARGET_PROPERTY:${arg},INTERFACE_COMPILE_OPTIONS>)
endif()
endforeach()
endif()
endfunction()
# This target propagates compiler flags, extra dependencies, etc. All other CAF
# targets pull this target in as PRIVATE dependency. Users that embed CAF into
# their own CMake scaffold (e.g., via FetchContent) may pass this target in with
# some properties predefined in order to force compiler flags or dependencies.
if(NOT TARGET caf_internal)
add_library(caf_internal INTERFACE)
endif()
function(caf_set_default_properties)
foreach(target ${ARGN})
if(MSVC)
# Disable 4275 and 4251 (warnings regarding C++ classes at ABI boundaries).
target_compile_options(${target} PRIVATE /wd4275 /wd4251)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# Flags for both compilers.
target_compile_options(${target} PRIVATE -Wall -Wextra -pedantic
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(caf_internal INTERFACE -Wall -Wextra -pedantic
-ftemplate-depth=512 -ftemplate-backtrace-limit=0)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Flags for Clang only.
target_compile_options(${target} PRIVATE -Wdocumentation)
target_compile_options(caf_internal INTERFACE -Wdocumentation)
else()
# Flags for GCC only.
target_compile_options(${target} PRIVATE
target_compile_options(caf_internal INTERFACE
-Wno-missing-field-initializers)
endif()
endif()
if(CAF_SANITIZERS)
target_compile_options(${target} PRIVATE
-fsanitize=${CAF_SANITIZERS}
-fno-omit-frame-pointer)
caf_target_link_libraries(${target} PRIVATE
-fsanitize=${CAF_SANITIZERS}
-fno-omit-frame-pointer)
endif()
# All of our object libraries can end up in shared libs => PIC.
get_target_property(targetType ${target} TYPE)
if (targetType STREQUAL OBJECT_LIBRARY)
set_property(TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
# We always place headers in the same directories and need to find generated
# headers from the bin dir.
target_include_directories(${target} PRIVATE "${CMAKE_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}")
endforeach()
endfunction()
endif()
# -- unit testing setup / caf_add_test_suites function ------------------------
......@@ -183,59 +145,17 @@ if(NOT CMAKE_CROSSCOMPILING)
\nPlease see README.md for supported compilers.\
\n\ntry_compile output:\n${cxx_check_output}")
endif()
add_compile_options("${cxx_flag}")
target_compile_options(caf_internal INTERFACE "${cxx_flag}")
endif()
endif()
# -- set default visibility to hidden when building shared libs ----------------
# -- export internal target (may be useful for re-using compiler flags) --------
if(BUILD_SHARED_LIBS)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN yes)
cmake_policy(SET CMP0063 NEW)
endif()
set_target_properties(caf_internal PROPERTIES EXPORT_NAME internal)
# -- utility targets -----------------------------------------------------------
add_library(CAF::internal ALIAS caf_internal)
if(CAF_ENABLE_UTILITY_TARGETS)
add_executable(caf-generate-enum-strings
EXCLUDE_FROM_ALL
cmake/caf-generate-enum-strings.cpp)
add_custom_target(consistency-check)
add_custom_target(update-enum-strings)
# adds a consistency check that verifies that `cpp_file` is still valid by
# re-generating the file and comparing it to the existing file
function(caf_add_enum_consistency_check hpp_file cpp_file)
set(input "${CMAKE_CURRENT_SOURCE_DIR}/${hpp_file}")
set(file_under_test "${CMAKE_CURRENT_SOURCE_DIR}/${cpp_file}")
set(output "${CMAKE_CURRENT_BINARY_DIR}/check/${cpp_file}")
get_filename_component(output_dir "${output}" DIRECTORY)
file(MAKE_DIRECTORY "${output_dir}")
add_custom_command(OUTPUT "${output}"
COMMAND caf-generate-enum-strings "${input}" "${output}"
DEPENDS caf-generate-enum-strings "${input}")
get_filename_component(target_name "${input}" NAME_WE)
add_custom_target("${target_name}"
COMMAND
"${CMAKE_COMMAND}"
"-Dfile_under_test=${file_under_test}"
"-Dgenerated_file=${output}"
-P "${PROJECT_SOURCE_DIR}/cmake/check-consistency.cmake"
DEPENDS "${output}")
add_dependencies(consistency-check "${target_name}")
add_custom_target("${target_name}-update"
COMMAND
caf-generate-enum-strings
"${input}"
"${file_under_test}"
DEPENDS caf-generate-enum-strings "${input}")
add_dependencies(update-enum-strings "${target_name}-update")
endfunction()
else()
function(caf_add_enum_consistency_check hpp_file cpp_file)
# nop
endfunction()
endif()
install(TARGETS caf_internal EXPORT CAFTargets)
# -- get CAF version -----------------------------------------------------------
......@@ -259,12 +179,6 @@ else()
CACHE INTERNAL "The version string used for shared library objects")
endif()
# -- generate build config header ----------------------------------------------
configure_file("${PROJECT_SOURCE_DIR}/cmake/build_config.hpp.in"
"${CMAKE_BINARY_DIR}/caf/detail/build_config.hpp"
@ONLY)
# -- install testing DSL headers -----------------------------------------------
add_library(libcaf_test INTERFACE)
......@@ -296,27 +210,67 @@ if(NOT TARGET uninstall)
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake)
endif()
# -- utility targets -----------------------------------------------------------
if(CAF_ENABLE_UTILITY_TARGETS)
add_executable(caf-generate-enum-strings
EXCLUDE_FROM_ALL
cmake/caf-generate-enum-strings.cpp)
target_link_libraries(caf-generate-enum-strings PRIVATE CAF::internal)
add_custom_target(consistency-check)
add_custom_target(update-enum-strings)
# adds a consistency check that verifies that `cpp_file` is still valid by
# re-generating the file and comparing it to the existing file
function(caf_add_enum_consistency_check hpp_file cpp_file)
set(input "${CMAKE_CURRENT_SOURCE_DIR}/${hpp_file}")
set(file_under_test "${CMAKE_CURRENT_SOURCE_DIR}/${cpp_file}")
set(output "${CMAKE_CURRENT_BINARY_DIR}/check/${cpp_file}")
get_filename_component(output_dir "${output}" DIRECTORY)
file(MAKE_DIRECTORY "${output_dir}")
add_custom_command(OUTPUT "${output}"
COMMAND caf-generate-enum-strings "${input}" "${output}"
DEPENDS caf-generate-enum-strings "${input}")
get_filename_component(target_name "${input}" NAME_WE)
add_custom_target("${target_name}"
COMMAND
"${CMAKE_COMMAND}"
"-Dfile_under_test=${file_under_test}"
"-Dgenerated_file=${output}"
-P "${PROJECT_SOURCE_DIR}/cmake/check-consistency.cmake"
DEPENDS "${output}")
add_dependencies(consistency-check "${target_name}")
add_custom_target("${target_name}-update"
COMMAND
caf-generate-enum-strings
"${input}"
"${file_under_test}"
DEPENDS caf-generate-enum-strings "${input}")
add_dependencies(update-enum-strings "${target_name}-update")
endfunction()
else()
function(caf_add_enum_consistency_check hpp_file cpp_file)
# nop
endfunction()
endif()
# -- utility function for installing library targets ---------------------------
# -- utility functions ---------------------------------------------------------
function(caf_export_and_install_lib component)
add_library(CAF::${component} ALIAS libcaf_${component})
string(TOUPPER "CAF_${component}_EXPORT" exportMacroName)
string(TOUPPER "CAF_${component}_EXPORT" export_macro_name)
target_include_directories(libcaf_${component} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
generate_export_header(
libcaf_${component}
EXPORT_MACRO_NAME ${exportMacroName}
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/caf/detail/${component}_export.hpp")
EXPORT_MACRO_NAME ${export_macro_name}
EXPORT_FILE_NAME "caf/detail/${component}_export.hpp")
set_target_properties(libcaf_${component} PROPERTIES
EXPORT_NAME ${component}
SOVERSION ${CAF_VERSION}
VERSION ${CAF_LIB_VERSION}
OUTPUT_NAME caf_${component})
install(FILES "${CMAKE_BINARY_DIR}/caf/detail/${component}_export.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/caf/detail")
install(TARGETS libcaf_${component}
EXPORT CAFTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${component}
......@@ -326,6 +280,125 @@ function(caf_export_and_install_lib component)
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT ${component}
FILES_MATCHING PATTERN "*.hpp")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/caf/detail/${component}_export.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/caf/detail/")
endfunction()
# TODO: remove when switching to CMake > 3.12
function(caf_target_link_libraries target)
if(CMAKE_VERSION VERSION_LESS 3.12)
get_target_property(target_type ${target} TYPE)
if (NOT target_type STREQUAL OBJECT_LIBRARY)
target_link_libraries(${target} ${ARGN})
else()
cmake_parse_arguments(CAF_TARGET_LINK_LIBRARIES "" ""
"PUBLIC;PRIVATE;INTERFACE" ${ARGN})
# If we can't link against it, at least make sure to pull in include paths
# and compiler options.
foreach(arg IN LISTS CAF_TARGET_LINK_LIBRARIES_PUBLIC
CAF_TARGET_LINK_LIBRARIES_PRIVATE)
if (TARGET ${arg})
target_include_directories(
${target} PRIVATE
$<TARGET_PROPERTY:${arg},INTERFACE_INCLUDE_DIRECTORIES>)
target_compile_options(
${target} PRIVATE
$<TARGET_PROPERTY:${arg},INTERFACE_COMPILE_OPTIONS>)
endif()
endforeach()
endif()
else()
target_link_libraries(${target} ${ARGN})
endif()
endfunction()
# -- convenience function for automating our component setup -------------------
# Usage:
# caf_add_component(
# foo
# DEPENDENCIES
# INTERFACE
# ...
# PUBLIC
# ...
# PRIVATE
# ...
# HEADERS
# ...
# SOURCES
# ...
# TEST_SOURCES
# ...
# TEST_SUITES
# ...
# )
function(caf_add_component name)
set(varargs DEPENDENCIES HEADERS SOURCES TEST_SOURCES TEST_SUITES
ENUM_CONSISTENCY_CHECKS)
cmake_parse_arguments(CAF_ADD_COMPONENT "" "" "${varargs}" ${ARGN})
if(NOT CAF_ADD_COMPONENT_HEADERS)
message(FATAL_ERROR "Cannot add CAF component without at least one header.")
endif()
if(NOT CAF_ADD_COMPONENT_SOURCES)
message(FATAL_ERROR "Cannot add CAF component without at least one source.")
endif()
foreach(param DEPENDENCIES HEADERS SOURCES)
if(NOT CAF_ADD_COMPONENT_${param})
message(FATAL_ERROR "caf_add_component(): missing parameter ${param}")
endif()
endforeach()
set(pub_lib_target "libcaf_${name}")
set(obj_lib_target "libcaf_${name}_obj")
set(tst_bin_target "caf-${name}-test")
if(CAF_ENABLE_TESTING AND CAF_ADD_COMPONENT_TEST_SOURCES)
set(targets ${pub_lib_target} ${obj_lib_target} ${tst_bin_target})
add_library(${obj_lib_target} OBJECT
${CAF_ADD_COMPONENT_HEADERS} ${CAF_ADD_COMPONENT_SOURCES})
if(BUILD_SHARED_LIBS)
set_property(TARGET ${obj_lib_target}
PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
caf_target_link_libraries(${obj_lib_target}
${CAF_ADD_COMPONENT_DEPENDENCIES})
add_library(${pub_lib_target}
"${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
$<TARGET_OBJECTS:${obj_lib_target}>)
add_executable(${tst_bin_target}
${CAF_ADD_COMPONENT_TEST_SOURCES}
$<TARGET_OBJECTS:${obj_lib_target}>)
target_link_libraries(${tst_bin_target} PRIVATE CAF::test
${CAF_ADD_COMPONENT_DEPENDENCIES})
target_include_directories(${tst_bin_target} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/test")
if(CAF_ADD_COMPONENT_TEST_SUITES)
caf_add_test_suites(${tst_bin_target} ${CAF_ADD_COMPONENT_TEST_SUITES})
endif()
else()
set(targets ${pub_lib_target})
add_library(${pub_lib_target}
${CAF_ADD_COMPONENT_HEADERS} ${CAF_ADD_COMPONENT_SOURCES})
endif()
target_link_libraries(${pub_lib_target} ${CAF_ADD_COMPONENT_DEPENDENCIES})
foreach(target ${targets})
target_compile_definitions(${target} PRIVATE "libcaf_${name}_EXPORTS")
target_include_directories(${target} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}")
if(BUILD_SHARED_LIBS)
set_target_properties(${target} PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON)
endif()
endforeach()
caf_export_and_install_lib(${name})
if(CAF_ADD_COMPONENT_ENUM_CONSISTENCY_CHECKS)
foreach(enum_name ${CAF_ADD_COMPONENT_ENUM_CONSISTENCY_CHECKS})
string(REPLACE "." "/" path "${enum_name}")
caf_add_enum_consistency_check("caf/${path}.hpp"
"src/${path}_strings.cpp")
endforeach()
endif()
endfunction()
# -- build all components the user asked for -----------------------------------
......@@ -348,6 +421,32 @@ if(CAF_ENABLE_TOOLS)
add_subdirectory(tools)
endif()
# -- add top-level compiler and linker flags that propagate to clients ---------
# Disable warnings regarding C++ classes at ABI boundaries on MSVC.
if(BUILD_SHARED_LIBS AND MSVC)
target_compile_options(libcaf_core INTERFACE /wd4275 /wd4251)
endif()
# Propgatate sanitizer flags to downstream targets.
if(CAF_SANITIZERS)
foreach(target caf_internal libcaf_core)
target_compile_options(${target} INTERFACE
-fsanitize=${CAF_SANITIZERS}
-fno-omit-frame-pointer)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(${target} INTERFACE
-fsanitize=${CAF_SANITIZERS}
-fno-omit-frame-pointer)
else()
target_link_libraries(${target} INTERFACE
-fsanitize=${CAF_SANITIZERS}
-fno-omit-frame-pointer)
endif()
endforeach()
endif()
# -- generate and install .cmake files -----------------------------------------
export(EXPORT CAFTargets FILE CAFTargets.cmake NAMESPACE CAF::)
......@@ -373,6 +472,7 @@ install(
DESTINATION
"${CAF_INSTALL_CMAKEDIR}")
# -- extra file output (primarily for CAF CI) ----------------------------------
if(CAF_BUILD_INFO_FILE_PATH)
......@@ -380,3 +480,5 @@ if(CAF_BUILD_INFO_FILE_PATH)
"${CAF_BUILD_INFO_FILE_PATH}"
@ONLY)
endif()
cmake_policy(POP)
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2016 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
// this header is auto-generated by CMake
#pragma once
#include "caf/detail/log_level.hpp"
// this header is auto-generated by CMake
#define CAF_LOG_LEVEL CAF_LOG_LEVEL_@CAF_LOG_LEVEL@
#cmakedefine CAF_ENABLE_RUNTIME_CHECKS
......
......@@ -2,13 +2,14 @@ add_custom_target(all_examples)
function(add_example folder name)
add_executable(${name} ${folder}/${name}.cpp ${ARGN})
install(FILES ${folder}/${name}.cpp DESTINATION ${CMAKE_INSTALL_DATADIR}/caf/examples/${folder})
install(FILES ${folder}/${name}.cpp
DESTINATION ${CMAKE_INSTALL_DATADIR}/caf/examples/${folder})
add_dependencies(${name} all_examples)
endfunction()
function(add_core_example folder name)
add_example(${folder} ${name} ${ARGN})
target_link_libraries(${name} CAF::core)
target_link_libraries(${name} PRIVATE CAF::internal CAF::core)
endfunction()
# -- examples for CAF::core ----------------------------------------------------
......@@ -43,7 +44,7 @@ add_core_example(custom_type custom_types_3)
# testing DSL
add_example(testing ping_pong)
target_link_libraries(ping_pong CAF::core CAF::test)
target_link_libraries(ping_pong PRIVATE CAF::internal CAF::core CAF::test)
# -- examples for CAF::io ------------------------------------------------------
......@@ -52,7 +53,7 @@ if(TARGET CAF::io)
function(add_io_example folder name)
add_example(${folder} ${name} ${ARGN})
target_link_libraries(${name} CAF::io CAF::core)
target_link_libraries(${name} PRIVATE CAF::internal CAF::io)
endfunction()
# basic remoting
......@@ -65,10 +66,7 @@ if(TARGET CAF::io)
add_io_example(broker simple_broker)
add_io_example(broker simple_http_broker)
endif()
if(CAF_ENABLE_PROTOBUF_EXAMPLES)
if(CAF_ENABLE_PROTOBUF_EXAMPLES)
find_package(Protobuf REQUIRED)
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
message(FATAL_ERROR "CMake was unable to set PROTOBUF_PROTOC_EXECUTABLE")
......@@ -77,11 +75,12 @@ if(CAF_ENABLE_PROTOBUF_EXAMPLES)
include_directories(${PROTOBUF_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(protobuf_broker broker/protobuf_broker.cpp ${ProtoSources})
target_link_libraries(protobuf_broker ${PROTOBUF_LIBRARIES} CAF::core CAF::io)
target_link_libraries(protobuf_broker
PRIVATE ${PROTOBUF_LIBRARIES} CAF::internal CAF::io)
add_dependencies(protobuf_broker all_examples)
endif()
endif()
if(CAF_ENABLE_QT5_EXAMPLES)
if(CAF_ENABLE_QT5_EXAMPLES)
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
message(STATUS "Found Qt5")
#include(${QT_USE_FILE})
......@@ -103,15 +102,16 @@ if(CAF_ENABLE_QT5_EXAMPLES)
Qt5::Core
Qt5::Gui
Qt5::Widgets
CAF::core
CAF::io)
add_dependencies(qt_group_chat all_examples)
endif()
endif()
if(CAF_ENABLE_CURL_EXAMPLES)
if(CAF_ENABLE_CURL_EXAMPLES)
find_package(CURL REQUIRED)
add_executable(curl_fuse curl/curl_fuse.cpp)
include_directories(${CURL_INCLUDE_DIRS})
target_link_libraries(curl_fuse ${CURL_LIBRARY} CAF::core CAF::io)
target_link_libraries(curl_fuse ${CURL_LIBRARY} CAF::io)
add_dependencies(curl_fuse all_examples)
endif()
endif()
# -- get header files for creating "proper" XCode projects ---------------------
# -- collect header files ------------------------------------------------------
file(GLOB_RECURSE CAF_CORE_HEADERS "caf/*.hpp")
# -- add consistency checks for enum to_string implementations -----------------
caf_add_enum_consistency_check("caf/sec.hpp" "src/sec_strings.cpp")
caf_add_enum_consistency_check("caf/pec.hpp" "src/pec_strings.cpp")
caf_add_enum_consistency_check("caf/stream_priority.hpp"
"src/stream_priority_strings.cpp")
caf_add_enum_consistency_check("caf/exit_reason.hpp"
"src/exit_reason_strings.cpp")
caf_add_enum_consistency_check("caf/invoke_message_result.hpp"
"src/invoke_msg_result_strings.cpp")
caf_add_enum_consistency_check("caf/message_priority.hpp"
"src/message_priority_strings.cpp")
caf_add_enum_consistency_check("caf/intrusive/inbox_result.hpp"
"src/intrusive/inbox_result_strings.cpp")
caf_add_enum_consistency_check("caf/intrusive/task_result.hpp"
"src/intrusive/task_result_strings.cpp")
# -- dependencies --------------------------------------------------------------
if(NOT TARGET Threads::Threads)
find_package(Threads REQUIRED)
endif()
# -- utility function for setting default properties ---------------------------
set(LIBCAF_CORE_OPTIONAL_DEPENDENCIES "")
function(caf_core_set_default_properties)
foreach(target ${ARGN})
# Set global defaults and set EXPORTS flag.
caf_set_default_properties(${target})
target_compile_definitions(${target} PRIVATE libcaf_core_EXPORTS)
# Pull in public dependencies.
caf_target_link_libraries(${target} PUBLIC Threads::Threads)
if(MSVC)
caf_target_link_libraries(${target} PUBLIC iphlpapi)
# Check whether we need to link against libatomic.
if(NOT CMAKE_CROSSCOMPILING)
set(snippet "#include <cstdint>
#include <atomic>
std::atomic<uint64_t> x;
int main(int, char**) { return static_cast<int>(x.load()); }")
check_cxx_source_compiles("${snippet}" has_64bit_atomic)
if(NOT has_64bit_atomic)
set(required_libs_backup "${CMAKE_REQUIRED_LIBRARIES}")
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_cxx_source_compiles("${snippet}" has_64bit_atomic_with_libatomic)
set(CMAKE_REQUIRED_LIBRARIES "${required_libs_backup}")
if(NOT has_64bit_atomic_with_libatomic)
message(FATAL_ERROR "Unable to compile code with std::atomic<uint64_t>")
endif()
list(APPEND LIBCAF_CORE_OPTIONAL_DEPENDENCIES atomic)
endif()
endforeach()
endfunction()
endif()
if(MSVC)
list(APPEND LIBCAF_CORE_OPTIONAL_DEPENDENCIES iphlpapi)
endif()
# -- add library target --------------------------------------------------------
# -- generated files -----------------------------------------------------------
add_library(libcaf_core_obj OBJECT ${CAF_CORE_HEADERS}
configure_file("${PROJECT_SOURCE_DIR}/cmake/build_config.hpp.in"
"caf/detail/build_config.hpp"
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/caf/detail/build_config.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/caf/detail/")
# -- add targets ---------------------------------------------------------------
caf_add_component(
core
DEPENDENCIES
PUBLIC
Threads::Threads
${LIBCAF_CORE_OPTIONAL_DEPENDENCIES}
PRIVATE
CAF::internal
ENUM_CONSISTENCY_CHECKS
exit_reason
intrusive.inbox_result
intrusive.task_result
invoke_message_result
message_priority
pec
sec
stream_priority
HEADERS
${CAF_CORE_HEADERS}
SOURCES
src/abstract_actor.cpp
src/abstract_channel.cpp
src/abstract_group.cpp
......@@ -125,7 +146,7 @@ add_library(libcaf_core_obj OBJECT ${CAF_CORE_HEADERS}
src/init_global_meta_objects.cpp
src/intrusive/inbox_result_strings.cpp
src/intrusive/task_result_strings.cpp
src/invoke_msg_result_strings.cpp
src/invoke_message_result_strings.cpp
src/ipv4_address.cpp
src/ipv4_endpoint.cpp
src/ipv4_subnet.cpp
......@@ -187,55 +208,10 @@ add_library(libcaf_core_obj OBJECT ${CAF_CORE_HEADERS}
src/uri.cpp
src/uri_builder.cpp
src/uuid.cpp
)
add_library(libcaf_core "${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
$<TARGET_OBJECTS:libcaf_core_obj>)
caf_core_set_default_properties(libcaf_core_obj libcaf_core)
caf_export_and_install_lib(core)
install(FILES "${CMAKE_BINARY_DIR}/caf/detail/build_config.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/caf/detail")
# Check whether we need to link against libatomic.
if(NOT CMAKE_CROSSCOMPILING)
set(snippet "#include <cstdint>
#include <atomic>
std::atomic<uint64_t> x;
int main(int, char**) { return static_cast<int>(x.load()); }")
check_cxx_source_compiles("${snippet}" has_64bit_atomic)
if(NOT has_64bit_atomic)
set(required_libs_backup "${CMAKE_REQUIRED_LIBRARIES}")
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_cxx_source_compiles("${snippet}" has_64bit_atomic_with_libatomic)
set(CMAKE_REQUIRED_LIBRARIES "${required_libs_backup}")
if(NOT has_64bit_atomic_with_libatomic)
message(FATAL_ERROR "Unable to compile code with std::atomic<uint64_t>")
endif()
target_link_libraries(libcaf_core INTERFACE atomic)
endif()
endif()
# -- build unit tests ----------------------------------------------------------
if(NOT CAF_ENABLE_TESTING)
return()
endif()
add_executable(caf-core-test
TEST_SOURCES
test/core-test.cpp
test/nasty.cpp
$<TARGET_OBJECTS:libcaf_core_obj>)
caf_core_set_default_properties(caf-core-test)
target_include_directories(caf-core-test PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/test")
target_link_libraries(caf-core-test PUBLIC CAF::test)
caf_add_test_suites(caf-core-test
TEST_SUITES
actor_clock
actor_factory
actor_lifetime
......@@ -361,9 +337,8 @@ caf_add_test_suites(caf-core-test
unit
uri
uuid
variant
)
variant)
if(CAF_ENABLE_EXCEPTIONS)
if(CAF_ENABLE_TESTING AND CAF_ENABLE_EXCEPTIONS)
caf_add_test_suites(caf-core-test custom_exception_handler)
endif()
# -- get header files for creating "proper" XCode projects ---------------------
# -- collect header files ------------------------------------------------------
file(GLOB_RECURSE CAF_IO_HEADERS "caf/*.hpp")
# -- add consistency checks for enum to_string implementations -----------------
caf_add_enum_consistency_check("caf/io/basp/message_type.hpp"
"src/io/basp/message_type_strings.cpp")
caf_add_enum_consistency_check("caf/io/network/operation.hpp"
"src/io/network/operation_strings.cpp")
# -- utility function for setting default properties ---------------------------
function(caf_io_set_default_properties)
foreach(target ${ARGN})
# Set global defaults and set EXPORTS flag.
caf_set_default_properties(${target})
target_compile_definitions(${target} PRIVATE libcaf_io_EXPORTS)
# Pull in public dependencies.
caf_target_link_libraries(${target} PUBLIC CAF::core)
if(MSVC)
caf_target_link_libraries(${target} PUBLIC ws2_32 iphlpapi)
endif()
endforeach()
endfunction()
# -- add library target --------------------------------------------------------
add_library(libcaf_io_obj OBJECT ${CAF_IO_HEADERS}
# -- add targets ---------------------------------------------------------------
caf_add_component(
io
DEPENDENCIES
PUBLIC
CAF::core
$<$<CXX_COMPILER_ID:MSVC>:ws2_32>
PRIVATE
CAF::internal
ENUM_CONSISTENCY_CHECKS
io.basp.message_type
io.network.operation
HEADERS
${CAF_IO_HEADERS}
SOURCES
src/detail/prometheus_broker.cpp
src/detail/remote_group_module.cpp
src/detail/socket_guard.cpp
......@@ -70,33 +60,9 @@ add_library(libcaf_io_obj OBJECT ${CAF_IO_HEADERS}
src/io/scribe.cpp
src/policy/tcp.cpp
src/policy/udp.cpp
)
add_library(libcaf_io
"${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
$<TARGET_OBJECTS:libcaf_io_obj>)
caf_io_set_default_properties(libcaf_io_obj libcaf_io)
caf_export_and_install_lib(io)
# -- build unit tests ----------------------------------------------------------
if(NOT CAF_ENABLE_TESTING)
return()
endif()
add_executable(caf-io-test
TEST_SOURCES
test/io-test.cpp
$<TARGET_OBJECTS:libcaf_io_obj>)
caf_io_set_default_properties(caf-io-test)
target_include_directories(caf-io-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/test")
target_link_libraries(caf-io-test PRIVATE CAF::test)
caf_add_test_suites(caf-io-test
TEST_SUITES
detail.prometheus_broker
io.basp.message_queue
io.basp_broker
......@@ -110,9 +76,8 @@ caf_add_test_suites(caf-io-test
io.remote_group
io.remote_spawn
io.unpublish
io.worker
)
io.worker)
if(NOT WIN32)
if(CAF_ENABLE_TESTING AND UNIX)
caf_add_test_suites(caf-io-test io.middleman)
endif()
# -- get header files for creating "proper" XCode projects ---------------------
# -- collect header files ------------------------------------------------------
file(GLOB_RECURSE CAF_OPENSSL_HEADERS "caf/*.hpp")
......@@ -8,55 +8,27 @@ if(NOT TARGET OpenSSL::SSL OR NOT TARGET OpenSSL::Crypto)
find_package(OpenSSL REQUIRED)
endif()
# -- utility function for setting default properties ---------------------------
function(caf_openssl_set_default_properties)
foreach(target ${ARGN})
# Set global defaults and set EXPORTS flag.
caf_set_default_properties(${target})
target_compile_definitions(${target} PRIVATE libcaf_openssl_EXPORTS)
# Pull in public dependencies.
caf_target_link_libraries(${target} PUBLIC
CAF::core CAF::io OpenSSL::SSL OpenSSL::Crypto)
endforeach()
endfunction()
# -- add library target --------------------------------------------------------
add_library(libcaf_openssl_obj OBJECT ${CAF_OPENSSL_HEADERS}
# -- add targets ---------------------------------------------------------------
caf_add_component(
openssl
DEPENDENCIES
PUBLIC
CAF::io
OpenSSL::SSL
OpenSSL::Crypto
PRIVATE
CAF::internal
HEADERS
${CAF_OPENSSL_HEADERS}
SOURCES
src/openssl/manager.cpp
src/openssl/middleman_actor.cpp
src/openssl/publish.cpp
src/openssl/remote_actor.cpp
src/openssl/session.cpp
)
add_library(libcaf_openssl
"${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
$<TARGET_OBJECTS:libcaf_openssl_obj>)
caf_openssl_set_default_properties(libcaf_openssl_obj libcaf_openssl)
caf_export_and_install_lib(openssl)
# -- build unit tests ----------------------------------------------------------
if(NOT CAF_ENABLE_TESTING)
return()
endif()
add_executable(caf-openssl-test
TEST_SOURCES
test/openssl-test.cpp
${CAF_OPENSSL_TEST_SOURCES}
$<TARGET_OBJECTS:libcaf_openssl_obj>)
caf_openssl_set_default_properties(caf-openssl-test)
target_include_directories(caf-openssl-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/test")
target_link_libraries(caf-openssl-test PRIVATE CAF::test)
caf_add_test_suites(caf-openssl-test
TEST_SUITES
openssl.authentication
openssl.remote_actor
)
openssl.remote_actor)
......@@ -7,13 +7,13 @@ macro(add name)
endmacro()
add(caf-vec)
target_link_libraries(caf-vec PRIVATE CAF::core)
target_link_libraries(caf-vec PRIVATE CAF::internal CAF::core)
if(TARGET CAF::io)
if(WIN32)
message(STATUS "skip caf-run (not supported on Windows)")
message(STATUS "Skip caf-run (not supported on Windows)")
else()
add(caf-run)
target_link_libraries(caf-run PRIVATE CAF::io CAF::core)
target_link_libraries(caf-run PRIVATE CAF::internal CAF::io)
endif()
endif()
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