WhisperCom/CMakeLists.txt

116 lines
3.5 KiB
CMake

cmake_minimum_required (VERSION 3.25 FATAL_ERROR)
project (whisperCom VERSION 0.0.1 LANGUAGES CXX C)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
#
# Options for compiling whisperCom
#
option(TEST_WHISPERCOM "Turn running of whisperCom specific tests on/off. Default: on" ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
#
# some stuff required inclusion
#
include(doxygen)
include(compdb)
include(protobuf)
IF(${TEST_WHISPERCOM})
include(CTest)
ENDIF()
#
# enable building documentation
#
build_docs(PROCESS_DOXYFILE DOXYFILE_PATH "docs/Doxyfile.in" )
#
# External required projects
#
IF(NOT TARGET Catch2 AND ${TEST_WHISPERCOM})
add_subdirectory(libs/Catch2 EXCLUDE_FROM_ALL)
include(libs/Catch2/extras/Catch.cmake)
ENDIF()
IF(NOT TARGET loguru)
add_library(loguru STATIC libs/loguru/loguru.cpp libs/loguru/loguru.hpp)
target_include_directories(loguru PUBLIC libs/loguru)
target_compile_options(loguru PUBLIC -DLOGURU_WITH_STREAMS=1)
set_property(TARGET loguru PROPERTY POSITION_INDEPENDENT_CODE 1)
target_link_libraries(loguru PUBLIC dl)
ENDIF()
IF(NOT TARGET libzmq)
set(BUILD_STATIC ON CACHE BOOL "enable building zmq as static library")
set(ENABLE_DRAFTS ON CACHE BOOL "enable zmq drafts")
set(ENABLE_RADIX_TREE ON CACHE BOOL "enable ENABLE_RADIX_TREE drafts")
set(ENABLE_WS OFF CACHE BOOL "enable websocket support")
set(WITH_OPENPGM OFF CACHE BOOL "enable pgm protocol")
set(WITH_LIBSODIUM ON CACHE BOOL "enable static libsodium support")
set(WITH_LIBSODIUM_STATIC ON CACHE BOOL "enable static libsodium support")
set(ENABLE_CURVE ON CACHE BOOL "enable curve cryptography in libsodium support")
set(ZMQ_BUILD_TESTS OFF CACHE BOOL "disable zmq tests")
set(OPENPGM_PKGCONFIG_NAME openpgm-5.3)
add_subdirectory(libs/libzmq EXCLUDE_FROM_ALL)
ENDIF()
IF(NOT TARGET cppzmq-static)
set(CPPZMQ_BUILD_TESTS OFF CACHE BOOL "disbale cppzmq tests")
add_subdirectory(libs/cppzmq EXCLUDE_FROM_ALL)
ENDIF()
IF(NOT TARGET protobuf)
SET(protobuf_BUILD_TESTS OFF CACHE BOOL "disable protobuf tests")
SET(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "disable shared libraries")
#SET(WITH_PROTOC ON CACHE BOOL "enable building of protoc")
add_subdirectory(libs/protobuf EXCLUDE_FROM_ALL)
set(PROTOC ${CMAKE_CURRENT_BINARY_DIR}/libs/protobuf/protoc CACHE INTERNAL "" )
set(PROTO_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libs/protobuf/src CACHE INTERNAL "" )
ENDIF()
# we are building with c++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
protobuf_generate_cpp(PROTO_PATH proto CPP_PATH proto HPP_PATH proto)
SET(WHISPERCOM_SOURCES
proto/RouterMessage.pb.cc
proto/Message.pb.cc
proto/TestMessage.pb.cc
include/WhisperCom/Router.hpp
src/WhisperCom/Router.cpp
include/WhisperCom/Service.hpp
src/WhisperCom/Service.cpp
)
add_library(whisperCom STATIC ${WHISPERCOM_SOURCES})
target_link_libraries(whisperCom loguru cppzmq-static protobuf::libprotobuf ${CMAKE_THREAD_LIBS_INIT} )
target_include_directories(whisperCom
PUBLIC
include
proto
PRIVATE
src
)
add_dependencies(whisperCom protoc)
add_executable(wctest src/main.cpp)
target_link_libraries(wctest whisperCom)
add_executable(wcListener src/Listener.cpp)
target_link_libraries(wcListener whisperCom)
#
# Everything TEST related
#
IF (${TEST_WHISPERCOM})
add_executable(test_Service tests/test_Service.cpp)
target_link_libraries(test_Service Catch2::Catch2WithMain whisperCom loguru)
catch_discover_tests(test_Service)
ENDIF()