From 5b16a0e5682b1020e75abe1c38595c4e9d0af23b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 11:28:44 -0500 Subject: [PATCH 01/14] cmGlobalVisualStudio7Generator: make `SupportsCxxModuleDyndep` protected The generator target will want to ask this question when determining whether C++ modules are supported or not. --- Source/cmGlobalVisualStudio7Generator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 15944576b2..6f6109e95a 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -115,6 +115,8 @@ public: cmIDEFlagTable const* ExtraFlagTable; + virtual bool SupportsCxxModuleDyndep() const { return false; } + protected: cmGlobalVisualStudio7Generator(cmake* cm, std::string const& platformInGeneratorName); @@ -158,8 +160,6 @@ protected: cmValue typeGuid, const std::set>>& dependencies) = 0; - virtual bool SupportsCxxModuleDyndep() const { return false; } - std::string ConvertToSolutionPath(const std::string& path); std::set IsPartOfDefaultBuild( From fce359c5de6dbcdbc29835f4e77e02020fbd4874 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 11:29:41 -0500 Subject: [PATCH 02/14] cmGlobalVisualStudioVersionedGenerator: support dyndep in VS2022 and up --- Source/cmGlobalVisualStudioVersionedGenerator.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h index 2e573ec8cf..39364c6cff 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.h +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -46,6 +46,11 @@ public: const char* GetAndroidApplicationTypeRevision() const override; + bool SupportsCxxModuleDyndep() const override + { + return this->Version >= cmGlobalVisualStudioGenerator::VSVersion::VS17; + } + protected: cmGlobalVisualStudioVersionedGenerator( VSVersion version, cmake* cm, const std::string& name, From 9ee7ee1fc208bef5f6fb65607dfd08e0966351ee Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 11:30:15 -0500 Subject: [PATCH 03/14] cmGlobalVisualStudioVersionedGenerator: check for C++ module support --- Source/cmGlobalVisualStudioVersionedGenerator.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h index 39364c6cff..4c69aeb2ed 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.h +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -46,6 +46,11 @@ public: const char* GetAndroidApplicationTypeRevision() const override; + bool CheckCxxModuleSupport() override + { + this->CxxModuleSupportCheck(); + return this->SupportsCxxModuleDyndep(); + } bool SupportsCxxModuleDyndep() const override { return this->Version >= cmGlobalVisualStudioGenerator::VSVersion::VS17; From b0283aaa7ca4b6e3020798ef20cee9f827ce16fc Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 11:30:34 -0500 Subject: [PATCH 04/14] cmVisualStudio10TargetGenerator: ask the generator for dyndep support --- Source/cmVisualStudio10TargetGenerator.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index e06dc9b42f..4097f95c36 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -356,7 +356,8 @@ void cmVisualStudio10TargetGenerator::Generate() this->GeneratorTarget->CheckCxxModuleStatus(config); } - if (this->GeneratorTarget->HaveCxx20ModuleSources()) { + if (this->GeneratorTarget->HaveCxx20ModuleSources() && + !this->GlobalGenerator->SupportsCxxModuleDyndep()) { this->Makefile->IssueMessage( MessageType::FATAL_ERROR, cmStrCat("The \"", this->GeneratorTarget->GetName(), From f0899e46fb52332c868f2246f99cea8cfd08384e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 23 Nov 2022 20:28:24 -0500 Subject: [PATCH 05/14] cmVisualStudio10TargetGenerator: write C++ module elements --- Source/cmVisualStudio10TargetGenerator.cxx | 40 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 4097f95c36..ef4bcf873a 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2711,6 +2711,8 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } for (std::string const& config : this->Configurations) { + this->GeneratorTarget->NeedCxxModuleSupport(lang, config); + std::string configUpper = cmSystemTools::UpperCase(config); std::string configDefines = defines; std::string defPropName = cmStrCat("COMPILE_DEFINITIONS_", configUpper); @@ -2723,6 +2725,31 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( configDefines += *ccdefs; } + bool const shouldScanForModules = lang == "CXX"_s && + this->GeneratorTarget->NeedDyndepForSource(lang, config, source); + auto const* fs = + this->GeneratorTarget->GetFileSetForSource(config, source); + const char* compileAsPerConfig = compileAs; + if (fs && + (fs->GetType() == "CXX_MODULES"_s || + fs->GetType() == "CXX_MODULE_HEADER_UNITS"_s)) { + if (lang == "CXX"_s) { + if (fs->GetType() == "CXX_MODULES"_s) { + compileAsPerConfig = "CompileAsCppModule"; + } else { + compileAsPerConfig = "CompileAsHeaderUnit"; + } + } else { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat( + "Target \"", this->GeneratorTarget->Target->GetName(), + "\" contains the source\n ", source->GetFullPath(), + "\nin a file set of type \"", fs->GetType(), + R"(" but the source is not classified as a "CXX" source.)")); + } + } + // We have pch state in the following situation: // 1. We have SKIP_PRECOMPILE_HEADERS == true // 2. We are creating the pre-compiled header @@ -2745,8 +2772,8 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( // if we have flags or defines for this config then // use them if (!flags.empty() || !options.empty() || !configDefines.empty() || - !includes.empty() || compileAs || noWinRT || !options.empty() || - needsPCHFlags) { + !includes.empty() || compileAsPerConfig || noWinRT || + !options.empty() || needsPCHFlags) { cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator; cmIDEFlagTable const* flagtable = nullptr; const std::string& srclang = source->GetLanguage(); @@ -2771,8 +2798,13 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( cmVS10GeneratorOptions clOptions( this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler, flagtable, this); - if (compileAs) { - clOptions.AddFlag("CompileAs", compileAs); + if (compileAsPerConfig) { + clOptions.AddFlag("CompileAs", compileAsPerConfig); + } + if (shouldScanForModules) { + clOptions.AddFlag("ScanSourceforModuleDependencies", "true"); + } else { + clOptions.AddFlag("ScanSourceforModuleDependencies", "false"); } if (noWinRT) { clOptions.AddFlag("CompileAsWinRT", "false"); From 7eb9b458618976181bb58f3077cb3170cdcb5fe6 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 11:33:23 -0500 Subject: [PATCH 06/14] Tests/RunCMake/CXXModules: mask scanning checks without control In Visual Studio, there is no mechanism to tell scanning apart from non-scanning, so skip the sanity checks. --- .../examples/scan_properties-stderr.txt | 2 +- .../examples/scan_properties/CMakeLists.txt | 7 +++++++ .../examples/scan_properties/always_scan.cxx | 6 ++++-- .../CXXModules/examples/scan_properties/join.cxx | 16 +++++++++------- .../CXXModules/examples/scan_properties/main.cxx | 16 +++++++++------- .../examples/scan_properties/module.cxx | 6 ++++-- .../examples/scan_properties/never_scan.cxx | 6 ++++-- 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties-stderr.txt b/Tests/RunCMake/CXXModules/examples/scan_properties-stderr.txt index 7d79bad01c..2cb59579b1 100644 --- a/Tests/RunCMake/CXXModules/examples/scan_properties-stderr.txt +++ b/Tests/RunCMake/CXXModules/examples/scan_properties-stderr.txt @@ -1,4 +1,4 @@ -CMake Warning \(dev\) at CMakeLists.txt:20 \(target_sources\): +CMake Warning \(dev\) at CMakeLists.txt:25 \(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. diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt index 551c55c2f5..f2f1c38bf4 100644 --- a/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt @@ -3,6 +3,11 @@ project(scan_properties CXX) include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") +set(scanning_control 1) +if (CMAKE_GENERATOR MATCHES "Visual Studio") + set(scanning_control 0) +endif () + # To detect that not-to-be scanned sources are not scanned, add a `-D` to the # scan flags so that the files can detect whether scanning happened and error # if not. @@ -31,6 +36,7 @@ target_sources(scans_everything module.cxx) target_compile_features(scans_everything PRIVATE cxx_std_20) target_compile_definitions(scans_everything PRIVATE SCAN_AT_TARGET_LEVEL=1) +target_compile_definitions(scans_everything PRIVATE "SCANNING_CONTROL=${scanning_control}") set(CMAKE_CXX_SCAN_FOR_MODULES 0) @@ -49,6 +55,7 @@ target_sources(no_scan_everything module.cxx) target_compile_features(no_scan_everything PRIVATE cxx_std_20) target_compile_definitions(no_scan_everything PRIVATE SCAN_AT_TARGET_LEVEL=0) +target_compile_definitions(no_scan_everything PRIVATE "SCANNING_CONTROL=${scanning_control}") add_test(NAME scanned COMMAND scans_everything) add_test(NAME unscanned COMMAND no_scan_everything) diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/always_scan.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/always_scan.cxx index 27087d7b5c..c3d449e5b0 100644 --- a/Tests/RunCMake/CXXModules/examples/scan_properties/always_scan.cxx +++ b/Tests/RunCMake/CXXModules/examples/scan_properties/always_scan.cxx @@ -1,5 +1,7 @@ -#ifndef CMAKE_SCANNED_THIS_SOURCE -# error "This file should have been scanned" +#if SCANNING_CONTROL +# ifndef CMAKE_SCANNED_THIS_SOURCE +# error "This file should have been scanned" +# endif #endif import M; diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/join.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/join.cxx index 8184a403fb..4ba23a68c4 100644 --- a/Tests/RunCMake/CXXModules/examples/scan_properties/join.cxx +++ b/Tests/RunCMake/CXXModules/examples/scan_properties/join.cxx @@ -1,10 +1,12 @@ -#if SCAN_AT_TARGET_LEVEL -# ifndef CMAKE_SCANNED_THIS_SOURCE -# error "This file should have been scanned" -# endif -#else -# ifdef CMAKE_SCANNED_THIS_SOURCE -# error "This file should not have been scanned" +#if SCANNING_CONTROL +# if SCAN_AT_TARGET_LEVEL +# ifndef CMAKE_SCANNED_THIS_SOURCE +# error "This file should have been scanned" +# endif +# else +# ifdef CMAKE_SCANNED_THIS_SOURCE +# error "This file should not have been scanned" +# endif # endif #endif diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/main.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/main.cxx index 81e93f4793..2c7ec3e3c7 100644 --- a/Tests/RunCMake/CXXModules/examples/scan_properties/main.cxx +++ b/Tests/RunCMake/CXXModules/examples/scan_properties/main.cxx @@ -1,10 +1,12 @@ -#if SCAN_AT_TARGET_LEVEL -# ifndef CMAKE_SCANNED_THIS_SOURCE -# error "This file should have been scanned" -# endif -#else -# ifdef CMAKE_SCANNED_THIS_SOURCE -# error "This file should not have been scanned" +#if SCANNING_CONTROL +# if SCAN_AT_TARGET_LEVEL +# ifndef CMAKE_SCANNED_THIS_SOURCE +# error "This file should have been scanned" +# endif +# else +# ifdef CMAKE_SCANNED_THIS_SOURCE +# error "This file should not have been scanned" +# endif # endif #endif diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/module.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/module.cxx index ad1e04dece..fe84261d5f 100644 --- a/Tests/RunCMake/CXXModules/examples/scan_properties/module.cxx +++ b/Tests/RunCMake/CXXModules/examples/scan_properties/module.cxx @@ -1,5 +1,7 @@ -#ifndef CMAKE_SCANNED_THIS_SOURCE -# error "This file should have been scanned" +#if SCANNING_CONTROL +# ifndef CMAKE_SCANNED_THIS_SOURCE +# error "This file should have been scanned" +# endif #endif export module M; diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx index 8374110cee..b47510bfc9 100644 --- a/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx +++ b/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx @@ -1,5 +1,7 @@ -#ifdef CMAKE_SCANNED_THIS_SOURCE -# error "This file should not have been scanned" +#if SCANNING_CONTROL +# ifdef CMAKE_SCANNED_THIS_SOURCE +# error "This file should not have been scanned" +# endif #endif int never_scan() From 4a4ce031cd99727e2adea42c1531c2626024dc48 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 11:34:06 -0500 Subject: [PATCH 07/14] Tests/RunCMake/CXXModules: catch VS circular error message --- Tests/RunCMake/CXXModules/examples/circular-build-stdout.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/RunCMake/CXXModules/examples/circular-build-stdout.txt b/Tests/RunCMake/CXXModules/examples/circular-build-stdout.txt index 433b46145e..ac80356b28 100644 --- a/Tests/RunCMake/CXXModules/examples/circular-build-stdout.txt +++ b/Tests/RunCMake/CXXModules/examples/circular-build-stdout.txt @@ -1 +1 @@ -(Ninja generators)?(build stopped: dependency cycle:) +((Ninja generators)?(build stopped: dependency cycle:)|(Visual Studio generators)?(error : Cannot build the following source files because there is a cyclic dependency between them)) From 736123464f421e7149061663d1cd6da8d975654e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 1 Dec 2022 09:12:30 -0500 Subject: [PATCH 08/14] Tests/RunCMake/CXXModules: update `NoDyndepSupport` for VS2019 and older --- Tests/RunCMake/CXXModules/NoDyndepSupport-stderr.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/RunCMake/CXXModules/NoDyndepSupport-stderr.txt b/Tests/RunCMake/CXXModules/NoDyndepSupport-stderr.txt index 52f781fa3b..2bee19ffb1 100644 --- a/Tests/RunCMake/CXXModules/NoDyndepSupport-stderr.txt +++ b/Tests/RunCMake/CXXModules/NoDyndepSupport-stderr.txt @@ -22,6 +22,11 @@ CMake Error: by the generator ( +CMake Warning \(dev\): + C\+\+20 modules support via CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP is + experimental. It is meant only for compiler developers to try. +This warning is for project developers. Use -Wno-dev to suppress it. +)?( CMake Error in CMakeLists.txt: The "nodyndep" target contains C\+\+ module sources which are not supported by the generator From ef03a3a2f534d694d0a58ce610db152d28abb1d7 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 11:34:31 -0500 Subject: [PATCH 09/14] Tests/RunCMake/CXXModules: factor out generator support detection This keeps the condition to a readable limit. --- Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index 81a086af5a..73853a09a5 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -36,10 +36,15 @@ if (RunCMake_GENERATOR MATCHES "Ninja") endif () endif () +set(generator_supports_cxx_modules 0) +if (RunCMake_GENERATOR MATCHES "Ninja" AND + ninja_version VERSION_GREATER_EQUAL "1.10" AND + "cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) + set(generator_supports_cxx_modules 1) +endif () + # Test behavior when the generator does not support C++20 modules. -if (NOT RunCMake_GENERATOR MATCHES "Ninja" OR - ninja_version VERSION_LESS "1.10" OR - NOT "cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) +if (NOT generator_supports_cxx_modules) if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) run_cmake(NoDyndepSupport) endif () From 069a32b03c812569a143e09e7025be76995495a6 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 11:35:37 -0500 Subject: [PATCH 10/14] Tests/RunCMake/CXXModules: split out collation-requiring tests Visual Studio does not currently have a place to insert the logic required to implement this test, so skip it if possible. --- .gitlab/ci/configure_linux_gcc_cxx_modules_ninja.cmake | 2 +- .../ci/configure_linux_gcc_cxx_modules_ninja_multi.cmake | 2 +- .gitlab/ci/configure_windows_msvc_cxx_modules_common.cmake | 2 +- Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 6 +++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitlab/ci/configure_linux_gcc_cxx_modules_ninja.cmake b/.gitlab/ci/configure_linux_gcc_cxx_modules_ninja.cmake index 2b04e89947..110df76458 100644 --- a/.gitlab/ci/configure_linux_gcc_cxx_modules_ninja.cmake +++ b/.gitlab/ci/configure_linux_gcc_cxx_modules_ninja.cmake @@ -1,4 +1,4 @@ -set(CMake_TEST_MODULE_COMPILATION "named,partitions,internal_partitions,export_bmi,install_bmi" CACHE STRING "") +set(CMake_TEST_MODULE_COMPILATION "named,collation,partitions,internal_partitions,export_bmi,install_bmi" CACHE STRING "") set(CMake_TEST_MODULE_COMPILATION_RULES "${CMAKE_CURRENT_LIST_DIR}/cxx_modules_rules_gcc.cmake" CACHE STRING "") include("${CMAKE_CURRENT_LIST_DIR}/configure_external_test.cmake") diff --git a/.gitlab/ci/configure_linux_gcc_cxx_modules_ninja_multi.cmake b/.gitlab/ci/configure_linux_gcc_cxx_modules_ninja_multi.cmake index 2b04e89947..110df76458 100644 --- a/.gitlab/ci/configure_linux_gcc_cxx_modules_ninja_multi.cmake +++ b/.gitlab/ci/configure_linux_gcc_cxx_modules_ninja_multi.cmake @@ -1,4 +1,4 @@ -set(CMake_TEST_MODULE_COMPILATION "named,partitions,internal_partitions,export_bmi,install_bmi" CACHE STRING "") +set(CMake_TEST_MODULE_COMPILATION "named,collation,partitions,internal_partitions,export_bmi,install_bmi" CACHE STRING "") set(CMake_TEST_MODULE_COMPILATION_RULES "${CMAKE_CURRENT_LIST_DIR}/cxx_modules_rules_gcc.cmake" CACHE STRING "") include("${CMAKE_CURRENT_LIST_DIR}/configure_external_test.cmake") diff --git a/.gitlab/ci/configure_windows_msvc_cxx_modules_common.cmake b/.gitlab/ci/configure_windows_msvc_cxx_modules_common.cmake index 8570196c26..38dd7293d4 100644 --- a/.gitlab/ci/configure_windows_msvc_cxx_modules_common.cmake +++ b/.gitlab/ci/configure_windows_msvc_cxx_modules_common.cmake @@ -1,2 +1,2 @@ -set(CMake_TEST_MODULE_COMPILATION "named,partitions,internal_partitions,shared,export_bmi,install_bmi" CACHE STRING "") +set(CMake_TEST_MODULE_COMPILATION "named,collation,partitions,internal_partitions,shared,export_bmi,install_bmi" CACHE STRING "") set(CMake_TEST_MODULE_COMPILATION_RULES "${CMAKE_CURRENT_LIST_DIR}/cxx_modules_rules_msvc.cmake" CACHE STRING "") diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index 73853a09a5..b6eb340de6 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -137,7 +137,6 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(simple) run_cxx_module_test(library library-static -DBUILD_SHARED_LIBS=OFF) run_cxx_module_test(generated) - run_cxx_module_test(public-req-private) run_cxx_module_test(deep-chain) run_cxx_module_test(duplicate) set(RunCMake_CXXModules_NO_TEST 1) @@ -146,6 +145,11 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(scan_properties) endif () +# Tests which require collation work. +if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION) + run_cxx_module_test(public-req-private) +endif () + # Tests which use named modules in shared libraries. if ("shared" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(library library-shared -DBUILD_SHARED_LIBS=ON) From 388acfd46dd33d574c46ad640215f56fb576da66 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 11:36:14 -0500 Subject: [PATCH 11/14] Tests/RunCMake/CXXModules: add support for Visual Studio --- Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 7 +++++++ Tests/RunCMake/CXXModules/compiler_introspection.cmake | 1 + 2 files changed, 8 insertions(+) diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index b6eb340de6..01d59f8ad7 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -43,6 +43,11 @@ if (RunCMake_GENERATOR MATCHES "Ninja" AND set(generator_supports_cxx_modules 1) endif () +if (RunCMake_GENERATOR MATCHES "Visual Studio" AND + CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "19.34") + set(generator_supports_cxx_modules 1) +endif () + # Test behavior when the generator does not support C++20 modules. if (NOT generator_supports_cxx_modules) if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) @@ -84,6 +89,8 @@ if (RunCMake_GENERATOR MATCHES "Ninja") run_cmake(NinjaDependInfoFileSet) run_cmake(NinjaDependInfoExport) run_cmake(NinjaDependInfoBMIInstall) +elseif (RunCMake_GENERATOR MATCHES "Visual Studio") + # Not supported yet. else () message(FATAL_ERROR "Please add 'DependInfo' tests for the '${RunCMake_GENERATOR}' generator.") diff --git a/Tests/RunCMake/CXXModules/compiler_introspection.cmake b/Tests/RunCMake/CXXModules/compiler_introspection.cmake index 7a2df3d35e..0e61383b09 100644 --- a/Tests/RunCMake/CXXModules/compiler_introspection.cmake +++ b/Tests/RunCMake/CXXModules/compiler_introspection.cmake @@ -20,6 +20,7 @@ string(APPEND info "\ set(CMAKE_CXX_COMPILE_FEATURES \"${CMAKE_CXX_COMPILE_FEATURES}\") set(CMAKE_MAKE_PROGRAM \"${CMAKE_MAKE_PROGRAM}\") set(forced_cxx_standard \"${forced_cxx_standard}\") +set(CMAKE_CXX_COMPILER_VERSION \"${CMAKE_CXX_COMPILER_VERSION}\") ") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "${info}") From 82833fb3c0f6253bec69db683d3358b4c820b99b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 12:07:02 -0500 Subject: [PATCH 12/14] Help/dev/experimental: document C++20 module limitations --- Help/dev/experimental.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Help/dev/experimental.rst b/Help/dev/experimental.rst index 03eb0762b5..581cdb4b59 100644 --- a/Help/dev/experimental.rst +++ b/Help/dev/experimental.rst @@ -24,6 +24,31 @@ In order to support C++20 modules, there are a number of behaviors that have CMake APIs to provide the required features to build and export them from a project. +Limitations +----------- + +There are a number of known limitations of the current C++20 module support in +CMake. This does not document known limitations or bugs in compilers as these +can change over time. + +For all generators: + +- Only in-project modules may be used. While there is some support for + exporting module information, there is no mechanism for using it at the + moment. + +For the Ninja Generators: + +- ``ninja`` 1.10 or newer is required. + +For the Visual Studio Generators: + +- Only Visual Studio 2022 and toolchains newer than 19.34 (Visual Studio + 17.4). +- No support for exporting or installing BMI or module information. +- No diagnosis of using modules provided by ``PRIVATE`` sources from + ``PUBLIC`` module sources. + C++20 Module Dependencies ========================= From 2991e92ea7f0ad0497221028e67192bc26aa83d9 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 12:13:35 -0500 Subject: [PATCH 13/14] cmExperimental: recycle C++20 module support UUID Visual Studio support warrants a new ID. --- Help/dev/experimental.rst | 2 +- Source/cmExperimental.cxx | 2 +- Tests/RunCMake/CXXModules/CMakeLists.txt | 2 +- Tests/RunCMake/CXXModules/examples/cxx-modules-rules.cmake | 2 +- .../examples/export-bmi-and-interface-build/test/CMakeLists.txt | 2 +- .../export-bmi-and-interface-install/test/CMakeLists.txt | 2 +- .../examples/export-interface-build/test/CMakeLists.txt | 2 +- .../examples/export-interface-install/test/CMakeLists.txt | 2 +- .../target_sources/FileSetDefaultWrongTypeExperimental.cmake | 2 +- .../RunCMake/target_sources/FileSetWrongTypeExperimental.cmake | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Help/dev/experimental.rst b/Help/dev/experimental.rst index 581cdb4b59..794a686f91 100644 --- a/Help/dev/experimental.rst +++ b/Help/dev/experimental.rst @@ -18,7 +18,7 @@ C++20 Module APIs ================= Variable: ``CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API`` -Value: ``3c375311-a3c9-4396-a187-3227ef642046`` +Value: ``9629ab6c-6c0e-423f-bb9d-cc5ac4a22041`` In order to support C++20 modules, there are a number of behaviors that have CMake APIs to provide the required features to build and export them from a diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index 922b53fd11..bbb5840e66 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -27,7 +27,7 @@ struct FeatureData bool Warned; } LookupTable[] = { // CxxModuleCMakeApi - { "3c375311-a3c9-4396-a187-3227ef642046", + { "9629ab6c-6c0e-423f-bb9d-cc5ac4a22041", "CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API", "CMake's C++ module support is experimental. It is meant only for " "experimentation and feedback to CMake developers.", diff --git a/Tests/RunCMake/CXXModules/CMakeLists.txt b/Tests/RunCMake/CXXModules/CMakeLists.txt index 708d92ce4f..461199966c 100644 --- a/Tests/RunCMake/CXXModules/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.23) project(${RunCMake_TEST} NONE) -set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046") +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "9629ab6c-6c0e-423f-bb9d-cc5ac4a22041") include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CXXModules/examples/cxx-modules-rules.cmake b/Tests/RunCMake/CXXModules/examples/cxx-modules-rules.cmake index 381094ea4e..9768543e24 100644 --- a/Tests/RunCMake/CXXModules/examples/cxx-modules-rules.cmake +++ b/Tests/RunCMake/CXXModules/examples/cxx-modules-rules.cmake @@ -1,4 +1,4 @@ -set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046") +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "9629ab6c-6c0e-423f-bb9d-cc5ac4a22041") if (NOT EXISTS "${CMake_TEST_MODULE_COMPILATION_RULES}") message(FATAL_ERROR diff --git a/Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-build/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-build/test/CMakeLists.txt index b814b3bf78..20e4b2bb32 100644 --- a/Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-build/test/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-build/test/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.24) project(cxx_modules_library NONE) -set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046") +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "9629ab6c-6c0e-423f-bb9d-cc5ac4a22041") find_package(export_bmi_and_interfaces REQUIRED) diff --git a/Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-install/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-install/test/CMakeLists.txt index db0484d74d..4fd9dca0aa 100644 --- a/Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-install/test/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-install/test/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.24) project(cxx_modules_library NONE) -set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046") +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "9629ab6c-6c0e-423f-bb9d-cc5ac4a22041") find_package(export_bmi_and_interfaces REQUIRED) diff --git a/Tests/RunCMake/CXXModules/examples/export-interface-build/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-interface-build/test/CMakeLists.txt index 6145210d38..80f7c36ede 100644 --- a/Tests/RunCMake/CXXModules/examples/export-interface-build/test/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/export-interface-build/test/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.24) project(cxx_modules_library NONE) -set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046") +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "9629ab6c-6c0e-423f-bb9d-cc5ac4a22041") find_package(export_interfaces REQUIRED) diff --git a/Tests/RunCMake/CXXModules/examples/export-interface-install/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-interface-install/test/CMakeLists.txt index 6145210d38..80f7c36ede 100644 --- a/Tests/RunCMake/CXXModules/examples/export-interface-install/test/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/export-interface-install/test/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.24) project(cxx_modules_library NONE) -set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046") +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "9629ab6c-6c0e-423f-bb9d-cc5ac4a22041") find_package(export_interfaces REQUIRED) diff --git a/Tests/RunCMake/target_sources/FileSetDefaultWrongTypeExperimental.cmake b/Tests/RunCMake/target_sources/FileSetDefaultWrongTypeExperimental.cmake index 5ade637df6..1809505e25 100644 --- a/Tests/RunCMake/target_sources/FileSetDefaultWrongTypeExperimental.cmake +++ b/Tests/RunCMake/target_sources/FileSetDefaultWrongTypeExperimental.cmake @@ -1,6 +1,6 @@ enable_language(C) -set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046") +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "9629ab6c-6c0e-423f-bb9d-cc5ac4a22041") add_library(lib1 STATIC empty.c) target_sources(lib1 PRIVATE FILE_SET UNKNOWN) diff --git a/Tests/RunCMake/target_sources/FileSetWrongTypeExperimental.cmake b/Tests/RunCMake/target_sources/FileSetWrongTypeExperimental.cmake index 332441c821..064cacb807 100644 --- a/Tests/RunCMake/target_sources/FileSetWrongTypeExperimental.cmake +++ b/Tests/RunCMake/target_sources/FileSetWrongTypeExperimental.cmake @@ -1,6 +1,6 @@ enable_language(C) -set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046") +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "9629ab6c-6c0e-423f-bb9d-cc5ac4a22041") add_library(lib1 STATIC empty.c) target_sources(lib1 PRIVATE FILE_SET a TYPE UNKNOWN) From 52c21cbbda3d3b920fa453213ce86830b66ebb32 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Nov 2022 12:14:19 -0500 Subject: [PATCH 14/14] ci: enable C++20 module testing with the VS 2022 generator --- .gitlab/ci/configure_windows_vs2022_x64.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab/ci/configure_windows_vs2022_x64.cmake b/.gitlab/ci/configure_windows_vs2022_x64.cmake index c7d41ea1d4..1e0f584eef 100644 --- a/.gitlab/ci/configure_windows_vs2022_x64.cmake +++ b/.gitlab/ci/configure_windows_vs2022_x64.cmake @@ -1 +1,4 @@ +set(CMake_TEST_MODULE_COMPILATION "named,partitions" CACHE STRING "") + +include("${CMAKE_CURRENT_LIST_DIR}/configure_windows_msvc_cxx_modules_common.cmake") include("${CMAKE_CURRENT_LIST_DIR}/configure_windows_vs_common.cmake")