|
1 | 1 | # 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