Merge topic 'misc-cxx-modules-fixes'

28ece63fee cxxmodules: Fix exported path to installed module sources in subdirs
f2a699261b cxxmodules: Do not expect collator install scripts with no CXX_MODULES
f9677cc122 Tests: Improve RunCMake.CXXModules expectation matching and error reporting

Acked-by: Kitware Robot <kwrobot@kitware.com>
Reviewed-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !8474
This commit is contained in:
Brad King 2023-05-25 13:47:47 +00:00 committed by Kitware Robot
commit cf7b7600c6
33 changed files with 194 additions and 44 deletions

View File

@ -358,6 +358,10 @@ cmDyndepCollation::ParseExportInfo(Json::Value const& tdi)
fsi.Name = tdi_cxx_module_info["name"].asString();
fsi.RelativeDirectory =
tdi_cxx_module_info["relative-directory"].asString();
if (!fsi.RelativeDirectory.empty() &&
fsi.RelativeDirectory.back() != '/') {
fsi.RelativeDirectory = cmStrCat(fsi.RelativeDirectory, '/');
}
fsi.SourcePath = tdi_cxx_module_info["source"].asString();
fsi.Type = tdi_cxx_module_info["type"].asString();
fsi.Visibility = cmFileSetVisibilityFromName(

View File

@ -542,6 +542,12 @@ bool cmExportBuildFileGenerator::GenerateImportCxxModuleConfigTargetInclusion(
os.SetCopyIfDifferent(true);
for (auto const* tgt : this->ExportedTargets) {
// Only targets with C++ module sources will have a
// collator-generated install script.
if (!tgt->HaveCxx20ModuleSources()) {
continue;
}
os << "include(\"${CMAKE_CURRENT_LIST_DIR}/target-" << tgt->GetExportName()
<< '-' << config << ".cmake\")\n";
}

View File

@ -752,6 +752,12 @@ bool cmExportInstallFileGenerator::
auto& prop_files = this->ConfigCxxModuleTargetFiles[config];
for (auto const* tgt : this->ExportedTargets) {
// Only targets with C++ module sources will have a
// collator-generated install script.
if (!tgt->HaveCxx20ModuleSources()) {
continue;
}
auto prop_filename = cmStrCat("target-", tgt->GetExportName(), '-',
filename_config, ".cmake");
prop_files.emplace_back(cmStrCat(dest, prop_filename));

View File

@ -1,4 +1,4 @@
CMake Warning \(dev\) at CMakeLists.txt:7 \(target_sources\):
CMake Warning \(dev\) at CMakeLists.txt:[0-9]+ \(target_sources\):
CMake's C\+\+ module support is experimental. It is meant only for
experimentation and feedback to CMake developers.
This warning is for project developers. Use -Wno-dev to suppress it.

View File

@ -18,10 +18,14 @@ target_sources(export_bmi_and_interfaces
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
importable.cxx)
importable.cxx
subdir/importable.cxx
)
target_compile_features(export_bmi_and_interfaces PUBLIC cxx_std_20)
install(TARGETS export_bmi_and_interfaces
add_library(no_modules STATIC no_modules.cxx)
install(TARGETS export_bmi_and_interfaces no_modules
EXPORT CXXModules
FILE_SET modules DESTINATION "lib/cxx/miu"
CXX_MODULES_BMI DESTINATION "lib/cxx/bmi")

View File

@ -0,0 +1,3 @@
void no_modules()
{
}

View File

@ -0,0 +1,6 @@
export module subdir_importable;
export int from_subdir()
{
return 0;
}

View File

@ -14,19 +14,31 @@ get_property(file_sets TARGET CXXModules::export_bmi_and_interfaces
PROPERTY INTERFACE_CXX_MODULE_SETS)
if (NOT file_sets STREQUAL "modules")
message(FATAL_ERROR
"Incorrect exported file sets in `CXXModules::export_bmi_and_interfaces`: `${file_sets}`")
"Incorrect exported file sets in CXXModules::export_bmi_and_interfaces:\n ${file_sets}")
endif ()
get_property(file_set_files TARGET CXXModules::export_bmi_and_interfaces
PROPERTY CXX_MODULE_SET_modules)
if (NOT file_set_files STREQUAL "${expected_source_dir}/importable.cxx")
set(expected_file_set_files
"${expected_source_dir}/importable.cxx"
"${expected_source_dir}/subdir/importable.cxx"
)
if (NOT file_set_files STREQUAL "${expected_file_set_files}")
message(FATAL_ERROR
"Incorrect exported file set paths in CXXModules::export_bmi_and_interfaces`: `${file_set_files}`")
"Incorrect exported file set paths in CXXModules::export_bmi_and_interfaces:\n ${file_set_files}")
endif ()
get_property(imported_modules TARGET CXXModules::export_bmi_and_interfaces
PROPERTY IMPORTED_CXX_MODULES_DEBUG)
if (NOT imported_modules MATCHES "importable=${expected_source_dir}/importable.cxx,${expected_binary_dir}/CMakeFiles/export_bmi_and_interfaces.dir(/Debug)?/importable.(gcm|pcm|ifc)")
set(expected_imported_modules
"importable=${expected_source_dir}/importable.cxx,${expected_binary_dir}/CMakeFiles/export_bmi_and_interfaces.dir(/Debug)?/importable.(gcm|pcm|ifc)"
"subdir_importable=${expected_source_dir}/subdir/importable.cxx,${expected_binary_dir}/CMakeFiles/export_bmi_and_interfaces.dir(/Debug)?/subdir_importable.(gcm|pcm|ifc)"
)
if (NOT imported_modules MATCHES "^${expected_imported_modules}$")
message(FATAL_ERROR
"Incorrect exported modules in CXXModules::export_bmi_and_interfaces`: `${imported_modules}`")
"Incorrect exported modules in CXXModules::export_bmi_and_interfaces:\n"
" ${imported_modules}\n"
"does not match:\n"
" ${expected_imported_modules}"
)
endif ()

View File

@ -1,4 +1,4 @@
CMake Warning \(dev\) at CMakeLists.txt:7 \(target_sources\):
CMake Warning \(dev\) at CMakeLists.txt:[0-9]+ \(target_sources\):
CMake's C\+\+ module support is experimental. It is meant only for
experimentation and feedback to CMake developers.
This warning is for project developers. Use -Wno-dev to suppress it.

View File

@ -18,10 +18,14 @@ target_sources(export_bmi_and_interfaces
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
importable.cxx)
importable.cxx
subdir/importable.cxx
)
target_compile_features(export_bmi_and_interfaces PUBLIC cxx_std_20)
install(TARGETS export_bmi_and_interfaces
add_library(no_modules STATIC no_modules.cxx)
install(TARGETS export_bmi_and_interfaces no_modules
EXPORT CXXModules
FILE_SET modules DESTINATION "lib/cxx/miu"
CXX_MODULES_BMI DESTINATION "lib/cxx/bmi")

View File

@ -0,0 +1,3 @@
void no_modules()
{
}

View File

@ -0,0 +1,6 @@
export module subdir_importable;
export int from_subdir()
{
return 0;
}

View File

@ -14,19 +14,31 @@ get_property(file_sets TARGET CXXModules::export_bmi_and_interfaces
PROPERTY INTERFACE_CXX_MODULE_SETS)
if (NOT file_sets STREQUAL "modules")
message(FATAL_ERROR
"Incorrect exported file sets in `CXXModules::export_bmi_and_interfaces`: `${file_sets}`")
"Incorrect exported file sets in CXXModules::export_bmi_and_interfaces:\n ${file_sets}")
endif ()
get_property(file_set_files TARGET CXXModules::export_bmi_and_interfaces
PROPERTY CXX_MODULE_SET_modules)
if (NOT file_set_files STREQUAL "${expected_source_dir}/importable.cxx")
set(expected_file_set_files
"${expected_source_dir}/importable.cxx"
"${expected_source_dir}/subdir/importable.cxx"
)
if (NOT file_set_files STREQUAL "${expected_file_set_files}")
message(FATAL_ERROR
"Incorrect exported file set paths in CXXModules::export_bmi_and_interfaces`: `${file_set_files}`")
"Incorrect exported file set paths in CXXModules::export_bmi_and_interfaces:\n ${file_set_files}")
endif ()
get_property(imported_modules TARGET CXXModules::export_bmi_and_interfaces
PROPERTY IMPORTED_CXX_MODULES_DEBUG)
if (NOT imported_modules MATCHES "importable=${expected_source_dir}/importable.cxx,${expected_binary_dir}/importable.(gcm|pcm|ifc)")
set(expected_imported_modules
"importable=${expected_source_dir}/importable.cxx,${expected_binary_dir}/importable.(gcm|pcm|ifc)"
"subdir_importable=${expected_source_dir}/subdir/importable.cxx,${expected_binary_dir}/subdir_importable.(gcm|pcm|ifc)"
)
if (NOT imported_modules MATCHES "^${expected_imported_modules}$")
message(FATAL_ERROR
"Incorrect exported modules in CXXModules::export_bmi_and_interfaces`: `${imported_modules}`")
"Incorrect exported modules in CXXModules::export_bmi_and_interfaces:\n"
" ${imported_modules}\n"
"does not match:\n"
" ${expected_imported_modules}"
)
endif ()

View File

@ -1,4 +1,4 @@
CMake Warning \(dev\) at CMakeLists.txt:7 \(target_sources\):
CMake Warning \(dev\) at CMakeLists.txt:[0-9] \(target_sources\):
CMake's C\+\+ module support is experimental. It is meant only for
experimentation and feedback to CMake developers.
This warning is for project developers. Use -Wno-dev to suppress it.

View File

@ -18,10 +18,14 @@ target_sources(export_interfaces
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
importable.cxx)
importable.cxx
subdir/importable.cxx
)
target_compile_features(export_interfaces PUBLIC cxx_std_20)
install(TARGETS export_interfaces
add_library(no_modules STATIC no_modules.cxx)
install(TARGETS export_interfaces no_modules
EXPORT CXXModules
FILE_SET modules DESTINATION "lib/cxx/miu")
export(EXPORT CXXModules

View File

@ -0,0 +1,3 @@
void no_modules()
{
}

View File

@ -0,0 +1,6 @@
export module subdir_importable;
export int from_subdir()
{
return 0;
}

View File

@ -14,19 +14,31 @@ get_property(file_sets TARGET CXXModules::export_interfaces
PROPERTY INTERFACE_CXX_MODULE_SETS)
if (NOT file_sets STREQUAL "modules")
message(FATAL_ERROR
"Incorrect exported file sets in `CXXModules::export_interfaces`: `${file_sets}`")
"Incorrect exported file sets in CXXModules::export_interfaces:\n ${file_sets}")
endif ()
get_property(file_set_files TARGET CXXModules::export_interfaces
PROPERTY CXX_MODULE_SET_modules)
if (NOT file_set_files STREQUAL "${expected_source_dir}/importable.cxx")
set(expected_file_set_files
"${expected_source_dir}/importable.cxx"
"${expected_source_dir}/subdir/importable.cxx"
)
if (NOT file_set_files STREQUAL "${expected_file_set_files}")
message(FATAL_ERROR
"Incorrect exported file set paths in CXXModules::export_interfaces`: `${file_set_files}`")
"Incorrect exported file set paths in CXXModules::export_interfaces:\n ${file_set_files}")
endif ()
get_property(imported_modules TARGET CXXModules::export_interfaces
PROPERTY IMPORTED_CXX_MODULES_DEBUG)
if (NOT imported_modules MATCHES "importable=${expected_source_dir}/importable.cxx,${expected_binary_dir}/CMakeFiles/export_interfaces.dir(/Debug)?/importable.(gcm|pcm|ifc)")
set(expected_imported_modules
"importable=${expected_source_dir}/importable.cxx,${expected_binary_dir}/CMakeFiles/export_interfaces.dir(/Debug)?/importable.(gcm|pcm|ifc)"
"subdir_importable=${expected_source_dir}/subdir/importable.cxx,${expected_binary_dir}/CMakeFiles/export_interfaces.dir(/Debug)?/subdir_importable.(gcm|pcm|ifc)"
)
if (NOT imported_modules MATCHES "^${expected_imported_modules}$")
message(FATAL_ERROR
"Incorrect exported modules in CXXModules::export_interfaces`: `${imported_modules}`\n`importable=${expected_source_dir}/importable.cxx,${expected_binary_dir}/CMakeFiles/export_interfaces.dir(/Debug)?/importable.(gcm|pcm|ifc)`")
"Incorrect exported modules in CXXModules::export_interfaces:\n"
" ${imported_modules}\n"
"does not match:\n"
" ${expected_imported_modules}"
)
endif ()

View File

@ -1,4 +1,4 @@
CMake Warning \(dev\) at CMakeLists.txt:7 \(target_sources\):
CMake Warning \(dev\) at CMakeLists.txt:[0-9]+ \(target_sources\):
CMake's C\+\+ module support is experimental. It is meant only for
experimentation and feedback to CMake developers.
This warning is for project developers. Use -Wno-dev to suppress it.

View File

@ -18,10 +18,14 @@ target_sources(export_interfaces
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
importable.cxx)
importable.cxx
subdir/importable.cxx
)
target_compile_features(export_interfaces PUBLIC cxx_std_20)
install(TARGETS export_interfaces
add_library(no_modules STATIC no_modules.cxx)
install(TARGETS export_interfaces no_modules
EXPORT CXXModules
FILE_SET modules DESTINATION "lib/cxx/miu")
install(EXPORT CXXModules

View File

@ -0,0 +1,3 @@
void no_modules()
{
}

View File

@ -0,0 +1,6 @@
export module subdir_importable;
export int from_subdir()
{
return 0;
}

View File

@ -14,19 +14,31 @@ get_property(file_sets TARGET CXXModules::export_interfaces
PROPERTY INTERFACE_CXX_MODULE_SETS)
if (NOT file_sets STREQUAL "modules")
message(FATAL_ERROR
"Incorrect exported file sets in `CXXModules::export_interfaces`: `${file_sets}`")
"Incorrect exported file sets in CXXModules::export_interfaces:\n ${file_sets}")
endif ()
get_property(file_set_files TARGET CXXModules::export_interfaces
PROPERTY CXX_MODULE_SET_modules)
if (NOT file_set_files STREQUAL "${expected_source_dir}/importable.cxx")
set(expected_file_set_files
"${expected_source_dir}/importable.cxx"
"${expected_source_dir}/subdir/importable.cxx"
)
if (NOT file_set_files STREQUAL "${expected_file_set_files}")
message(FATAL_ERROR
"Incorrect exported file set paths in CXXModules::export_interfaces`: `${file_set_files}`")
"Incorrect exported file set paths in CXXModules::export_interfaces:\n ${file_set_files}")
endif ()
get_property(imported_modules TARGET CXXModules::export_interfaces
PROPERTY IMPORTED_CXX_MODULES_DEBUG)
if (NOT imported_modules STREQUAL "importable=${expected_source_dir}/importable.cxx")
set(expected_imported_modules
"importable=${expected_source_dir}/importable.cxx"
"subdir_importable=${expected_source_dir}/subdir/importable.cxx"
)
if (NOT imported_modules STREQUAL "${expected_imported_modules}")
message(FATAL_ERROR
"Incorrect exported modules in CXXModules::export_interfaces`: `${imported_modules}`")
"Incorrect exported modules in CXXModules::export_interfaces:\n"
" ${imported_modules}\n"
"does not match:\n"
" ${expected_imported_modules}"
)
endif ()

View File

@ -1,4 +1,4 @@
CMake Warning \(dev\) at CMakeLists.txt:7 \(target_sources\):
CMake Warning \(dev\) at CMakeLists.txt:[0-9]+ \(target_sources\):
CMake's C\+\+ module support is experimental. It is meant only for
experimentation and feedback to CMake developers.
This warning is for project developers. Use -Wno-dev to suppress it.

View File

@ -18,10 +18,14 @@ target_sources(export_interfaces_no_properties
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
importable.cxx)
importable.cxx
subdir/importable.cxx
)
target_compile_features(export_interfaces_no_properties PUBLIC cxx_std_20)
install(TARGETS export_interfaces_no_properties
add_library(no_modules STATIC no_modules.cxx)
install(TARGETS export_interfaces_no_properties no_modules
EXPORT CXXModules
FILE_SET modules DESTINATION "lib/cxx/miu")
export(EXPORT CXXModules

View File

@ -0,0 +1,3 @@
void no_modules()
{
}

View File

@ -0,0 +1,6 @@
export module subdir_importable;
export int from_subdir()
{
return 0;
}

View File

@ -14,14 +14,18 @@ get_property(file_sets TARGET CXXModules::export_interfaces_no_properties
PROPERTY INTERFACE_CXX_MODULE_SETS)
if (NOT file_sets STREQUAL "modules")
message(FATAL_ERROR
"Incorrect exported file sets in `CXXModules::export_interfaces_no_properties`: `${file_sets}`")
"Incorrect exported file sets in CXXModules::export_interfaces_no_properties:\n ${file_sets}")
endif ()
get_property(file_set_files TARGET CXXModules::export_interfaces_no_properties
PROPERTY CXX_MODULE_SET_modules)
if (NOT file_set_files STREQUAL "${expected_dir}/importable.cxx")
set(expected_file_set_files
"${expected_dir}/importable.cxx"
"${expected_dir}/subdir/importable.cxx"
)
if (NOT file_set_files STREQUAL "${expected_file_set_files}")
message(FATAL_ERROR
"Incorrect exported file set paths in CXXModules::export_interfaces_no_properties`: `${file_set_files}`")
"Incorrect exported file set paths in CXXModules::export_interfaces_no_properties:\n ${file_set_files}")
endif ()
get_property(imported_modules_set TARGET CXXModules::export_interfaces_no_properties

View File

@ -1,4 +1,4 @@
CMake Warning \(dev\) at CMakeLists.txt:7 \(target_sources\):
CMake Warning \(dev\) at CMakeLists.txt:[0-9]+ \(target_sources\):
CMake's C\+\+ module support is experimental. It is meant only for
experimentation and feedback to CMake developers.
This warning is for project developers. Use -Wno-dev to suppress it.

View File

@ -18,10 +18,14 @@ target_sources(export_interfaces_no_properties
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
importable.cxx)
importable.cxx
subdir/importable.cxx
)
target_compile_features(export_interfaces_no_properties PUBLIC cxx_std_20)
install(TARGETS export_interfaces_no_properties
add_library(no_modules STATIC no_modules.cxx)
install(TARGETS export_interfaces_no_properties no_modules
EXPORT CXXModules
FILE_SET modules DESTINATION "lib/cxx/miu")
install(EXPORT CXXModules

View File

@ -0,0 +1,3 @@
void no_modules()
{
}

View File

@ -0,0 +1,6 @@
export module subdir_importable;
export int from_subdir()
{
return 0;
}

View File

@ -14,14 +14,18 @@ get_property(file_sets TARGET CXXModules::export_interfaces_no_properties
PROPERTY INTERFACE_CXX_MODULE_SETS)
if (NOT file_sets STREQUAL "modules")
message(FATAL_ERROR
"Incorrect exported file sets in `CXXModules::export_interfaces_no_properties`: `${file_sets}`")
"Incorrect exported file sets in CXXModules::export_interfaces_no_properties:\n ${file_sets}")
endif ()
get_property(file_set_files TARGET CXXModules::export_interfaces_no_properties
PROPERTY CXX_MODULE_SET_modules)
if (NOT file_set_files STREQUAL "${expected_dir}/importable.cxx")
set(expected_file_set_files
"${expected_dir}/importable.cxx"
"${expected_dir}/subdir/importable.cxx"
)
if (NOT file_set_files STREQUAL "${expected_file_set_files}")
message(FATAL_ERROR
"Incorrect exported file set paths in CXXModules::export_interfaces_no_properties`: `${file_set_files}`")
"Incorrect exported file set paths in CXXModules::export_interfaces_no_properties:\n ${file_set_files}")
endif ()
get_property(imported_modules_set TARGET CXXModules::export_interfaces_no_properties