diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eaf609a..120f6b6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,11 +41,6 @@ jobs: matrix: os: [ debian-bullseye, fedora-41 ] root: [ "with-root", "no-root" ] - include: - - os: debian-bullseye - static-libstdcxx: ON - - os: fedora-41 - static-libstdcxx: OFF name: ${{ matrix.os }}-${{ matrix.root }} env: CMAKE_GENERATOR: Ninja @@ -77,7 +72,7 @@ jobs: source $PARENT_DIR/miniconda3/bin/activate conda activate srs mkdir ${PARENT_DIR}/srs-install - cmake --preset static -DCMAKE_INSTALL_PREFIX=${PARENT_DIR}/srs-install -DBUILD_STATIC_STDCXX=${{ matrix.static-libstdcxx }} -DNO_ROOT=$DISABLE_ROOT + cmake --preset static -DCMAKE_INSTALL_PREFIX=${PARENT_DIR}/srs-install -DNO_ROOT=$DISABLE_ROOT -DENABLE_TEST=OFF cmake --build ./build --target install -- -j2 cd ${{ env.PARENT_DIR }} tar czf "srs-${{ matrix.os}}-x86-64-${{ env.TAG_NAME }}-${{ matrix.root }}.tar.gz" srs-install diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ce7044..c8f48fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.28) +include(${CMAKE_SOURCE_DIR}/cmake/option_settings.cmake) +set(ENV{CMAKE_ENABLE_TEST} ${ENABLE_TEST}) + project( srs VERSION 0.1.1 @@ -8,7 +11,6 @@ project( include(${CMAKE_SOURCE_DIR}/cmake/install_config.cmake) include(${CMAKE_SOURCE_DIR}/cmake/install_packages.cmake) include(${CMAKE_SOURCE_DIR}/cmake/project_config.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option_settings.cmake) include(${CMAKE_SOURCE_DIR}/cmake/check_compilers.cmake) set(CMAKE_CXX_STANDARD 23) @@ -23,5 +25,4 @@ endif() add_subdirectory(frontend) add_subdirectory(backend) add_subdirectory(test) - -include(${CMAKE_SOURCE_DIR}/cmake/install_targets.cmake) +add_subdirectory(examples) diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index 67bd0e9..a1ce2f3 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -1,6 +1,7 @@ # some operating systems don't have static libstdc++.a library -if(BUILD_STATIC AND BUILD_STATIC_STDCXX) +if(BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++") + set(CMAKE_SHARED_LINKER_FLAGS "-static-libstdc++") endif() find_package(Boost REQUIRED CONFIG COMPONENTS thread) @@ -39,3 +40,5 @@ add_subdirectory(srs) add_executable(srs_control main.cpp) target_link_libraries(srs_control PRIVATE srscpp spdlog::spdlog CLI11::CLI11 Boost::thread) target_compile_definitions(srs_control PUBLIC SRS_PROJECT_VERSION="v${CMAKE_PROJECT_VERSION}") + +include(${CMAKE_SOURCE_DIR}/cmake/install_targets.cmake) diff --git a/backend/srs/CMakeLists.txt b/backend/srs/CMakeLists.txt index 582bb95..1538aa7 100644 --- a/backend/srs/CMakeLists.txt +++ b/backend/srs/CMakeLists.txt @@ -1,9 +1,4 @@ -if(BUILD_STATIC) - add_library(srscpp STATIC) - target_compile_options(srscpp PRIVATE "-static") -else() - add_library(srscpp SHARED) -endif() +add_library(srscpp SHARED) target_sources(srscpp PRIVATE Application.cpp) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") diff --git a/backend/srs/converters/DataConvertOptions.hpp b/backend/srs/converters/DataConvertOptions.hpp index 14ca020..f97a2e4 100644 --- a/backend/srs/converters/DataConvertOptions.hpp +++ b/backend/srs/converters/DataConvertOptions.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace srs { @@ -16,6 +17,26 @@ namespace srs proto_frame }; + constexpr auto convert_option_to_string(DataConvertOptions option) -> std::string_view + { + using enum DataConvertOptions; + switch (option) + { + case none: + return std::string_view{ "none" }; + case raw: + return std::string_view{ "raw" }; + case raw_frame: + return std::string_view{ "raw_frame" }; + case structure: + return std::string_view{ "structure" }; + case proto: + return std::string_view{ "proto" }; + case proto_frame: + return std::string_view{ "proto_frame" }; + } + } + struct ConvertOptionRelation { constexpr ConvertOptionRelation(DataConvertOptions option, DataConvertOptions next_option) @@ -48,6 +69,11 @@ namespace srs constexpr auto convert_option_has_dependency(DataConvertOptions dependee, DataConvertOptions depender) -> bool { + if (dependee == depender) + { + return true; + } + return std::ranges::any_of(CONVERT_OPTION_RELATIONS, [dependee, depender](ConvertOptionRelation relation) -> bool { diff --git a/backend/srs/data/CMakeLists.txt b/backend/srs/data/CMakeLists.txt index 01db203..85c3297 100644 --- a/backend/srs/data/CMakeLists.txt +++ b/backend/srs/data/CMakeLists.txt @@ -1,13 +1,9 @@ -if(BUILD_STATIC) - add_library(srs_data STATIC) -else() - add_library(srs_data SHARED) -endif() +add_library(srs_data SHARED) target_link_libraries( srs_data - PUBLIC protobuf::libprotobuf fmt::fmt - PRIVATE Boost::thread) + PUBLIC $ $ + PRIVATE $) target_sources( srs_data diff --git a/backend/srs/utils/CommonFunctions.hpp b/backend/srs/utils/CommonFunctions.hpp index 8c31ee1..e270b6d 100644 --- a/backend/srs/utils/CommonFunctions.hpp +++ b/backend/srs/utils/CommonFunctions.hpp @@ -58,6 +58,10 @@ namespace srs auto create_coro_future(auto& coro, auto&& pre_fut) { + if (not pre_fut.valid()) + { + throw std::runtime_error("Previous future is not valid!"); + } return pre_fut.then( [&coro](std::remove_cvref_t fut) { diff --git a/cmake/install_targets.cmake b/cmake/install_targets.cmake index cbdd905..15df27a 100644 --- a/cmake/install_targets.cmake +++ b/cmake/install_targets.cmake @@ -21,12 +21,10 @@ set_target_properties( SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION}) -if(NOT BUILD_STATIC) - install( - TARGETS srs_data - EXPORT srsTargets - FILE_SET HEADERS) -endif() +install( + TARGETS srs_data + EXPORT srsTargets + FILE_SET HEADERS) install( TARGETS srscpp @@ -39,6 +37,8 @@ install( NAMESPACE srs:: FILE srsConfig-targets.cmake) +install(IMPORTED_RUNTIME_ARTIFACTS TBB::tbb LIBRARY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/srsConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/srsConfig-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/srs) diff --git a/cmake/option_settings.cmake b/cmake/option_settings.cmake index 5892755..609625b 100644 --- a/cmake/option_settings.cmake +++ b/cmake/option_settings.cmake @@ -1,4 +1,4 @@ option(USE_ROOT "Force to use ROOT dependency." OFF) option(NO_ROOT "Disable the usage of ROOT dependency." OFF) -option(BUILD_STATIC "Enable static of libaries." OFF) -option(BUILD_STATIC_STDCXX "Enable static link of libstdc++." ON) +option(BUILD_STATIC "Enable static linking of libstdc++." OFF) +option(ENABLE_TEST "Enable testing framework of the project." ON) diff --git a/conanfile.py b/conanfile.py index 337c4b2..f1ed23f 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,3 +1,5 @@ +import os + from conan import ConanFile from conan.tools.cmake import CMakeToolchain @@ -39,8 +41,11 @@ "wave", ) -BOOST_OPTIONS = {f"without_{_name}": True for _name in BOOST_LIBS \ - if _name not in ['thread', 'atomic', 'chrono', 'container', 'date_time', 'exception', 'system']} +BOOST_OPTIONS = { + f"without_{_name}": True + for _name in BOOST_LIBS + if _name not in ["thread", "atomic", "chrono", "container", "date_time", "exception", "system"] +} BOOST_OPTIONS.update({"shared": False}) @@ -54,8 +59,10 @@ def requirements(self): self.requires("spdlog/1.14.1") self.requires("zpp_bits/4.4.24") self.requires("fmt/11.0.1", override=True) - self.requires("protobuf/5.27.0", options = {"with_zlib": True, "fPIC": True, "shared": False, "lite": False}) - self.requires("boost/1.86.0", options = BOOST_OPTIONS) + self.requires("protobuf/5.27.0", options={"with_zlib": True, "fPIC": True, "shared": False, "lite": False}) + self.requires("boost/1.86.0", options=BOOST_OPTIONS) + if os.environ["CMAKE_ENABLE_TEST"] == "ON": + self.requires("catch2/3.7.1") def generate(self): tc = CMakeToolchain(self) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..adf4a06 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,6 @@ +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/check_udp_message.py + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/srs_check_udp COPYONLY USE_SOURCE_PERMISSIONS) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/check_binpb_message.py + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/srs_check_binpb COPYONLY USE_SOURCE_PERMISSIONS) + diff --git a/test/check_binpb_message.py b/examples/check_binpb_message.py similarity index 100% rename from test/check_binpb_message.py rename to examples/check_binpb_message.py diff --git a/test/check_udp_message.py b/examples/check_udp_message.py similarity index 100% rename from test/check_udp_message.py rename to examples/check_udp_message.py diff --git a/test/message_pb2.py b/examples/message_pb2.py similarity index 100% rename from test/message_pb2.py rename to examples/message_pb2.py diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ce828fc..3dbbe65 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,3 @@ -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/check_udp_message.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/srs_check_udp COPYONLY USE_SOURCE_PERMISSIONS) - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/check_binpb_message.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/srs_check_binpb COPYONLY USE_SOURCE_PERMISSIONS) +if(ENABLE_TEST) + add_subdirectory(integration) +endif() diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt new file mode 100644 index 0000000..e69de29