I am trying to export some targets I have in a project, and I've been using the install command for that. I need to export and install both Debug and Release configurations since I need to export some of the targets to clients that will use them in development and need to do debugging. However I can't get the my_export-debug.cmake no matter what I do.
What I'm doing is basically the pseudo-code bellow:
install(TARGETS ${my_targets} EXPORT my_export CONFIGURATIONS Debug;Release Runtime DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS Debug;Release ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS Debug;Release)
install(EXPORT my_export DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake CONFIGURATIONS Debug;Release)
However, once I install I only get the my_export.cmake and my_export-release.cmake files, and when I try to use them in the installation the Debug version does not work (since there are no Debug imported targets, only the release ones).
In the my_export.cmake I see the code
file(GLOB _cmake_config_files "${CMAKE_CURRENT_LIST_DIR}/my_export-*.cmake")
foreach(_cmake_config_file IN LISTS _cmake_config_files)
include("${_cmake_config_file}")
endforeach()
so if I had the my_export-debug.cmake file I would have the debug exported targets. Why is this happening and how can I export debug targets?
Edit: I found a solution. There were two problems: first I didn't pass the --config argument when calling cmake --install, which I needed to since I am using a multiconfig generator (visual studio). So I need to call cmake --install twice with the Debug and Release configurations each time. Second, the targets have to be installed to different locations depending on the configuration. That can be achieved with the $<CONFIG> generator expression. However I prefer to use $<LOWER_CASE:$<CONFIG>> since it's better to use lower case paths. So the install command is changed to
install(TARGETS ${my_targets} EXPORT my_export CONFIGURATIONS Debug;Release Runtime DESTINATION ${CMAKE_INSTALL_LIBDIR}/$<LOWER_CASE:$<CONFIG>> CONFIGURATIONS Debug;Release ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/$<LOWER_CASE:$<CONFIG>> CONFIGURATIONS Debug;Release)
I hope this helps someone else as well.
I found a solution. There were two problems: first I didn't pass the --config argument when calling cmake --install, which I needed to since I am using a multiconfig generator (visual studio). So I need to call cmake --install twice with the Debug and Release configurations each time. Second, the targets have to be installed to different locations depending on the configuration. That can be achieved with the $ generator expression. However I prefer to use $<LOWER_CASE:$> since it's better to use lower case paths. So the install command is changed to
I hope this helps someone else as well.