- Notifications
You must be signed in to change notification settings - Fork0
Cross-platform CMake/C++ library to get the installation prefix of shared library in a relocatable way.
License
ami-iit/reloc-cpp
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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 ofCMAKE_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 fromCMAKE_INSTALL_PREFIX after the installation (i.e. making it arelocatable installation), as long as the library is compiled as shared. This is useful when the C++ shared library is packaged in package managers that create the package with a givenCMAKE_INSTALL_PREFIX and install it with a different prefix, such asconda,vcpkg orconan.
In the case that the library is compiled as static,reloc-cpp will fall back to hardcodeCMAKE_INSTALL_PREFIX in the library.
reloc-cpp requires the use of C++ 17 or any later version.
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)In your CMake build system you can usereloc-cpp as:
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:
#include<yourLibrary_getInstallationPrefix.h>// This return the value corresponding to CMAKE_INSTALL_PREFIXstd::string installPrefix = yourLibrary::getInstallPrefix().value();
Pull requests are welcome. For major changes, please open an issue firstto discuss what you would like to change.
References that were useful as inspiration when developing reloc-cpp:
- "Helping C/C++ Packages be Relocatable" presentation
- Resourceful: Techniques for installing and accessing resource files using C++ and Python.
- "Qt is relocatable" blog post
- binreloc: Library for creating relocatable software
Resources that could be useful as an alternative to reloc-cpp:
About
Cross-platform CMake/C++ library to get the installation prefix of shared library in a relocatable way.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.