cxxmodules: Multiple rules generated for C++ modules (Ninja Multi-Config)
I am using:
- CMake 3.28.1
- Ninja 1.11.1
- clang-17
As I want my project (https://github.com/mpusz/mp-units) to be distributed both with "old-style" headers and with C++ modules as well, my module interface units just include the header files. This means that I need to install those headers as well and specify them in the CMake target's interface. More details can be found at https://github.com/mpusz/mp-units/blob/master/src/cmake/AddMPUnitsModule.cmake.
Here is a simplified code:
add_library(my_library)
target_sources(my_library PUBLIC FILE_SET HEADERS BASE_DIRS include
FILES
include/my_library/my_library.h
)
target_include_directories(my_library PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>
)
target_sources(my_library PUBLIC FILE_SET CXX_MODULES
FILES
my_library.cpp
)
target_compile_features(my_library PUBLIC cxx_std_20)
install(TARGETS my_library EXPORT my_libraryTargets
FILE_SET HEADERS
FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_LIBDIR}/miu
)
The problem is that when I want to use an installed target, I get the error from Ninja stating that multiple rules generate the same target.
A simple repro project is attached here: bug.tgz
To reproduce the issue:
cd my_library
mkdir build && cd build
cmake .. -DCMAKE_CXX_COMPILER=clang-17 -G "Ninja Multi-Config"
cmake --build . --config Release
cmake --install . --config Release --prefix ../../local
cd ../../application
mkdir build && cd build
cmake .. -DCMAKE_CXX_COMPILER=clang-17 -G "Ninja Multi-Config" -DCMAKE_INSTALL_PREFIX=../../local
cmake --build . --config Release