Re: [CMake] Installing and exporting multiple configurations of the same library
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. 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. The main reason for the directory structure is to allow existing projects to work while getting the newer projects to rely on CMake. On Sat, Dec 16, 2017 at 2:56 PM Domen Vrankarwrote: > 2017-12-16 0:18 GMT+01:00 Saad Khattak : > >> 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. >> > > A simple solution would be to write > > install(TARGETS ${LIB_NAME} > CONFIGURATIONS DEBUG > EXPORT ${LIB_NAME}Config-d > 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/" > ) > > 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. > > See here for details: > https://cmake.org/cmake/help/latest/command/install.html#installing-exports > . > > Also one thing that you can do is set: > > set(CMAKE_DEBUG_POSTFIX "-debug") > > 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). > > >> 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? >> > > 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: > ${LIB_NAME}Config.cmake and ${LIB_NAME}Config-debug.cmake or > ${LIB_NAME}Config-release.cmake > > 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. > > I hope somebody else will shed some light on this part. > > Regards, > Domen > -- 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:
Re: [CMake] Installing and exporting multiple configurations of the same library
2017-12-16 0:18 GMT+01:00 Saad Khattak: > 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. > A simple solution would be to write install(TARGETS ${LIB_NAME} CONFIGURATIONS DEBUG EXPORT ${LIB_NAME}Config-d 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/" ) 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. See here for details: https://cmake.org/cmake/help/latest/command/install.html#installing-exports. Also one thing that you can do is set: set(CMAKE_DEBUG_POSTFIX "-debug") 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). > 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? > 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: ${LIB_NAME}Config.cmake and ${LIB_NAME}Config-debug.cmake or ${LIB_NAME}Config-release.cmake 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. I hope somebody else will shed some light on this part. Regards, Domen -- 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: https://cmake.org/mailman/listinfo/cmake
[CMake] Installing and exporting multiple configurations of the same library
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 -- 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: https://cmake.org/mailman/listinfo/cmake