<div dir="ltr">Thank you Domen for the workaround. With the workaround I'll have to pick the correct CMake config file by directory. I was hoping for one ${LIB_NAME}Config.cmake file for all configurations.<div><br></div><div>I did indeed set the postfix, however our current build requirements (since we have a mix of CMake and non-CMake enabled projects) dictate the specific folder structure. Otherwise, I would be fine with the configuration postfix.<br><div><br></div><div>The main reason for the directory structure is to allow existing projects to work while getting the newer projects to rely on CMake.</div><div><div><div><br><div class="gmail_quote"><div dir="ltr">On Sat, Dec 16, 2017 at 2:56 PM Domen Vrankar <<a href="mailto:domen.vrankar@gmail.com" target="_blank">domen.vrankar@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">2017-12-16 0:18 GMT+01:00 Saad Khattak <span dir="ltr"><<a href="mailto:saadrustam@gmail.com" target="_blank">saadrustam@gmail.com</a>></span>:<br></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>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.</div><div><br></div><div>Installing without worrying about configurations looks like this:</div><div><br></div><div><div>    install(TARGETS ${LIB_NAME}</div><div>        EXPORT ${LIB_NAME}Config<br></div><div>        PUBLIC_HEADER DESTINATION "include/${LIB_NAME}"</div><div>        LIBRARY DESTINATION "bin/${LIB_NAME}/"</div><div>        ARCHIVE DESTINATION "lib/${LIB_NAME}/"</div><div>        )</div></div><div><br></div><div>However, different configurations overwrite the binaries. So instead, I did something like this (I'm going over all my configurations in a foreach):</div><div><br></div><div><div>    install(TARGETS ${LIB_NAME}</div><div>        CONFIGURATIONS DEBUG</div><div>        EXPORT ${LIB_NAME}Config<br></div><div>        PUBLIC_HEADER DESTINATION "include/${LIB_NAME}"</div><div>        LIBRARY DESTINATION "bin/${LIB_NAME}/debug/"</div><div>        ARCHIVE DESTINATION "lib/${LIB_NAME}/debug"</div><div>        )</div></div><div><br></div><div><div>    install(TARGETS ${LIB_NAME}</div><div>        CONFIGURATIONS RELEASE</div><div>        EXPORT ${LIB_NAME}Config<br></div><div>        PUBLIC_HEADER DESTINATION "include/${LIB_NAME}"</div><div>        LIBRARY DESTINATION "bin/${LIB_NAME}/release/"</div><div>        ARCHIVE DESTINATION "lib/${LIB_NAME}/release/"</div><div>        )</div></div><div><br></div><div>however, that results in the error:</div><div>CMake Error: INSTALL(EXPORT ...) includes target "MyLibrary" more than once in the export set.</div><div><br></div><div>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.</div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>A simple solution would be to write</div><div><br></div><div></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>    install(TARGETS ${LIB_NAME}</div><div>        CONFIGURATIONS DEBUG</div></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>        EXPORT ${LIB_NAME}Config-d<br></div></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>        PUBLIC_HEADER DESTINATION "include/${LIB_NAME}"</div><div>        LIBRARY DESTINATION "bin/${LIB_NAME}/debug/"</div><div>        ARCHIVE DESTINATION "lib/${LIB_NAME}/debug"</div><div>        )</div></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>    install(TARGETS ${LIB_NAME}</div><div>        CONFIGURATIONS RELEASE</div><div>        EXPORT ${LIB_NAME}Config<br></div><div>        PUBLIC_HEADER DESTINATION "include/${LIB_NAME}"</div><div>        LIBRARY DESTINATION "bin/${LIB_NAME}/release/"</div><div>        ARCHIVE DESTINATION "lib/${LIB_NAME}/release/"</div><div>        )</div><div><br></div></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>and then use FILE parameter for install(EXPORT ... FILE ${LIB_NAME}Config.cmake ...) command to rename the file from ${LIB_NAME}Config-d.cmake to ${LIB_NAME}Config.cmake.</div><div><br></div><div>See here for details: <a href="https://cmake.org/cmake/help/latest/command/install.html#installing-exports" target="_blank">https://cmake.org/cmake/help/latest/command/install.html#installing-exports</a>.</div><div><br></div><div>Also one thing that you can do is set:</div><div><br></div><div>set(CMAKE_DEBUG_POSTFIX "-debug")</div><div><br></div><div>so that your libraries when built in Debug mode will automatically get -debug suffix (example: my_lib.so for Release and my_lib-debug.so for debug). This way you don't need to install the library in two separate sub directories (named debug/ and release/ in your case).<br></div></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>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:</div><div><br></div><div>lib/${LIB_NAME}/${CONFIG}/libname</div><div><br></div><div>Any way to get CMake to install the libraries this way?</div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Not certain what the intended way of doing this debug/releas export on Linux is as you can only build one build type at a time but the install(EXPORT ...) command already generates:</div><div class="gmail_quote">${LIB_NAME}Config.cmake and ${LIB_NAME}Config-debug.cmake or ${LIB_NAME}Config-release.cmake</div><div class="gmail_quote"><br></div><div class="gmail_quote">If you install the files in two separate directories and diff them you'll notice that ${LIB_NAME}Config.cmake files (and Version files if you generate one) are the same and -debug.cmake and -release.cmake differ so possibly it's intended to simply override the two files and don't care about it since the build specific files are exported under different names and included automatically in ${LIB_NAME}Config.cmake file anyway.<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">I hope somebody else will shed some light on this part.</div><div class="gmail_quote"><br></div><div class="gmail_quote">Regards,</div><div class="gmail_quote">Domen<br></div></div></div>
</blockquote></div></div></div></div></div></div>