diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index b47098f..0336471 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -21,7 +21,7 @@ jobs: cache-downloads: true - name: Configure using CMake - run: cmake -G Ninja -Bbuild -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSPARROW_IPC_BUILD_DOCS=ON + run: cmake -G Ninja -Bbuild -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_PREFIX_PATH=$CONDA_PREFIX -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSPARROW_IPC_BUILD_DOCS=ON - name: Build docs target run: cmake --build build --target docs diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 9be6d73..86b445f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -33,8 +33,8 @@ jobs: cmake -G Ninja \ -Bbuild \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ - -DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX% \ - -DCMAKE_PREFIX_PATH=%CONDA_PREFIX% \ + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \ + -DCMAKE_PREFIX_PATH=$CONDA_PREFIX \ -DSPARROW_IPC_BUILD_SHARED=${{ matrix.build_shared }} \ -DSPARROW_IPC_BUILD_TESTS=ON @@ -50,6 +50,10 @@ jobs: working-directory: build run: cmake --build . --target run_tests_with_junit_report + - name: Install + working-directory: build + run: cmake --install . + linux_build_fetch_from_source: runs-on: ubuntu-latest strategy: @@ -80,3 +84,7 @@ jobs: - name: Run tests working-directory: build run: cmake --build . --target run_tests_with_junit_report + + - name: Install + working-directory: build + run: sudo cmake --install . diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index ea4c739..42c90c9 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -38,8 +38,8 @@ jobs: cmake -G Ninja \ -Bbuild \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ - -DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX% \ - -DCMAKE_PREFIX_PATH=%CONDA_PREFIX% \ + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \ + -DCMAKE_PREFIX_PATH=$CONDA_PREFIX \ -DSPARROW_IPC_BUILD_SHARED=${{ matrix.build_shared }} \ -DSPARROW_IPC_BUILD_TESTS=ON @@ -55,6 +55,10 @@ jobs: working-directory: build run: cmake --build . --target run_tests_with_junit_report + - name: Install + working-directory: build + run: cmake --install . + osx_build_fetch_from_source: runs-on: macos-latest strategy: @@ -90,3 +94,7 @@ jobs: - name: Run tests working-directory: build run: cmake --build . --target run_tests_with_junit_report + + - name: Install + working-directory: build + run: sudo cmake --install . diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 7b043c0..221127d 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -50,6 +50,10 @@ jobs: run: | cmake --build . --config ${{ matrix.build_type }} --target run_tests_with_junit_report + - name: Install + working-directory: build + run: cmake --install . --config ${{ matrix.build_type }} + windows_build_fetch_from_source: runs-on: windows-latest strategy: @@ -86,6 +90,10 @@ jobs: working-directory: build run: cmake --build . --config ${{ matrix.build_type }} --target run_tests_with_junit_report + - name: Install + working-directory: build + run: cmake --install . --config ${{ matrix.build_type }} + - name: Tests coverage if: matrix.build_type == 'Debug' working-directory: build diff --git a/CMakeLists.txt b/CMakeLists.txt index fdef7fb..f678a06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,13 +29,13 @@ if(ACTIVATE_LINTER) include(clang-tidy) endif() -# Versionning -# =========== +# Versioning +# ========== file(STRINGS "${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/config/sparrow_ipc_version.hpp" sparrow_ipc_version_defines REGEX "constexpr int SPARROW_IPC_VERSION_(MAJOR|MINOR|PATCH)") foreach(ver ${sparrow_ipc_version_defines}) - if(ver MATCHES "constexpr int SPARROW_VERSION_(MAJOR|MINOR|PATCH) = ([0-9]+);$") + if(ver MATCHES "constexpr int SPARROW_IPC_VERSION_(MAJOR|MINOR|PATCH) = ([0-9]+);$") set(PROJECT_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") endif() endforeach() @@ -43,10 +43,10 @@ endforeach() set(CMAKE_PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) -message(STATUS "Building sparrow_ipc v${CMAKE_PROJECT_VERSION}") +message(STATUS "Building sparrow-ipc v${CMAKE_PROJECT_VERSION}") # Binary version -# See the following URL for explanations about the binary versionning +# See the following URL for more info on the binary versioning # https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info file(STRINGS "${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/config/sparrow_ipc_version.hpp" sparrow_ipc_version_defines REGEX "constexpr int SPARROW_IPC_BINARY_(CURRENT|REVISION|AGE)") @@ -60,7 +60,7 @@ endforeach() set(SPARROW_IPC_BINARY_VERSION ${SPARROW_IPC_BINARY_CURRENT}.${SPARROW_IPC_BINARY_REVISION}.${SPARROW_IPC_BINARY_AGE}) -message(STATUS "sparrow_ipc binary version: v${SPARROW_IPC_BINARY_VERSION}") +message(STATUS "sparrow-ipc binary version: v${SPARROW_IPC_BINARY_VERSION}") # Build options # ============= @@ -101,6 +101,7 @@ set(SPARROW_IPC_HEADERS ${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/arrow_interface/arrow_schema.hpp ${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/arrow_interface/arrow_schema/private_data.hpp ${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/config/config.hpp + ${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/config/sparrow_ipc_version.hpp ${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/deserialize_variable_size_binary_array.hpp ${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/deserialize_fixedsizebinary_array.hpp ${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/deserialize_primitive_array.hpp @@ -200,8 +201,26 @@ target_compile_definitions(sparrow-ipc ${SPARROW_IPC_COMPILE_DEFINITIONS}) if(UNIX) + # CMake does not compute the version number of so files as libtool + # does on Linux. Strictly speaking, we should exclude FreeBSD and + # Apple from this, but that would require having different version + # numbers depending on the platform. We prefer to follow the + # libtool pattern everywhere. + math(EXPR SPARROW_IPC_BINARY_COMPATIBLE "${SPARROW_IPC_BINARY_CURRENT} - ${SPARROW_IPC_BINARY_AGE}") + set_target_properties( + sparrow-ipc + PROPERTIES + VERSION "${SPARROW_IPC_BINARY_COMPATIBLE}.${SPARROW_IPC_BINARY_REVISION}.${SPARROW_IPC_BINARY_AGE}" + SOVERSION ${SPARROW_IPC_BINARY_COMPATIBLE} + ) target_compile_options(sparrow-ipc PRIVATE "-fvisibility=hidden") else() + set_target_properties( + sparrow-ipc + PROPERTIES + VERSION ${SPARROW_IPC_BINARY_VERSION} + SOVERSION ${SPARROW_IPC_BINARY_CURRENT} + ) target_compile_definitions(sparrow-ipc PRIVATE SPARROW_IPC_EXPORTS) endif() @@ -235,3 +254,60 @@ if(SPARROW_IPC_BUILD_DOCS) message(STATUS "📚 Create docs targets") add_subdirectory(docs) endif() + +# Installation +# ============ +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +# Install CMake configuration files +set(SPARROW_IPC_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE + STRING "install path for sparrow-ipcConfig.cmake") + +configure_package_config_file(cmake/${PROJECT_NAME}Config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION ${SPARROW_IPC_CMAKECONFIG_INSTALL_DIR}) + +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + VERSION ${CMAKE_PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${SPARROW_IPC_CMAKECONFIG_INSTALL_DIR}) + +# Install target +set(SPARROW_IPC_EXPORTED_TARGETS sparrow-ipc) +if (TARGET flatbuffers) + get_target_property(is_imported flatbuffers IMPORTED) + if(NOT is_imported) + # This means `flatbuffers` was fetched using FetchContent + # We need to export `flatbuffers` target explicitly + list(APPEND SPARROW_IPC_EXPORTED_TARGETS flatbuffers) + if(TARGET ProjectConfig) + # This is an internal target from the flatbuffers build system + # that also needs to be exported + list(APPEND SPARROW_IPC_EXPORTED_TARGETS ProjectConfig) + endif() + endif() +endif() + +install(TARGETS ${SPARROW_IPC_EXPORTED_TARGETS} + EXPORT ${PROJECT_NAME}-targets) + +install(EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE sparrow-ipc:: + DESTINATION ${SPARROW_IPC_CMAKECONFIG_INSTALL_DIR}) + +# Makes the project importable from the build directory +export(EXPORT ${PROJECT_NAME}-targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" + NAMESPACE sparrow-ipc::) + +# Install headers +install(DIRECTORY ${SPARROW_IPC_INCLUDE_DIR} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + PATTERN ".clang-*" EXCLUDE + PATTERN "README.md" EXCLUDE) diff --git a/cmake/sparrow-ipcConfig.cmake.in b/cmake/sparrow-ipcConfig.cmake.in index 3bd4e21..d3b69f9 100644 --- a/cmake/sparrow-ipcConfig.cmake.in +++ b/cmake/sparrow-ipcConfig.cmake.in @@ -3,7 +3,7 @@ # # sparrow-ipc_FOUND - true if sparrow-ipc found on the system # sparrow-ipc_INCLUDE_DIRS - the directory containing sparrow-ipc headers -# sparrow-ipc_LIBRARY - empty +# sparrow-ipc_LIBRARY - the location of the sparrow-ipc library (or empty if not applicable) @PACKAGE_INIT@ diff --git a/environment-dev.yml b/environment-dev.yml index 2e46112..7a3f086 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -8,6 +8,7 @@ dependencies: - cxx-compiler # Libraries dependencies - flatbuffers + - nlohmann_json - sparrow-devel >=1.1.2 - doctest # Documentation dependencies diff --git a/include/sparrow_ipc/config/sparrow_ipc_version.hpp b/include/sparrow_ipc/config/sparrow_ipc_version.hpp index 4f718d7..5f1ae32 100644 --- a/include/sparrow_ipc/config/sparrow_ipc_version.hpp +++ b/include/sparrow_ipc/config/sparrow_ipc_version.hpp @@ -9,4 +9,6 @@ namespace sparrow_ipc constexpr int SPARROW_IPC_BINARY_CURRENT = 1; constexpr int SPARROW_IPC_BINARY_REVISION = 0; constexpr int SPARROW_IPC_BINARY_AGE = 0; + + static_assert(SPARROW_IPC_BINARY_AGE <= SPARROW_IPC_BINARY_CURRENT, "SPARROW_IPC_BINARY_AGE cannot be greater than SPARROW_IPC_BINARY_CURRENT"); } diff --git a/tests/main.cpp b/tests/main.cpp index a56a610..cd51f43 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,5 +1,21 @@ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include + #include "doctest/doctest.h" -//TODO check version? +#include "sparrow_ipc/config/sparrow_ipc_version.hpp" + +TEST_CASE("versions exist and are readable") +{ + using namespace sparrow_ipc; + [[maybe_unused]] const std::string printable_version = std::string("sparrow-ipc version: ") + + std::to_string(SPARROW_IPC_VERSION_MAJOR) + "." + + std::to_string(SPARROW_IPC_VERSION_MINOR) + "." + + std::to_string(SPARROW_IPC_VERSION_PATCH); + + [[maybe_unused]] const std::string printable_binary_version = std::string("sparrow-ipc binary version: ") + + std::to_string(SPARROW_IPC_BINARY_CURRENT) + "." + + std::to_string(SPARROW_IPC_BINARY_REVISION) + "." + + std::to_string(SPARROW_IPC_BINARY_AGE); +}