Unverified Commit 9d7a9c4b authored by Dominik Charousset's avatar Dominik Charousset Committed by GitHub

Merge pull request #66

Modernize CMake setup, enable bundled builds
parents 9eac8a21 eaaea8e9
......@@ -32,10 +32,13 @@ IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MacroBlockBegin: "^BEGIN_STATE$|CAF_BEGIN_TYPE_ID_BLOCK"
MacroBlockEnd: "^END_STATE$|CAF_END_TYPE_ID_BLOCK"
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 1000
PenaltyBreakBeforeFirstCallParameter: 1000
PenaltyBreakAssignment: 25
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyReturnTypeOnItsOwnLine: 25
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
......
# -- project setup -------------------------------------------------------------
cmake_minimum_required(VERSION 3.13.5 FATAL_ERROR)
project(CAF_INC CXX)
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(caf_incubator CXX)
# -- project options -----------------------------------------------------------
option(BUILD_SHARED_LIBS "Build all modules as shared library" ON)
set(CMAKE_CXX_STANDARD 17)
# -- includes ------------------------------------------------------------------
include(CMakePackageConfigHelpers) # For creating .cmake files
include(CheckCXXSourceCompiles) # Check wether compiler works
include(FetchContent) # For bundling CAF with the incubator
include(GNUInstallDirs) # Sets default install paths
include(GenerateExportHeader) # Auto-generates dllexport macros
# -- general options -----------------------------------------------------------
option(BUILD_SHARED_LIBS "Build shared library targets" ON)
option(CMAKE_EXPORT_COMPILE_COMMANDS "Write JSON compile commands database" ON)
# -- incubator options that are off by default ---------------------------------
option(CAF_INC_ENABLE_UTILITY_TARGETS
"Include targets like consistency-check" OFF)
option(CAF_INC_ENABLE_STANDALONE_BUILD
"Fetch and bulid required CAF modules" OFF)
# -- incubator options that are on by default ----------------------------------
option(CAF_INC_ENABLE_TESTING "Build unit test suites" ON)
option(CAF_INC_ENABLE_NET_MODULE "Build networking module" ON)
option(CAF_INC_ENABLE_BB_MODULE "Build building blocks module" ON)
# -- incubator options with non-boolean values ---------------------------------
set(CAF_INC_SANITIZERS "" CACHE STRING
"Comma separated sanitizers, e.g., 'address,undefined'")
# -- 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")
# -- check whether we are running as CMake subdirectory ------------------------
# -- get dependencies ----------------------------------------------------------
get_directory_property(_parent PARENT_DIRECTORY)
if(_parent)
set(caf_is_subproject ON)
if(CAF_INC_ENABLE_STANDALONE_BUILD)
FetchContent_Declare(
actor_framework
GIT_REPOSITORY https://github.com/actor-framework/actor-framework.git
GIT_TAG b3c59ff
)
FetchContent_Populate(actor_framework)
set(CAF_ENABLE_EXAMPLES OFF CACHE BOOL "" FORCE)
set(CAF_ENABLE_IO_MODULE OFF CACHE BOOL "" FORCE)
set(CAF_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(CAF_ENABLE_TOOLS OFF CACHE BOOL "" FORCE)
set(CAF_ENABLE_OPENSSL_MODULE OFF CACHE BOOL "" FORCE)
set(CAF_SANITIZERS "${CAF_INC_SANITIZERS}" CACHE STRING "" FORCE)
add_subdirectory(${actor_framework_SOURCE_DIR} ${actor_framework_BINARY_DIR})
else()
set(caf_is_subproject OFF)
find_package(CAF COMPONENTS core test REQUIRED)
endif()
unset(_parent)
# enable tests if not disabled
if(NOT CAF_NO_UNIT_TESTS)
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()
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()
# -- sanity checks -------------------------------------------------------------
if(MSVC AND CAF_INC_SANITIZERS)
message(FATAL_ERROR "Sanitizer builds are currently not supported on MSVC")
endif()
# -- make sure we have at least C++17 available --------------------------------
# -- compiler setup ------------------------------------------------------------
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)
function(caf_incubator_set_default_properties)
foreach(target ${ARGN})
if(MSVC)
set(cxx_flag "/std:c++17")
else()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
set(cxx_flag "-std=c++1z")
# 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
-ftemplate-depth=512 -ftemplate-backtrace-limit=0
-Wall -Wextra -pedantic)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Flags for Clang only.
target_compile_options(${target} PRIVATE -Wdocumentation)
else()
set(cxx_flag "-std=c++17")
# Flags for GCC only.
target_compile_options(${target} PRIVATE
-Wno-missing-field-initializers)
endif()
endif()
# Re-run compiler check.
try_compile(caf_has_cxx_17
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/check-compiler-features.cpp"
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!\
\nPlease see README.md for supported compilers.\
\n\ntry_compile output:\n${cxx_check_output}")
endif()
add_compile_options("${cxx_flag}")
if(CAF_INC_SANITIZERS)
target_compile_options(${target} PRIVATE
-fsanitize=${CAF_INC_SANITIZERS}
-fno-omit-frame-pointer)
target_link_libraries(${target} PRIVATE
-fsanitize=${CAF_INC_SANITIZERS}
-fno-omit-frame-pointer)
endif()
endforeach()
endfunction()
# -- unit testing setup / caf_add_test_suites function ------------------------
if(CAF_INC_ENABLE_TESTING)
enable_testing()
function(caf_incubator_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()
endfunction()
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()
# -- helper targets ------------------------------------------------------------
# Simplifies re-running configuration setup.
add_custom_target(configure COMMAND ${CMAKE_CURRENT_BINARY_DIR}/config.status)
# -- check for static builds ---------------------------------------------------
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()
# Silence annoying MSVC warning.
if(MSVC)
add_compile_options(/wd4275 /wd4251)
endif()
################################################################################
# utility functions #
################################################################################
# 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)
# -- utility targets -----------------------------------------------------------
add_executable(caf-generate-enum-strings
if(CAF_INC_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)
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_incubator_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}")
......@@ -212,166 +163,39 @@ function(add_enum_consistency_check hpp_file cpp_file)
"${file_under_test}"
DEPENDS caf-generate-enum-strings "${input}")
add_dependencies(update-enum-strings "${target_name}-update")
endfunction()
# -- binary and library path setup ---------------------------------------------
# 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()
# -- get dependencies ----------------------------------------------------------
find_package(CAF COMPONENTS core io test)
# -- fetch CAF version ---------------------------------------------------------
# read content of config.hpp
file(READ "${CAF_INCLUDE_DIR_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}")
# 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")
# create full version string
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}")
endfunction()
else()
set(CAF_LIB_VERSION "${CAF_VERSION}")
endif()
# -- compiler setup ------------------------------------------------------------
# Enable ASAN 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()
# Add Windows-specific linker flags.
if (WIN32)
list(APPEND CAF_EXTRA_LDFLAGS ws2_32 iphlpapi)
endif()
# Support macOS/iOS-specific magic.
if(CAF_OSX_SYSROOT)
set(CMAKE_OSX_SYSROOT "${CAF_OSX_SYSROOT}")
endif()
# Add iOS target if requested by user.
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()
function(caf_incubator_add_enum_consistency_check hpp_file cpp_file)
# nop
endfunction()
endif()
# -- install targets -----------------------------------------------------------
# -- 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.
add_custom_target(uninstall
# Add uninstall target if it does not exist yet.
if(NOT TARGET uninstall)
add_custom_target(uninstall)
endif()
add_custom_target(caf-incubator-uninstall)
add_custom_command(TARGET caf-incubator-uninstall
PRE_BUILD
COMMAND "${CMAKE_COMMAND}" -P
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
# -- set include paths for all subprojects -------------------------------------
include_directories("${CMAKE_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/libcaf_net"
"${CAF_INCLUDE_DIRS}")
################################################################################
# add targets #
################################################################################
add_subdirectory(libcaf_net)
add_subdirectory(libcaf_bb)
export(EXPORT CAFTargets FILE CAFTargets.cmake NAMESPACE caf::)
install(EXPORT CAFTargets
DESTINATION "${INSTALL_CAF_CMAKEDIR}"
NAMESPACE caf::)
add_dependencies(uninstall caf-incubator-uninstall)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/CAFConfigVersion.cmake"
VERSION ${CAF_VERSION}
COMPATIBILITY ExactVersion)
# -- build all components the user asked for -----------------------------------
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}")
# -- print summary -------------------------------------------------------------
if(CAF_INC_ENABLE_NET_MODULE)
add_subdirectory(libcaf_net)
endif()
# Inverts 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_UNIT_TESTS CAF_BUILD_UNIT_TESTS)
get_property(all_cxx_flags DIRECTORY PROPERTY COMPILE_OPTIONS)
# Print summary.
if(NOT CAF_NO_SUMMARY)
message(STATUS
"\n====================| Build Summary |===================="
"\n"
"\nBuild type: ${CMAKE_BUILD_TYPE}"
"\nLink type: ${LINK_TYPE}"
"\nBuild static runtime: ${CAF_BUILD_STATIC_RUNTIME}"
"\n"
"\nCXX: ${CMAKE_CXX_COMPILER}"
"\nCXXFLAGS: ${all_cxx_flags}"
"\nLINKER_FLAGS (shared): ${ALL_LD_FLAGS}"
"\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")
if(CAF_INC_ENABLE_NET_MODULE)
add_subdirectory(libcaf_bb)
endif()
......@@ -4,12 +4,14 @@
// Default CMake flags for release builds.
defaultReleaseBuildFlags = [
'CAF_ENABLE_RUNTIME_CHECKS:BOOL=yes',
'CAF_INC_ENABLE_STANDALONE_BUILD:BOOL=ON',
'CAF_ENABLE_RUNTIME_CHECKS:BOOL=ON',
]
// Default CMake flags for debug builds.
defaultDebugBuildFlags = defaultReleaseBuildFlags + [
'CAF_SANITIZERS:STRING=address,undefined',
'CAF_INC_ENABLE_STANDALONE_BUILD:BOOL=ON',
'CAF_INC_SANITIZERS:STRING=address,undefined',
'CAF_LOG_LEVEL:STRING=TRACE',
]
......@@ -24,38 +26,13 @@ config = [
'tests',
'coverage',
],
// Dependencies that we need to fetch before each build.
dependencies: [
artifact: [
'CAF/actor-framework/master',
],
cmakeRootVariables: [
'CAF_ROOT_DIR',
],
],
// Our build matrix. Keys are the operating system labels and values are build configurations.
buildMatrix: [
// Various Linux builds for debug and release.
['debian-8', [
builds: ['debug', 'release'],
tools: ['clang-4'],
]],
['centos-6', [
builds: ['debug', 'release'],
tools: ['gcc-7'],
]],
['centos-7', [
builds: ['debug', 'release'],
tools: ['gcc-7'],
]],
['ubuntu-16.04', [
builds: ['debug', 'release'],
tools: ['clang-4'],
]],
['ubuntu-18.04', [
builds: ['debug', 'release'],
tools: ['gcc-7'],
]],
// On Fedora 28, our debug build also produces the coverage report.
['fedora-28', [
builds: ['debug'],
......@@ -99,7 +76,10 @@ config = [
],
// Configures what binary the coverage report uses and what paths to exclude.
coverage: [
binary: 'build/libcaf_net/caf-net-test',
binaries: [
'build/libcaf_net/caf-net-test',
'build/libcaf_bb/caf-bb-test',
],
relativeExcludePaths: [
'libcaf_net/test'
],
......@@ -111,9 +91,6 @@ pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '3'))
}
triggers {
upstream(upstreamProjects: 'CAF/actor-framework/master/', threshold: hudson.model.Result.SUCCESS)
}
agent {
label 'master'
}
......@@ -134,6 +111,26 @@ pipeline {
runClangFormat(config)
}
}
stage('Check Consistency') {
agent { label 'unix' }
steps {
deleteDir()
unstash('sources')
dir('sources') {
cmakeBuild([
buildDir: 'build',
installation: 'cmake in search path',
sourceDir: '.',
cmakeArgs: '-DCAF_INC_ENABLE_STANDALONE_BUILD:BOOL=ON ' +
'-DCAF_INC_ENABLE_UTILITY_TARGETS:BOOL=ON',
steps: [[
args: '--target consistency-check',
withCmake: true,
]],
])
}
}
}
stage('Build') {
steps {
buildParallel(config, PrettyJobBaseName)
......
......@@ -26,20 +26,20 @@ endif()
foreach (comp ${CAF_FIND_COMPONENTS})
# we use uppercase letters only for variable names
string(TOUPPER "${comp}" UPPERCOMP)
if ("${comp}" STREQUAL "core")
if("${comp}" STREQUAL "core")
set(HDRNAME "caf/all.hpp")
elseif ("${comp}" STREQUAL "test")
elseif("${comp}" STREQUAL "test")
set(HDRNAME "caf/test/unit_test.hpp")
else ()
set(HDRNAME "caf/${comp}/all.hpp")
endif ()
if (CAF_ROOT_DIR)
endif()
if(CAF_ROOT_DIR)
set(header_hints
"${CAF_ROOT_DIR}/include"
"${CAF_ROOT_DIR}/libcaf_${comp}"
"${CAF_ROOT_DIR}/../libcaf_${comp}"
"${CAF_ROOT_DIR}/../../libcaf_${comp}")
endif ()
endif()
find_path(CAF_INCLUDE_DIR_${UPPERCOMP}
NAMES
${HDRNAME}
......@@ -51,12 +51,12 @@ foreach (comp ${CAF_FIND_COMPONENTS})
/sw/include
${CMAKE_INSTALL_PREFIX}/include)
mark_as_advanced(CAF_INCLUDE_DIR_${UPPERCOMP})
if (NOT "${CAF_INCLUDE_DIR_${UPPERCOMP}}"
if(NOT "${CAF_INCLUDE_DIR_${UPPERCOMP}}"
STREQUAL "CAF_INCLUDE_DIR_${UPPERCOMP}-NOTFOUND")
# mark as found (set back to false when missing library or build header)
set(CAF_${comp}_FOUND true)
# check for CMake-generated build header for the core component
if ("${comp}" STREQUAL "core")
if("${comp}" STREQUAL "core")
find_path(caf_build_header_path
NAMES
caf/detail/build_config.hpp
......@@ -68,7 +68,7 @@ foreach (comp ${CAF_FIND_COMPONENTS})
/opt/local/include
/sw/include
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
if ("${caf_build_header_path}" STREQUAL "caf_build_header_path-NOTFOUND")
if("${caf_build_header_path}" STREQUAL "caf_build_header_path-NOTFOUND")
message(WARNING "Found all.hpp for CAF core, but not build_config.hpp")
set(CAF_${comp}_FOUND false)
else()
......@@ -78,10 +78,10 @@ foreach (comp ${CAF_FIND_COMPONENTS})
list(APPEND CAF_INCLUDE_DIRS "${CAF_INCLUDE_DIR_${UPPERCOMP}}")
# look for (.dll|.so|.dylib) file, again giving hints for non-installed CAFs
# skip probe_event as it is header only
if (NOT ${comp} STREQUAL "probe_event" AND NOT ${comp} STREQUAL "test")
if (CAF_ROOT_DIR)
set(library_hints "${CAF_ROOT_DIR}/lib")
endif ()
if(NOT ${comp} STREQUAL "probe_event" AND NOT ${comp} STREQUAL "test")
if(CAF_ROOT_DIR)
set(library_hints "${CAF_ROOT_DIR}/libcaf_${comp}")
endif()
find_library(CAF_LIBRARY_${UPPERCOMP}
NAMES
"caf_${comp}"
......@@ -94,20 +94,39 @@ foreach (comp ${CAF_FIND_COMPONENTS})
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_BUILD_TYPE})
mark_as_advanced(CAF_LIBRARY_${UPPERCOMP})
if ("${CAF_LIBRARY_${UPPERCOMP}}"
if("${CAF_LIBRARY_${UPPERCOMP}}"
STREQUAL "CAF_LIBRARY_${UPPERCOMP}-NOTFOUND")
set(CAF_${comp}_FOUND false)
else ()
set(CAF_LIBRARIES ${CAF_LIBRARIES} ${CAF_LIBRARY_${UPPERCOMP}})
endif ()
endif ()
endif ()
endif()
endif()
endif()
endforeach ()
if (DEFINED CAF_INCLUDE_DIRS)
if(DEFINED CAF_INCLUDE_DIRS)
list(REMOVE_DUPLICATES CAF_INCLUDE_DIRS)
endif()
if(CAF_core_FOUND)
# Get line containing the version from config.hpp and extract version number.
file(READ "${CAF_INCLUDE_DIR_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 "${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 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}")
else()
set(CAF_LIB_VERSION "${CAF_VERSION}")
endif()
endif()
# let CMake check whether all requested components have been found
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CAF
......@@ -120,36 +139,44 @@ mark_as_advanced(CAF_ROOT_DIR
CAF_LIBRARIES
CAF_INCLUDE_DIRS)
if (CAF_core_FOUND AND NOT TARGET caf::core)
add_library(caf::core UNKNOWN IMPORTED)
set_target_properties(caf::core PROPERTIES
if(CAF_core_FOUND AND NOT TARGET CAF::core)
add_library(CAF::core UNKNOWN IMPORTED)
if(caf_build_header_path
AND NOT CAF_INCLUDE_DIR_CORE STREQUAL caf_build_header_path)
set(caf_core_include_dirs "${CAF_INCLUDE_DIR_CORE};${caf_build_header_path}")
else()
set(caf_core_include_dirs "${CAF_INCLUDE_DIR_CORE}")
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set_target_properties(CAF::core PROPERTIES
IMPORTED_LOCATION "${CAF_LIBRARY_CORE}"
INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_CORE}")
endif ()
if (CAF_io_FOUND AND NOT TARGET caf::io)
add_library(caf::io UNKNOWN IMPORTED)
set_target_properties(caf::io PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${caf_core_include_dirs}"
INTERFACE_LINK_LIBRARIES "Threads::Threads")
endif()
if(CAF_io_FOUND AND NOT TARGET CAF::io)
add_library(CAF::io UNKNOWN IMPORTED)
set_target_properties(CAF::io PROPERTIES
IMPORTED_LOCATION "${CAF_LIBRARY_IO}"
INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_IO}"
INTERFACE_LINK_LIBRARIES "caf::core")
endif ()
if (CAF_openssl_FOUND AND NOT TARGET caf::openssl)
add_library(caf::openssl UNKNOWN IMPORTED)
set_target_properties(caf::openssl PROPERTIES
INTERFACE_LINK_LIBRARIES "CAF::core")
endif()
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)
set_target_properties(CAF::openssl PROPERTIES
IMPORTED_LOCATION "${CAF_LIBRARY_OPENSSL}"
INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_OPENSSL}"
INTERFACE_LINK_LIBRARIES "caf::core;caf::io")
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 ()
if (CAF_test_FOUND AND NOT TARGET caf::test)
add_library(caf::test INTERFACE IMPORTED)
set_target_properties(caf::test PROPERTIES
INTERFACE_LINK_LIBRARIES "CAF::core;CAF::io;OpenSSL::SSL;OpenSSL::Crypto")
endif()
if(CAF_test_FOUND AND NOT TARGET CAF::test)
add_library(CAF::test INTERFACE IMPORTED)
set_target_properties(CAF::test PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_TEST}"
INTERFACE_LINK_LIBRARIES "caf::core")
endif ()
INTERFACE_LINK_LIBRARIES "CAF::core")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files
"${file_under_test}" "${generated_file}"
RESULT_VARIABLE result)
if(result EQUAL 0)
# files still in sync
else()
message(SEND_ERROR "${file_under_test} is out of sync! Run target "
"'update-enum-strings' to update automatically")
endif()
#!/bin/sh
# Convenience wrapper for easily viewing/setting options that
# the project's CMake scripts will recognize.
set -e
command="$0 $*"
dirname_0=`dirname $0`
sourcedir=`cd $dirname_0 && pwd`
# Convenience wrapper for easily setting options that the project's CMake
# scripts will recognize.
Command="$0 $*"
CommandDirname=`dirname $0`
SourceDir=`cd $CommandDirname && pwd`
usage="\
Usage: $0 [OPTION]... [VAR=VALUE]...
Usage:
$0 [--<variable>=<value>...]
General CMake options:
Build Options:
--cmake=PATH set a custom path to the CMake binary
--generator=GENERATOR set CMake generator (see cmake --help)
--build-type=TYPE set CMake build type [RelWithDebInfo]:
- Debug: debugging flags enabled
- MinSizeRel: minimal output size
- Release: optimizations on, debugging off
- RelWithDebInfo: release flags plus debugging
--extra-flags=STRING additional compiler flags (sets CMAKE_CXX_FLAGS)
--build-dir=DIR place build files in directory [build]
--bin-dir=DIR executable directory [build/bin]
--lib-dir=DIR library directory [build/lib]
--build-static build as static and shared library
--build-static-only build as static library only
--static-runtime build with static C++ runtime
--no-compiler-check disable compiler version check
--no-auto-libc++ do not automatically enable libc++ for Clang
Required packages in non-standard locations:
--with-caf=PATH path to CAF install root or build directory
Installation Directories:
--prefix=PREFIX installation directory [/usr/local]
Debugging:
--with-sanitizers=LIST build with this list of sanitizers enabled
Convenience options:
--dev-mode sets --build-type=debug and
--build-dir=PATH set build directory [build]
--build-type=STRING set build type of single-configuration generators
--generator=STRING set CMake generator (see cmake --help)
--cxx-flags=STRING set CMAKE_CXX_FLAGS when running CMake
--prefix=PATH set installation directory
Locating packages in non-standard locations:
--caf-root-dir=PATH set root directory of a CAF installation
Debugging options:
--sanitizers=STRING build with this list of sanitizers enabled
Convenience options:
--dev-mode shortcut for passing:
--build-type=Debug
--sanitizers=address,undefined
--enable-utility-targets
Flags (use --enable-<name> to activate and --disable-<name> to deactivate):
shared-libs build shared library targets [ON]
export-compile-commands write JSON compile commands database [ON]
prefer-pthread-flag prefer -pthread flag if available [ON]
curl-examples build examples with libcurl [OFF]
protobuf-examples build examples with Google Protobuf [OFF]
qt5-examples build examples with the Qt5 framework [OFF]
runtime-checks build CAF with extra runtime assertions [OFF]
utility-targets include targets like consistency-check [OFF]
standalone-build Fetch and bulid required CAF modules [OFF]
testing build unit test suites [ON]
net-module build networking module [ON]
bb-module build building blocks module [ON]
Influential Environment Variables (only on first invocation):
Influential Environment Variables (only on first invocation):
CXX C++ compiler command
CXXFLAGS C++ compiler flags (overrides defaults)
CXXFLAGS Additional C++ compiler flags
LDFLAGS Additional linker flags
CMAKE_GENERATOR Selects a custom generator
Python Build Options:
--with-python-config=FILE Use python-conf binary to determine includes and libs
iOS Build Options (should be used with XCode generator):
--sysroot=DIR set system root for Clang
- iphoneos: for iOS device
- iphonesimulator: for iOS simulator
--ios-min-ver=VERSION set the ios deployment target version
"
# Appends a CMake cache entry definition to the CMakeCacheEntries variable.
# $1 is the cache entry variable name
# $2 is the cache entry variable type
# $3 is the cache entry variable value
append_cache_entry ()
{
# $1: variable name
# $2: CMake type
# $3: value
append_cache_entry() {
case "$3" in
*\ * )
# string contains whitespace
CMakeCacheEntries="$CMakeCacheEntries -D \"$1:$2=$3\""
;;
*)
# string contains whitespace
# string contains no whitespace
CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3"
;;
esac
}
# -- set defaults --------------------------------------------------------------
builddir="$sourcedir/build"
# Appends a BOOL cache entry to the CMakeCacheEntries variable.
# $1: flag name
# $2: value (ON or OFF)
set_build_flag() {
FlagName=''
case "$1" in
shared-libs) FlagName='BUILD_SHARED_LIBS' ;;
export-compile-commands) FlagName='CMAKE_EXPORT_COMPILE_COMMANDS' ;;
prefer-pthread-flag) FlagName='THREADS_PREFER_PTHREAD_FLAG' ;;
utility-targets) FlagName='CAF_INC_ENABLE_UTILITY_TARGETS' ;;
standalone-build) FlagName='CAF_INC_ENABLE_STANDALONE_BUILD' ;;
testing) FlagName='CAF_INC_ENABLE_TESTING' ;;
net-module) FlagName='CAF_INC_ENABLE_NET_MODULE' ;;
bb-module) FlagName='CAF_INC_ENABLE_BB_MODULE' ;;
*)
echo "Invalid flag '$1'. Try $0 --help to see available options."
exit 1
;;
esac
append_cache_entry $FlagName BOOL $2
}
# Set defaults.
CMakeBuildDir="$SourceDir/build"
CMakeCacheEntries=""
append_cache_entry CMAKE_INSTALL_PREFIX PATH /usr/local
# -- parse custom environment variables ----------------------------------------
if [ -n "$CMAKE_GENERATOR" ]; then
CMakeGenerator="$CMAKE_GENERATOR"
fi
# -- parse arguments -----------------------------------------------------------
# Parse user input.
while [ $# -ne 0 ]; do
# Fetch the option argument.
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
--*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
--enable-*) optarg=`echo "$1" | sed 's/--enable-//'` ;;
--disable-*) optarg=`echo "$1" | sed 's/--disable-//'` ;;
*) ;;
esac
# Consume current input.
case "$1" in
--help|-h)
echo "${usage}" 1>&2
......@@ -105,81 +121,50 @@ while [ $# -ne 0 ]; do
--cmake=*)
CMakeCommand="$optarg"
;;
--build-dir=*)
CMakeBuildDir="$optarg"
;;
--generator=*)
CMakeGenerator="$optarg"
;;
--prefix=*)
append_cache_entry CMAKE_INSTALL_PREFIX PATH "$optarg"
;;
--with-sanitizers=*)
append_cache_entry CAF_SANITIZERS STRING "$optarg"
;;
--no-compiler-check)
append_cache_entry CAF_NO_COMPILER_CHECK BOOL yes
;;
--no-auto-libc++)
append_cache_entry CAF_NO_AUTO_LIBCPP BOOL yes
;;
--with-caf=*)
append_cache_entry CAF_ROOT_DIR PATH "$optarg"
;;
--sysroot=*)
append_cache_entry CAF_OSX_SYSROOT PATH "$optarg"
;;
--ios-min-ver=*)
append_cache_entry CMAKE_OSX_ARCHITECTURES STRING "\$(ARCHS_STANDARD_32_64_BIT)"
append_cache_entry CAF_IOS_DEPLOYMENT_TARGET STRING "$optarg"
;;
--build-type=*)
append_cache_entry CMAKE_BUILD_TYPE STRING "$optarg"
CMakeBuildType="$optarg"
;;
--extra-flags=*)
--cxx-flags=*)
append_cache_entry CMAKE_CXX_FLAGS STRING "$optarg"
;;
--build-dir=*)
builddir="$optarg"
;;
--bin-dir=*)
append_cache_entry EXECUTABLE_OUTPUT_PATH PATH "$optarg"
;;
--lib-dir=*)
append_cache_entry LIBRARY_OUTPUT_PATH PATH "$optarg"
;;
--no-curl-examples)
append_cache_entry CAF_NO_CURL_EXAMPLES BOOL yes
;;
--no-unit-tests)
append_cache_entry CAF_NO_UNIT_TESTS BOOL yes
--prefix=*)
append_cache_entry CMAKE_INSTALL_PREFIX PATH "$optarg"
;;
--no-openssl)
append_cache_entry CAF_NO_OPENSSL BOOL yes
--sanitizers=*)
append_cache_entry CAF_INC_SANITIZERS STRING "$optarg"
;;
--build-static)
append_cache_entry CAF_BUILD_STATIC BOOL yes
--dev-mode)
CMakeBuildType='Debug'
append_cache_entry CAF_INC_SANITIZERS STRING 'address,undefined'
set_build_flag utility-targets ON
;;
--build-static-only)
append_cache_entry CAF_BUILD_STATIC_ONLY BOOL yes
--enable-*)
set_build_flag $optarg ON
;;
--static-runtime)
append_cache_entry CAF_BUILD_STATIC_RUNTIME BOOL yes
--disable-*)
set_build_flag $optarg OFF
;;
--dev-mode)
append_cache_entry CMAKE_BUILD_TYPE STRING Debug
append_cache_entry CAF_SANITIZERS STRING address,undefined
--caf-root-dir=*)
append_cache_entry CAF_ROOT_DIR PATH "$optarg"
;;
*)
echo "Invalid option '$1'. Try $0 --help to see available options."
exit 1
;;
esac
# Get next input.
shift
done
# -- CMake setup ---------------------------------------------------------------
# Check for `cmake` command.
if [ -z "$CMakeCommand" ]; then
# prefer cmake3 over "regular" cmake (cmake == cmake2 on RHEL)
# Prefer cmake3 over "regular" cmake (cmake == cmake2 on RHEL).
if command -v cmake3 >/dev/null 2>&1 ; then
CMakeCommand="cmake3"
elif command -v cmake >/dev/null 2>&1 ; then
......@@ -188,50 +173,42 @@ if [ -z "$CMakeCommand" ]; then
echo "This package requires CMake, please install it first."
echo "Then you may use this script to configure the CMake build."
echo "Note: pass --cmake=PATH to use cmake in non-standard locations."
exit 1;
exit 1
fi
fi
CMakeDefaultCache=$CMakeCacheEntries
CMakeCacheEntries=$CMakeDefaultCache
# Set $workdir to the absolute path of $builddir.
case "$builddir" in
# Make sure the build directory is an absolute path.
case "$CMakeBuildDir" in
/*)
# Absolute path given
workdir="$builddir"
CMakeAbsoluteBuildDir="$CMakeBuildDir"
;;
*)
# Relative path given, convert to absolute path.
workdir="$PWD/$builddir"
CMakeAbsoluteBuildDir="$PWD/$CMakeBuildDir"
;;
esac
# Make sure the build directory exists but has no CMakeCache.txt in it.
if [ -d "$workdir" ]; then
if [ -f "$workdir/CMakeCache.txt" ]; then
rm -f "$workdir/CMakeCache.txt"
# If a build directory exists, delete any existing cache to have a clean build.
if [ -d "$CMakeAbsoluteBuildDir" ]; then
if [ -f "$CMakeAbsoluteBuildDir/CMakeCache.txt" ]; then
rm -f "$CMakeAbsoluteBuildDir/CMakeCache.txt"
fi
else
mkdir -p "$workdir"
mkdir -p "$CMakeAbsoluteBuildDir"
fi
cd "$workdir"
# Run CMake.
cd "$CMakeAbsoluteBuildDir"
if [ -n "$CMakeGenerator" ]; then
"$CMakeCommand" -G "$CMakeGenerator" $CMakeCacheEntries "$sourcedir"
"$CMakeCommand" -G "$CMakeGenerator" $CMakeCacheEntries "$SourceDir"
else
"$CMakeCommand" $CMakeCacheEntries "$sourcedir"
"$CMakeCommand" $CMakeCacheEntries "$SourceDir"
fi
# Generate a config.status file that allows re-running a clean build.
printf "#!/bin/sh\n\n" > config.status
printf "# Switch to the source of this build directory.\n" >> config.status
printf "cd \"$sourcedir\"\n\n" >> config.status
printf "cd \"%s\"\n\n" "$CMakeAbsoluteBuildDir" >> config.status
printf "# Invoke the command to configure this build.\n" >> config.status
if [ -n "$CC" ]; then
printf "CC=\"%s\"\n" "$CC" >> config.status
fi
if [ -n "$CXX" ]; then
printf "CXX=\"%s\"\n" "$CXX" >> config.status
fi
......@@ -241,5 +218,5 @@ fi
if [ -n "$LDFLAGS" ]; then
printf "LDFLAGS=\"%s\"\n" "$LDFLAGS" >> config.status
fi
echo $command >> config.status
echo $Command >> config.status
chmod u+x config.status
......@@ -4,60 +4,20 @@ file(GLOB_RECURSE CAF_BB_HEADERS "caf/*.hpp")
# -- list cpp files for caf::bb ------------------------------------------------
set(CAF_BB_SOURCES
# nop
)
# -- list cpp files for caf-bb-test --------------------------------------------
add_library(libcaf_bb INTERFACE)
set(CAF_BB_TEST_SOURCES
test/container_source.cpp
test/stream_reader.cpp
test/tokenized_integer_reader.cpp
)
target_link_libraries(libcaf_bb INTERFACE CAF::core)
# -- add library target --------------------------------------------------------
# --> Uncomment this block when adding the first .cpp file
#
# add_library(libcaf_bb_obj OBJECT ${CAF_BB_SOURCES} ${CAF_BB_HEADERS})
#
# add_library(libcaf_bb
# "${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
# $<TARGET_OBJECTS:libcaf_bb_obj>)
#
# add_library(caf::bb ALIAS libcaf_bb)
#
# if(BUILD_SHARED_LIBS AND NOT WIN32)
# target_compile_options(libcaf_bb PRIVATE -fPIC)
# target_compile_options(libcaf_bb_obj PRIVATE -fPIC)
# endif()
#
# target_link_libraries(libcaf_bb PUBLIC ${CAF_EXTRA_LDFLAGS} ${CAF_LIBRARIES})
#
# generate_export_header(libcaf_bb
# EXPORT_MACRO_NAME CAF_BB_EXPORT
# EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/caf/detail/bb_export.hpp"
# STATIC_DEFINE CAF_STATIC_BUILD)
#
# target_compile_definitions(libcaf_bb_obj PRIVATE libcaf_bb_EXPORTS)
#
# set_target_properties(libcaf_bb PROPERTIES
# EXPORT_NAME bb
# SOVERSION ${CAF_VERSION}
# VERSION ${CAF_LIB_VERSION}
# OUTPUT_NAME caf_bb)
#
# -- install library and header files ------------------------------------------
#
# install(FILES "${CMAKE_BINARY_DIR}/caf/detail/bb_export.hpp"
# DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/caf/detail")
#
# install(TARGETS libcaf_bb
# EXPORT CAFTargets
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bb
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bb
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bb)
install(TARGETS libcaf_bb
EXPORT CAFTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bb
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bb
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bb)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
......@@ -66,25 +26,24 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
# -- build unit tests ----------------------------------------------------------
if(NOT CAF_NO_UNIT_TESTS)
message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(caf-bb-test
"${PROJECT_SOURCE_DIR}/cmake/incubator-test.cpp"
"${CAF_INCLUDE_DIR_TEST}/caf/test/unit_test.hpp"
"${CAF_INCLUDE_DIR_TEST}/caf/test/unit_test_impl.hpp"
${CAF_BB_TEST_SOURCES})
# --> Remove this when adding the first cpp
target_include_directories(caf-bb-test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# $<TARGET_OBJECTS:libcaf_bb_obj>)
# target_compile_definitions(caf-bb-test PRIVATE libcaf_bb_EXPORTS)
target_link_libraries(caf-bb-test ${CAF_EXTRA_LDFLAGS} ${CAF_LIBRARIES})
add_test_suites(caf-bb-test
"${CMAKE_CURRENT_SOURCE_DIR}"
${CAF_BB_TEST_SOURCES})
if(NOT CAF_INC_ENABLE_TESTING)
return()
endif()
# -- add this library to the global CAF_LIBRARIES ------------------------------
add_executable(caf-bb-test test/bb-test.cpp)
list(APPEND CAF_LIBRARIES libcaf_bb)
caf_incubator_set_default_properties(caf-bb-test)
set(CAF_LIBRARIES ${CAF_LIBRARIES} PARENT_SCOPE)
target_include_directories(caf-bb-test PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/test")
target_compile_definitions(caf-bb-test PRIVATE libcaf_bb_EXPORTS)
target_link_libraries(caf-bb-test PRIVATE CAF::core CAF::test)
caf_incubator_add_test_suites(caf-bb-test
container_source
stream_reader
tokenized_integer_reader
)
......@@ -78,8 +78,8 @@ behavior container_source(container_source_type<Container>* self, Container xs,
return {};
// Spin up stream manager and connect the first sink.
self->state.init(std::move(xs));
auto src = self->make_source(
std::move(sink),
auto src = attach_stream_source(
self, std::move(sink),
[&](unit_t&) {
// nop
},
......
......@@ -21,6 +21,7 @@
#include <string>
#include <vector>
#include "caf/attach_stream_source.hpp"
#include "caf/behavior.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/stateful_actor.hpp"
......@@ -77,8 +78,8 @@ void stream_reader(stream_source_type<InputStream>* self,
if (self->state.at_end())
return;
// Spin up stream manager and connect the first sink.
auto src = self->make_source(
std::move(sink),
auto src = attach_stream_source(
self, std::move(sink),
[&](Policy&) {
// nop
},
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2020 Dominik Charousset *
* *
* 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. *
******************************************************************************/
#include "caf/test/dsl.hpp"
CAF_BEGIN_TYPE_ID_BLOCK(bb_test, caf::first_custom_type_id)
CAF_ADD_TYPE_ID(bb_test, (caf::stream<int>) )
CAF_ADD_TYPE_ID(bb_test, (std::vector<int>) )
CAF_END_TYPE_ID_BLOCK(bb_test)
#define CAF_TEST_NO_MAIN
#include "bb-test.hpp"
#include "caf/init_global_meta_objects.hpp"
#include "caf/test/unit_test_impl.hpp"
int main(int argc, char** argv) {
using namespace caf;
init_global_meta_objects<id_block::bb_test>();
core::init_global_meta_objects();
return test::main(argc, argv);
}
#include "caf/test/dsl.hpp"
using i32_vector = std::vector<int32_t>;
CAF_BEGIN_TYPE_ID_BLOCK(bb_test, caf::first_custom_type_id)
CAF_ADD_TYPE_ID(bb_test, (caf::stream<int32_t>) )
CAF_ADD_TYPE_ID(bb_test, (std::vector<int32_t>) )
CAF_END_TYPE_ID_BLOCK(bb_test)
......@@ -20,19 +20,19 @@
#include "caf/bb/container_source.hpp"
#include "caf/bb/test/bb_test_type_ids.hpp"
#include "caf/test/dsl.hpp"
#include "bb-test.hpp"
#include <vector>
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/attach_stream_sink.hpp"
using namespace caf;
namespace {
using container_type = std::vector<int>;
using container_type = std::vector<int32_t>;
TESTEE_SETUP();
......@@ -41,8 +41,10 @@ TESTEE_STATE(container_sink) {
};
TESTEE(container_sink) {
return {[=](stream<container_type::value_type> in) {
return self->make_sink(
return {
[=](stream<container_type::value_type> in) {
return attach_stream_sink(
self,
// input stream
in,
// initialize state
......@@ -54,8 +56,11 @@ TESTEE(container_sink) {
self->state.con.emplace_back(std::move(val));
},
// cleanup and produce result message
[=](unit_t&, const error&) { CAF_MESSAGE(self->name() << " is done"); });
}};
[=](unit_t&, const error&) {
CAF_MESSAGE(self->name() << " is done");
});
},
};
}
TESTEE_STATE(container_monitor) {
......
......@@ -19,10 +19,8 @@
#define CAF_SUITE stream_reader
#include "caf/bb/stream_reader.hpp"
#include "caf/policy/tokenized_integer_reader.hpp"
#include "caf/bb/test/bb_test_type_ids.hpp"
#include "caf/test/dsl.hpp"
#include "bb-test.hpp"
#include <memory>
#include <string>
......@@ -30,6 +28,8 @@
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/attach_stream_sink.hpp"
#include "caf/policy/tokenized_integer_reader.hpp"
using namespace caf;
......@@ -45,8 +45,10 @@ TESTEE_STATE(stream_reader_sink) {
};
TESTEE(stream_reader_sink) {
return {[=](stream<value_type> in) {
return self->make_sink(
return {
[=](stream<value_type> in) {
return attach_stream_sink(
self,
// input stream
in,
// initialize state
......@@ -65,7 +67,8 @@ TESTEE(stream_reader_sink) {
CAF_MESSAGE(self->name() << " is done");
}
});
}};
},
};
}
TESTEE_STATE(stream_monitor) {
......
......@@ -4,18 +4,36 @@ file(GLOB_RECURSE CAF_NET_HEADERS "caf/*.hpp")
# -- add consistency checks for enum to_string implementations -----------------
add_enum_consistency_check("caf/net/basp/connection_state.hpp"
caf_incubator_add_enum_consistency_check("caf/net/basp/connection_state.hpp"
"src/basp/connection_state_strings.cpp")
add_enum_consistency_check("caf/net/basp/ec.hpp"
caf_incubator_add_enum_consistency_check("caf/net/basp/ec.hpp"
"src/basp/ec_strings.cpp")
add_enum_consistency_check("caf/net/basp/message_type.hpp"
caf_incubator_add_enum_consistency_check("caf/net/basp/message_type.hpp"
"src/basp/message_type_strings.cpp")
add_enum_consistency_check("caf/net/operation.hpp"
caf_incubator_add_enum_consistency_check("caf/net/operation.hpp"
"src/basp/operation_strings.cpp")
# -- list cpp files for caf::net -----------------------------------------------
# -- utility function for setting default properties ---------------------------
set(CAF_NET_SOURCES
function(caf_net_set_default_properties)
foreach(target ${ARGN})
caf_incubator_set_default_properties(${target})
# Make sure we find our headers plus the the generated export header.
target_include_directories(${target} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_BINARY_DIR}")
target_compile_definitions(${target} PRIVATE libcaf_net_EXPORTS)
# Pull in public dependencies.
target_link_libraries(${target} PUBLIC CAF::core)
if(MSVC)
target_link_libraries(${target} PUBLIC ws2_32 iphlpapi)
endif()
endforeach()
endfunction()
# -- add library targets -------------------------------------------------------
add_library(libcaf_net_obj OBJECT ${CAF_NET_HEADERS}
src/actor_proxy_impl.cpp
src/application.cpp
src/basp/connection_state_strings.cpp
......@@ -49,59 +67,21 @@ set(CAF_NET_SOURCES
src/worker.cpp
)
# -- list cpp files for caf-net-test ------------------------------------------
set(CAF_NET_TEST_SOURCES
test/net/basp/message_queue.cpp
test/net/basp/ping_pong.cpp
test/net/basp/worker.cpp
test/accept_socket.cpp
test/pipe_socket.cpp
test/application.cpp
test/socket.cpp
test/convert_ip_endpoint.cpp
test/socket_guard.cpp
test/datagram_socket.cpp
test/stream_application.cpp
test/datagram_transport.cpp
test/stream_socket.cpp
test/doorman.cpp
test/stream_transport.cpp
test/endpoint_manager.cpp
test/string_application.cpp
test/header.cpp
test/tcp_sockets.cpp
test/ip.cpp
test/transport_worker.cpp
test/multiplexer.cpp
test/transport_worker_dispatcher.cpp
test/udp_datagram_socket.cpp
test/network_socket.cpp
)
# -- add library target --------------------------------------------------------
add_library(libcaf_net_obj OBJECT ${CAF_NET_SOURCES} ${CAF_NET_HEADERS})
add_library(libcaf_net
"${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
add_library(libcaf_net "${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
$<TARGET_OBJECTS:libcaf_net_obj>)
add_library(caf::net ALIAS libcaf_net)
generate_export_header(libcaf_net
EXPORT_MACRO_NAME CAF_NET_EXPORT
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/caf/detail/net_export.hpp")
if(BUILD_SHARED_LIBS AND NOT WIN32)
target_compile_options(libcaf_net PRIVATE -fPIC)
target_compile_options(libcaf_net_obj PRIVATE -fPIC)
endif()
set_property(TARGET libcaf_net_obj PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(libcaf_net PUBLIC ${CAF_EXTRA_LDFLAGS} ${CAF_LIBRARIES})
caf_net_set_default_properties(libcaf_net_obj libcaf_net)
generate_export_header(libcaf_net
EXPORT_MACRO_NAME CAF_NET_EXPORT
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/caf/detail/net_export.hpp"
STATIC_DEFINE CAF_STATIC_BUILD)
target_include_directories(libcaf_net INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_compile_definitions(libcaf_net_obj PRIVATE libcaf_net_EXPORTS)
add_library(CAF::net ALIAS libcaf_net)
set_target_properties(libcaf_net PROPERTIES
EXPORT_NAME net
......@@ -117,8 +97,8 @@ install(FILES "${CMAKE_BINARY_DIR}/caf/detail/net_export.hpp"
install(TARGETS libcaf_net
EXPORT CAFTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT net
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT net
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT net)
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT net
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT net)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
......@@ -127,22 +107,44 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
# -- build unit tests ----------------------------------------------------------
if(NOT CAF_NO_UNIT_TESTS)
add_executable(caf-net-test
"${PROJECT_SOURCE_DIR}/cmake/incubator-test.cpp"
"${CAF_INCLUDE_DIR_TEST}/caf/test/unit_test.hpp"
"${CAF_INCLUDE_DIR_TEST}/caf/test/unit_test_impl.hpp"
${CAF_NET_TEST_SOURCES}
$<TARGET_OBJECTS:libcaf_net_obj>)
target_compile_definitions(caf-net-test PRIVATE libcaf_net_EXPORTS)
target_link_libraries(caf-net-test ${CAF_EXTRA_LDFLAGS} ${CAF_LIBRARIES})
add_test_suites(caf-net-test
"${CMAKE_CURRENT_SOURCE_DIR}"
${CAF_NET_TEST_SOURCES})
if(NOT CAF_INC_ENABLE_TESTING)
return()
endif()
# -- add this library to the global CAF_LIBRARIES ------------------------------
list(APPEND CAF_LIBRARIES libcaf_net)
add_executable(caf-net-test
test/net-test.cpp
$<TARGET_OBJECTS:libcaf_net_obj>)
set(CAF_LIBRARIES ${CAF_LIBRARIES} PARENT_SCOPE)
caf_net_set_default_properties(caf-net-test)
target_include_directories(caf-net-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/test")
target_link_libraries(caf-net-test PRIVATE CAF::test)
caf_incubator_add_test_suites(caf-net-test
net.basp.message_queue
net.basp.ping_pong
net.basp.worker
accept_socket
pipe_socket
application
socket
convert_ip_endpoint
socket_guard
datagram_socket
stream_application
datagram_transport
stream_socket
doorman
stream_transport
endpoint_manager
string_application
header
tcp_sockets
ip
transport_worker
multiplexer
transport_worker_dispatcher
udp_datagram_socket
network_socket
)
......@@ -38,6 +38,10 @@ public:
using middleman_backend_list = std::vector<middleman_backend_ptr>;
// -- static utility functions -----------------------------------------------
static void init_global_meta_objects();
// -- constructors, destructors, and assignment operators --------------------
~middleman() override;
......
......@@ -29,6 +29,10 @@
namespace caf::net {
void middleman::init_global_meta_objects() {
// nop
}
middleman::middleman(actor_system& sys) : sys_(sys) {
mpx_ = std::make_shared<multiplexer>();
}
......
#define CAF_TEST_NO_MAIN
#include "caf/test/unit_test_impl.hpp"
#include "caf/init_global_meta_objects.hpp"
#include "caf/net/middleman.hpp"
int main(int argc, char** argv) {
using namespace caf;
net::middleman::init_global_meta_objects();
core::init_global_meta_objects();
return test::main(argc, argv);
}
......@@ -19,6 +19,7 @@
#define CAF_SUITE net.basp.ping_pong
#include "caf/net/test/host_fixture.hpp"
#include "caf/test/dsl.hpp"
#include "caf/net/backend/test.hpp"
......@@ -123,7 +124,7 @@ behavior ping_actor(event_based_actor* self, actor pong, size_t num_pings,
CAF_MESSAGE("received " << num_pings << " pings, call self->quit");
self->quit();
}
return std::make_tuple(ping_atom_v, value + 1);
return caf::make_result(ping_atom_v, value + 1);
},
};
}
......@@ -142,9 +143,9 @@ behavior pong_actor(event_based_actor* self) {
self->monitor(self->current_sender());
// set next behavior
self->become(
[](ping_atom, int val) { return std::make_tuple(pong_atom_v, val); });
[](ping_atom, int val) { return caf::make_result(pong_atom_v, val); });
// reply to 'ping'
return std::make_tuple(pong_atom_v, value);
return caf::make_result(pong_atom_v, value);
},
};
}
......
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