Skip to content

Commit d349abb

Browse files
authored
Add first working version of the library (#1)
1 parent 8aac183 commit d349abb

8 files changed

Lines changed: 503 additions & 1 deletion

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: C++ CI Workflow with conda-forge dependencies
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
# * is a special character in YAML so you have to quote this string
8+
# Execute a "weekly" build at 2 AM UTC on Sunday
9+
- cron: '0 2 * * 0'
10+
11+
jobs:
12+
build:
13+
name: '[${{ matrix.os }}@${{ matrix.build_type }}@conda]'
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
matrix:
17+
build_type: [Release]
18+
os: [ubuntu-latest, windows-2019, macOS-latest]
19+
fail-fast: false
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- uses: conda-incubator/setup-miniconda@v2
25+
with:
26+
mamba-version: "*"
27+
channels: conda-forge,defaults
28+
miniforge-variant: Mambaforge
29+
channel-priority: true
30+
31+
- name: Dependencies
32+
shell: bash -l {0}
33+
run: |
34+
mamba install cmake compilers make ninja pkg-config ycm-cmake-modules
35+
36+
- name: Additional Dependencies [Windows]
37+
if: contains(matrix.os, 'windows')
38+
shell: bash -l {0}
39+
run: |
40+
mamba install vs2019_win-64
41+
42+
43+
- name: Configure&Build&Test&Install [Linux&macOS]
44+
if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu')
45+
shell: bash -l {0}
46+
run: |
47+
mkdir -p build
48+
cd build
49+
cmake -GNinja -DBUILD_TESTING:BOOL=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install ..
50+
cmake --build . --config ${{ matrix.build_type }}
51+
ctest --output-on-failure -C ${{ matrix.build_type }}
52+
cmake --install . --config ${{ matrix.build_type }}
53+
54+
- name: Configure&Build&Test&Install [Windows]
55+
if: contains(matrix.os, 'windows')
56+
shell: cmd /C CALL {0}
57+
run: |
58+
mkdir build
59+
cd build
60+
cmake -GNinja -DBUILD_TESTING:BOOL=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install ..
61+
cmake --build . --config ${{ matrix.build_type }}
62+
ctest --output-on-failure -C ${{ matrix.build_type }}
63+
cmake --install . --config ${{ matrix.build_type }}

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6+
7+
## [Unreleased]
8+
9+
## [0.1.0] - 2022-11-14
10+
11+
### Added
12+
13+
- First version of the library (https://github.com/ami-iit/reloc-cpp/pull/1).

CMakeLists.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# SPDX-FileCopyrightText: Fondazione Istituto Italiano di Tecnologia (IIT)
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
cmake_minimum_required(VERSION 3.16)
5+
6+
project(reloc-cpp
7+
LANGUAGES CXX C
8+
VERSION 0.1.0)
9+
10+
include(GNUInstallDirs)
11+
12+
# Make reloc_cpp_generate available
13+
include(${CMAKE_CURRENT_SOURCE_DIR}/RelocCPPGenerate.cmake)
14+
15+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
16+
set(RELOC_CPP_STANDALONE ON)
17+
endif()
18+
19+
option(RELOC_CPP_INSTALL "Enable installation of reloc-cpp" ${RELOC_CPP_STANDALONE})
20+
21+
# Build test related commands?
22+
option(BUILD_TESTING "Create tests using CMake" ${RELOC_CPP_STANDALONE})
23+
if(BUILD_TESTING)
24+
enable_testing()
25+
endif()
26+
27+
if(RELOC_CPP_INSTALL)
28+
set(RELOC_CPP_INSTALL_MODULE_DIR "${CMAKE_INSTALL_DATADIR}/reloc-cpp")
29+
set(RELOC_CPP_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_DATADIR}/reloc-cpp/cmake")
30+
31+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/RelocCPPGenerate.cmake
32+
DESTINATION "${CMAKE_INSTALL_DATADIR}/reloc-cpp")
33+
34+
find_package(YCM REQUIRED)
35+
include(InstallBasicPackageFiles)
36+
install_basic_package_files(${PROJECT_NAME}
37+
VERSION ${${PROJECT_NAME}_VERSION}
38+
COMPATIBILITY AnyNewerVersion
39+
VARS_PREFIX ${PROJECT_NAME}
40+
NO_CHECK_REQUIRED_COMPONENTS_MACRO
41+
ARCH_INDEPENDENT
42+
NO_EXPORT)
43+
include(AddUninstallTarget)
44+
endif()
45+
46+
# Add integration tests (unit tests for each library should be in each sublibrary directory).
47+
if(BUILD_TESTING)
48+
add_subdirectory(tests)
49+
endif()

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,66 @@
11
# reloc-cpp
2-
CMake/C++ library to get the installation prefix of shared library.
2+
3+
CMake/C++ library to get the installation prefix of a shared library in a relocatable way.
4+
5+
In a nutshell, it permits to avoid the need to hardcode the location of `CMAKE_INSTALL_PREFIX` in a shared library if you need it to localize other resources installed with the package. This permits to easily move the installation prefix in a location different from `CMAKE_INSTALL_PREFIX` after the installation (i.e. making it a *relocatable* installation), as long as the library is compiled as shared.
6+
7+
In the case that the library is compiled as static, `reloc-cpp` will fall back to hardcode `CMAKE_INSTALL_PREFIX` in the library.
8+
9+
## Installation
10+
11+
### FetchContent
12+
13+
~~~cmake
14+
include(FetchContent)
15+
FetchContent_Declare(
16+
reloc-cpp
17+
GIT_REPOSITORY https://github.com/ami-iit/reloc-cpp.git
18+
GIT_TAG v0.1.0
19+
)
20+
21+
FetchContent_MakeAvailable(reloc-cpp)
22+
~~~
23+
24+
## Usage
25+
26+
In your CMake build system you can use `reloc-cpp` as:
27+
28+
```cmake
29+
add_library(yourLibrary)
30+
31+
# ...
32+
33+
reloc_cpp_generate(yourLibrary
34+
GENERATED_HEADER ${CMAKE_CURRENT_BINARY_DIR}/yourLibrary_getInstallPrefix.h
35+
GENERATED_FUNCTION yourLibrary::getInstallPrefix)
36+
```
37+
38+
then, you can use it in C++ as:
39+
40+
~~~cpp
41+
#include <yourLibrary_getInstallationPrefix.h>
42+
43+
// This return the value corresponding to CMAKE_INSTALL_PREFIX
44+
std::string installPrefix = yourLibrary::getInstallPrefix().value();
45+
~~~
46+
47+
48+
## Contributing
49+
50+
Pull requests are welcome. For major changes, please open an issue first
51+
to discuss what you would like to change.
52+
53+
## References
54+
55+
References that were useful as inspiration when developing reloc-cpp:
56+
* ["Helping C/C++ Packages be Relocatable" presentation](https://indico.cern.ch/event/848215/contributions/3591953/attachments/1923018/3181752/HSFPackagingRelocation.pdf)
57+
* [Resourceful: Techniques for installing and accessing resource files using C++ and Python.](https://github.com/drbenmorgan/Resourceful)
58+
* ["Qt is relocatable" blog post](https://www.qt.io/blog/qt-is-relocatable)
59+
* [binreloc: Library for creating relocatable software](https://github.com/limbahq/binreloc)
60+
61+
Resources that could be useful as an alternative to reloc-cpp:
62+
* [cmrc: A Resource Compiler in a Single CMake Script ](https://github.com/vector-of-bool/cmrc)
63+
64+
## License
65+
66+
[BSD-3-Clause](https://choosealicense.com/licenses/bsd-3-clause/)

0 commit comments

Comments
 (0)