-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first working version of the library (#1)
- Loading branch information
1 parent
8aac183
commit d349abb
Showing
8 changed files
with
503 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: C++ CI Workflow with conda-forge dependencies | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
# * is a special character in YAML so you have to quote this string | ||
# Execute a "weekly" build at 2 AM UTC on Sunday | ||
- cron: '0 2 * * 0' | ||
|
||
jobs: | ||
build: | ||
name: '[${{ matrix.os }}@${{ matrix.build_type }}@conda]' | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
build_type: [Release] | ||
os: [ubuntu-latest, windows-2019, macOS-latest] | ||
fail-fast: false | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: conda-incubator/setup-miniconda@v2 | ||
with: | ||
mamba-version: "*" | ||
channels: conda-forge,defaults | ||
miniforge-variant: Mambaforge | ||
channel-priority: true | ||
|
||
- name: Dependencies | ||
shell: bash -l {0} | ||
run: | | ||
mamba install cmake compilers make ninja pkg-config ycm-cmake-modules | ||
- name: Additional Dependencies [Windows] | ||
if: contains(matrix.os, 'windows') | ||
shell: bash -l {0} | ||
run: | | ||
mamba install vs2019_win-64 | ||
- name: Configure&Build&Test&Install [Linux&macOS] | ||
if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu') | ||
shell: bash -l {0} | ||
run: | | ||
mkdir -p build | ||
cd build | ||
cmake -GNinja -DBUILD_TESTING:BOOL=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install .. | ||
cmake --build . --config ${{ matrix.build_type }} | ||
ctest --output-on-failure -C ${{ matrix.build_type }} | ||
cmake --install . --config ${{ matrix.build_type }} | ||
- name: Configure&Build&Test&Install [Windows] | ||
if: contains(matrix.os, 'windows') | ||
shell: cmd /C CALL {0} | ||
run: | | ||
mkdir build | ||
cd build | ||
cmake -GNinja -DBUILD_TESTING:BOOL=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_INSTALL_PREFIX=./install .. | ||
cmake --build . --config ${{ matrix.build_type }} | ||
ctest --output-on-failure -C ${{ matrix.build_type }} | ||
cmake --install . --config ${{ matrix.build_type }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). | ||
|
||
## [Unreleased] | ||
|
||
## [0.1.0] - 2022-11-14 | ||
|
||
### Added | ||
|
||
- First version of the library (https://github.com/ami-iit/reloc-cpp/pull/1). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# SPDX-FileCopyrightText: Fondazione Istituto Italiano di Tecnologia (IIT) | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(reloc-cpp | ||
LANGUAGES CXX C | ||
VERSION 0.1.0) | ||
|
||
include(GNUInstallDirs) | ||
|
||
# Make reloc_cpp_generate available | ||
include(${CMAKE_CURRENT_SOURCE_DIR}/RelocCPPGenerate.cmake) | ||
|
||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) | ||
set(RELOC_CPP_STANDALONE ON) | ||
endif() | ||
|
||
option(RELOC_CPP_INSTALL "Enable installation of reloc-cpp" ${RELOC_CPP_STANDALONE}) | ||
|
||
# Build test related commands? | ||
option(BUILD_TESTING "Create tests using CMake" ${RELOC_CPP_STANDALONE}) | ||
if(BUILD_TESTING) | ||
enable_testing() | ||
endif() | ||
|
||
if(RELOC_CPP_INSTALL) | ||
set(RELOC_CPP_INSTALL_MODULE_DIR "${CMAKE_INSTALL_DATADIR}/reloc-cpp") | ||
set(RELOC_CPP_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_DATADIR}/reloc-cpp/cmake") | ||
|
||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/RelocCPPGenerate.cmake | ||
DESTINATION "${CMAKE_INSTALL_DATADIR}/reloc-cpp") | ||
|
||
find_package(YCM REQUIRED) | ||
include(InstallBasicPackageFiles) | ||
install_basic_package_files(${PROJECT_NAME} | ||
VERSION ${${PROJECT_NAME}_VERSION} | ||
COMPATIBILITY AnyNewerVersion | ||
VARS_PREFIX ${PROJECT_NAME} | ||
NO_CHECK_REQUIRED_COMPONENTS_MACRO | ||
ARCH_INDEPENDENT | ||
NO_EXPORT) | ||
include(AddUninstallTarget) | ||
endif() | ||
|
||
# Add integration tests (unit tests for each library should be in each sublibrary directory). | ||
if(BUILD_TESTING) | ||
add_subdirectory(tests) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,66 @@ | ||
# reloc-cpp | ||
CMake/C++ library to get the installation prefix of shared library. | ||
|
||
CMake/C++ library to get the installation prefix of a shared library in a relocatable way. | ||
|
||
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. | ||
|
||
In the case that the library is compiled as static, `reloc-cpp` will fall back to hardcode `CMAKE_INSTALL_PREFIX` in the library. | ||
|
||
## Installation | ||
|
||
### FetchContent | ||
|
||
~~~cmake | ||
include(FetchContent) | ||
FetchContent_Declare( | ||
reloc-cpp | ||
GIT_REPOSITORY https://github.com/ami-iit/reloc-cpp.git | ||
GIT_TAG v0.1.0 | ||
) | ||
FetchContent_MakeAvailable(reloc-cpp) | ||
~~~ | ||
|
||
## Usage | ||
|
||
In your CMake build system you can use `reloc-cpp` as: | ||
|
||
```cmake | ||
add_library(yourLibrary) | ||
# ... | ||
reloc_cpp_generate(yourLibrary | ||
GENERATED_HEADER ${CMAKE_CURRENT_BINARY_DIR}/yourLibrary_getInstallPrefix.h | ||
GENERATED_FUNCTION yourLibrary::getInstallPrefix) | ||
``` | ||
|
||
then, you can use it in C++ as: | ||
|
||
~~~cpp | ||
#include <yourLibrary_getInstallationPrefix.h> | ||
|
||
// This return the value corresponding to CMAKE_INSTALL_PREFIX | ||
std::string installPrefix = yourLibrary::getInstallPrefix().value(); | ||
~~~ | ||
|
||
|
||
## Contributing | ||
|
||
Pull requests are welcome. For major changes, please open an issue first | ||
to discuss what you would like to change. | ||
|
||
## References | ||
|
||
References that were useful as inspiration when developing reloc-cpp: | ||
* ["Helping C/C++ Packages be Relocatable" presentation](https://indico.cern.ch/event/848215/contributions/3591953/attachments/1923018/3181752/HSFPackagingRelocation.pdf) | ||
* [Resourceful: Techniques for installing and accessing resource files using C++ and Python.](https://github.com/drbenmorgan/Resourceful) | ||
* ["Qt is relocatable" blog post](https://www.qt.io/blog/qt-is-relocatable) | ||
* [binreloc: Library for creating relocatable software](https://github.com/limbahq/binreloc) | ||
|
||
Resources that could be useful as an alternative to reloc-cpp: | ||
* [cmrc: A Resource Compiler in a Single CMake Script ](https://github.com/vector-of-bool/cmrc) | ||
|
||
## License | ||
|
||
[BSD-3-Clause](https://choosealicense.com/licenses/bsd-3-clause/) |
Oops, something went wrong.