[CMake] Installing and Exporting for multiple configurations

Saad Khattak saadrustam at gmail.com
Wed Apr 3 22:06:29 EDT 2013


Hi,

I am trying my best to understand CMake's install and export commands so
that separate projects are able to find libraries easily.

I am having a tremendously hard time understand what CMake is doing. After
'add_library()' where the library is called 'myLib' I called the following:

install(TARGETS myLib
    DESTINATION ${PROJECT_BINARY_DIR}/lib/
    EXPORT repoA-targets
    )

Then in the top-level CMakeLists I added:

install(EXPORT repoA-targets
    DESTINATION ${PROJECT_BINARY_DIR}/lib/
    )

When I build my project (in Visual Studio on Windows) it dumps libraries
from all configurations in the same folder which is:

${PROJECT_BINARY_DIR}/lib

and over-writes the previous library file from a different configuration
because they are named the same. At the same time, it actually generates a
repoA-targets-debug.cmake file, but points to the now over-written library
file which is of a different configuration. Why would CMake do this? Makes
no sense.

That is only part of the problem. Now in RepoB, I want to import the
libraries. CMake documentation here:
http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets

states that I can do something like this:
include(${PATH_OF_REPO_A_BUILD}/repoA-targets.cmake)

target_link_libraries(repoBExecutable myLib)

and CMake should be able to find myLib and correctly add it to the linker's
properties. This does not appear to be working. CMake simply adds "myLib"
to the linker instead of "${FULL_PATH_OF_MYLIB}/myLib".

I hope that somebody can explain what I am doing wrong and how to install
and export libraries properly with CMake and then successfully import and
use them in another project.

Thank you,
Saad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130403/0eece767/attachment.htm>


More information about the CMake mailing list