Skip to content

Commit 60a6a51

Browse files
authored
Handle versioning and install (#14)
* Handle versioning * Add static_assert * Handle install * Fix install * Fix again * Change version * Add install job * Add sparrow-ipcConfig.cmake.in in conanfile.py * Remove redundancy * Fix path * Export flatbuffers explicitly * Add condition * Export ProjectConfig * Fix unix syntax and add config to win install * Add sudo to install when from source * Add missing config to windows and arg to docs workflow * Add nlohmann_json in env file
1 parent 963b02b commit 60a6a51

File tree

9 files changed

+132
-13
lines changed

9 files changed

+132
-13
lines changed

.github/workflows/docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
cache-downloads: true
2222

2323
- name: Configure using CMake
24-
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
24+
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
2525

2626
- name: Build docs target
2727
run: cmake --build build --target docs

.github/workflows/linux.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
cmake -G Ninja \
3434
-Bbuild \
3535
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
36-
-DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX% \
37-
-DCMAKE_PREFIX_PATH=%CONDA_PREFIX% \
36+
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
37+
-DCMAKE_PREFIX_PATH=$CONDA_PREFIX \
3838
-DSPARROW_IPC_BUILD_SHARED=${{ matrix.build_shared }} \
3939
-DSPARROW_IPC_BUILD_TESTS=ON
4040
@@ -50,6 +50,10 @@ jobs:
5050
working-directory: build
5151
run: cmake --build . --target run_tests_with_junit_report
5252

53+
- name: Install
54+
working-directory: build
55+
run: cmake --install .
56+
5357
linux_build_fetch_from_source:
5458
runs-on: ubuntu-latest
5559
strategy:
@@ -80,3 +84,7 @@ jobs:
8084
- name: Run tests
8185
working-directory: build
8286
run: cmake --build . --target run_tests_with_junit_report
87+
88+
- name: Install
89+
working-directory: build
90+
run: sudo cmake --install .

.github/workflows/osx.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
cmake -G Ninja \
3939
-Bbuild \
4040
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
41-
-DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX% \
42-
-DCMAKE_PREFIX_PATH=%CONDA_PREFIX% \
41+
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
42+
-DCMAKE_PREFIX_PATH=$CONDA_PREFIX \
4343
-DSPARROW_IPC_BUILD_SHARED=${{ matrix.build_shared }} \
4444
-DSPARROW_IPC_BUILD_TESTS=ON
4545
@@ -55,6 +55,10 @@ jobs:
5555
working-directory: build
5656
run: cmake --build . --target run_tests_with_junit_report
5757

58+
- name: Install
59+
working-directory: build
60+
run: cmake --install .
61+
5862
osx_build_fetch_from_source:
5963
runs-on: macos-latest
6064
strategy:
@@ -90,3 +94,7 @@ jobs:
9094
- name: Run tests
9195
working-directory: build
9296
run: cmake --build . --target run_tests_with_junit_report
97+
98+
- name: Install
99+
working-directory: build
100+
run: sudo cmake --install .

.github/workflows/windows.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ jobs:
5050
run: |
5151
cmake --build . --config ${{ matrix.build_type }} --target run_tests_with_junit_report
5252
53+
- name: Install
54+
working-directory: build
55+
run: cmake --install . --config ${{ matrix.build_type }}
56+
5357
windows_build_fetch_from_source:
5458
runs-on: windows-latest
5559
strategy:
@@ -86,6 +90,10 @@ jobs:
8690
working-directory: build
8791
run: cmake --build . --config ${{ matrix.build_type }} --target run_tests_with_junit_report
8892

93+
- name: Install
94+
working-directory: build
95+
run: cmake --install . --config ${{ matrix.build_type }}
96+
8997
- name: Tests coverage
9098
if: matrix.build_type == 'Debug'
9199
working-directory: build

CMakeLists.txt

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ if(ACTIVATE_LINTER)
2929
include(clang-tidy)
3030
endif()
3131

32-
# Versionning
33-
# ===========
32+
# Versioning
33+
# ==========
3434
file(STRINGS "${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/config/sparrow_ipc_version.hpp" sparrow_ipc_version_defines
3535
REGEX "constexpr int SPARROW_IPC_VERSION_(MAJOR|MINOR|PATCH)")
3636

3737
foreach(ver ${sparrow_ipc_version_defines})
38-
if(ver MATCHES "constexpr int SPARROW_VERSION_(MAJOR|MINOR|PATCH) = ([0-9]+);$")
38+
if(ver MATCHES "constexpr int SPARROW_IPC_VERSION_(MAJOR|MINOR|PATCH) = ([0-9]+);$")
3939
set(PROJECT_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
4040
endif()
4141
endforeach()
4242

4343
set(CMAKE_PROJECT_VERSION
4444
${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
4545

46-
message(STATUS "Building sparrow_ipc v${CMAKE_PROJECT_VERSION}")
46+
message(STATUS "Building sparrow-ipc v${CMAKE_PROJECT_VERSION}")
4747

4848
# Binary version
49-
# See the following URL for explanations about the binary versionning
49+
# See the following URL for more info on the binary versioning
5050
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
5151
file(STRINGS "${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/config/sparrow_ipc_version.hpp" sparrow_ipc_version_defines
5252
REGEX "constexpr int SPARROW_IPC_BINARY_(CURRENT|REVISION|AGE)")
@@ -60,7 +60,7 @@ endforeach()
6060
set(SPARROW_IPC_BINARY_VERSION
6161
${SPARROW_IPC_BINARY_CURRENT}.${SPARROW_IPC_BINARY_REVISION}.${SPARROW_IPC_BINARY_AGE})
6262

63-
message(STATUS "sparrow_ipc binary version: v${SPARROW_IPC_BINARY_VERSION}")
63+
message(STATUS "sparrow-ipc binary version: v${SPARROW_IPC_BINARY_VERSION}")
6464

6565
# Build options
6666
# =============
@@ -101,6 +101,7 @@ set(SPARROW_IPC_HEADERS
101101
${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/arrow_interface/arrow_schema.hpp
102102
${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/arrow_interface/arrow_schema/private_data.hpp
103103
${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/config/config.hpp
104+
${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/config/sparrow_ipc_version.hpp
104105
${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/deserialize_variable_size_binary_array.hpp
105106
${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/deserialize_fixedsizebinary_array.hpp
106107
${SPARROW_IPC_INCLUDE_DIR}/sparrow_ipc/deserialize_primitive_array.hpp
@@ -200,8 +201,26 @@ target_compile_definitions(sparrow-ipc
200201
${SPARROW_IPC_COMPILE_DEFINITIONS})
201202

202203
if(UNIX)
204+
# CMake does not compute the version number of so files as libtool
205+
# does on Linux. Strictly speaking, we should exclude FreeBSD and
206+
# Apple from this, but that would require having different version
207+
# numbers depending on the platform. We prefer to follow the
208+
# libtool pattern everywhere.
209+
math(EXPR SPARROW_IPC_BINARY_COMPATIBLE "${SPARROW_IPC_BINARY_CURRENT} - ${SPARROW_IPC_BINARY_AGE}")
210+
set_target_properties(
211+
sparrow-ipc
212+
PROPERTIES
213+
VERSION "${SPARROW_IPC_BINARY_COMPATIBLE}.${SPARROW_IPC_BINARY_REVISION}.${SPARROW_IPC_BINARY_AGE}"
214+
SOVERSION ${SPARROW_IPC_BINARY_COMPATIBLE}
215+
)
203216
target_compile_options(sparrow-ipc PRIVATE "-fvisibility=hidden")
204217
else()
218+
set_target_properties(
219+
sparrow-ipc
220+
PROPERTIES
221+
VERSION ${SPARROW_IPC_BINARY_VERSION}
222+
SOVERSION ${SPARROW_IPC_BINARY_CURRENT}
223+
)
205224
target_compile_definitions(sparrow-ipc PRIVATE SPARROW_IPC_EXPORTS)
206225
endif()
207226

@@ -235,3 +254,60 @@ if(SPARROW_IPC_BUILD_DOCS)
235254
message(STATUS "📚 Create docs targets")
236255
add_subdirectory(docs)
237256
endif()
257+
258+
# Installation
259+
# ============
260+
include(GNUInstallDirs)
261+
include(CMakePackageConfigHelpers)
262+
263+
# Install CMake configuration files
264+
set(SPARROW_IPC_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE
265+
STRING "install path for sparrow-ipcConfig.cmake")
266+
267+
configure_package_config_file(cmake/${PROJECT_NAME}Config.cmake.in
268+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
269+
INSTALL_DESTINATION ${SPARROW_IPC_CMAKECONFIG_INSTALL_DIR})
270+
271+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
272+
VERSION ${CMAKE_PROJECT_VERSION}
273+
COMPATIBILITY AnyNewerVersion)
274+
275+
install(FILES
276+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
277+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
278+
DESTINATION ${SPARROW_IPC_CMAKECONFIG_INSTALL_DIR})
279+
280+
# Install target
281+
set(SPARROW_IPC_EXPORTED_TARGETS sparrow-ipc)
282+
if (TARGET flatbuffers)
283+
get_target_property(is_imported flatbuffers IMPORTED)
284+
if(NOT is_imported)
285+
# This means `flatbuffers` was fetched using FetchContent
286+
# We need to export `flatbuffers` target explicitly
287+
list(APPEND SPARROW_IPC_EXPORTED_TARGETS flatbuffers)
288+
if(TARGET ProjectConfig)
289+
# This is an internal target from the flatbuffers build system
290+
# that also needs to be exported
291+
list(APPEND SPARROW_IPC_EXPORTED_TARGETS ProjectConfig)
292+
endif()
293+
endif()
294+
endif()
295+
296+
install(TARGETS ${SPARROW_IPC_EXPORTED_TARGETS}
297+
EXPORT ${PROJECT_NAME}-targets)
298+
299+
install(EXPORT ${PROJECT_NAME}-targets
300+
FILE ${PROJECT_NAME}Targets.cmake
301+
NAMESPACE sparrow-ipc::
302+
DESTINATION ${SPARROW_IPC_CMAKECONFIG_INSTALL_DIR})
303+
304+
# Makes the project importable from the build directory
305+
export(EXPORT ${PROJECT_NAME}-targets
306+
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
307+
NAMESPACE sparrow-ipc::)
308+
309+
# Install headers
310+
install(DIRECTORY ${SPARROW_IPC_INCLUDE_DIR}
311+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
312+
PATTERN ".clang-*" EXCLUDE
313+
PATTERN "README.md" EXCLUDE)

cmake/sparrow-ipcConfig.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# sparrow-ipc_FOUND - true if sparrow-ipc found on the system
55
# sparrow-ipc_INCLUDE_DIRS - the directory containing sparrow-ipc headers
6-
# sparrow-ipc_LIBRARY - empty
6+
# sparrow-ipc_LIBRARY - the location of the sparrow-ipc library (or empty if not applicable)
77

88
@PACKAGE_INIT@
99

environment-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies:
88
- cxx-compiler
99
# Libraries dependencies
1010
- flatbuffers
11+
- nlohmann_json
1112
- sparrow-devel >=1.1.2
1213
- doctest
1314
# Documentation dependencies

include/sparrow_ipc/config/sparrow_ipc_version.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ namespace sparrow_ipc
99
constexpr int SPARROW_IPC_BINARY_CURRENT = 1;
1010
constexpr int SPARROW_IPC_BINARY_REVISION = 0;
1111
constexpr int SPARROW_IPC_BINARY_AGE = 0;
12+
13+
static_assert(SPARROW_IPC_BINARY_AGE <= SPARROW_IPC_BINARY_CURRENT, "SPARROW_IPC_BINARY_AGE cannot be greater than SPARROW_IPC_BINARY_CURRENT");
1214
}

tests/main.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
22

3+
#include <string>
4+
35
#include "doctest/doctest.h"
46

5-
//TODO check version?
7+
#include "sparrow_ipc/config/sparrow_ipc_version.hpp"
8+
9+
TEST_CASE("versions exist and are readable")
10+
{
11+
using namespace sparrow_ipc;
12+
[[maybe_unused]] const std::string printable_version = std::string("sparrow-ipc version: ")
13+
+ std::to_string(SPARROW_IPC_VERSION_MAJOR) + "."
14+
+ std::to_string(SPARROW_IPC_VERSION_MINOR) + "."
15+
+ std::to_string(SPARROW_IPC_VERSION_PATCH);
16+
17+
[[maybe_unused]] const std::string printable_binary_version = std::string("sparrow-ipc binary version: ")
18+
+ std::to_string(SPARROW_IPC_BINARY_CURRENT) + "."
19+
+ std::to_string(SPARROW_IPC_BINARY_REVISION) + "."
20+
+ std::to_string(SPARROW_IPC_BINARY_AGE);
21+
}

0 commit comments

Comments
 (0)