Commit 52f8ae6b authored by Dominik Charousset's avatar Dominik Charousset

Modernize CMake scaffold

parent ea970422
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(caf CXX)
# -- project options -----------------------------------------------------------
option(BUILD_SHARED_LIBS "Build all modules as shared library" ON)
project(CAF CXX)
# -- includes ------------------------------------------------------------------
include(CMakeDependentOption) # Conditional default values
include(CMakePackageConfigHelpers) # For creating .cmake files
include(GNUInstallDirs) # Sets default install paths
include(GenerateExportHeader) # Auto-generates dllexport macros
# -- general options -----------------------------------------------------------
option(BUILD_SHARED_LIBS "Shared library targets" ON)
option(CMAKE_EXPORT_COMPILE_COMMANDS "JSON compile commands database" ON)
# -- CAF options that are off by default ----------------------------------------
option(CAF_BUILD_CURL_EXAMPLES "Build examples with libcurl" OFF)
option(CAF_BUILD_PROTOBUF_EXAMPLES "Build examples with Google Protobuf" OFF)
option(CAF_BUILD_QT5_EXAMPLES "Build examples with the Qt5 framework" OFF)
option(CAF_ENABLE_RUNTIME_CHECKS "Build CAF with extra runtime assertions" OFF)
option(CAF_ENABLE_UTILITY_TARGETS "Include targets like consistency-check" OFF)
# -- CAF options that are on by default ----------------------------------------
option(CAF_BUILD_EXAMPLES "Build small programs showcasing CAF features" ON)
option(CAF_BUILD_IO_MODULE "Build networking I/O module" ON)
option(CAF_BUILD_TESTING "Build unit test suites" ON)
option(CAF_BUILD_TOOLS "Build utility programs such as caf-run" ON)
option(CAF_BUILD_WITH_EXCEPTIONS "Build CAF with support for exceptions" ON)
# -- CAF options that depend on others -----------------------------------------
cmake_dependent_option(CAF_BUILD_OPENSSL_MODULE "CAF networking I/O module" ON
"CAF_BUILD_IO_MODULE" OFF)
# -- CAF options with non-boolean values ---------------------------------------
set(CAF_LOG_LEVEL "QUIET" CACHE STRING "Max. log verbosity of CAF components")
set(CAF_SANITIZERS "" CACHE STRING
"Comma separated sanitizers, e.g., 'address,undefined'")
set(CAF_INSTALL_CMAKEDIR
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/CAF" CACHE STRING
"Path for installing CMake files, enables 'find_package(CAF)'")
# -- macOS-specific options ----------------------------------------------------
if(APPLE)
option(CMAKE_MACOSX_RPATH "Use rpaths on macOS and iOS" ON)
endif()
# -- project-specific CMake settings -------------------------------------------
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# -- sanity checking -----------------------------------------------------------
if(CAF_BUILD_OPENSSL_MODULE AND NOT CAF_BUILD_IO_MODULE)
message(FATAL_ERROR "Invalid options: cannot build OpenSSL without I/O")
endif()
# TODO: use `if (CAF_LOG_LEVEL IN_LIST ...)` when switching to CMake ≥ 3.3
if(NOT ";QUIET;ERROR;WARNING;INFO;DEBUG;TRACE;" MATCHES ";${CAF_LOG_LEVEL};")
message(FATAL_ERROR "Invalid log level: \"${CAF_LOG_LEVEL}\"")
endif()
# -- compiler setup ------------------------------------------------------------
if(MSVC)
# disable 4275 and 4251 (warnings regarding C++ classes at ABI boundaries)
add_compile_options(caf-project INTERFACE /wd4275 /wd4251)
if(CAF_SANITIZERS)
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")
# Flags for both compilers.
add_compile_options(-ftemplate-depth=512 -ftemplate-backtrace-limit=0
-Wall -Wextra -pedantic)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Flags for Clang only.
add_compile_options(-Wdocumentation)
else()
# Flags for GCC only.
add_compile_options(-Wno-missing-field-initializers)
endif()
endif()
if(CAF_SANITIZERS)
add_compile_options(-fsanitize=${CAF_SANITIZERS} -fno-omit-frame-pointer)
endif()
# -- check whether we are running as CMake subdirectory ------------------------
get_directory_property(_parent PARENT_DIRECTORY)
if(_parent)
if(NOT CMAKE_PROJECT_NAME STREQUAL "caf")
set(caf_is_subproject ON)
else()
set(caf_is_subproject OFF)
endif()
unset(_parent)
# enable tests if not disabled
if(NOT CAF_NO_UNIT_TESTS)
# -- unit testing setup / caf_add_test_suites function ------------------------
if(CAF_BUILD_TESTING)
enable_testing()
function(add_test_suites executable dir)
# enumerate all test suites.
set(suites "")
foreach(cpp_file ${ARGN})
file(STRINGS "${dir}/${cpp_file}" contents)
foreach(line ${contents})
if ("${line}" MATCHES "SUITE (.+)")
string(REGEX REPLACE ".*SUITE (.+)" "\\1" suite ${line})
list(APPEND suites "${suite}")
endif()
endforeach()
function(caf_add_test_suites target)
foreach(suiteName ${ARGN})
string(REPLACE "." "/" suitePath ${suiteName})
target_sources(${target} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/test/${suitePath}.cpp")
add_test(NAME ${suiteName}
COMMAND ${target} -r300 -n -v5 -s"^${suiteName}$")
endforeach()
list(REMOVE_DUPLICATES suites)
list(LENGTH suites num_suites)
message(STATUS "Found ${num_suites} test suite for ${executable}")
# creates one CMake test per test suite.
macro (make_test suite)
string(REPLACE " " "_" test_name ${suite})
add_test(NAME ${test_name} COMMAND ${executable} -r300 -n -v5 -s"^${suite}$")
endmacro ()
list(LENGTH suites num_suites)
foreach(suite ${suites})
make_test("${suite}")
endforeach ()
endfunction()
endif()
# -- make sure we have at least C++17 available --------------------------------
# TODO: simply set CXX_STANDARD when switching to CMake ≥ 3.9.6
if(NOT CMAKE_CROSSCOMPILING)
# Check whether the user already provided flags that enable C++ >= 17.
try_compile(caf_has_cxx_17
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/check-compiler-features.cpp")
# Try enabling C++17 mode if user-provided flags aren't sufficient.
if(NOT caf_has_cxx_17)
if(MSVC)
set(cxx_flag "/std:c++17")
......@@ -81,7 +138,7 @@ if(NOT CMAKE_CROSSCOMPILING)
COMPILE_DEFINITIONS "${cxx_flag}"
OUTPUT_VARIABLE cxx_check_output)
if(NOT caf_has_cxx_17)
MESSAGE(FATAL_ERROR "\nFatal error: unable activate C++17 mode!\
message(FATAL_ERROR "\nFatal error: unable activate C++17 mode!\
\nPlease see README.md for supported compilers.\
\n\ntry_compile output:\n${cxx_check_output}")
endif()
......@@ -89,181 +146,70 @@ if(NOT CMAKE_CROSSCOMPILING)
endif()
endif()
set(CMAKE_INSTALL_CMAKEBASEDIR "${CMAKE_INSTALL_LIBDIR}/cmake" CACHE PATH
"Base directory for installing cmake specific artifacts")
set(INSTALL_CAF_CMAKEDIR "${CMAKE_INSTALL_CMAKEBASEDIR}/caf")
# -- set default visibility to hidden when building shared libs ----------------
if(BUILD_SHARED_LIBS)
set(LINK_TYPE "shared")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN yes)
if(POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif()
else()
set(CAF_STATIC_BUILD yes)
set(LINK_TYPE "static")
endif()
# Be nice to VIM users and Clang tools.
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Silence policy CMP0042 warning by enabling RPATH explicitly.
if(APPLE AND NOT DEFINED CMAKE_MACOSX_RPATH)
set(CMAKE_MACOSX_RPATH true)
endif()
if(CAF_BUILD_STATIC_RUNTIME)
set(flags_configs
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_MINSIZEREL
)
foreach(flags ${flags_configs})
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(NOT ${flags} MATCHES "-static-libstdc\\+\\+")
set(${flags} "${${flags}} -static-libstdc++")
endif()
if(NOT ${flags} MATCHES "-static-libgcc")
set(${flags} "${${flags}} -static-libgcc")
endif()
elseif(MSVC)
if(${flags} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flags} "${${flags}}")
endif()
endif()
endforeach()
else()
set(CAF_BUILD_STATIC_RUNTIME no)
endif()
# add helper target that simplifies re-running configure
if(NOT caf_is_subproject)
add_custom_target(configure COMMAND ${CMAKE_CURRENT_BINARY_DIR}/config.status)
endif()
# Silence annoying MSVC warning.
if(MSVC)
add_compile_options(/wd4275 /wd4251)
endif()
################################################################################
# utility functions #
################################################################################
# Appends `str` to the variable named `var` with a whitespace as separator.
# Suppresses a leading whitespace if the variable is empty and does nothing if
# `str` is empty.
function(build_string var str)
if(NOT str STREQUAL "")
if("${${var}}" STREQUAL "")
set("${var}" "${str}" PARENT_SCOPE)
else()
set("${var}" "${${var}} ${str}" PARENT_SCOPE)
endif()
endif()
endfunction(build_string)
# Forces `var` to 'no' if the content of the variables evaluates to false.
function(pretty_no var)
if(NOT "${${var}}")
set("${var}" no PARENT_SCOPE)
endif()
endfunction(pretty_no)
# Forces `var` to 'yes' if the content of the variables evaluates to false.
function(pretty_yes var)
if("${${var}}")
set("${var}" yes PARENT_SCOPE)
endif()
endfunction(pretty_yes)
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(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()
################################################################################
# set prefix paths if available #
################################################################################
build_string("CMAKE_PREFIX_PATH" "${CAF_QT_PREFIX_PATH}")
################################################################################
# make sure config parameters are printed with yes or no in summary #
################################################################################
pretty_yes("CAF_FORCE_NO_EXCEPTIONS")
pretty_no("CAF_ENABLE_RUNTIME_CHECKS")
pretty_no("CAF_NO_MEM_MANAGEMENT")
pretty_no("CAF_NO_EXCEPTIONS")
pretty_no("CAF_NO_OPENSSL")
pretty_no("CAF_NO_TOOLS")
pretty_no("CAF_NO_SUMMARY")
if(NOT CAF_NO_IO)
set(CAF_NO_IO no)
# -- utility targets -----------------------------------------------------------
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(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()
set(CAF_NO_TOOLS yes)
function(add_enum_consistency_check hpp_file cpp_file)
# nop
endfunction()
endif()
################################################################################
# get version of CAF #
################################################################################
# -- get CAF version -----------------------------------------------------------
# read content of config.hpp
file(READ "libcaf_core/caf/config.hpp" CONFIG_HPP)
# get line containing the version
string(REGEX MATCH "#define CAF_VERSION [0-9]+" VERSION_LINE "${CONFIG_HPP}")
# extract version number from line
string(REGEX MATCH "[0-9]+" VERSION_INT "${VERSION_LINE}")
# get line containing the version from config.hpp and extract version number
file(READ "libcaf_core/caf/config.hpp" CAF_CONFIG_HPP)
string(REGEX MATCH "#define CAF_VERSION [0-9]+" CAF_VERSION_LINE "${CAF_CONFIG_HPP}")
string(REGEX MATCH "[0-9]+" CAF_VERSION_INT "${CAF_VERSION_LINE}")
# calculate major, minor, and patch version
math(EXPR CAF_VERSION_MAJOR "${VERSION_INT} / 10000")
math(EXPR CAF_VERSION_MINOR "( ${VERSION_INT} / 100) % 100")
math(EXPR CAF_VERSION_PATCH "${VERSION_INT} % 100")
math(EXPR CAF_VERSION_MAJOR "${CAF_VERSION_INT} / 10000")
math(EXPR CAF_VERSION_MINOR "( ${CAF_VERSION_INT} / 100) % 100")
math(EXPR CAF_VERSION_PATCH "${CAF_VERSION_INT} % 100")
# create full version string
set(CAF_VERSION
"${CAF_VERSION_MAJOR}.${CAF_VERSION_MINOR}.${CAF_VERSION_PATCH}")
set(CAF_VERSION "${CAF_VERSION_MAJOR}.${CAF_VERSION_MINOR}.${CAF_VERSION_PATCH}")
# set the library version for our shared library targets
if(CMAKE_HOST_SYSTEM_NAME MATCHES "OpenBSD")
set(CAF_LIB_VERSION "${CAF_VERSION_MAJOR}.${CAF_VERSION_MINOR}")
......@@ -271,241 +217,69 @@ else()
set(CAF_LIB_VERSION "${CAF_VERSION}")
endif()
################################################################################
# set output paths for binaries and libraries if not provided by the user #
################################################################################
# -- generate build config header ----------------------------------------------
# prohibit in-source builds
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed. Please use "
"./configure to choose a build directory and "
"initialize the build configuration.")
endif()
if(NOT XCODE)
# set binary output path if not defined by user
if(NOT EXECUTABLE_OUTPUT_PATH)
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/bin")
endif()
# set library output path if not defined by user
if(NOT LIBRARY_OUTPUT_PATH)
set(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib")
endif()
endif()
################################################################################
# compiler setup #
################################################################################
# set optional build flags
# increase max. template depth on GCC and Clang
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options("-ftemplate-depth=512"
"-ftemplate-backtrace-limit=0")
endif()
# enable useful warnings by default
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wdocumentation)
endif()
# explicitly disable obnoxious GCC warnings
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options(-Wno-missing-field-initializers)
endif()
# set -fno-exception if requested
if(CAF_FORCE_NO_EXCEPTIONS)
add_compile_options(-fno-exceptions)
endif()
# allow enabling IPO on gcc/clang
if(POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
else()
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-flto)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options(-flto -fno-fat-lto-objects)
endif()
endif()
endif()
# enable address sanitizer if requested by the user
if(CAF_SANITIZERS)
add_compile_options("-fsanitize=${CAF_SANITIZERS}"
"-fno-omit-frame-pointer")
list(APPEND CAF_EXTRA_LDFLAGS "-fsanitize=${CAF_SANITIZERS}")
endif()
# -pthread is ignored on MacOSX but required on other platforms
if(NOT APPLE AND NOT WIN32)
add_compile_options(-pthread)
list(APPEND CAF_EXTRA_LDFLAGS "-pthread")
endif()
# -fPIC generates warnings on MinGW and Cygwin plus extra setup steps needed on MinGW
if(MINGW)
add_definitions(-D_WIN32_WINNT=0x0600 -DWIN32)
list(APPEND CAF_EXTRA_LDFLAGS -lws2_32 -liphlpapi -lpsapi)
# build static to avoid runtime dependencies to GCC libraries
add_compile_options(-static)
elseif(CYGWIN)
add_compile_options(-U__STRICT_ANSI__)
endif()
if (WIN32)
list(APPEND CAF_EXTRA_LDFLAGS ws2_32 iphlpapi)
endif()
configure_file("${PROJECT_SOURCE_DIR}/cmake/build_config.hpp.in"
"${CMAKE_BINARY_DIR}/caf/detail/build_config.hpp"
@ONLY)
# iOS support
if(CAF_OSX_SYSROOT)
set(CMAKE_OSX_SYSROOT "${CAF_OSX_SYSROOT}")
endif()
if(CAF_IOS_DEPLOYMENT_TARGET)
if(CAF_OSX_SYSROOT STREQUAL "iphonesimulator")
add_compile_options("-mios-simulator-version-min=${CAF_IOS_DEPLOYMENT_TARGET}")
else()
add_compile_options("-miphoneos-version-min=${CAF_IOS_DEPLOYMENT_TARGET}")
endif()
endif()
# -- install testing DSL headers -----------------------------------------------
################################################################################
# setup logging #
################################################################################
# install includes from test
install(DIRECTORY libcaf_test/caf/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/caf
FILES_MATCHING PATTERN "*.hpp")
# make sure log level is defined and all-uppercase
if(NOT CAF_LOG_LEVEL)
set(CAF_LOG_LEVEL "QUIET")
else()
string(TOUPPER "${CAF_LOG_LEVEL}" CAF_LOG_LEVEL)
endif()
add_library(libcaf_test INTERFACE)
set(validLogLevels QUIET ERROR WARNING INFO DEBUG TRACE)
list(FIND validLogLevels "${CAF_LOG_LEVEL}" logLevelIndex)
if(logLevelIndex LESS 0)
MESSAGE(FATAL_ERROR "Invalid log level: \"${CAF_LOG_LEVEL}\"")
endif()
target_include_directories(libcaf_test INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/libcaf_test>)
################################################################################
# setup for install target #
################################################################################
add_library(CAF::test ALIAS libcaf_test)
# install includes from test
install(DIRECTORY libcaf_test/caf/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/caf
FILES_MATCHING PATTERN "*.hpp")
# -- provide an uinstall target ------------------------------------------------
# process cmake_uninstall.cmake.in
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
# add uninstall target if it does not exist yet
if(NOT TARGET uninstall)
add_custom_target(uninstall)
endif()
add_custom_command(TARGET uninstall
PRE_BUILD
COMMAND "${CMAKE_COMMAND}" -P
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
# -- set include paths for subprojects -----------------------------------------
# -- build all components the user asked for -----------------------------------
configure_file("${PROJECT_SOURCE_DIR}/cmake/build_config.hpp.in"
"${CMAKE_BINARY_DIR}/caf/detail/build_config.hpp"
@ONLY)
# -- set include paths for all subprojects -------------------------------------
include_directories("${CMAKE_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/libcaf_core"
"${CMAKE_CURRENT_SOURCE_DIR}/libcaf_io"
"${CMAKE_CURRENT_SOURCE_DIR}/libcaf_test"
"${CMAKE_CURRENT_SOURCE_DIR}/libcaf_openssl")
add_subdirectory(libcaf_core)
################################################################################
# add targets #
################################################################################
if(CAF_BUILD_IO_MODULE)
add_subdirectory(libcaf_io)
endif()
macro(add_optional_caf_lib name)
string(TOUPPER ${name} upper_name)
set(flag_varname CAF_NO_${upper_name})
if(NOT ${flag_varname}
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libcaf_${name}/CMakeLists.txt")
add_subdirectory("libcaf_${name}")
else()
set(${flag_varname} yes)
endif()
endmacro()
macro(add_optional_caf_binaries name)
string(TOUPPER ${name} upper_name)
set(dependency_failed no)
# check all additional dependency flags
foreach(flag_name ${ARGN})
if(${flag_name})
set(dependency_failed yes)
endif()
endforeach()
if(NOT dependency_failed)
if(NOT CAF_NO_${upper_name}
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${name}/CMakeLists.txt")
add_subdirectory(${name})
else()
# make sure variable is set for nicer build log
set(CAF_NO_${upper_name} yes)
endif()
else()
message(STATUS
"Disable ${name}, one of the following flags was set: ${ARGN}")
# make sure variable is set for nicer build log
set(CAF_NO_${upper_name} yes)
endif()
endmacro()
if(CAF_BUILD_OPENSSL_MODULE)
add_subdirectory(libcaf_openssl)
endif()
# build core and I/O library
add_subdirectory(libcaf_core)
add_optional_caf_lib(io)
# build SSL module if OpenSSL library is available
if(NOT CAF_NO_OPENSSL)
find_package(OpenSSL)
if(OPENSSL_FOUND)
# Check OpenSSL version >= 1.0.1
if (OPENSSL_VERSION VERSION_LESS 1.0.1)
message(STATUS
"Disable OpenSSL. Required >= 1.0.1 due to TLSv1.2 support.")
set(CAF_NO_OPENSSL yes)
else()
if(NOT CMAKE_CROSSCOMPILING)
# Check if openssl headers and library versions match
try_run(sslRunResult sslCompileResult
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/openssl-check.cpp"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${OPENSSL_INCLUDE_DIR}"
LINK_LIBRARIES ${OPENSSL_LIBRARIES}
OUTPUT_VARIABLE sslOutput)
if (NOT sslCompileResult)
message(FATAL_ERROR "failed to compile/link against OpenSSL")
endif()
if(NOT sslRunResult EQUAL 0)
message(FATAL_ERROR
"OpenSSL version does not match headers: ${sslOutput}")
endif()
endif()
include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
add_optional_caf_lib(openssl)
endif()
else(OPENSSL_FOUND)
set(CAF_NO_OPENSSL yes)
endif(OPENSSL_FOUND)
if(CAF_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# build examples if not being told otherwise
add_optional_caf_binaries(examples)
if(CAF_BUILD_TOOLS)
add_subdirectory(tools)
endif()
# build tools if not being told otherwise
add_optional_caf_binaries(tools)
# -- generate and install .cmake files -----------------------------------------
export(EXPORT CAFTargets FILE CAFTargets.cmake NAMESPACE caf::)
export(EXPORT CAFTargets FILE CAFTargets.cmake NAMESPACE CAF::)
install(EXPORT CAFTargets
DESTINATION "${INSTALL_CAF_CMAKEDIR}"
NAMESPACE caf::)
DESTINATION "${CAF_INSTALL_CMAKEDIR}"
NAMESPACE CAF::)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/CAFConfigVersion.cmake"
......@@ -514,74 +288,12 @@ write_basic_package_version_file(
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CAFConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CAFConfig.cmake" INSTALL_DESTINATION
"${INSTALL_CAF_CMAKEDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/CAFConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CAFConfigVersion.cmake"
DESTINATION "${INSTALL_CAF_CMAKEDIR}")
################################################################################
# Add additional project files to GUI #
################################################################################
file(GLOB_RECURSE script_files "scripts/*")
add_custom_target(gui_dummy SOURCES configure ${script_files})
################################################################################
# print summary #
################################################################################
# little helper macro to invert a boolean
macro(invertYesNo in out)
if(${in})
set(${out} no)
else()
set(${out} yes)
endif()
endmacro()
# invert CAF_NO_* variables for nicer output
invertYesNo(CAF_NO_IO CAF_BUILD_IO)
invertYesNo(CAF_NO_EXAMPLES CAF_BUILD_EXAMPLES)
invertYesNo(CAF_NO_TOOLS CAF_BUILD_TOOLS)
invertYesNo(CAF_NO_UNIT_TESTS CAF_BUILD_UNIT_TESTS)
invertYesNo(CAF_NO_EXCEPTIONS CAF_BUILD_WITH_EXCEPTIONS)
invertYesNo(CAF_NO_MEM_MANAGEMENT CAF_BUILD_MEM_MANAGEMENT)
invertYesNo(CAF_NO_OPENSSL CAF_BUILD_OPENSSL)
if(GENERATOR_IS_MULTI_CONFIG)
set(summary_build_type "Multi-Config")
else()
set(summary_build_type "${CMAKE_BUILD_TYPE}")
endif()
# done
if(NOT CAF_NO_SUMMARY)
message(STATUS
"\n====================| Build Summary |===================="
"\n"
"\nCAF version: ${CAF_VERSION}"
"\n"
"\nCXX: ${CMAKE_CXX_COMPILER}"
"\nBuild type: ${summary_build_type}"
"\nLink type: ${LINK_TYPE}"
"\nBuild static runtime: ${CAF_BUILD_STATIC_RUNTIME}"
"\nRuntime checks: ${CAF_ENABLE_RUNTIME_CHECKS}"
"\nLog level: ${CAF_LOG_LEVEL}"
"\nWith mem. mgmt.: ${CAF_BUILD_MEM_MANAGEMENT}"
"\nWith exceptions: ${CAF_BUILD_WITH_EXCEPTIONS}"
"\n"
"\nBuild I/O module: ${CAF_BUILD_IO}"
"\nBuild OpenSSL module: ${CAF_BUILD_OPENSSL}"
"\nBuild tools: ${CAF_BUILD_TOOLS}"
"\nBuild examples: ${CAF_BUILD_EXAMPLES}"
"\nBuild unit tests: ${CAF_BUILD_UNIT_TESTS}"
"\n"
"\n"
"\nSource directory: ${CMAKE_CURRENT_SOURCE_DIR}"
"\nBuild directory: ${CMAKE_CURRENT_BINARY_DIR}"
"\nExecutable path: ${EXECUTABLE_OUTPUT_PATH}"
"\nLibrary path: ${LIBRARY_OUTPUT_PATH}"
"\nInstall prefix: ${CMAKE_INSTALL_PREFIX}"
"\nGenerator: ${CMAKE_GENERATOR}"
"\n"
"\n===========================================================\n")
endif()
"${CMAKE_CURRENT_BINARY_DIR}/CAFConfig.cmake"
INSTALL_DESTINATION "${CAF_INSTALL_CMAKEDIR}")
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/CAFConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CAFConfigVersion.cmake"
DESTINATION
"${CAF_INSTALL_CMAKEDIR}")
add_custom_target(all_examples)
include_directories(${LIBCAF_INCLUDE_DIRS})
macro(add folder name)
function(add_example folder name)
add_executable(${name} ${folder}/${name}.cpp ${ARGN})
target_link_libraries(${name}
${CAF_EXTRA_LDFLAGS}
${CAF_LIBRARIES}
${PTHREAD_LIBRARIES})
install(FILES ${folder}/${name}.cpp DESTINATION ${CMAKE_INSTALL_DATADIR}/caf/examples/${folder})
add_dependencies(${name} all_examples)
endmacro()
endfunction()
function(add_core_example folder name)
add_example(${folder} ${name} ${ARGN})
target_link_libraries(${name} CAF::core)
endfunction()
# -- examples for CAF::core ----------------------------------------------------
# introductionary applications
add(. aout)
add(. hello_world)
add_core_example(. aout)
add_core_example(. hello_world)
# basic message passing primitives
add(message_passing calculator)
add(message_passing cell)
add(message_passing dancing_kirby)
add(message_passing delegating)
add(message_passing divider)
add(message_passing fan_out_request)
add(message_passing fixed_stack)
add(message_passing promises)
add(message_passing request)
add(message_passing typed_calculator)
add_core_example(message_passing calculator)
add_core_example(message_passing cell)
add_core_example(message_passing dancing_kirby)
add_core_example(message_passing delegating)
add_core_example(message_passing divider)
add_core_example(message_passing fan_out_request)
add_core_example(message_passing fixed_stack)
add_core_example(message_passing promises)
add_core_example(message_passing request)
add_core_example(message_passing typed_calculator)
# streaming API
add(streaming integer_stream)
add_core_example(streaming integer_stream)
# dynamic behavior changes using 'become'
add(dynamic_behavior skip_messages)
add(dynamic_behavior dining_philosophers)
add_core_example(dynamic_behavior skip_messages)
add_core_example(dynamic_behavior dining_philosophers)
# adding custom message types
add(custom_type custom_types_1)
add(custom_type custom_types_2)
add(custom_type custom_types_3)
add_core_example(custom_type custom_types_1)
add_core_example(custom_type custom_types_2)
add_core_example(custom_type custom_types_3)
# basic remoting
add(remoting group_chat)
add(remoting group_server)
add(remoting remote_spawn)
add(remoting distributed_calculator)
# testing DSL
add_example(testing ping_pong)
target_link_libraries(ping_pong CAF::core CAF::test)
# basic I/O with brokers
add(broker simple_broker)
add(broker simple_http_broker)
# testing DSL
add(testing ping_pong)
# -- examples for CAF::io ------------------------------------------------------
if(TARGET CAF::io)
function(add_io_example folder name)
add_example(${folder} ${name} ${ARGN})
target_link_libraries(${name} CAF::io CAF::core)
endfunction()
# basic remoting
add_io_example(remoting group_chat)
add_io_example(remoting group_server)
add_io_example(remoting remote_spawn)
add_io_example(remoting distributed_calculator)
# basic I/O with brokers
add_io_example(broker simple_broker)
add_io_example(broker simple_http_broker)
if(CAF_BUILD_PROTOBUF_EXAMPLES)
find_package(Protobuf)
if(PROTOBUF_FOUND AND PROTOBUF_PROTOC_EXECUTABLE)
PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders "${CMAKE_CURRENT_SOURCE_DIR}/remoting/pingpong.proto")
include_directories(${PROTOBUF_INCLUDE_DIR})
# add binary dir as include path as generated headers will be located there
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(protobuf_broker broker/protobuf_broker.cpp ${ProtoSources})
target_link_libraries(protobuf_broker ${CMAKE_DL_LIBS} ${CAF_LIBRARIES} ${PTHREAD_LIBRARIES} ${PROTOBUF_LIBRARIES})
add_dependencies(protobuf_broker all_examples)
endif(PROTOBUF_FOUND AND PROTOBUF_PROTOC_EXECUTABLE)
endif()
if(CAF_BUILD_QT_EXAMPLES)
find_package(Qt5 COMPONENTS Core Gui Widgets QUIET)
if(Qt5_FOUND)
message(STATUS "Found Qt5")
#include(${QT_USE_FILE})
QT5_ADD_RESOURCES(GROUP_CHAT_RCS )
QT5_WRAP_UI(GROUP_CHAT_UI_HDR qtsupport/chatwindow.ui)
QT5_WRAP_CPP(GROUP_CHAT_MOC_SRC qtsupport/chatwidget.hpp)
# generated headers will be in cmake build directory
#include_directories(. qtsupport ${CMAKE_CURRENT_BINARY_DIR} ${CPPA_INCLUDE})
include_directories(qtsupport
${CMAKE_CURRENT_BINARY_DIR}
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS})
set(GROUP_CHAT_SRC qtsupport/qt_group_chat.cpp qtsupport/chatwidget.cpp)
add_executable(qt_group_chat
${GROUP_CHAT_SRC}
${GROUP_CHAT_MOC_SRC}
${GROUP_CHAT_UI_HDR})
target_link_libraries(qt_group_chat
${CMAKE_DL_LIBS}
${CAF_LIBRARIES}
Qt5::Core
Qt5::Gui
Qt5::Widgets)
add_dependencies(qt_group_chat all_examples)
else()
find_package(Qt4)
if(QT4_FOUND)
message(STATUS "Found Qt4")
include(${QT_USE_FILE})
QT4_ADD_RESOURCES(GROUP_CHAT_RCS )
QT4_WRAP_UI(GROUP_CHAT_UI_HDR qtsupport/chatwindow.ui)
QT4_WRAP_CPP(GROUP_CHAT_MOC_SRC qtsupport/chatwidget.hpp)
# generated headers will be in cmake build directory
#include_directories(. qtsupport ${CMAKE_CURRENT_BINARY_DIR} ${CPPA_INCLUDE})
include_directories(qtsupport ${CMAKE_CURRENT_BINARY_DIR})
set(GROUP_CHAT_SRCS qtsupport/qt_group_chat.cpp qtsupport/chatwidget.cpp)
add_executable(qt_group_chat
${GROUP_CHAT_SRCS}
${GROUP_CHAT_MOC_SRC}
${GROUP_CHAT_UI_HDR})
target_link_libraries(qt_group_chat
${CMAKE_DL_LIBS}
${CAF_LIBRARIES}
${QT_LIBRARIES})
add_dependencies(qt_group_chat all_examples)
endif()
if(CAF_BUILD_PROTOBUF_EXAMPLES)
find_package(Protobuf REQUIRED)
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
message(FATAL_ERROR "CMake was unable to set PROTOBUF_PROTOC_EXECUTABLE")
endif()
protobuf_generate_cpp(ProtoSources ProtoHeaders "${CMAKE_CURRENT_SOURCE_DIR}/remoting/pingpong.proto")
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)
add_dependencies(protobuf_broker all_examples)
endif()
if(CAF_BUILD_QT5_EXAMPLES)
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
message(STATUS "Found Qt5")
#include(${QT_USE_FILE})
QT5_ADD_RESOURCES(GROUP_CHAT_RCS )
QT5_WRAP_UI(GROUP_CHAT_UI_HDR qtsupport/chatwindow.ui)
QT5_WRAP_CPP(GROUP_CHAT_MOC_SRC qtsupport/chatwidget.hpp)
# generated headers will be in cmake build directory
include_directories(qtsupport
${CMAKE_CURRENT_BINARY_DIR}
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS})
set(GROUP_CHAT_SRC qtsupport/qt_group_chat.cpp qtsupport/chatwidget.cpp)
add_executable(qt_group_chat
${GROUP_CHAT_SRC}
${GROUP_CHAT_MOC_SRC}
${GROUP_CHAT_UI_HDR})
target_link_libraries(qt_group_chat
Qt5::Core
Qt5::Gui
Qt5::Widgets
CAF::core
CAF::io)
add_dependencies(qt_group_chat all_examples)
endif()
if(NOT CAF_NO_CURL_EXAMPLES)
find_package(CURL)
if(CURL_FOUND)
add_executable(curl_fuse curl/curl_fuse.cpp)
include_directories(${CURL_INCLUDE_DIRS})
target_link_libraries(curl_fuse ${CMAKE_DL_LIBS} ${CAF_LIBRARIES} ${PTHREAD_LIBRARIES} ${CURL_LIBRARY})
add_dependencies(curl_fuse all_examples)
endif(CURL_FOUND)
if(CAF_BUILD_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)
add_dependencies(curl_fuse all_examples)
endif()
......@@ -19,9 +19,9 @@ add_enum_consistency_check("caf/intrusive/inbox_result.hpp"
add_enum_consistency_check("caf/intrusive/task_result.hpp"
"src/intrusive/task_result_strings.cpp")
# -- list cpp files for libcaf_core --------------------------------------------
# -- add library target --------------------------------------------------------
set(CAF_CORE_SOURCES
add_library(libcaf_core_obj OBJECT ${CAF_CORE_HEADERS}
src/abstract_actor.cpp
src/abstract_channel.cpp
src/abstract_group.cpp
......@@ -154,140 +154,38 @@ set(CAF_CORE_SOURCES
src/uuid.cpp
)
# -- list cpp files for caf-core-test ------------------------------------------
target_include_directories(libcaf_core_obj PRIVATE
"${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
set(CAF_CORE_TEST_SOURCES
test/actor_clock.cpp
test/actor_factory.cpp
test/actor_lifetime.cpp
test/actor_pool.cpp
test/actor_profiler.cpp
test/actor_registry.cpp
test/actor_system_config.cpp
test/actor_termination.cpp
test/aout.cpp
test/behavior.cpp
test/binary_deserializer.cpp
test/binary_serializer.cpp
test/blocking_actor.cpp
test/broadcast_downstream_manager.cpp
test/byte.cpp
test/composition.cpp
test/config_option.cpp
test/config_option_set.cpp
test/config_value.cpp
test/config_value_adaptor.cpp
test/const_typed_message_view.cpp
test/constructor_attach.cpp
test/continuous_streaming.cpp
test/cow_tuple.cpp
test/custom_exception_handler.cpp
test/decorator/sequencer.cpp
test/deep_to_string.cpp
test/detached_actors.cpp
test/detail/bounds_checker.cpp
test/detail/ini_consumer.cpp
test/detail/limited_vector.cpp
test/detail/meta_object.cpp
test/detail/parse.cpp
test/detail/parser/read_bool.cpp
test/detail/parser/read_floating_point.cpp
test/detail/parser/read_ini.cpp
test/detail/parser/read_number.cpp
test/detail/parser/read_number_or_timespan.cpp
test/detail/parser/read_signed_integer.cpp
test/detail/parser/read_string.cpp
test/detail/parser/read_timespan.cpp
test/detail/parser/read_unsigned_integer.cpp
test/detail/ringbuffer.cpp
test/detail/ripemd_160.cpp
test/detail/serialized_size.cpp
test/detail/tick_emitter.cpp
test/detail/type_id_list_builder.cpp
test/detail/unique_function.cpp
test/detail/unordered_flat_map.cpp
test/dictionary.cpp
test/dynamic_spawn.cpp
test/error.cpp
test/expected.cpp
test/function_view.cpp
test/fused_downstream_manager.cpp
test/handles.cpp
test/hash/fnv.cpp
test/inspector.cpp
test/intrusive/drr_cached_queue.cpp
test/intrusive/drr_queue.cpp
test/intrusive/fifo_inbox.cpp
test/intrusive/lifo_inbox.cpp
test/intrusive/task_queue.cpp
test/intrusive/wdrr_dynamic_multiplexed_queue.cpp
test/intrusive/wdrr_fixed_multiplexed_queue.cpp
test/intrusive_ptr.cpp
test/ipv4_address.cpp
test/ipv4_endpoint.cpp
test/ipv4_subnet.cpp
test/ipv6_address.cpp
test/ipv6_endpoint.cpp
test/ipv6_subnet.cpp
test/local_group.cpp
test/logger.cpp
test/mailbox_element.cpp
test/make_config_value_field.cpp
test/message.cpp
test/message_id.cpp
test/message_lifetime.cpp
test/metaprogramming.cpp
test/mixin/requester.cpp
test/mixin/sender.cpp
test/mock_streaming_classes.cpp
test/native_streaming_classes.cpp
test/node_id.cpp
test/optional.cpp
test/or_else.cpp
test/pipeline_streaming.cpp
test/policy/categorized.cpp
test/policy/select_all.cpp
test/policy/select_any.cpp
test/request_timeout.cpp
test/result.cpp
test/selective_streaming.cpp
test/serialization.cpp
test/settings.cpp
test/simple_timeout.cpp
test/span.cpp
test/stateful_actor.cpp
test/string_algorithms.cpp
test/string_view.cpp
test/sum_type.cpp
test/thread_hook.cpp
test/tracing_data.cpp
test/type_id_list.cpp
test/typed_behavior.cpp
test/typed_message_view.cpp
test/typed_response_promise.cpp
test/typed_spawn.cpp
test/unit.cpp
test/uri.cpp
test/uuid.cpp
test/variant.cpp
)
add_library(libcaf_core "${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
$<TARGET_OBJECTS:libcaf_core_obj>)
# -- add library target --------------------------------------------------------
target_include_directories(libcaf_core INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
add_library(libcaf_core_obj OBJECT ${CAF_CORE_SOURCES} ${CAF_CORE_HEADERS})
target_include_directories(libcaf_core INTERFACE
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>)
add_library(libcaf_core
"${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
$<TARGET_OBJECTS:libcaf_core_obj>)
add_library(CAF::core ALIAS libcaf_core)
add_library(caf::core ALIAS libcaf_core)
# -- dependencies and compiler flags -------------------------------------------
if(BUILD_SHARED_LIBS AND NOT WIN32)
target_compile_options(libcaf_core PRIVATE -fPIC)
target_compile_options(libcaf_core_obj PRIVATE -fPIC)
endif()
target_link_libraries(libcaf_core PUBLIC ${CAF_EXTRA_LDFLAGS})
if(NOT TARGET Threads::Threads)
find_package(Threads REQUIRED)
endif()
target_link_libraries(libcaf_core PUBLIC Threads::Threads)
if(CAF_SANITIZERS)
target_link_libraries(caf-incubator PUBLIC -fsanitize=${CAF_SANITIZERS})
endif()
# -- API exports ---------------------------------------------------------------
generate_export_header(libcaf_core
EXPORT_MACRO_NAME CAF_CORE_EXPORT
......@@ -321,21 +219,136 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
# -- build unit tests ----------------------------------------------------------
if(NOT CAF_NO_UNIT_TESTS)
add_executable(caf-core-test
test/core-test.cpp
${CAF_CORE_TEST_SOURCES}
$<TARGET_OBJECTS:libcaf_core_obj>)
target_include_directories(caf-core-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/test")
target_compile_definitions(caf-core-test PRIVATE libcaf_core_EXPORTS)
target_link_libraries(caf-core-test ${CAF_EXTRA_LDFLAGS})
add_test_suites(caf-core-test
"${CMAKE_CURRENT_SOURCE_DIR}"
${CAF_CORE_TEST_SOURCES})
if(NOT CAF_BUILD_TESTING)
return()
endif()
# -- add this library to the global CAF_LIBRARIES ------------------------------
add_executable(caf-core-test
test/core-test.cpp
$<TARGET_OBJECTS:libcaf_core_obj>)
target_include_directories(caf-core-test PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/test")
list(APPEND CAF_LIBRARIES libcaf_core)
target_compile_definitions(caf-core-test PRIVATE libcaf_core_EXPORTS)
set(CAF_LIBRARIES ${CAF_LIBRARIES} PARENT_SCOPE)
target_link_libraries(caf-core-test PUBLIC CAF::test)
target_include_directories(caf-core-test PRIVATE
"${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
caf_add_test_suites(caf-core-test
actor_clock
actor_factory
actor_lifetime
actor_pool
actor_profiler
actor_registry
actor_system_config
actor_termination
aout
behavior
binary_deserializer
binary_serializer
blocking_actor
broadcast_downstream_manager
byte
composition
config_option
config_option_set
config_value
config_value_adaptor
const_typed_message_view
constructor_attach
continuous_streaming
cow_tuple
custom_exception_handler
decorator.sequencer
deep_to_string
detached_actors
detail.bounds_checker
detail.ini_consumer
detail.limited_vector
detail.meta_object
detail.parse
detail.parser.read_bool
detail.parser.read_floating_point
detail.parser.read_ini
detail.parser.read_number
detail.parser.read_number_or_timespan
detail.parser.read_signed_integer
detail.parser.read_string
detail.parser.read_timespan
detail.parser.read_unsigned_integer
detail.ringbuffer
detail.ripemd_160
detail.serialized_size
detail.tick_emitter
detail.type_id_list_builder
detail.unique_function
detail.unordered_flat_map
dictionary
dynamic_spawn
error
expected
function_view
fused_downstream_manager
handles
hash.fnv
inspector
intrusive.drr_cached_queue
intrusive.drr_queue
intrusive.fifo_inbox
intrusive.lifo_inbox
intrusive.task_queue
intrusive.wdrr_dynamic_multiplexed_queue
intrusive.wdrr_fixed_multiplexed_queue
intrusive_ptr
ipv4_address
ipv4_endpoint
ipv4_subnet
ipv6_address
ipv6_endpoint
ipv6_subnet
local_group
logger
mailbox_element
make_config_value_field
message
message_id
message_lifetime
metaprogramming
mixin.requester
mixin.sender
mock_streaming_classes
native_streaming_classes
node_id
optional
or_else
pipeline_streaming
policy.categorized
policy.select_all
policy.select_any
request_timeout
result
selective_streaming
serialization
settings
simple_timeout
span
stateful_actor
string_algorithms
string_view
sum_type
thread_hook
tracing_data
type_id_list
typed_behavior
typed_message_view
typed_response_promise
typed_spawn
unit
uri
uuid
variant
)
......@@ -10,9 +10,9 @@ add_enum_consistency_check("caf/io/basp/message_type.hpp"
add_enum_consistency_check("caf/io/network/operation.hpp"
"src/io/network/operation_strings.cpp")
# -- list cpp files ------------------------------------------------------------
# -- add library target --------------------------------------------------------
set(CAF_IO_SOURCES
add_library(libcaf_io_obj OBJECT ${CAF_IO_HEADERS}
src/detail/socket_guard.cpp
src/io/abstract_broker.cpp
src/io/basp/header.cpp
......@@ -55,38 +55,29 @@ set(CAF_IO_SOURCES
src/policy/udp.cpp
)
set(CAF_IO_TEST_SOURCES
test/io/basp/message_queue.cpp
test/io/basp_broker.cpp
test/io/broker.cpp
test/io/http_broker.cpp
test/io/monitor.cpp
test/io/network/default_multiplexer.cpp
test/io/network/ip_endpoint.cpp
test/io/receive_buffer.cpp
test/io/remote_actor.cpp
test/io/remote_group.cpp
test/io/remote_spawn.cpp
test/io/unpublish.cpp
test/io/worker.cpp
)
# -- add library target --------------------------------------------------------
add_library(libcaf_io_obj OBJECT ${CAF_IO_SOURCES} ${CAF_IO_HEADERS})
target_include_directories(libcaf_io_obj PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}")
add_library(libcaf_io
"${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
$<TARGET_OBJECTS:libcaf_io_obj>)
add_library(caf::io ALIAS libcaf_io)
target_include_directories(libcaf_io INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
add_library(CAF::io ALIAS libcaf_io)
if(BUILD_SHARED_LIBS AND NOT WIN32)
target_compile_options(libcaf_io PRIVATE -fPIC)
target_compile_options(libcaf_io_obj PRIVATE -fPIC)
endif()
target_link_libraries(libcaf_io PUBLIC caf::core ${CAF_EXTRA_LDFLAGS})
target_link_libraries(libcaf_io_obj PRIVATE CAF::core)
target_link_libraries(libcaf_io PUBLIC CAF::core)
if(MSVC)
target_link_libraries(libcaf_io PUBLIC ws2_32 iphlpapi)
endif()
generate_export_header(libcaf_io
EXPORT_MACRO_NAME CAF_IO_EXPORT
......@@ -119,21 +110,34 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
# -- build unit tests ----------------------------------------------------------
if(NOT CAF_NO_UNIT_TESTS)
add_executable(caf-io-test
test/io-test.cpp
${CAF_IO_TEST_SOURCES}
$<TARGET_OBJECTS:libcaf_io_obj>)
target_include_directories(caf-io-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/test")
target_compile_definitions(caf-io-test PRIVATE libcaf_io_EXPORTS)
target_link_libraries(caf-io-test caf::core ${CAF_EXTRA_LDFLAGS})
add_test_suites(caf-io-test
"${CMAKE_CURRENT_SOURCE_DIR}"
${CAF_IO_TEST_SOURCES})
if(NOT CAF_BUILD_TESTING)
return()
endif()
# -- add this library to the global CAF_LIBRARIES ------------------------------
add_executable(caf-io-test
test/io-test.cpp
$<TARGET_OBJECTS:libcaf_io_obj>)
target_include_directories(caf-io-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/test")
list(APPEND CAF_LIBRARIES libcaf_io)
target_compile_definitions(caf-io-test PRIVATE libcaf_io_EXPORTS)
set(CAF_LIBRARIES ${CAF_LIBRARIES} PARENT_SCOPE)
target_link_libraries(caf-io-test CAF::core CAF::test)
target_include_directories(caf-io-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
caf_add_test_suites(caf-io-test
io.basp.message_queue
io.basp_broker
io.broker
io.http_broker
io.monitor
io.network.default_multiplexer
io.network.ip_endpoint
io.receive_buffer
io.remote_actor
io.remote_group
io.remote_spawn
io.unpublish
io.worker
)
......@@ -2,9 +2,9 @@
file(GLOB_RECURSE CAF_OPENSSL_HEADERS "caf/*.hpp")
# -- list cpp files ------------------------------------------------------------
# -- add library target --------------------------------------------------------
set(CAF_OPENSSL_SOURCES
add_library(libcaf_openssl_obj OBJECT ${CAF_OPENSSL_HEADERS}
src/openssl/manager.cpp
src/openssl/middleman_actor.cpp
src/openssl/publish.cpp
......@@ -12,33 +12,35 @@ set(CAF_OPENSSL_SOURCES
src/openssl/session.cpp
)
set(CAF_OPENSSL_TEST_SOURCES
test/openssl/authentication.cpp
test/openssl/remote_actor.cpp
)
# -- add library target --------------------------------------------------------
add_library(libcaf_openssl_obj OBJECT ${CAF_OPENSSL_SOURCES} ${CAF_OPENSSL_HEADERS})
target_include_directories(libcaf_openssl_obj PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}")
add_library(libcaf_openssl
"${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
$<TARGET_OBJECTS:libcaf_openssl_obj>)
add_library(caf::openssl ALIAS libcaf_openssl)
target_include_directories(libcaf_openssl INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
add_library(CAF::openssl ALIAS libcaf_openssl)
if(BUILD_SHARED_LIBS AND NOT WIN32)
target_compile_options(libcaf_openssl PRIVATE -fPIC)
target_compile_options(libcaf_openssl_obj PRIVATE -fPIC)
endif()
target_link_libraries(libcaf_openssl PUBLIC
caf::core caf::io ${OPENSSL_LIBRARIES})
if(NOT APPLE AND NOT WIN32)
target_link_libraries(libcaf_openssl PUBLIC "-pthread")
if(NOT TARGET OpenSSL::SSL OR NOT TARGET OpenSSL::Crypto)
find_package(OpenSSL REQUIRED)
endif()
target_link_libraries(libcaf_openssl_obj PUBLIC
CAF::core CAF::io
OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(libcaf_openssl PUBLIC
CAF::core CAF::io
OpenSSL::SSL OpenSSL::Crypto)
generate_export_header(libcaf_openssl
EXPORT_MACRO_NAME CAF_OPENSSL_EXPORT
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/caf/detail/openssl_export.hpp"
......@@ -75,22 +77,26 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
# -- build unit tests ----------------------------------------------------------
if(NOT CAF_NO_UNIT_TESTS)
add_executable(caf-openssl-test
test/openssl-test.cpp
${CAF_OPENSSL_TEST_SOURCES}
$<TARGET_OBJECTS:libcaf_openssl_obj>)
target_include_directories(caf-openssl-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/test")
target_compile_definitions(caf-openssl-test PRIVATE libcaf_openssl_EXPORTS)
target_link_libraries(caf-openssl-test caf::core caf::io
${OPENSSL_LIBRARIES} ${CAF_EXTRA_LDFLAGS})
add_test_suites(caf-openssl-test
"${CMAKE_CURRENT_SOURCE_DIR}"
${CAF_OPENSSL_TEST_SOURCES})
if(NOT CAF_BUILD_TESTING)
return()
endif()
# -- add this library to the global CAF_LIBRARIES ------------------------------
add_executable(caf-openssl-test
test/openssl-test.cpp
${CAF_OPENSSL_TEST_SOURCES}
$<TARGET_OBJECTS:libcaf_openssl_obj>)
target_include_directories(caf-openssl-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/test")
list(APPEND CAF_LIBRARIES libcaf_openssl)
target_compile_definitions(caf-openssl-test PRIVATE libcaf_openssl_EXPORTS)
set(CAF_LIBRARIES ${CAF_LIBRARIES} PARENT_SCOPE)
target_link_libraries(caf-openssl-test PRIVATE
CAF::io CAF::core CAF::test OpenSSL::SSL OpenSSL::Crypto)
target_include_directories(caf-openssl-test PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}")
caf_add_test_suites(caf-openssl-test
openssl.authentication
openssl.remote_actor
)
......@@ -4,10 +4,7 @@ include_directories(${LIBCAF_INCLUDE_DIRS})
macro(add name)
add_executable(${name} ${name}.cpp ${ARGN})
target_link_libraries(${name}
${CAF_EXTRA_LDFLAGS}
${CAF_LIBRARIES}
${PTHREAD_LIBRARIES})
target_link_libraries(${name} CAF::core CAF::io)
install(FILES ${name}.cpp DESTINATION ${CMAKE_INSTALL_DATADIR}/caf/tools/${folder})
add_dependencies(${name} all_tools)
endmacro()
......
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