Commit fe3984f0 authored by Dominik Charousset's avatar Dominik Charousset

Modernize CMake scaffold, enable bundled builds

parent 9eac8a21
...@@ -32,10 +32,13 @@ IndentWidth: 2 ...@@ -32,10 +32,13 @@ IndentWidth: 2
IndentWrappedFunctionNames: false IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp Language: Cpp
MacroBlockBegin: "^BEGIN_STATE$|CAF_BEGIN_TYPE_ID_BLOCK"
MacroBlockEnd: "^END_STATE$|CAF_END_TYPE_ID_BLOCK"
MaxEmptyLinesToKeep: 1 MaxEmptyLinesToKeep: 1
NamespaceIndentation: None NamespaceIndentation: None
PenaltyBreakAssignment: 1000 PenaltyBreakAssignment: 25
PenaltyBreakBeforeFirstCallParameter: 1000 PenaltyBreakBeforeFirstCallParameter: 30
PenaltyReturnTypeOnItsOwnLine: 25
PointerAlignment: Left PointerAlignment: Left
ReflowComments: true ReflowComments: true
SortIncludes: 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) set(CMAKE_CXX_STANDARD 17)
project(caf_incubator CXX)
# -- project options -----------------------------------------------------------
option(BUILD_SHARED_LIBS "Build all modules as shared library" ON)
# -- includes ------------------------------------------------------------------ # -- includes ------------------------------------------------------------------
include(CMakePackageConfigHelpers) # For creating .cmake files include(CMakePackageConfigHelpers) # For creating .cmake files
include(CheckCXXSourceCompiles) # Check wether compiler works include(CheckCXXSourceCompiles) # Check wether compiler works
include(FetchContent) # For bundling CAF with the incubator
include(GNUInstallDirs) # Sets default install paths include(GNUInstallDirs) # Sets default install paths
include(GenerateExportHeader) # Auto-generates dllexport macros 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 ------------------------------------------- # -- project-specific CMake settings -------------------------------------------
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 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(CAF_INC_ENABLE_STANDALONE_BUILD)
if(_parent) FetchContent_Declare(
set(caf_is_subproject ON) 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() else()
set(caf_is_subproject OFF) find_package(CAF COMPONENTS core test REQUIRED)
endif() endif()
unset(_parent)
# enable tests if not disabled # -- base target to propagate dependencies and flags ---------------------------
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()
endif()
# -- make sure we have at least C++17 available -------------------------------- add_library(caf-incubator-project INTERFACE)
if(NOT CMAKE_CROSSCOMPILING) # -- compiler setup ------------------------------------------------------------
# Check whether the user already provided flags that enable C++ >= 17.
try_compile(caf_has_cxx_17 if(MSVC)
"${CMAKE_CURRENT_BINARY_DIR}" # Disable 4275 and 4251 (warnings regarding C++ classes at ABI boundaries).
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/check-compiler-features.cpp") target_compile_options(caf-incubator-project INTERFACE /wd4275 /wd4251)
# Try enabling C++17 mode if user-provided flags aren't sufficient. if(CAF_INC_SANITIZERS)
if(NOT caf_has_cxx_17) message(FATAL_ERROR "Sanitizer builds are currently not supported on MSVC")
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")
else()
set(cxx_flag "-std=c++17")
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() endif()
add_compile_options("${cxx_flag}") elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# Flags for both compilers.
target_compile_options(caf-incubator-project INTERFACE
-ftemplate-depth=512 -ftemplate-backtrace-limit=0
-Wall -Wextra -pedantic)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Flags for Clang only.
target_compile_options(caf-incubator-project INTERFACE -Wdocumentation)
else()
# Flags for GCC only.
target_compile_options(caf-incubator-project INTERFACE
-Wno-missing-field-initializers)
endif() endif()
endif() endif()
set(CMAKE_INSTALL_CMAKEBASEDIR "${CMAKE_INSTALL_LIBDIR}/cmake" CACHE PATH if(CAF_INC_SANITIZERS)
"Base directory for installing cmake specific artifacts") target_compile_options(caf-incubator-project INTERFACE
set(INSTALL_CAF_CMAKEDIR "${CMAKE_INSTALL_CMAKEBASEDIR}/caf") -fsanitize=${CAF_INC_SANITIZERS}
-fno-omit-frame-pointer)
target_link_libraries(caf-incubator-project INTERFACE
-fsanitize=${CAF_INC_SANITIZERS}
-fno-omit-frame-pointer)
endif()
if(BUILD_SHARED_LIBS) if(NOT TARGET Threads::Threads)
set(LINK_TYPE "shared") find_package(Threads REQUIRED)
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() endif()
# Be nice to VIM users and Clang tools. target_link_libraries(caf-incubator-project INTERFACE Threads::Threads)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Silence policy CMP0042 warning by enabling RPATH explicitly. # -- unit testing setup / caf_add_test_suites function ------------------------
if(APPLE AND NOT DEFINED CMAKE_MACOSX_RPATH)
set(CMAKE_MACOSX_RPATH true)
endif()
# -- helper targets ------------------------------------------------------------ if(CAF_INC_ENABLE_TESTING)
enable_testing()
# Simplifies re-running configuration setup. function(caf_incubator_add_test_suites target)
add_custom_target(configure COMMAND ${CMAKE_CURRENT_BINARY_DIR}/config.status) foreach(suiteName ${ARGN})
string(REPLACE "." "/" suitePath ${suiteName})
# -- check for static builds --------------------------------------------------- target_sources(${target} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/test/${suitePath}.cpp")
if(CAF_BUILD_STATIC_RUNTIME) add_test(NAME ${suiteName}
set(flags_configs COMMAND ${target} -r300 -n -v5 -s"^${suiteName}$")
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() endforeach()
else() endfunction()
set(CAF_BUILD_STATIC_RUNTIME no)
endif()
# Silence annoying MSVC warning.
if(MSVC)
add_compile_options(/wd4275 /wd4251)
endif() endif()
################################################################################ # -- set default visibility to hidden when building shared libs ----------------
# utility functions #
################################################################################
# Forces `var` to 'no' if the content of the variables evaluates to false. if(BUILD_SHARED_LIBS)
function(pretty_no var) set(CMAKE_CXX_VISIBILITY_PRESET hidden)
if(NOT "${${var}}") set(CMAKE_VISIBILITY_INLINES_HIDDEN yes)
set("${var}" no PARENT_SCOPE) if(POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif() endif()
endfunction(pretty_no) endif()
# Forces `var` to 'yes' if the content of the variables evaluates to false. # -- utility targets -----------------------------------------------------------
function(pretty_yes var)
if("${${var}}")
set("${var}" yes PARENT_SCOPE)
endif()
endfunction(pretty_yes)
add_executable(caf-generate-enum-strings if(CAF_INC_ENABLE_UTILITY_TARGETS)
add_executable(caf-generate-enum-strings
EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL
cmake/caf-generate-enum-strings.cpp) cmake/caf-generate-enum-strings.cpp)
add_custom_target(consistency-check)
add_custom_target(consistency-check) add_custom_target(update-enum-strings)
# adds a consistency check that verifies that `cpp_file` is still valid by
add_custom_target(update-enum-strings) # re-generating the file and comparing it to the existing file
function(caf_incubator_add_enum_consistency_check hpp_file cpp_file)
# 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(input "${CMAKE_CURRENT_SOURCE_DIR}/${hpp_file}")
set(file_under_test "${CMAKE_CURRENT_SOURCE_DIR}/${cpp_file}") set(file_under_test "${CMAKE_CURRENT_SOURCE_DIR}/${cpp_file}")
set(output "${CMAKE_CURRENT_BINARY_DIR}/check/${cpp_file}") set(output "${CMAKE_CURRENT_BINARY_DIR}/check/${cpp_file}")
...@@ -212,166 +167,39 @@ function(add_enum_consistency_check hpp_file cpp_file) ...@@ -212,166 +167,39 @@ function(add_enum_consistency_check hpp_file cpp_file)
"${file_under_test}" "${file_under_test}"
DEPENDS caf-generate-enum-strings "${input}") DEPENDS caf-generate-enum-strings "${input}")
add_dependencies(update-enum-strings "${target_name}-update") add_dependencies(update-enum-strings "${target_name}-update")
endfunction() 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}")
else() else()
set(CAF_LIB_VERSION "${CAF_VERSION}") function(caf_incubator_add_enum_consistency_check hpp_file cpp_file)
endif() # nop
endfunction()
# -- 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()
endif() endif()
# -- install targets ----------------------------------------------------------- # -- provide an uinstall target ------------------------------------------------
# Process cmake_uninstall.cmake.in. # Process cmake_uninstall.cmake.in.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY) IMMEDIATE @ONLY)
# Add uninstall target. # Add uninstall target if it does not exist yet.
add_custom_target(uninstall 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 COMMAND "${CMAKE_COMMAND}" -P
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
# -- set include paths for all subprojects ------------------------------------- add_dependencies(uninstall caf-incubator-uninstall)
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 # -- build all components the user asked for -----------------------------------
DESTINATION "${INSTALL_CAF_CMAKEDIR}"
NAMESPACE caf::)
write_basic_package_version_file( if(CAF_INC_ENABLE_NET_MODULE)
"${CMAKE_CURRENT_BINARY_DIR}/CAFConfigVersion.cmake" add_subdirectory(libcaf_net)
VERSION ${CAF_VERSION} endif()
COMPATIBILITY ExactVersion)
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 -------------------------------------------------------------
# Inverts a boolean. if(CAF_INC_ENABLE_NET_MODULE)
macro(invertYesNo in out) add_subdirectory(libcaf_bb)
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")
endif() endif()
...@@ -4,12 +4,14 @@ ...@@ -4,12 +4,14 @@
// Default CMake flags for release builds. // Default CMake flags for release builds.
defaultReleaseBuildFlags = [ 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. // Default CMake flags for debug builds.
defaultDebugBuildFlags = defaultReleaseBuildFlags + [ 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', 'CAF_LOG_LEVEL:STRING=TRACE',
] ]
...@@ -24,22 +26,9 @@ config = [ ...@@ -24,22 +26,9 @@ config = [
'tests', 'tests',
'coverage', '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. // Our build matrix. Keys are the operating system labels and values are build configurations.
buildMatrix: [ buildMatrix: [
// Various Linux builds for debug and release. // Various Linux builds for debug and release.
['debian-8', [
builds: ['debug', 'release'],
tools: ['clang-4'],
]],
['centos-6', [ ['centos-6', [
builds: ['debug', 'release'], builds: ['debug', 'release'],
tools: ['gcc-7'], tools: ['gcc-7'],
...@@ -99,7 +88,10 @@ config = [ ...@@ -99,7 +88,10 @@ config = [
], ],
// Configures what binary the coverage report uses and what paths to exclude. // Configures what binary the coverage report uses and what paths to exclude.
coverage: [ coverage: [
binary: 'build/libcaf_net/caf-net-test', binaries: [
'build/libcaf_net/caf-net-test',
'build/libcaf_bb/caf-bb-test',
],
relativeExcludePaths: [ relativeExcludePaths: [
'libcaf_net/test' 'libcaf_net/test'
], ],
...@@ -111,9 +103,6 @@ pipeline { ...@@ -111,9 +103,6 @@ pipeline {
options { options {
buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '3')) buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '3'))
} }
triggers {
upstream(upstreamProjects: 'CAF/actor-framework/master/', threshold: hudson.model.Result.SUCCESS)
}
agent { agent {
label 'master' label 'master'
} }
...@@ -134,6 +123,26 @@ pipeline { ...@@ -134,6 +123,26 @@ pipeline {
runClangFormat(config) 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_ENABLE_IO_MODULE:BOOL=OFF ' +
'-DCAF_ENABLE_UTILITY_TARGETS:BOOL=ON',
steps: [[
args: '--target consistency-check',
withCmake: true,
]],
])
}
}
}
stage('Build') { stage('Build') {
steps { steps {
buildParallel(config, PrettyJobBaseName) buildParallel(config, PrettyJobBaseName)
......
...@@ -26,20 +26,20 @@ endif() ...@@ -26,20 +26,20 @@ endif()
foreach (comp ${CAF_FIND_COMPONENTS}) foreach (comp ${CAF_FIND_COMPONENTS})
# we use uppercase letters only for variable names # we use uppercase letters only for variable names
string(TOUPPER "${comp}" UPPERCOMP) string(TOUPPER "${comp}" UPPERCOMP)
if ("${comp}" STREQUAL "core") if("${comp}" STREQUAL "core")
set(HDRNAME "caf/all.hpp") set(HDRNAME "caf/all.hpp")
elseif ("${comp}" STREQUAL "test") elseif("${comp}" STREQUAL "test")
set(HDRNAME "caf/test/unit_test.hpp") set(HDRNAME "caf/test/unit_test.hpp")
else () else ()
set(HDRNAME "caf/${comp}/all.hpp") set(HDRNAME "caf/${comp}/all.hpp")
endif () endif()
if (CAF_ROOT_DIR) if(CAF_ROOT_DIR)
set(header_hints set(header_hints
"${CAF_ROOT_DIR}/include" "${CAF_ROOT_DIR}/include"
"${CAF_ROOT_DIR}/libcaf_${comp}" "${CAF_ROOT_DIR}/libcaf_${comp}"
"${CAF_ROOT_DIR}/../libcaf_${comp}" "${CAF_ROOT_DIR}/../libcaf_${comp}"
"${CAF_ROOT_DIR}/../../libcaf_${comp}") "${CAF_ROOT_DIR}/../../libcaf_${comp}")
endif () endif()
find_path(CAF_INCLUDE_DIR_${UPPERCOMP} find_path(CAF_INCLUDE_DIR_${UPPERCOMP}
NAMES NAMES
${HDRNAME} ${HDRNAME}
...@@ -51,12 +51,12 @@ foreach (comp ${CAF_FIND_COMPONENTS}) ...@@ -51,12 +51,12 @@ foreach (comp ${CAF_FIND_COMPONENTS})
/sw/include /sw/include
${CMAKE_INSTALL_PREFIX}/include) ${CMAKE_INSTALL_PREFIX}/include)
mark_as_advanced(CAF_INCLUDE_DIR_${UPPERCOMP}) 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") STREQUAL "CAF_INCLUDE_DIR_${UPPERCOMP}-NOTFOUND")
# mark as found (set back to false when missing library or build header) # mark as found (set back to false when missing library or build header)
set(CAF_${comp}_FOUND true) set(CAF_${comp}_FOUND true)
# check for CMake-generated build header for the core component # check for CMake-generated build header for the core component
if ("${comp}" STREQUAL "core") if("${comp}" STREQUAL "core")
find_path(caf_build_header_path find_path(caf_build_header_path
NAMES NAMES
caf/detail/build_config.hpp caf/detail/build_config.hpp
...@@ -68,7 +68,7 @@ foreach (comp ${CAF_FIND_COMPONENTS}) ...@@ -68,7 +68,7 @@ foreach (comp ${CAF_FIND_COMPONENTS})
/opt/local/include /opt/local/include
/sw/include /sw/include
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) ${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") message(WARNING "Found all.hpp for CAF core, but not build_config.hpp")
set(CAF_${comp}_FOUND false) set(CAF_${comp}_FOUND false)
else() else()
...@@ -78,10 +78,10 @@ foreach (comp ${CAF_FIND_COMPONENTS}) ...@@ -78,10 +78,10 @@ foreach (comp ${CAF_FIND_COMPONENTS})
list(APPEND CAF_INCLUDE_DIRS "${CAF_INCLUDE_DIR_${UPPERCOMP}}") list(APPEND CAF_INCLUDE_DIRS "${CAF_INCLUDE_DIR_${UPPERCOMP}}")
# look for (.dll|.so|.dylib) file, again giving hints for non-installed CAFs # look for (.dll|.so|.dylib) file, again giving hints for non-installed CAFs
# skip probe_event as it is header only # skip probe_event as it is header only
if (NOT ${comp} STREQUAL "probe_event" AND NOT ${comp} STREQUAL "test") if(NOT ${comp} STREQUAL "probe_event" AND NOT ${comp} STREQUAL "test")
if (CAF_ROOT_DIR) if(CAF_ROOT_DIR)
set(library_hints "${CAF_ROOT_DIR}/lib") set(library_hints "${CAF_ROOT_DIR}/libcaf_${comp}")
endif () endif()
find_library(CAF_LIBRARY_${UPPERCOMP} find_library(CAF_LIBRARY_${UPPERCOMP}
NAMES NAMES
"caf_${comp}" "caf_${comp}"
...@@ -94,20 +94,39 @@ foreach (comp ${CAF_FIND_COMPONENTS}) ...@@ -94,20 +94,39 @@ foreach (comp ${CAF_FIND_COMPONENTS})
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_BUILD_TYPE}) ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_BUILD_TYPE})
mark_as_advanced(CAF_LIBRARY_${UPPERCOMP}) mark_as_advanced(CAF_LIBRARY_${UPPERCOMP})
if ("${CAF_LIBRARY_${UPPERCOMP}}" if("${CAF_LIBRARY_${UPPERCOMP}}"
STREQUAL "CAF_LIBRARY_${UPPERCOMP}-NOTFOUND") STREQUAL "CAF_LIBRARY_${UPPERCOMP}-NOTFOUND")
set(CAF_${comp}_FOUND false) set(CAF_${comp}_FOUND false)
else () else ()
set(CAF_LIBRARIES ${CAF_LIBRARIES} ${CAF_LIBRARY_${UPPERCOMP}}) set(CAF_LIBRARIES ${CAF_LIBRARIES} ${CAF_LIBRARY_${UPPERCOMP}})
endif () endif()
endif () endif()
endif () endif()
endforeach () endforeach ()
if (DEFINED CAF_INCLUDE_DIRS) if(DEFINED CAF_INCLUDE_DIRS)
list(REMOVE_DUPLICATES CAF_INCLUDE_DIRS) list(REMOVE_DUPLICATES CAF_INCLUDE_DIRS)
endif() 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 # let CMake check whether all requested components have been found
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CAF find_package_handle_standard_args(CAF
...@@ -120,36 +139,42 @@ mark_as_advanced(CAF_ROOT_DIR ...@@ -120,36 +139,42 @@ mark_as_advanced(CAF_ROOT_DIR
CAF_LIBRARIES CAF_LIBRARIES
CAF_INCLUDE_DIRS) CAF_INCLUDE_DIRS)
if (CAF_core_FOUND AND NOT TARGET caf::core) if(CAF_core_FOUND AND NOT TARGET CAF::core)
add_library(caf::core UNKNOWN IMPORTED) add_library(CAF::core UNKNOWN IMPORTED)
set_target_properties(caf::core PROPERTIES 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_target_properties(CAF::core PROPERTIES
IMPORTED_LOCATION "${CAF_LIBRARY_CORE}" IMPORTED_LOCATION "${CAF_LIBRARY_CORE}"
INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_CORE}") INTERFACE_INCLUDE_DIRECTORIES "${caf_core_include_dirs}")
endif () endif()
if (CAF_io_FOUND AND NOT TARGET caf::io) if(CAF_io_FOUND AND NOT TARGET CAF::io)
add_library(caf::io UNKNOWN IMPORTED) add_library(CAF::io UNKNOWN IMPORTED)
set_target_properties(caf::io PROPERTIES set_target_properties(CAF::io PROPERTIES
IMPORTED_LOCATION "${CAF_LIBRARY_IO}" IMPORTED_LOCATION "${CAF_LIBRARY_IO}"
INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_IO}" INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_IO}"
INTERFACE_LINK_LIBRARIES "caf::core") INTERFACE_LINK_LIBRARIES "CAF::core")
endif () endif()
if (CAF_openssl_FOUND AND NOT TARGET caf::openssl) if(CAF_openssl_FOUND AND NOT TARGET CAF::openssl)
add_library(caf::openssl UNKNOWN IMPORTED) add_library(CAF::openssl UNKNOWN IMPORTED)
set_target_properties(caf::openssl PROPERTIES set_target_properties(CAF::openssl PROPERTIES
IMPORTED_LOCATION "${CAF_LIBRARY_OPENSSL}" IMPORTED_LOCATION "${CAF_LIBRARY_OPENSSL}"
INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_OPENSSL}" INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_OPENSSL}"
INTERFACE_LINK_LIBRARIES "caf::core;caf::io") INTERFACE_LINK_LIBRARIES "CAF::core;CAF::io")
if (NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
include(CMakeFindDependencyMacro) include(CMakeFindDependencyMacro)
set(OPENSSL_USE_STATIC_LIBS TRUE) set(OPENSSL_USE_STATIC_LIBS TRUE)
find_dependency(OpenSSL) find_dependency(OpenSSL)
set_property(TARGET caf::openssl APPEND PROPERTY set_property(TARGET CAF::openssl APPEND PROPERTY
INTERFACE_LINK_LIBRARIES "OpenSSL::SSL") INTERFACE_LINK_LIBRARIES "OpenSSL::SSL")
endif () endif()
endif () endif()
if (CAF_test_FOUND AND NOT TARGET caf::test) if(CAF_test_FOUND AND NOT TARGET CAF::test)
add_library(caf::test INTERFACE IMPORTED) add_library(CAF::test INTERFACE IMPORTED)
set_target_properties(caf::test PROPERTIES set_target_properties(CAF::test PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_TEST}" INTERFACE_INCLUDE_DIRECTORIES "${CAF_INCLUDE_DIR_TEST}"
INTERFACE_LINK_LIBRARIES "caf::core") INTERFACE_LINK_LIBRARIES "CAF::core")
endif () endif()
#!/bin/sh #!/bin/sh
# Convenience wrapper for easily viewing/setting options that set -e
# the project's CMake scripts will recognize.
command="$0 $*" # Convenience wrapper for easily setting options that the project's CMake
dirname_0=`dirname $0` # scripts will recognize.
sourcedir=`cd $dirname_0 && pwd`
Command="$0 $*"
CommandDirname=`dirname $0`
SourceDir=`cd $CommandDirname && pwd`
usage="\ 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 --cmake=PATH set a custom path to the CMake binary
--generator=GENERATOR set CMake generator (see cmake --help) --build-dir=PATH set build directory [build]
--build-type=TYPE set CMake build type [RelWithDebInfo]: --build-type=STRING set build type of single-configuration generators
- Debug: debugging flags enabled --generator=STRING set CMake generator (see cmake --help)
- MinSizeRel: minimal output size --cxx-flags=STRING set CMAKE_CXX_FLAGS when running CMake
- Release: optimizations on, debugging off --prefix=PATH set installation directory
- RelWithDebInfo: release flags plus debugging
--extra-flags=STRING additional compiler flags (sets CMAKE_CXX_FLAGS) Locating packages in non-standard locations:
--build-dir=DIR place build files in directory [build]
--bin-dir=DIR executable directory [build/bin] --caf-root-dir=PATH set root directory of a CAF installation
--lib-dir=DIR library directory [build/lib]
--build-static build as static and shared library Debugging options:
--build-static-only build as static library only
--static-runtime build with static C++ runtime --sanitizers=STRING build with this list of sanitizers enabled
--no-compiler-check disable compiler version check
--no-auto-libc++ do not automatically enable libc++ for Clang Convenience options:
Required packages in non-standard locations: --dev-mode shortcut for passing:
--with-caf=PATH path to CAF install root or build directory --build-type=Debug
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
--sanitizers=address,undefined --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 CXX C++ compiler command
CXXFLAGS C++ compiler flags (overrides defaults) CXXFLAGS Additional C++ compiler flags
LDFLAGS Additional linker flags LDFLAGS Additional linker flags
CMAKE_GENERATOR Selects a custom generator 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. # Appends a CMake cache entry definition to the CMakeCacheEntries variable.
# $1 is the cache entry variable name # $1: variable name
# $2 is the cache entry variable type # $2: CMake type
# $3 is the cache entry variable value # $3: value
append_cache_entry () append_cache_entry() {
{
case "$3" in case "$3" in
*\ * ) *\ * )
# string contains whitespace # string contains whitespace
CMakeCacheEntries="$CMakeCacheEntries -D \"$1:$2=$3\"" CMakeCacheEntries="$CMakeCacheEntries -D \"$1:$2=$3\""
;; ;;
*) *)
# string contains whitespace # string contains no whitespace
CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3" CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3"
;; ;;
esac esac
} }
# -- set defaults -------------------------------------------------------------- # Appends a BOOL cache entry to the CMakeCacheEntries variable.
# $1: flag name
builddir="$sourcedir/build" # $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="" CMakeCacheEntries=""
append_cache_entry CMAKE_INSTALL_PREFIX PATH /usr/local # Parse user input.
# -- parse custom environment variables ----------------------------------------
if [ -n "$CMAKE_GENERATOR" ]; then
CMakeGenerator="$CMAKE_GENERATOR"
fi
# -- parse arguments -----------------------------------------------------------
while [ $# -ne 0 ]; do while [ $# -ne 0 ]; do
# Fetch the option argument.
case "$1" in case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; --*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;; --enable-*) optarg=`echo "$1" | sed 's/--enable-//'` ;;
--disable-*) optarg=`echo "$1" | sed 's/--disable-//'` ;;
*) ;;
esac esac
# Consume current input.
case "$1" in case "$1" in
--help|-h) --help|-h)
echo "${usage}" 1>&2 echo "${usage}" 1>&2
...@@ -105,81 +121,50 @@ while [ $# -ne 0 ]; do ...@@ -105,81 +121,50 @@ while [ $# -ne 0 ]; do
--cmake=*) --cmake=*)
CMakeCommand="$optarg" CMakeCommand="$optarg"
;; ;;
--build-dir=*)
CMakeBuildDir="$optarg"
;;
--generator=*) --generator=*)
CMakeGenerator="$optarg" 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=*) --build-type=*)
append_cache_entry CMAKE_BUILD_TYPE STRING "$optarg" CMakeBuildType="$optarg"
;; ;;
--extra-flags=*) --cxx-flags=*)
append_cache_entry CMAKE_CXX_FLAGS STRING "$optarg" append_cache_entry CMAKE_CXX_FLAGS STRING "$optarg"
;; ;;
--build-dir=*) --prefix=*)
builddir="$optarg" append_cache_entry CMAKE_INSTALL_PREFIX PATH "$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
;; ;;
--no-openssl) --sanitizers=*)
append_cache_entry CAF_NO_OPENSSL BOOL yes append_cache_entry CAF_INC_SANITIZERS STRING "$optarg"
;; ;;
--build-static) --dev-mode)
append_cache_entry CAF_BUILD_STATIC BOOL yes CMakeBuildType='Debug'
append_cache_entry CAF_INC_SANITIZERS STRING 'address,undefined'
set_build_flag utility-targets ON
;; ;;
--build-static-only) --enable-*)
append_cache_entry CAF_BUILD_STATIC_ONLY BOOL yes set_build_flag $optarg ON
;; ;;
--static-runtime) --disable-*)
append_cache_entry CAF_BUILD_STATIC_RUNTIME BOOL yes set_build_flag $optarg OFF
;; ;;
--dev-mode) --caf-root-dir=*)
append_cache_entry CMAKE_BUILD_TYPE STRING Debug append_cache_entry CAF_ROOT_DIR PATH "$optarg"
append_cache_entry CAF_SANITIZERS STRING address,undefined
;; ;;
*) *)
echo "Invalid option '$1'. Try $0 --help to see available options." echo "Invalid option '$1'. Try $0 --help to see available options."
exit 1 exit 1
;; ;;
esac esac
# Get next input.
shift shift
done done
# -- CMake setup ---------------------------------------------------------------
# Check for `cmake` command. # Check for `cmake` command.
if [ -z "$CMakeCommand" ]; then 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 if command -v cmake3 >/dev/null 2>&1 ; then
CMakeCommand="cmake3" CMakeCommand="cmake3"
elif command -v cmake >/dev/null 2>&1 ; then elif command -v cmake >/dev/null 2>&1 ; then
...@@ -188,50 +173,42 @@ if [ -z "$CMakeCommand" ]; then ...@@ -188,50 +173,42 @@ if [ -z "$CMakeCommand" ]; then
echo "This package requires CMake, please install it first." echo "This package requires CMake, please install it first."
echo "Then you may use this script to configure the CMake build." echo "Then you may use this script to configure the CMake build."
echo "Note: pass --cmake=PATH to use cmake in non-standard locations." echo "Note: pass --cmake=PATH to use cmake in non-standard locations."
exit 1; exit 1
fi fi
fi fi
CMakeDefaultCache=$CMakeCacheEntries # Make sure the build directory is an absolute path.
case "$CMakeBuildDir" in
CMakeCacheEntries=$CMakeDefaultCache
# Set $workdir to the absolute path of $builddir.
case "$builddir" in
/*) /*)
# Absolute path given CMakeAbsoluteBuildDir="$CMakeBuildDir"
workdir="$builddir"
;; ;;
*) *)
# Relative path given, convert to absolute path. CMakeAbsoluteBuildDir="$PWD/$CMakeBuildDir"
workdir="$PWD/$builddir"
;; ;;
esac esac
# Make sure the build directory exists but has no CMakeCache.txt in it. # If a build directory exists, delete any existing cache to have a clean build.
if [ -d "$workdir" ]; then if [ -d "$CMakeAbsoluteBuildDir" ]; then
if [ -f "$workdir/CMakeCache.txt" ]; then if [ -f "$CMakeAbsoluteBuildDir/CMakeCache.txt" ]; then
rm -f "$workdir/CMakeCache.txt" rm -f "$CMakeAbsoluteBuildDir/CMakeCache.txt"
fi fi
else else
mkdir -p "$workdir" mkdir -p "$CMakeAbsoluteBuildDir"
fi fi
cd "$workdir" # Run CMake.
cd "$CMakeAbsoluteBuildDir"
if [ -n "$CMakeGenerator" ]; then if [ -n "$CMakeGenerator" ]; then
"$CMakeCommand" -G "$CMakeGenerator" $CMakeCacheEntries "$sourcedir" "$CMakeCommand" -G "$CMakeGenerator" $CMakeCacheEntries "$SourceDir"
else else
"$CMakeCommand" $CMakeCacheEntries "$sourcedir" "$CMakeCommand" $CMakeCacheEntries "$SourceDir"
fi fi
# Generate a config.status file that allows re-running a clean build.
printf "#!/bin/sh\n\n" > config.status printf "#!/bin/sh\n\n" > config.status
printf "# Switch to the source of this build directory.\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 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 if [ -n "$CXX" ]; then
printf "CXX=\"%s\"\n" "$CXX" >> config.status printf "CXX=\"%s\"\n" "$CXX" >> config.status
fi fi
...@@ -241,5 +218,5 @@ fi ...@@ -241,5 +218,5 @@ fi
if [ -n "$LDFLAGS" ]; then if [ -n "$LDFLAGS" ]; then
printf "LDFLAGS=\"%s\"\n" "$LDFLAGS" >> config.status printf "LDFLAGS=\"%s\"\n" "$LDFLAGS" >> config.status
fi fi
echo $command >> config.status echo $Command >> config.status
chmod u+x config.status chmod u+x config.status
...@@ -4,60 +4,20 @@ file(GLOB_RECURSE CAF_BB_HEADERS "caf/*.hpp") ...@@ -4,60 +4,20 @@ file(GLOB_RECURSE CAF_BB_HEADERS "caf/*.hpp")
# -- list cpp files for caf::bb ------------------------------------------------ # -- list cpp files for caf::bb ------------------------------------------------
set(CAF_BB_SOURCES add_library(libcaf_bb INTERFACE)
# nop
)
# -- list cpp files for caf-bb-test --------------------------------------------
set(CAF_BB_TEST_SOURCES
test/container_source.cpp
test/stream_reader.cpp
test/tokenized_integer_reader.cpp
)
# -- add library target -------------------------------------------------------- target_link_libraries(libcaf_bb INTERFACE CAF::core)
# --> 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 library and header files ------------------------------------------
#
# install(FILES "${CMAKE_BINARY_DIR}/caf/detail/bb_export.hpp" # install(FILES "${CMAKE_BINARY_DIR}/caf/detail/bb_export.hpp"
# DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/caf/detail") # DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/caf/detail")
#
# install(TARGETS libcaf_bb install(TARGETS libcaf_bb
# EXPORT CAFTargets EXPORT CAFTargets
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bb ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bb
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bb LIBRARY 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" install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
...@@ -66,25 +26,22 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf" ...@@ -66,25 +26,22 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
# -- build unit tests ---------------------------------------------------------- # -- build unit tests ----------------------------------------------------------
if(NOT CAF_NO_UNIT_TESTS) if(NOT CAF_INC_ENABLE_TESTING)
message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}") return()
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})
endif() endif()
# -- add this library to the global CAF_LIBRARIES ------------------------------ add_executable(caf-bb-test test/bb-test.cpp)
target_include_directories(caf-bb-test PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/test")
list(APPEND CAF_LIBRARIES libcaf_bb) target_compile_definitions(caf-bb-test PRIVATE libcaf_bb_EXPORTS)
set(CAF_LIBRARIES ${CAF_LIBRARIES} PARENT_SCOPE) 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, ...@@ -78,8 +78,8 @@ behavior container_source(container_source_type<Container>* self, Container xs,
return {}; return {};
// Spin up stream manager and connect the first sink. // Spin up stream manager and connect the first sink.
self->state.init(std::move(xs)); self->state.init(std::move(xs));
auto src = self->make_source( auto src = attach_stream_source(
std::move(sink), self, std::move(sink),
[&](unit_t&) { [&](unit_t&) {
// nop // nop
}, },
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "caf/attach_stream_source.hpp"
#include "caf/behavior.hpp" #include "caf/behavior.hpp"
#include "caf/event_based_actor.hpp" #include "caf/event_based_actor.hpp"
#include "caf/stateful_actor.hpp" #include "caf/stateful_actor.hpp"
...@@ -77,8 +78,8 @@ void stream_reader(stream_source_type<InputStream>* self, ...@@ -77,8 +78,8 @@ void stream_reader(stream_source_type<InputStream>* self,
if (self->state.at_end()) if (self->state.at_end())
return; return;
// Spin up stream manager and connect the first sink. // Spin up stream manager and connect the first sink.
auto src = self->make_source( auto src = attach_stream_source(
std::move(sink), self, std::move(sink),
[&](Policy&) { [&](Policy&) {
// nop // 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 @@ ...@@ -20,19 +20,19 @@
#include "caf/bb/container_source.hpp" #include "caf/bb/container_source.hpp"
#include "caf/bb/test/bb_test_type_ids.hpp" #include "bb-test.hpp"
#include "caf/test/dsl.hpp"
#include <vector> #include <vector>
#include "caf/actor_system.hpp" #include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp" #include "caf/actor_system_config.hpp"
#include "caf/attach_stream_sink.hpp"
using namespace caf; using namespace caf;
namespace { namespace {
using container_type = std::vector<int>; using container_type = std::vector<int32_t>;
TESTEE_SETUP(); TESTEE_SETUP();
...@@ -41,8 +41,10 @@ TESTEE_STATE(container_sink) { ...@@ -41,8 +41,10 @@ TESTEE_STATE(container_sink) {
}; };
TESTEE(container_sink) { TESTEE(container_sink) {
return {[=](stream<container_type::value_type> in) { return {
return self->make_sink( [=](stream<container_type::value_type> in) {
return attach_stream_sink(
self,
// input stream // input stream
in, in,
// initialize state // initialize state
...@@ -54,8 +56,11 @@ TESTEE(container_sink) { ...@@ -54,8 +56,11 @@ TESTEE(container_sink) {
self->state.con.emplace_back(std::move(val)); self->state.con.emplace_back(std::move(val));
}, },
// cleanup and produce result message // 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) { TESTEE_STATE(container_monitor) {
......
...@@ -19,10 +19,8 @@ ...@@ -19,10 +19,8 @@
#define CAF_SUITE stream_reader #define CAF_SUITE stream_reader
#include "caf/bb/stream_reader.hpp" #include "caf/bb/stream_reader.hpp"
#include "caf/policy/tokenized_integer_reader.hpp"
#include "caf/bb/test/bb_test_type_ids.hpp" #include "bb-test.hpp"
#include "caf/test/dsl.hpp"
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -30,6 +28,8 @@ ...@@ -30,6 +28,8 @@
#include "caf/actor_system.hpp" #include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp" #include "caf/actor_system_config.hpp"
#include "caf/attach_stream_sink.hpp"
#include "caf/policy/tokenized_integer_reader.hpp"
using namespace caf; using namespace caf;
...@@ -45,8 +45,10 @@ TESTEE_STATE(stream_reader_sink) { ...@@ -45,8 +45,10 @@ TESTEE_STATE(stream_reader_sink) {
}; };
TESTEE(stream_reader_sink) { TESTEE(stream_reader_sink) {
return {[=](stream<value_type> in) { return {
return self->make_sink( [=](stream<value_type> in) {
return attach_stream_sink(
self,
// input stream // input stream
in, in,
// initialize state // initialize state
...@@ -65,7 +67,8 @@ TESTEE(stream_reader_sink) { ...@@ -65,7 +67,8 @@ TESTEE(stream_reader_sink) {
CAF_MESSAGE(self->name() << " is done"); CAF_MESSAGE(self->name() << " is done");
} }
}); });
}}; },
};
} }
TESTEE_STATE(stream_monitor) { TESTEE_STATE(stream_monitor) {
......
...@@ -4,18 +4,34 @@ file(GLOB_RECURSE CAF_NET_HEADERS "caf/*.hpp") ...@@ -4,18 +4,34 @@ file(GLOB_RECURSE CAF_NET_HEADERS "caf/*.hpp")
# -- add consistency checks for enum to_string implementations ----------------- # -- 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") "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") "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") "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") "src/basp/operation_strings.cpp")
# -- list cpp files for caf::net ----------------------------------------------- # -- collect shared flags in a helper target -----------------------------------
set(CAF_NET_SOURCES add_library(libcaf_net_helper INTERFACE)
target_include_directories(libcaf_net_helper INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_BINARY_DIR}")
if(BUILD_SHARED_LIBS AND NOT WIN32)
target_compile_options(libcaf_net_helper INTERFACE -fPIC)
endif()
target_link_libraries(libcaf_net_helper INTERFACE CAF::core)
target_compile_definitions(libcaf_net_helper INTERFACE libcaf_net_EXPORTS)
# -- add library targets -------------------------------------------------------
add_library(libcaf_net_obj OBJECT ${CAF_NET_HEADERS}
src/actor_proxy_impl.cpp src/actor_proxy_impl.cpp
src/application.cpp src/application.cpp
src/basp/connection_state_strings.cpp src/basp/connection_state_strings.cpp
...@@ -49,59 +65,23 @@ set(CAF_NET_SOURCES ...@@ -49,59 +65,23 @@ set(CAF_NET_SOURCES
src/worker.cpp src/worker.cpp
) )
# -- list cpp files for caf-net-test ------------------------------------------ add_library(libcaf_net "${PROJECT_SOURCE_DIR}/cmake/dummy.cpp"
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"
$<TARGET_OBJECTS:libcaf_net_obj>) $<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_link_libraries(libcaf_net_obj PRIVATE libcaf_net_helper)
target_compile_options(libcaf_net PRIVATE -fPIC)
target_compile_options(libcaf_net_obj PRIVATE -fPIC)
endif()
target_link_libraries(libcaf_net PUBLIC ${CAF_EXTRA_LDFLAGS} ${CAF_LIBRARIES}) target_link_libraries(libcaf_net PRIVATE libcaf_net_helper)
generate_export_header(libcaf_net target_link_libraries(libcaf_net INTERFACE CAF::core)
EXPORT_MACRO_NAME CAF_NET_EXPORT
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/caf/detail/net_export.hpp"
STATIC_DEFINE CAF_STATIC_BUILD)
target_compile_definitions(libcaf_net_obj PRIVATE libcaf_net_EXPORTS) target_include_directories(libcaf_net INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
add_library(CAF::net ALIAS libcaf_net)
set_target_properties(libcaf_net PROPERTIES set_target_properties(libcaf_net PROPERTIES
EXPORT_NAME net EXPORT_NAME net
...@@ -117,8 +97,8 @@ install(FILES "${CMAKE_BINARY_DIR}/caf/detail/net_export.hpp" ...@@ -117,8 +97,8 @@ install(FILES "${CMAKE_BINARY_DIR}/caf/detail/net_export.hpp"
install(TARGETS libcaf_net install(TARGETS libcaf_net
EXPORT CAFTargets EXPORT CAFTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT net 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" install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
...@@ -127,22 +107,45 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf" ...@@ -127,22 +107,45 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
# -- build unit tests ---------------------------------------------------------- # -- build unit tests ----------------------------------------------------------
if(NOT CAF_NO_UNIT_TESTS) if(NOT CAF_INC_ENABLE_TESTING)
add_executable(caf-net-test return()
"${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})
endif() endif()
# -- add this library to the global CAF_LIBRARIES ------------------------------ add_executable(caf-net-test
test/net-test.cpp
list(APPEND CAF_LIBRARIES libcaf_net) $<TARGET_OBJECTS:libcaf_net_obj>)
set(CAF_LIBRARIES ${CAF_LIBRARIES} PARENT_SCOPE) target_include_directories(caf-net-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/test")
target_compile_definitions(caf-net-test PRIVATE libcaf_net_EXPORTS)
target_link_libraries(caf-net-test PRIVATE
libcaf_net_helper CAF::core 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: ...@@ -38,6 +38,10 @@ public:
using middleman_backend_list = std::vector<middleman_backend_ptr>; using middleman_backend_list = std::vector<middleman_backend_ptr>;
// -- static utility functions -----------------------------------------------
static void init_global_meta_objects();
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
~middleman() override; ~middleman() override;
......
...@@ -29,6 +29,10 @@ ...@@ -29,6 +29,10 @@
namespace caf::net { namespace caf::net {
void middleman::init_global_meta_objects() {
// nop
}
middleman::middleman(actor_system& sys) : sys_(sys) { middleman::middleman(actor_system& sys) : sys_(sys) {
mpx_ = std::make_shared<multiplexer>(); 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 @@ ...@@ -19,6 +19,7 @@
#define CAF_SUITE net.basp.ping_pong #define CAF_SUITE net.basp.ping_pong
#include "caf/net/test/host_fixture.hpp" #include "caf/net/test/host_fixture.hpp"
#include "caf/test/dsl.hpp" #include "caf/test/dsl.hpp"
#include "caf/net/backend/test.hpp" #include "caf/net/backend/test.hpp"
...@@ -123,7 +124,7 @@ behavior ping_actor(event_based_actor* self, actor pong, size_t num_pings, ...@@ -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"); CAF_MESSAGE("received " << num_pings << " pings, call self->quit");
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) { ...@@ -142,9 +143,9 @@ behavior pong_actor(event_based_actor* self) {
self->monitor(self->current_sender()); self->monitor(self->current_sender());
// set next behavior // set next behavior
self->become( 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' // 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