<div dir="ltr">Hi,<div><br></div><div>I am trying my best to understand CMake&#39;s install and export commands so that separate projects are able to find libraries easily. </div><div><br></div><div>I am having a tremendously hard time understand what CMake is doing. After &#39;add_library()&#39; where the library is called &#39;myLib&#39; I called the following:</div>


<div><br></div><div>install(TARGETS myLib</div><div>    DESTINATION ${PROJECT_BINARY_DIR}/lib/</div><div>    EXPORT repoA-targets</div><div>    )</div><div><br></div><div>Then in the top-level CMakeLists I added:</div>
<div><br></div><div>install(EXPORT repoA-targets</div><div>    DESTINATION ${PROJECT_BINARY_DIR}/lib/</div><div>    )</div><div><br></div><div style>When I build my project (in Visual Studio on Windows) it dumps libraries from all configurations in the same folder which is: </div>

<div style><br></div><div style>${PROJECT_BINARY_DIR}/lib </div><div style><br></div><div style>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.</div>

<div style><br></div><div style>That is only part of the problem. Now in RepoB, I want to import the libraries. CMake documentation here: <a href="http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets">http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets</a></div>

<div style><br></div><div style>states that I can do something like this: </div><div style>include(${PATH_OF_REPO_A_BUILD}/repoA-targets.cmake)</div><div style><br></div><div style>target_link_libraries(repoBExecutable myLib)</div>

<div style><br></div><div style>and CMake should be able to find myLib and correctly add it to the linker&#39;s properties. This does not appear to be working. CMake simply adds &quot;myLib&quot; to the linker instead of &quot;${FULL_PATH_OF_MYLIB}/myLib&quot;. </div>

<div style><br></div><div style>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.</div><div style>

<br></div><div style>Thank you,</div><div style>Saad</div><div style><br></div><div><br></div><div><br></div><div><br></div></div>