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

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to