[CMake] Installing and exporting multiple configurations of the same library

Saad Khattak saadrustam at gmail.com
Fri Dec 15 18:18:26 EST 2017


Hi,

I have 4 configurations (2 for Debug and 2 for Release) and I would like to
install the libraries such that they are installed in the correct
directories.

Installing without worrying about configurations looks like this:

    install(TARGETS ${LIB_NAME}
        EXPORT ${LIB_NAME}Config
        PUBLIC_HEADER DESTINATION "include/${LIB_NAME}"
        LIBRARY DESTINATION "bin/${LIB_NAME}/"
        ARCHIVE DESTINATION "lib/${LIB_NAME}/"
        )

However, different configurations overwrite the binaries. So instead, I did
something like this (I'm going over all my configurations in a foreach):

    install(TARGETS ${LIB_NAME}
        CONFIGURATIONS DEBUG
        EXPORT ${LIB_NAME}Config
        PUBLIC_HEADER DESTINATION "include/${LIB_NAME}"
        LIBRARY DESTINATION "bin/${LIB_NAME}/debug/"
        ARCHIVE DESTINATION "lib/${LIB_NAME}/debug"
        )

    install(TARGETS ${LIB_NAME}
        CONFIGURATIONS RELEASE
        EXPORT ${LIB_NAME}Config
        PUBLIC_HEADER DESTINATION "include/${LIB_NAME}"
        LIBRARY DESTINATION "bin/${LIB_NAME}/release/"
        ARCHIVE DESTINATION "lib/${LIB_NAME}/release/"
        )

however, that results in the error:
CMake Error: INSTALL(EXPORT ...) includes target "MyLibrary" more than once
in the export set.

The error makes sense, in that I cannot have multiple exports in the same
export set, in this case ${LIB_NAME}Config. However, I would like CMake to
choose a different directory based on the configuration.

Now there is a workaround... sort of. I could name the binaries based on
the configuration but that doesn't work with our existing build systems. We
want the following:

lib/${LIB_NAME}/${CONFIG}/libname

Any way to get CMake to install the libraries this way?

Thank you,
Saad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cmake.org/pipermail/cmake/attachments/20171215/d464db7d/attachment.html>


More information about the CMake mailing list