Commit 65a7dae4 authored by Jakob Otto's avatar Jakob Otto

Rework libcaf_net CMakeLists.txt

parent d6b9e2c1
# get header files; only needed by CMake generators, # -- get header files for creating "proper" XCode projects ---------------------
# e.g., for creating proper Xcode projects
file(GLOB_RECURSE LIBCAF_NET_HDRS "caf/*.hpp") file(GLOB_RECURSE CAF_NET_HEADERS "caf/*.hpp")
# -- auto generate to_string for enum types ------------------------------------
enum_to_string("caf/net/basp/connection_state.hpp" "basp_conn_strings.cpp") enum_to_string("caf/net/basp/connection_state.hpp" "basp_conn_strings.cpp")
enum_to_string("caf/net/basp/ec.hpp" "basp_ec_strings.cpp") enum_to_string("caf/net/basp/ec.hpp" "basp_ec_strings.cpp")
enum_to_string("caf/net/basp/message_type.hpp" "basp_message_type_strings.cpp") enum_to_string("caf/net/basp/message_type.hpp" "basp_message_type_strings.cpp")
enum_to_string("caf/net/operation.hpp" "operation_strings.cpp") enum_to_string("caf/net/operation.hpp" "operation_strings.cpp")
# list cpp files excluding platform-dependent files # -- list cpp files for caf::net -----------------------------------------------
set(LIBCAF_NET_SRCS
"${CMAKE_CURRENT_BINARY_DIR}/basp_conn_strings.cpp" set(CAF_NET_SOURCES
"${CMAKE_CURRENT_BINARY_DIR}/basp_ec_strings.cpp" "${CMAKE_BINARY_DIR}/basp_conn_strings.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/basp_message_type_strings.cpp" "${CMAKE_BINARY_DIR}/basp_ec_strings.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/operation_strings.cpp" "${CMAKE_BINARY_DIR}/basp_message_type_strings.cpp"
"${CMAKE_BINARY_DIR}/operation_strings.cpp"
src/actor_proxy_impl.cpp src/actor_proxy_impl.cpp
src/application.cpp src/application.cpp
src/convert_ip_endpoint.cpp src/convert_ip_endpoint.cpp
...@@ -43,44 +46,99 @@ set(LIBCAF_NET_SRCS ...@@ -43,44 +46,99 @@ set(LIBCAF_NET_SRCS
src/worker.cpp src/worker.cpp
) )
add_custom_target(libcaf_net) # -- list cpp files for caf-net-test ------------------------------------------
# build shared library if not compiling static only set(CAF_NET_TEST_SOURCES
if (NOT CAF_BUILD_STATIC_ONLY) test/net/basp/message_queue.cpp
add_library(libcaf_net_shared SHARED ${LIBCAF_NET_SRCS} ${LIBCAF_NET_HDRS}) test/net/basp/ping_pong.cpp
target_link_libraries(libcaf_net_shared ${CAF_EXTRA_LDFLAGS} ${CAF_LIBRARY_CORE}) test/net/basp/worker.cpp
target_include_directories(libcaf_net_shared PUBLIC test/accept_socket.cpp
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> test/pipe_socket.cpp
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> test/application.cpp
$<INSTALL_INTERFACE:include> test/socket.cpp
) test/convert_ip_endpoint.cpp
set_target_properties(libcaf_net_shared test/socket_guard.cpp
PROPERTIES 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 $<TARGET_OBJECTS:libcaf_net_obj>)
add_library(caf::net ALIAS libcaf_net)
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 PUBLIC ${CAF_EXTRA_LDFLAGS})
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_compile_definitions(libcaf_net_obj PRIVATE libcaf_net_EXPORTS)
set_target_properties(libcaf_net PROPERTIES
EXPORT_NAME net
SOVERSION ${CAF_VERSION} SOVERSION ${CAF_VERSION}
VERSION ${CAF_LIB_VERSION} VERSION ${CAF_LIB_VERSION}
OUTPUT_NAME caf_net OUTPUT_NAME caf_net)
)
install(TARGETS libcaf_net_shared # -- install library and header files ------------------------------------------
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib install(FILES "${CMAKE_BINARY_DIR}/caf/detail/build_config.hpp"
) "${CMAKE_BINARY_DIR}/caf/detail/net_export.hpp"
add_dependencies(libcaf_net_shared libcaf_net) DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/caf/detail")
endif ()
install(TARGETS libcaf_net
# build static library only if --build-static or --build-static-only was set EXPORT CAFTargets
if (CAF_BUILD_STATIC_ONLY OR CAF_BUILD_STATIC) ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT net
add_library(libcaf_net_static STATIC ${LIBCAF_NET_HDRS} ${LIBCAF_NET_SRCS}) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT net
target_link_libraries(libcaf_net_static ${CAF_EXTRA_LDFLAGS} ${CAF_LIBRARY_CORE_STATIC}) LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT net)
target_include_directories(libcaf_net_static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
set_target_properties(libcaf_net_static PROPERTIES OUTPUT_NAME caf_net_static)
install(TARGETS libcaf_net_static ARCHIVE DESTINATION lib)
add_dependencies(libcaf_net_static libcaf_net)
endif ()
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf" install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/caf"
DESTINATION include DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT net
FILES_MATCHING PATTERN "*.hpp") FILES_MATCHING PATTERN "*.hpp")
# -- build unit tests ----------------------------------------------------------
if(NOT CAF_NO_UNIT_TESTS)
add_executable(caf-net-test
"${CAF_ROOT_DIR}/../libcaf_test/src/caf-test.cpp"
"${CAF_ROOT_DIR}/../libcaf_test/caf/test/unit_test.hpp"
"${CAF_ROOT_DIR}/../libcaf_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})
add_test_suites(caf-net-test
"${CMAKE_CURRENT_SOURCE_DIR}"
${CAF_NET_TEST_SOURCES})
endif()
# -- add this library to the global CAF_LIBRARIES ------------------------------
list(APPEND CAF_LIBRARIES libcaf_net)
set(CAF_LIBRARIES ${CAF_LIBRARIES} PARENT_SCOPE)
\ No newline at end of file
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