[CMake] Evaluate generator expressions with install interface
paul
pfultz2 at yahoo.com
Wed May 31 14:49:36 EDT 2017
So if I do something like this:
function(auto_pkgconfig TARGET)
get_target_property(INCLUDE_DIRS ${TARGET} INTERFACE_INCLUDE_DIRECTORIES)
string(REPLACE "$<BUILD_INTERFACE:" "$<0:" INCLUDE_DIRS "${INCLUDE_DIRS}")
string(REPLACE "$<INSTALL_INTERFACE:" "$<1:" INCLUDE_DIRS
"${INCLUDE_DIRS}")
string(REPLACE "$<INSTALL_PREFIX>" "${CMAKE_INSTALL_PREFIX}" INCLUDE_DIRS
"${INCLUDE_DIRS}")
file(GENERATE OUTPUT ${TARGET}.pc CONTENT "
Name: ${TARGET}
Cflags: -I$<JOIN:${INCLUDE_DIRS}, -I>
Libs: -L${CMAKE_INSTALL_PREFIX}/lib -l${TARGET}
")
install(FILES ${TARGET}.pc DESTINATION lib/pkgconfig)
endfunction()
It will evaluate the `INSTALL_INTERFACE`. It seems looking at the source code
of cmake, the export targets do something similiar. The only problem with this
approach is that it doesn't handle the properties if they are set after
calling `auto_pkgconfig`.
Is there a way to have cmake call a function or cmake code at the end of
configuration or after? Using `install(CODE)` will not work as it doesn't have
access to the targets during install.
On Tue, 2017-05-16 at 13:02 -0500, P F wrote:
> Hi,
>
> I would like to evaluate generator expressions to generate a pkgconfig file.
> Something like:
>
> function(auto_pkgconfig TARGET)
> file(GENERATE OUTPUT ${TARGET}.pc CONTENT "
> Name: ${TARGET}
> Cflags: -I$<JOIN:$<TARGET_PROPERTY:${TARGET},INTERFACE_INCLUDE_DIRECTORIES>,
> -I>
> Libs: -L$<TARGET_FILE_DIR:${TARGET}> -l${TARGET}
> ")
> install(FILES ${TARGET}.pc DESTINATION lib/pkgconfig)
> endfunction()
>
> However, this doesn’t work very well. It always evaluates the build
> interface or computes the TARGET_FILE_DIR according the build directory
> instead of installation. Also, if include directories are added to the
> target after calling `auto_pkgconfig` it doesn’t capture those(ie it runs
> file(GENERATE) at config time instead of generator time).
>
> So, is there a way to evaluate generator expressions for installation? And
> evaluate them at generator time?
>
> Calling `file(GENERATE)` at installation time(with install(CODE) or
> install(SCRIPT)) does not solve this problem either.
>
> Thanks,
> Paul
More information about the CMake
mailing list