Commit fe3984f0 authored by Dominik Charousset's avatar Dominik Charousset

Modernize CMake scaffold, enable bundled builds

parent 9eac8a21
......@@ -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
......
This diff is collapsed.
......@@ -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,22 +26,9 @@ 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'],
......@@ -99,7 +88,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 +103,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 +123,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_ENABLE_IO_MODULE:BOOL=OFF ' +
'-DCAF_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,42 @@ 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_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}")
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)
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)
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
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
endif()
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()
This diff is collapsed.
......@@ -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,22 @@ 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)
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,
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,21 +41,26 @@ TESTEE_STATE(container_sink) {
};
TESTEE(container_sink) {
return {[=](stream<container_type::value_type> in) {
return self->make_sink(
// input stream
in,
// initialize state
[=](unit_t&) {
// nop
},
// Consumer
[=](unit_t&, container_type::value_type val) {
self->state.con.emplace_back(std::move(val));
},
// cleanup and produce result message
[=](unit_t&, const error&) { CAF_MESSAGE(self->name() << " is done"); });
}};
return {
[=](stream<container_type::value_type> in) {
return attach_stream_sink(
self,
// input stream
in,
// initialize state
[=](unit_t&) {
// nop
},
// Consumer
[=](unit_t&, container_type::value_type val) {
self->state.con.emplace_back(std::move(val));
},
// cleanup and produce result message
[=](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,27 +45,30 @@ TESTEE_STATE(stream_reader_sink) {
};
TESTEE(stream_reader_sink) {
return {[=](stream<value_type> in) {
return self->make_sink(
// input stream
in,
// initialize state
[=](unit_t&) {
// nop
},
// consume values
[=](unit_t&, value_type val) {
self->state.vec.emplace_back(std::move(val));
},
// cleanup and produce result message
[=](unit_t&, const error& e) {
if (e) {
CAF_MESSAGE(self->name() << " " << e);
} else {
CAF_MESSAGE(self->name() << " is done");
}
});
}};
return {
[=](stream<value_type> in) {
return attach_stream_sink(
self,
// input stream
in,
// initialize state
[=](unit_t&) {
// nop
},
// consume values
[=](unit_t&, value_type val) {
self->state.vec.emplace_back(std::move(val));
},
// cleanup and produce result message
[=](unit_t&, const error& e) {
if (e) {
CAF_MESSAGE(self->name() << " " << e);
} else {
CAF_MESSAGE(self->name() << " is done");
}
});
},
};
}
TESTEE_STATE(stream_monitor) {
......
......@@ -4,18 +4,34 @@ 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"
"src/basp/connection_state_strings.cpp")
add_enum_consistency_check("caf/net/basp/ec.hpp"
"src/basp/ec_strings.cpp")
add_enum_consistency_check("caf/net/basp/message_type.hpp"
"src/basp/message_type_strings.cpp")
add_enum_consistency_check("caf/net/operation.hpp"
"src/basp/operation_strings.cpp")
# -- list cpp files for caf::net -----------------------------------------------
set(CAF_NET_SOURCES
caf_incubator_add_enum_consistency_check("caf/net/basp/connection_state.hpp"
"src/basp/connection_state_strings.cpp")
caf_incubator_add_enum_consistency_check("caf/net/basp/ec.hpp"
"src/basp/ec_strings.cpp")
caf_incubator_add_enum_consistency_check("caf/net/basp/message_type.hpp"
"src/basp/message_type_strings.cpp")
caf_incubator_add_enum_consistency_check("caf/net/operation.hpp"
"src/basp/operation_strings.cpp")
# -- collect shared flags in a helper target -----------------------------------
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/application.cpp
src/basp/connection_state_strings.cpp
......@@ -49,59 +65,23 @@ 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()
target_link_libraries(libcaf_net_obj PRIVATE libcaf_net_helper)
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
EXPORT_MACRO_NAME CAF_NET_EXPORT
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/caf/detail/net_export.hpp"
STATIC_DEFINE CAF_STATIC_BUILD)
target_link_libraries(libcaf_net INTERFACE CAF::core)
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,45 @@ 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)
set(CAF_LIBRARIES ${CAF_LIBRARIES} PARENT_SCOPE)
add_executable(caf-net-test
test/net-test.cpp
$<TARGET_OBJECTS:libcaf_net_obj>)
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:
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