cxxmodules: `install(TARGET ...)`'s `INCLUDES DESTINATION` not set correctly for generated imported targets
I'm trying to export a C++ module aware target with the upcoming support from !8828 (merged). This target not only provides importable module units but some headers as well.
Thus, I'm defining the target like this:
add_library(mylib SHARED)
target_include_directories(mylib
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
target_link_libraries(mylib PUBLIC libc++::std)
target_compile_features(mylib PUBLIC cxx_std_20)
add_library(mylib::mylib ALIAS mylib)
...and installing it like this:
install(
TARGETS mylib
EXPORT ${PROJECT_NAME}-targets
FILE_SET HEADERS
FILE_SET CXX_MODULES DESTINATION "${CMAKE_INSTALL_CXXMODULESDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
I'm only using BUILD_INTERFACE
and not INSTALL_INTERFACE
in the target_include_directories
call. Instead, I'm using the INCLUDES DESTINATION
feature to avoid having to use ${CMAKE_INSTALL_INCLUDEDIR}
in my src/
folder.
While this populates the INTERFACE_INCLUDE_DIRECTORIES
property of the created imported target correctly, the IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES
property stays empty (and the build of the synthetic target fails). However, when I'm using $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
in the target_include_directories
call everything works as expected.
To solve this I tried to apply the logic from cmExportFileGenerator::PopulateIncludeDirectoriesInterface
, which is responsible for the handling of INCLUDES DESTINATION
, to cmExportFileGenerator::PopulateCxxModuleExportProperties
where the IMPORTED_CXX_MODULES_*
properties are created. The result is here: jiixyj/cmake@7f83ba8c This seems to work as expected.
Now while I'm writing this I'm wondering why I need the INCLUDES DESTINATION
at all since I'm using a FILE_SET HEADERS
. I'll try to investigate a bit more...