1

I have a very simple library with a header file and a source file. I'm using CMake to compile it, initially like this:

add_library(libOEInfoProvider SHARED
    ${CMAKE_CURRENT_LIST_DIR}/src/OE/InfoProvider.h
    ${CMAKE_CURRENT_LIST_DIR}/src/OE/InfoProvider.cpp)

# see: https://stackoverflow.com/a/25681179/276451
target_include_directories(libOEInfoProvider
    PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
    $<INSTALL_INTERFACE:dist/include>)

I've now configured it so that make install generates all necessary files in a dist folder, like so:

install(TARGETS libOEInfoProvider EXPORT libOEInfoProviderConfig
    LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/dist/lib
)

install(DIRECTORY
    src/ DESTINATION ${CMAKE_SOURCE_DIR}/dist/include)

install(EXPORT
    libOEInfoProviderConfig DESTINATION ${CMAKE_SOURCE_DIR}/dist/cmake)

export(TARGETS libOEInfoProvider FILE libOEInfoProviderConfig.cmake)

The problem I have is that the geneerated .cmake files contain absolute paths to the dist folder, but I need to deploy this library somewhere else with a different directory structure. Therefore I'd need to have relative paths in the .cmake, so wherever I place the library, the moment I use find_package in the client code it should be able to find the code.

José Tomás Tocino
  • 9,873
  • 5
  • 44
  • 78

0 Answers0