From d7a23c874c1376085e0b3ac5f115510325066e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20R=C3=B6hling?= Date: Sat, 11 May 2024 23:25:11 +0200 Subject: [PATCH] New upstream version 3.29.3 --- Help/prop_tgt/OBJC_STANDARD.rst | 10 ++ Help/release/3.28.rst | 6 + Help/release/3.29.rst | 6 +- Modules/CMakeDetermineCompilerABI.cmake | 3 + Modules/CMakePackageConfigHelpers.cmake | 158 ++++++++++-------- Modules/CMakeTestCXXCompiler.cmake | 13 ++ Modules/FindBoost.cmake | 4 +- Modules/FindHDF5.cmake | 2 +- .../AppleArchitectureSelection.cmake.in | 21 +++ .../Internal/ApplePlatformSelection.cmake.in | 21 +++ Source/CMakeVersion.cmake | 4 +- Source/cmDyndepCollation.cxx | 16 +- Source/cmExportBuildFileGenerator.cxx | 4 +- Source/cmExportInstallFileGenerator.cxx | 4 +- Source/cmGeneratorTarget.cxx | 47 +++++- Source/cmGeneratorTarget.h | 8 + Source/cmVisualStudio10TargetGenerator.cxx | 25 ++- Source/cmVisualStudio10TargetGenerator.h | 1 + .../ApplePlatformGenSubdir-stdout.txt | 3 + .../CMakePackage/ApplePlatformGenSubdir.cmake | 50 ++++++ .../RunCMake/CMakePackage/RunCMakeTest.cmake | 14 +- ...DependInfoExportFilesystemSafe-check.cmake | 39 +++++ .../NinjaDependInfoExportFilesystemSafe.cmake | 84 ++++++++++ Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 17 ++ .../CMakeLists.txt | 37 ++++ .../subdir/CMakeLists.txt | 9 + .../subdir/importable.cxx | 6 + .../test/CMakeLists.txt | 16 ++ .../CMakeLists.txt | 40 +++++ .../subdir/CMakeLists.txt | 9 + .../subdir/importable.cxx | 6 + .../test/CMakeLists.txt | 16 ++ .../export-with-headers-build/CMakeLists.txt | 49 ++++++ .../export-with-headers-build/importable.cxx | 14 ++ .../include/subdir/header.h | 3 + .../test/CMakeLists.txt | 19 +++ .../CMakeLists.txt | 51 ++++++ .../importable.cxx | 14 ++ .../include/subdir/header.h | 3 + .../test/CMakeLists.txt | 21 +++ .../examples/import-modules/CMakeLists.txt | 4 + .../expect/NinjaDependInfoExport-private.json | 4 + .../expect/NinjaDependInfoExport-public.json | 4 + ...ependInfoExportFilesystemSafe-private.json | 83 +++++++++ ...DependInfoExportFilesystemSafe-public.json | 83 +++++++++ 45 files changed, 946 insertions(+), 105 deletions(-) create mode 100644 Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt create mode 100644 Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir.cmake create mode 100644 Tests/RunCMake/CXXModules/NinjaDependInfoExportFilesystemSafe-check.cmake create mode 100644 Tests/RunCMake/CXXModules/NinjaDependInfoExportFilesystemSafe.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/subdir/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/subdir/importable.cxx create mode 100644 Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/test/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/subdir/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/subdir/importable.cxx create mode 100644 Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/test/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-with-headers-build/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-with-headers-build/importable.cxx create mode 100644 Tests/RunCMake/CXXModules/examples/export-with-headers-build/include/subdir/header.h create mode 100644 Tests/RunCMake/CXXModules/examples/export-with-headers-build/test/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-with-headers-install/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-with-headers-install/importable.cxx create mode 100644 Tests/RunCMake/CXXModules/examples/export-with-headers-install/include/subdir/header.h create mode 100644 Tests/RunCMake/CXXModules/examples/export-with-headers-install/test/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json create mode 100644 Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json diff --git a/Help/prop_tgt/OBJC_STANDARD.rst b/Help/prop_tgt/OBJC_STANDARD.rst index 0609239f5..a3c565313 100644 --- a/Help/prop_tgt/OBJC_STANDARD.rst +++ b/Help/prop_tgt/OBJC_STANDARD.rst @@ -20,6 +20,16 @@ Supported values are: ``11`` Objective C11 +``17`` + .. versionadded:: 3.21 + + Objective C17 + +``23`` + .. versionadded:: 3.21 + + Objective C23 + If the value requested does not result in a compile flag being added for the compiler in use, a previous standard flag will be added instead. This means that using: diff --git a/Help/release/3.28.rst b/Help/release/3.28.rst index 9e2a422fa..77f03f63f 100644 --- a/Help/release/3.28.rst +++ b/Help/release/3.28.rst @@ -213,3 +213,9 @@ Changes made since CMake 3.28.0 include the following. * Apple visionOS support has been updated for the official Xcode 15.2 release of the ``xros`` and ``xrsimulator`` SDKs. + +3.28.5 +------ + +* This version made no changes to documented features or interfaces. + Some implementation updates were made to C++ modules support. diff --git a/Help/release/3.29.rst b/Help/release/3.29.rst index 302bdf4e6..35f6d396e 100644 --- a/Help/release/3.29.rst +++ b/Help/release/3.29.rst @@ -212,9 +212,9 @@ Changes made since CMake 3.29.0 include the following. :prop_tgt:`LINKER_TYPE` target property now work with compilers for the ``Swift`` language. -3.29.2 ------- +3.29.2, 3.29.3 +-------------- -* This version made no changes to documented features or interfaces. +* These versions made no changes to documented features or interfaces. Some implementation updates were made to support ecosystem changes and/or fix regressions. diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake index 012a87caf..87218d207 100644 --- a/Modules/CMakeDetermineCompilerABI.cmake +++ b/Modules/CMakeDetermineCompilerABI.cmake @@ -39,6 +39,9 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src) endif() set(CMAKE_${lang}_RUNTIME_LIBRARY "Static") endif() + if(lang STREQUAL "CXX") + set(CMAKE_${lang}_SCAN_FOR_MODULES OFF) + endif() if(NOT "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xMSVC") # Avoid adding our own platform standard libraries for compilers # from which we might detect implicit link libraries. diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake index dfe1ec7dc..9fa30b6b7 100644 --- a/Modules/CMakePackageConfigHelpers.cmake +++ b/Modules/CMakePackageConfigHelpers.cmake @@ -5,7 +5,7 @@ CMakePackageConfigHelpers ------------------------- -Helpers functions for creating config files that can be included by other +Helper functions for creating config files that can be included by other projects to find and use a package. Generating a Package Configuration File @@ -26,11 +26,11 @@ Generating a Package Configuration File ``configure_package_config_file()`` should be used instead of the plain :command:`configure_file()` command when creating the ``Config.cmake`` or ``-config.cmake`` file for installing a project or library. -It helps making the resulting package relocatable by avoiding hardcoded paths -in the installed ``Config.cmake`` file. +It helps make the resulting package relocatable by avoiding hardcoded paths +in the installed ``Config.cmake`` file. In a ``FooConfig.cmake`` file there may be code like this to make the install -destinations know to the using project: +destinations known to the using project: .. code-block:: cmake @@ -40,27 +40,25 @@ destinations know to the using project: #...logic to determine installedPrefix from the own location... set(FOO_CONFIG_DIR "${installedPrefix}/@CONFIG_INSTALL_DIR@" ) -All 4 options shown above are not sufficient, since the first 3 hardcode the -absolute directory locations, and the 4th case works only if the logic to +All four options shown above are not sufficient The first three hardcode the +absolute directory locations. The fourth case works only if the logic to determine the ``installedPrefix`` is correct, and if ``CONFIG_INSTALL_DIR`` contains a relative path, which in general cannot be guaranteed. This has the effect that the resulting ``FooConfig.cmake`` file would work poorly under -Windows and OSX, where users are used to choose the install location of a +Windows and macOS, where users are used to choosing the install location of a binary package at install time, independent from how :variable:`CMAKE_INSTALL_PREFIX` was set at build/cmake time. -Using ``configure_package_config_file`` helps. If used correctly, it makes +Using ``configure_package_config_file()`` helps. If used correctly, it makes the resulting ``FooConfig.cmake`` file relocatable. Usage: -1. write a ``FooConfig.cmake.in`` file as you are used to -2. insert a line containing only the string ``@PACKAGE_INIT@`` -3. instead of ``set(FOO_DIR "@SOME_INSTALL_DIR@")``, use +1. Write a ``FooConfig.cmake.in`` file as you are used to. +2. Insert a line at the top containing only the string ``@PACKAGE_INIT@``. +3. Instead of ``set(FOO_DIR "@SOME_INSTALL_DIR@")``, use ``set(FOO_DIR "@PACKAGE_SOME_INSTALL_DIR@")`` (this must be after the - ``@PACKAGE_INIT@`` line) -4. instead of using the normal :command:`configure_file()`, use - ``configure_package_config_file()`` - - + ``@PACKAGE_INIT@`` line). +4. Instead of using the normal :command:`configure_file()` command, use + ``configure_package_config_file()``. The ```` and ```` arguments are the input and output file, the same way as in :command:`configure_file()`. @@ -70,48 +68,47 @@ the ``FooConfig.cmake`` file will be installed to. This path can either be absolute, or relative to the ``INSTALL_PREFIX`` path. The variables ```` to ```` given as ``PATH_VARS`` are the -variables which contain install destinations. For each of them the macro will +variables which contain install destinations. For each of them, the macro will create a helper variable ``PACKAGE_``. These helper variables must be used in the ``FooConfig.cmake.in`` file for setting the installed location. -They are calculated by ``configure_package_config_file`` so that they are +They are calculated by ``configure_package_config_file()`` so that they are always relative to the installed location of the package. This works both for -relative and also for absolute locations. For absolute locations it works +relative and also for absolute locations. For absolute locations, it works only if the absolute location is a subdirectory of ``INSTALL_PREFIX``. .. versionadded:: 3.1 - If the ``INSTALL_PREFIX`` argument is passed, this is used as base path to + If the ``INSTALL_PREFIX`` argument is passed, this is used as the base path to calculate all the relative paths. The ```` argument must be an absolute path. If this argument is not passed, the :variable:`CMAKE_INSTALL_PREFIX` variable will be used instead. The default value is good when generating a - FooConfig.cmake file to use your package from the install tree. When - generating a FooConfig.cmake file to use your package from the build tree this - option should be used. + ``FooConfig.cmake`` file to use your package from the install tree. When + generating a ``FooConfig.cmake`` file to use your package from the build tree, + this option should be used. -By default ``configure_package_config_file`` also generates two helper macros, -``set_and_check()`` and ``check_required_components()`` into the +By default, ``configure_package_config_file()`` also generates two helper +macros, ``set_and_check()`` and ``check_required_components()``, into the ``FooConfig.cmake`` file. -``set_and_check()`` should be used instead of the normal ``set()`` command for -setting directories and file locations. Additionally to setting the variable -it also checks that the referenced file or directory actually exists and fails -with a ``FATAL_ERROR`` otherwise. This makes sure that the created +``set_and_check()`` should be used instead of the normal :command:`set` command +for setting directories and file locations. In addition to setting the +variable, it also checks that the referenced file or directory actually exists +and fails with a fatal error if it doesn't. This ensures that the generated ``FooConfig.cmake`` file does not contain wrong references. -When using the ``NO_SET_AND_CHECK_MACRO``, this macro is not generated -into the ``FooConfig.cmake`` file. +Add the ``NO_SET_AND_CHECK_MACRO`` option to prevent the generation of the +``set_and_check()`` macro in the ``FooConfig.cmake`` file. ``check_required_components()`` should be called at the end of the ``FooConfig.cmake`` file. This macro checks whether all requested, -non-optional components have been found, and if this is not the case, sets -the ``Foo_FOUND`` variable to ``FALSE``, so that the package is considered to +non-optional components have been found, and if this is not the case, it sets +the ``Foo_FOUND`` variable to ``FALSE`` so that the package is considered to be not found. It does that by testing the ``Foo__FOUND`` variables for all requested required components. This macro should be called even if the package doesn't provide any components to make sure -users are not specifying components erroneously. When using the -``NO_CHECK_REQUIRED_COMPONENTS_MACRO`` option, this macro is not generated -into the ``FooConfig.cmake`` file. +users are not specifying components erroneously. Add the +``NO_CHECK_REQUIRED_COMPONENTS_MACRO`` option to prevent the generation of the +``check_required_components()`` macro in the ``FooConfig.cmake`` file. -For an example see below the documentation for -:command:`write_basic_package_version_file()`. +See also :ref:`CMakePackageConfigHelpers Examples`. Generating a Package Version File ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -126,11 +123,11 @@ Generating a Package Version File [ARCH_INDEPENDENT] ) -Writes a file for use as ``ConfigVersion.cmake`` file to +Writes a file for use as a ``ConfigVersion.cmake`` file to ````. See the documentation of :command:`find_package()` for -details on this. +details on such files. -```` is the output filename, it should be in the build tree. +```` is the output filename, which should be in the build tree. ```` is the version number of the project to be installed. If no ``VERSION`` is given, the :variable:`PROJECT_VERSION` variable is used. @@ -153,9 +150,9 @@ the requested version matches exactly its own version number (not considering the tweak version). For example, version 1.2.3 of a package is only considered compatible to requested version 1.2.3. This mode is for packages without compatibility guarantees. -If your project has more elaborated version matching rules, you will need to -write your own custom ``ConfigVersion.cmake`` file instead of using this -macro. +If your project has more elaborate version matching rules, you will need to +write your own custom ``ConfigVersion.cmake`` file instead of +using this macro. .. versionadded:: 3.11 The ``SameMinorVersion`` compatibility mode. @@ -170,13 +167,13 @@ macro. unless ``ARCH_INDEPENDENT`` is given, in which case the package is considered compatible on any architecture. -.. note:: ``ARCH_INDEPENDENT`` is intended for header-only libraries or similar - packages with no binaries. + .. note:: ``ARCH_INDEPENDENT`` is intended for header-only libraries or + similar packages with no binaries. .. versionadded:: 3.19 The version file generated by ``AnyNewerVersion``, ``SameMajorVersion`` and - ``SameMinorVersion`` arguments of ``COMPATIBILITY`` handle the version range - if any is specified (see :command:`find_package` command for the details). + ``SameMinorVersion`` arguments of ``COMPATIBILITY`` handle the version range, + if one is specified (see :command:`find_package` command for the details). ``ExactVersion`` mode is incompatible with version ranges and will display an author warning if one is specified. @@ -184,8 +181,9 @@ Internally, this macro executes :command:`configure_file()` to create the resulting version file. Depending on the ``COMPATIBILITY``, the corresponding ``BasicConfigVersion-.cmake.in`` file is used. Please note that these files are internal to CMake and you should not call -:command:`configure_file()` on them yourself, but they can be used as starting -point to create more sophisticated custom ``ConfigVersion.cmake`` files. +:command:`configure_file()` on them yourself, but they can be used as a starting +point to create more sophisticated custom ``ConfigVersion.cmake`` +files. Generating an Apple Platform Selection File ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -268,6 +266,9 @@ Generating an Apple Platform Selection File consider the platform to be unsupported. The behavior is determined by the ``ERROR_VARIABLE`` option. +Generating an Apple Architecture Selection File +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + .. command:: generate_apple_architecture_selection_file .. versionadded:: 3.29 @@ -328,15 +329,16 @@ Generating an Apple Platform Selection File information to pretend the package was not found. If this option is not given, the default behavior is to issue a fatal error. +.. _`CMakePackageConfigHelpers Examples`: + Example Generating Package Files ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Example using both :command:`configure_package_config_file` and -``write_basic_package_version_file()``: - -``CMakeLists.txt``: +Example using both the :command:`configure_package_config_file` and +:command:`write_basic_package_version_file()` commands: .. code-block:: cmake + :caption: ``CMakeLists.txt`` include(GNUInstallDirs) set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/Foo @@ -357,9 +359,9 @@ Example using both :command:`configure_package_config_file` and ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Foo ) -``FooConfig.cmake.in``: - -:: +.. code-block:: cmake + :caption: ``FooConfig.cmake.in`` + :force: set(FOO_VERSION x.y.z) ... @@ -597,8 +599,15 @@ function(generate_apple_architecture_selection_file _output_file) ) endif() string(APPEND _branch_code - "endif()\n" + "endif()\n\n" + "set(_cmake_apple_archs \"\${CMAKE_OSX_ARCHITECTURES}\")\n" ) + if(NOT "${_gasf_UNIVERSAL_ARCHITECTURES}" STREQUAL "") + string(APPEND _branch_code "list(REMOVE_ITEM _cmake_apple_archs ${_gasf_UNIVERSAL_ARCHITECTURES})\n") + endif() + string(APPEND _branch_code "\n") + + set(maybe_else "") foreach(pair IN ZIP_LISTS _gasf_SINGLE_ARCHITECTURES _gasf_SINGLE_ARCHITECTURE_INCLUDE_FILES) set(arch "${pair_0}") @@ -607,40 +616,45 @@ function(generate_apple_architecture_selection_file _output_file) string(PREPEND config_file [[${PACKAGE_PREFIX_DIR}/]]) endif() string(APPEND _branch_code - "\n" - "if(CMAKE_OSX_ARCHITECTURES STREQUAL \"${arch}\")\n" + "${maybe_else}if(CMAKE_OSX_ARCHITECTURES STREQUAL \"${arch}\")\n" " include(\"${config_file}\")\n" - " return()\n" - "endif()\n" ) + set(maybe_else else) endforeach() if(_gasf_UNIVERSAL_ARCHITECTURES AND _gasf_UNIVERSAL_INCLUDE_FILE) - string(JOIN " " universal_archs "${_gasf_UNIVERSAL_ARCHITECTURES}") set(config_file "${_gasf_UNIVERSAL_INCLUDE_FILE}") if(NOT IS_ABSOLUTE "${config_file}") string(PREPEND config_file [[${PACKAGE_PREFIX_DIR}/]]) endif() string(APPEND _branch_code - "\n" - "set(_cmake_apple_archs \"\${CMAKE_OSX_ARCHITECTURES}\")\n" - "list(REMOVE_ITEM _cmake_apple_archs ${universal_archs})\n" - "if(NOT _cmake_apple_archs)\n" + "${maybe_else}if(NOT _cmake_apple_archs)\n" " include(\"${config_file}\")\n" - " return()\n" - "endif()\n" ) + set(maybe_else else) elseif(_gasf_UNIVERSAL_ARCHITECTURES) message(FATAL_ERROR "UNIVERSAL_INCLUDE_FILE requires UNIVERSAL_ARCHITECTURES") elseif(_gasf_UNIVERSAL_INCLUDE_FILE) message(FATAL_ERROR "UNIVERSAL_ARCHITECTURES requires UNIVERSAL_INCLUDE_FILE") endif() - string(APPEND _branch_code "\n") + if(maybe_else) + string(APPEND _branch_code "else()\n") + set(_indent " ") + else() + set(_indent "") + endif() if(_gasf_ERROR_VARIABLE) - string(APPEND _branch_code "set(\"${_gasf_ERROR_VARIABLE}\" \"Architecture not supported\")") + string(APPEND _branch_code + "${_indent}set(\"${_gasf_ERROR_VARIABLE}\" \"Architecture not supported\")\n" + ) else() - string(APPEND _branch_code "message(FATAL_ERROR \"Architecture not supported\")") + string(APPEND _branch_code + "${_indent}message(FATAL_ERROR \"Architecture not supported\")\n" + ) + endif() + if(maybe_else) + string(APPEND _branch_code "endif()\n") endif() configure_package_config_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Internal/AppleArchitectureSelection.cmake.in" "${_output_file}" diff --git a/Modules/CMakeTestCXXCompiler.cmake b/Modules/CMakeTestCXXCompiler.cmake index e640ff9b3..a9fbb26ca 100644 --- a/Modules/CMakeTestCXXCompiler.cmake +++ b/Modules/CMakeTestCXXCompiler.cmake @@ -37,6 +37,13 @@ endif() # any makefiles or projects. if(NOT CMAKE_CXX_COMPILER_WORKS) PrintTestCompilerStatus("CXX") + # FIXME: Use a block() to isolate the variables we set/unset here. + if(DEFINED CMAKE_CXX_SCAN_FOR_MODULES) + set(__CMAKE_SAVED_CXX_SCAN_FOR_MODULES "${CMAKE_CXX_SCAN_FOR_MODULES}") + else() + unset(__CMAKE_SAVED_CXX_SCAN_FOR_MODULES) + endif() + set(CMAKE_CXX_SCAN_FOR_MODULES OFF) __TestCompiler_setTryCompileTargetType() string(CONCAT __TestCompiler_testCXXCompilerSource "#ifndef __cplusplus\n" @@ -49,6 +56,12 @@ if(NOT CMAKE_CXX_COMPILER_WORKS) try_compile(CMAKE_CXX_COMPILER_WORKS SOURCE_FROM_VAR testCXXCompiler.cxx __TestCompiler_testCXXCompilerSource OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT) + if(DEFINED __CMAKE_SAVED_CXX_SCAN_FOR_MODULES) + set(CMAKE_CXX_SCAN_FOR_MODULES "${__CMAKE_SAVED_CXX_SCAN_FOR_MODULES}") + unset(__CMAKE_SAVED_CXX_SCAN_FOR_MODULES) + else() + unset(CMAKE_CXX_SCAN_FOR_MODULES) + endif() unset(__TestCompiler_testCXXCompilerSource) # Move result from cache to normal variable. set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS}) diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index 248ea8b63..54d1a78a5 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -1394,7 +1394,7 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret) set(_Boost_THREAD_DEPENDENCIES chrono atomic) set(_Boost_WAVE_DEPENDENCIES filesystem serialization thread chrono atomic) set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - if(Boost_VERSION_STRING VERSION_GREATER_EQUAL 1.85.0 AND NOT Boost_NO_WARN_NEW_VERSIONS) + if(Boost_VERSION_STRING VERSION_GREATER_EQUAL 1.86.0 AND NOT Boost_NO_WARN_NEW_VERSIONS) message(WARNING "New Boost version may have incorrect or missing dependencies and imported targets") endif() endif() @@ -1669,7 +1669,7 @@ else() # _Boost_COMPONENT_HEADERS. See the instructions at the top of # _Boost_COMPONENT_DEPENDENCIES. set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} - "1.84.0" "1.84" + "1.85.0" "1.85" "1.84.0" "1.84" "1.83.0" "1.83" "1.82.0" "1.82" "1.81.0" "1.81" "1.80.0" "1.80" "1.79.0" "1.79" "1.78.0" "1.78" "1.77.0" "1.77" "1.76.0" "1.76" "1.75.0" "1.75" "1.74.0" "1.74" "1.73.0" "1.73" "1.72.0" "1.72" "1.71.0" "1.71" "1.70.0" "1.70" "1.69.0" "1.69" diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake index a44c6f99b..cc6186f33 100644 --- a/Modules/FindHDF5.cmake +++ b/Modules/FindHDF5.cmake @@ -987,7 +987,7 @@ if( NOT HDF5_FOUND ) HDF5_VERSION_DEFINE REGEX "^[ \t]*#[ \t]*define[ \t]+H5_VERSION[ \t]+" ) if( "${HDF5_VERSION_DEFINE}" MATCHES - "H5_VERSION[ \t]+\"([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?\"" ) + "H5_VERSION[ \t]+\"([0-9\\.]+)(-patch([0-9]+))?\"" ) set( HDF5_VERSION "${CMAKE_MATCH_1}" ) if( CMAKE_MATCH_3 ) set( HDF5_VERSION ${HDF5_VERSION}.${CMAKE_MATCH_3}) diff --git a/Modules/Internal/AppleArchitectureSelection.cmake.in b/Modules/Internal/AppleArchitectureSelection.cmake.in index b7315b68a..0c3a3a24b 100644 --- a/Modules/Internal/AppleArchitectureSelection.cmake.in +++ b/Modules/Internal/AppleArchitectureSelection.cmake.in @@ -1,2 +1,23 @@ +# Save this now so we can restore it before returning +if(NOT DEFINED PACKAGE_PREFIX_DIR) + list(APPEND _gasf_PACKAGE_PREFIX_DIR "<__CMAKE_UNDEFINED__>") +elseif("${PACKAGE_PREFIX_DIR}" STREQUAL "") + list(APPEND _gasf_PACKAGE_PREFIX_DIR "<__CMAKE_EMPTY__>") +else() + list(APPEND _gasf_PACKAGE_PREFIX_DIR "${PACKAGE_PREFIX_DIR}") +endif() + @PACKAGE_INIT@ @_branch_code@ + +# Restore PACKAGE_PREFIX_DIR +list(LENGTH _gasf_PACKAGE_PREFIX_DIR _gasf_tmp) +math(EXPR _gasf_tmp "${_gasf_tmp} - 1") +list(GET _gasf_PACKAGE_PREFIX_DIR ${_gasf_tmp} PACKAGE_PREFIX_DIR) +list(REMOVE_AT _gasf_PACKAGE_PREFIX_DIR ${_gasf_tmp}) +unset(_gasf_tmp) +if("${PACKAGE_PREFIX_DIR}" STREQUAL "<__CMAKE_UNDEFINED__>") + unset(PACKAGE_PREFIX_DIR) +elseif("${PACKAGE_PREFIX_DIR}" STREQUAL "<__CMAKE_EMPTY__>") + set(PACKAGE_PREFIX_DIR "") +endif() diff --git a/Modules/Internal/ApplePlatformSelection.cmake.in b/Modules/Internal/ApplePlatformSelection.cmake.in index 6c03ab6a7..c07f139a8 100644 --- a/Modules/Internal/ApplePlatformSelection.cmake.in +++ b/Modules/Internal/ApplePlatformSelection.cmake.in @@ -1,3 +1,12 @@ +# Save this now so we can restore it before returning +if(NOT DEFINED PACKAGE_PREFIX_DIR) + list(APPEND _gpsf_PACKAGE_PREFIX_DIR "<__CMAKE_UNDEFINED__>") +elseif("${PACKAGE_PREFIX_DIR}" STREQUAL "") + list(APPEND _gpsf_PACKAGE_PREFIX_DIR "<__CMAKE_EMPTY__>") +else() + list(APPEND _gpsf_PACKAGE_PREFIX_DIR "${PACKAGE_PREFIX_DIR}") +endif() + @PACKAGE_INIT@ string(TOLOWER "${CMAKE_OSX_SYSROOT}" _CMAKE_OSX_SYSROOT_LOWER) @@ -23,3 +32,15 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") else() @_branch_ELSE@ endif() + +# Restore PACKAGE_PREFIX_DIR +list(LENGTH _gpsf_PACKAGE_PREFIX_DIR _gpsf_tmp) +math(EXPR _gpsf_tmp "${_gpsf_tmp} - 1") +list(GET _gpsf_PACKAGE_PREFIX_DIR ${_gpsf_tmp} PACKAGE_PREFIX_DIR) +list(REMOVE_AT _gpsf_PACKAGE_PREFIX_DIR ${_gpsf_tmp}) +unset(_gpsf_tmp) +if("${PACKAGE_PREFIX_DIR}" STREQUAL "<__CMAKE_UNDEFINED__>") + unset(PACKAGE_PREFIX_DIR) +elseif("${PACKAGE_PREFIX_DIR}" STREQUAL "<__CMAKE_EMPTY__>") + set(PACKAGE_PREFIX_DIR "") +endif() diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index a906ee091..6cacae7b9 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 29) -set(CMake_VERSION_PATCH 2) +set(CMake_VERSION_PATCH 3) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) @@ -21,7 +21,7 @@ endif() if(NOT CMake_VERSION_NO_GIT) # If this source was exported by 'git archive', use its commit info. - set(git_info [==[d3190d6a73 CMake 3.29.2]==]) + set(git_info [==[b39fb31bf4 CMake 3.29.3]==]) # Otherwise, try to identify the current development source version. if(NOT git_info MATCHES "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]?[0-9a-f]?)[0-9a-f]* " diff --git a/Source/cmDyndepCollation.cxx b/Source/cmDyndepCollation.cxx index ed4762b41..bfe3a75ea 100644 --- a/Source/cmDyndepCollation.cxx +++ b/Source/cmDyndepCollation.cxx @@ -207,6 +207,7 @@ Json::Value CollationInformationExports(cmGeneratorTarget const* gt) { Json::Value tdi_exports = Json::arrayValue; std::string export_name = gt->GetExportName(); + std::string fs_export_name = gt->GetFilesystemExportName(); auto const& all_install_exports = gt->GetGlobalGenerator()->GetExportSets(); for (auto const& exp : all_install_exports) { @@ -232,6 +233,7 @@ Json::Value CollationInformationExports(cmGeneratorTarget const* gt) tdi_export_info["namespace"] = ns; tdi_export_info["export-name"] = export_name; + tdi_export_info["filesystem-export-name"] = fs_export_name; tdi_export_info["destination"] = dest; tdi_export_info["cxx-module-info-dir"] = cxxm_dir; tdi_export_info["export-prefix"] = export_prefix; @@ -241,8 +243,10 @@ Json::Value CollationInformationExports(cmGeneratorTarget const* gt) } } - auto const& all_build_exports = gt->Makefile->GetExportBuildFileGenerators(); - for (auto const& exp : all_build_exports) { + auto const& all_build_exports = + gt->GetGlobalGenerator()->GetBuildExportSets(); + for (auto const& exp_entry : all_build_exports) { + auto const* exp = exp_entry.second; std::vector targets; exp->GetTargets(targets); @@ -268,6 +272,7 @@ Json::Value CollationInformationExports(cmGeneratorTarget const* gt) tdi_export_info["namespace"] = ns; tdi_export_info["export-name"] = export_name; + tdi_export_info["filesystem-export-name"] = fs_export_name; tdi_export_info["destination"] = dest; tdi_export_info["cxx-module-info-dir"] = cxxm_dir; tdi_export_info["export-prefix"] = export_prefix; @@ -315,6 +320,7 @@ struct CxxModuleBmiInstall struct CxxModuleExport { std::string Name; + std::string FilesystemName; std::string Destination; std::string Prefix; std::string CxxModuleInfoDir; @@ -352,6 +358,7 @@ cmDyndepCollation::ParseExportInfo(Json::Value const& tdi) CxxModuleExport exp; exp.Install = tdi_export["install"].asBool(); exp.Name = tdi_export["export-name"].asString(); + exp.FilesystemName = tdi_export["filesystem-export-name"].asString(); exp.Destination = tdi_export["destination"].asString(); exp.Prefix = tdi_export["export-prefix"].asString(); exp.CxxModuleInfoDir = tdi_export["cxx-module-info-dir"].asString(); @@ -426,8 +433,9 @@ bool cmDyndepCollation::WriteDyndepMetadata( std::string const export_dir = cmStrCat(exp.Prefix, '/', exp.CxxModuleInfoDir, '/'); - std::string const property_file_path = cmStrCat( - export_dir, "target-", exp.Name, '-', export_info.Config, ".cmake"); + std::string const property_file_path = + cmStrCat(export_dir, "target-", exp.FilesystemName, '-', + export_info.Config, ".cmake"); properties = cm::make_unique(property_file_path); // Set up the preamble. diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 81e3d546c..2345d64b9 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -591,8 +591,8 @@ bool cmExportBuildFileGenerator::GenerateImportCxxModuleConfigTargetInclusion( continue; } - os << "include(\"${CMAKE_CURRENT_LIST_DIR}/target-" << tgt->GetExportName() - << '-' << config << ".cmake\")\n"; + os << "include(\"${CMAKE_CURRENT_LIST_DIR}/target-" + << tgt->GetFilesystemExportName() << '-' << config << ".cmake\")\n"; } return true; diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index c5b9dc9bb..5c95ecd89 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -780,8 +780,8 @@ bool cmExportInstallFileGenerator:: continue; } - auto prop_filename = cmStrCat("target-", tgt->GetExportName(), '-', - filename_config, ".cmake"); + auto prop_filename = cmStrCat("target-", tgt->GetFilesystemExportName(), + '-', filename_config, ".cmake"); prop_files.emplace_back(cmStrCat(dest, prop_filename)); os << "include(\"${CMAKE_CURRENT_LIST_DIR}/" << prop_filename << "\")\n"; } diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index a40af8b49..0fe19de31 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -368,6 +368,16 @@ std::string cmGeneratorTarget::GetExportName() const return this->GetName(); } +std::string cmGeneratorTarget::GetFilesystemExportName() const +{ + auto fs_safe = this->GetExportName(); + // First escape any `_` characters to avoid collisions. + cmSystemTools::ReplaceString(fs_safe, "_", "__"); + // Escape other characters that are not generally filesystem-safe. + cmSystemTools::ReplaceString(fs_safe, ":", "_c"); + return fs_safe; +} + cmValue cmGeneratorTarget::GetProperty(const std::string& prop) const { if (cmValue result = @@ -8483,6 +8493,10 @@ bool cmGeneratorTarget::DiscoverSyntheticTargets(cmSyntheticTargetCache& cache, // generation. tgt->CopyImportedCxxModulesProperties(model); + tgt->AddLinkLibrary(*mf, + cmStrCat("$GetName(), '>'), + GENERAL_LibraryType); + // Apply usage requirements to the target. usage.ApplyToTarget(tgt); @@ -9484,11 +9498,25 @@ bool cmGeneratorTarget::NeedDyndepForSource(std::string const& lang, return true; } + auto targetDyndep = this->NeedCxxDyndep(config); + if (targetDyndep == CxxModuleSupport::Unavailable) { + return false; + } + auto const sfProp = sf->GetProperty("CXX_SCAN_FOR_MODULES"); + if (sfProp.IsSet()) { + return sfProp.IsOn(); + } + return targetDyndep == CxxModuleSupport::Enabled; +} + +cmGeneratorTarget::CxxModuleSupport cmGeneratorTarget::NeedCxxDyndep( + std::string const& config) const +{ bool haveRule = false; switch (this->HaveCxxModuleSupport(config)) { case Cxx20SupportLevel::MissingCxx: case Cxx20SupportLevel::NoCxx20: - return false; + return CxxModuleSupport::Unavailable; case Cxx20SupportLevel::MissingRule: break; case Cxx20SupportLevel::Supported: @@ -9498,28 +9526,29 @@ bool cmGeneratorTarget::NeedDyndepForSource(std::string const& lang, bool haveGeneratorSupport = this->GetGlobalGenerator()->CheckCxxModuleSupport( cmGlobalGenerator::CxxModuleSupportQuery::Inspect); - auto const sfProp = sf->GetProperty("CXX_SCAN_FOR_MODULES"); - if (sfProp.IsSet()) { - return sfProp.IsOn(); - } auto const tgtProp = this->GetProperty("CXX_SCAN_FOR_MODULES"); if (tgtProp.IsSet()) { - return tgtProp.IsOn(); + return tgtProp.IsOn() ? CxxModuleSupport::Enabled + : CxxModuleSupport::Disabled; } - bool policyAnswer = false; + CxxModuleSupport policyAnswer = CxxModuleSupport::Unavailable; switch (this->GetPolicyStatusCMP0155()) { case cmPolicies::WARN: case cmPolicies::OLD: // The OLD behavior is to not scan the source. - policyAnswer = false; + policyAnswer = CxxModuleSupport::Disabled; break; case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::REQUIRED_IF_USED: case cmPolicies::NEW: // The NEW behavior is to scan the source if the compiler supports // scanning and the generator supports it. - policyAnswer = haveRule && haveGeneratorSupport; + if (haveRule && haveGeneratorSupport) { + policyAnswer = CxxModuleSupport::Enabled; + } else { + policyAnswer = CxxModuleSupport::Disabled; + } break; } return policyAnswer; diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index fd4b2ec7e..71785b6a8 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -99,6 +99,7 @@ public: cmStateEnums::TargetType GetType() const; const std::string& GetName() const; std::string GetExportName() const; + std::string GetFilesystemExportName() const; std::vector GetPropertyKeys() const; //! Might return a nullptr if the property is not set or invalid @@ -1340,6 +1341,13 @@ public: cmSourceFile const* sf) const; bool NeedDyndepForSource(std::string const& lang, std::string const& config, cmSourceFile const* sf) const; + enum class CxxModuleSupport + { + Unavailable, + Enabled, + Disabled, + }; + CxxModuleSupport NeedCxxDyndep(std::string const& config) const; private: void BuildFileSetInfoCache(std::string const& config) const; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index d572f30b0..fbd676d78 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -281,6 +281,16 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( this->Makefile->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); this->NsightTegra = gg->IsNsightTegra(); this->Android = gg->TargetsAndroid(); + auto scanProp = target->GetProperty("CXX_SCAN_FOR_MODULES"); + for (auto const& config : this->Configurations) { + if (scanProp.IsSet()) { + this->ScanSourceForModuleDependencies[config] = scanProp.IsOn(); + } else { + this->ScanSourceForModuleDependencies[config] = + target->NeedCxxDyndep(config) == + cmGeneratorTarget::CxxModuleSupport::Enabled; + } + } for (unsigned int& version : this->NsightTegraVersion) { version = 0; } @@ -2827,7 +2837,9 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( // use them if (!flags.empty() || !options.empty() || !configDefines.empty() || !includes.empty() || compileAsPerConfig || noWinRT || - !options.empty() || needsPCHFlags || shouldScanForModules) { + !options.empty() || needsPCHFlags || + (shouldScanForModules != + this->ScanSourceForModuleDependencies[config])) { cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator; cmIDEFlagTable const* flagtable = nullptr; const std::string& srclang = source->GetLanguage(); @@ -2855,8 +2867,10 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( if (compileAsPerConfig) { clOptions.AddFlag("CompileAs", compileAsPerConfig); } - if (shouldScanForModules) { - clOptions.AddFlag("ScanSourceForModuleDependencies", "true"); + if (shouldScanForModules != + this->ScanSourceForModuleDependencies[config]) { + clOptions.AddFlag("ScanSourceForModuleDependencies", + shouldScanForModules ? "true" : "false"); } if (noWinRT) { clOptions.AddFlag("CompileAsWinRT", "false"); @@ -3573,8 +3587,9 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( } } - // Disable C++ source scanning by default. - e2.Element("ScanSourceForModuleDependencies", "false"); + e2.Element("ScanSourceForModuleDependencies", + this->ScanSourceForModuleDependencies[configName] ? "true" + : "false"); } bool cmVisualStudio10TargetGenerator::ComputeRcOptions() diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 2080e9eac..1f8b2eb34 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -238,6 +238,7 @@ private: bool NsightTegra; bool Android; bool HaveCustomCommandDepfile = false; + std::map ScanSourceForModuleDependencies; unsigned int NsightTegraVersion[4]; bool TargetCompileAsWinRT; std::set IPOEnabledConfigurations; diff --git a/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt b/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt new file mode 100644 index 000000000..8821dadf3 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt @@ -0,0 +1,3 @@ +(-- )?Hello from platform switch +(-- )?Hello from arch switch +(-- )?Hello from pkg_a diff --git a/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir.cmake b/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir.cmake new file mode 100644 index 000000000..e47266574 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir.cmake @@ -0,0 +1,50 @@ +set(CMAKE_INSTALL_DATADIR share) +set(SWITCH_DIR platform/cmake) + +include(CMakePackageConfigHelpers) + +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pkg_a-config.cmake.in [[ +@PACKAGE_INIT@ +include("@PACKAGE_SWITCH_DIR@/platform-switch.cmake") +include("@PACKAGE_CMAKE_INSTALL_DATADIR@/pkg_a_included.cmake") +]]) +configure_package_config_file( + ${CMAKE_CURRENT_BINARY_DIR}/pkg_a-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/install/pkg_a-config.cmake + INSTALL_DESTINATION . + PATH_VARS CMAKE_INSTALL_DATADIR SWITCH_DIR +) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/install/${CMAKE_INSTALL_DATADIR}/pkg_a_included.cmake + [[message(STATUS "Hello from pkg_a")]] +) + +# To expose re-using the same package prefix variable, we need to use a +# different install prefix. This is really contrived and not representative of +# what a package should do. +generate_apple_platform_selection_file( + ${CMAKE_CURRENT_BINARY_DIR}/install/platform/cmake/platform-switch.cmake + INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/platform + INSTALL_DESTINATION cmake + MACOS_INCLUDE_FILE cmake/switch_included.cmake # relative to install prefix +) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/install/platform/cmake/switch_included.cmake +[[ +message(STATUS "Hello from platform switch") +include("${CMAKE_CURRENT_LIST_DIR}/../arch/cmake/arch-switch.cmake") +]] +) + +generate_apple_architecture_selection_file( + ${CMAKE_CURRENT_BINARY_DIR}/install/platform/arch/cmake/arch-switch.cmake + INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/platform/arch + INSTALL_DESTINATION cmake + UNIVERSAL_ARCHITECTURES i386 x86_64 arm64 $(ARCHS_STANDARD) + UNIVERSAL_INCLUDE_FILE cmake/switch_included.cmake # relative to install prefix +) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/install/platform/arch/cmake/switch_included.cmake + [[message(STATUS "Hello from arch switch")]] +) + +find_package(pkg_a REQUIRED NO_DEFAULT_PATH + PATHS ${CMAKE_CURRENT_BINARY_DIR}/install +) diff --git a/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake b/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake index 1551b55f6..3b4bef520 100644 --- a/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake @@ -48,9 +48,6 @@ if(APPLE) endif() if(APPLE AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang") - set(apple_install ${RunCMake_BINARY_DIR}/apple-install) - file(REMOVE_RECURSE "${apple_install}") - if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 12) set(macos_archs "x86_64;arm64") set(tvos_sim_archs "x86_64;arm64") @@ -78,6 +75,17 @@ if(APPLE AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang") set(enable_visionos 1) endif() + string(REPLACE ";" "\\;" macos_archs_for_cmd "${macos_archs}") + run_cmake_with_options(ApplePlatformGenSubdir + "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_for_cmd}" + ${maybe_CMAKE_BUILD_TYPE} + ) + unset(macos_archs_for_cmd) + + # Place all export/import steps in a single install prefix. + set(apple_install ${RunCMake_BINARY_DIR}/apple-install) + file(REMOVE_RECURSE "${apple_install}") + apple_export(macos Darwin "${macos_archs}" macosx) apple_export(ios iOS "arm64" iphoneos) apple_export(tvos tvOS "arm64" appletvos) diff --git a/Tests/RunCMake/CXXModules/NinjaDependInfoExportFilesystemSafe-check.cmake b/Tests/RunCMake/CXXModules/NinjaDependInfoExportFilesystemSafe-check.cmake new file mode 100644 index 000000000..d08aef780 --- /dev/null +++ b/Tests/RunCMake/CXXModules/NinjaDependInfoExportFilesystemSafe-check.cmake @@ -0,0 +1,39 @@ +include("${CMAKE_CURRENT_LIST_DIR}/check-json.cmake") + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(have_file 0) + foreach (CXXModules_config IN ITEMS Release Debug RelWithDebInfo MinSizeRel) + if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/ninja-exports-public.dir/${CXXModules_config}/CXXDependInfo.json") + continue () + endif () + set(have_file 1) + + set(CMAKE_BUILD_TYPE "${CXXModules_config}") + + file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/ninja-exports-public.dir/${CXXModules_config}/CXXDependInfo.json" actual_contents) + file(READ "${CMAKE_CURRENT_LIST_DIR}/expect/NinjaDependInfoExportFilesystemSafe-public.json" expect_contents) + check_json("${actual_contents}" "${expect_contents}") + + file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/ninja-exports-private.dir/${CXXModules_config}/CXXDependInfo.json" actual_contents) + file(READ "${CMAKE_CURRENT_LIST_DIR}/expect/NinjaDependInfoExportFilesystemSafe-private.json" expect_contents) + check_json("${actual_contents}" "${expect_contents}") + endforeach () + + if (NOT have_file) + list(APPEND RunCMake_TEST_FAILED + "No recognized build configurations found.") + endif () +else () + set(CXXModules_config "${CXXModules_default_build_type}") + set(CMAKE_BUILD_TYPE "${CXXModules_default_build_type}") + + file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/ninja-exports-public.dir/CXXDependInfo.json" actual_contents) + file(READ "${CMAKE_CURRENT_LIST_DIR}/expect/NinjaDependInfoExportFilesystemSafe-public.json" expect_contents) + check_json("${actual_contents}" "${expect_contents}") + + file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/ninja-exports-private.dir/CXXDependInfo.json" actual_contents) + file(READ "${CMAKE_CURRENT_LIST_DIR}/expect/NinjaDependInfoExportFilesystemSafe-private.json" expect_contents) + check_json("${actual_contents}" "${expect_contents}") +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/NinjaDependInfoExportFilesystemSafe.cmake b/Tests/RunCMake/CXXModules/NinjaDependInfoExportFilesystemSafe.cmake new file mode 100644 index 000000000..890b5e41a --- /dev/null +++ b/Tests/RunCMake/CXXModules/NinjaDependInfoExportFilesystemSafe.cmake @@ -0,0 +1,84 @@ +# Fake out that we have dyndep; we only need to generate, not actually build +# here. +set(CMAKE_CXX_SCANDEP_SOURCE "") + +enable_language(CXX) + +if (NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "This test requires a 'Ninja' generator to be used.") +endif () + +add_library(ninja-exports-public) +target_sources(ninja-exports-public + PRIVATE + sources/module-impl.cxx + sources/module-internal-part-impl.cxx + sources/module-part-impl.cxx + sources/module-use.cxx + PUBLIC + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}/sources" + FILES + sources/module.cxx + sources/module-part.cxx + FILE_SET internal_partitions TYPE CXX_MODULES FILES + sources/module-internal-part.cxx) +target_compile_features(ninja-exports-public + PRIVATE + cxx_std_20) +set_property(TARGET ninja-exports-public + PROPERTY EXPORT_NAME "with::public_") + +install(TARGETS ninja-exports-public + EXPORT exp + FILE_SET modules + DESTINATION "lib/cxx" + COMPONENT "modules" + FILE_SET internal_partitions + DESTINATION "lib/cxx/internals" + COMPONENT "modules-internal") + +add_library(ninja-exports-private) +target_sources(ninja-exports-private + PRIVATE + sources/module-impl.cxx + sources/module-internal-part-impl.cxx + sources/module-part-impl.cxx + sources/module-use.cxx + PRIVATE + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}/sources" + FILES + sources/module.cxx + sources/module-part.cxx + FILE_SET internal_partitions TYPE CXX_MODULES FILES + sources/module-internal-part.cxx) +target_compile_features(ninja-exports-private + PRIVATE + cxx_std_20) +set_property(TARGET ninja-exports-private + PROPERTY EXPORT_NAME "with::private_") + +install(TARGETS ninja-exports-private + EXPORT exp) + +# Test multiple build exports. +export(EXPORT exp + FILE "${CMAKE_BINARY_DIR}/lib/cmake/export1/export1-targets.cmake" + NAMESPACE export1:: + CXX_MODULES_DIRECTORY "cxx-modules") +export(EXPORT exp + FILE "${CMAKE_BINARY_DIR}/lib/cmake/export2/export2-targets.cmake" + CXX_MODULES_DIRECTORY "cxx-modules") + +# Test multiple install exports. +install(EXPORT exp + DESTINATION "lib/cmake/export1" + NAMESPACE export1:: + CXX_MODULES_DIRECTORY "cxx-modules") +install(EXPORT exp + DESTINATION "lib/cmake/export2" + CXX_MODULES_DIRECTORY "cxx-modules") diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index 14829a164..23c32c008 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -95,6 +95,7 @@ run_cmake(ExportInstallCxxModules) if (RunCMake_GENERATOR MATCHES "Ninja") run_cmake(NinjaDependInfoFileSet) run_cmake(NinjaDependInfoExport) + run_cmake(NinjaDependInfoExportFilesystemSafe) run_cmake(NinjaDependInfoBMIInstall) run_cmake(NinjaForceResponseFile) # issue#25367 elseif (RunCMake_GENERATOR MATCHES "Visual Studio") @@ -264,9 +265,11 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(export-include-directories-old-cmake-build) run_cxx_module_test(export-usage-build) run_cxx_module_test(export-bmi-and-interface-build) + run_cxx_module_test(export-command-sepdir-build) run_cxx_module_test(export-transitive-targets-build) run_cxx_module_test(export-transitive-modules1-build) run_cxx_module_test(export-transitive-modules-build export-transitive-modules-build "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/export-transitive-modules1-build-build" ) + run_cxx_module_test(export-with-headers-build) if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND "bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION) @@ -282,11 +285,17 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) set(test_suffix export-bmi-and-interface-build) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DWITH_BMIS=1) + set(test_suffix export-command-sepdir-build) + run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DEXPORT_COMMAND_SEPDIR=1) + set(test_suffix export-transitive-targets-build) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DTRANSITIVE_TARGETS=1) set(test_suffix export-transitive-modules-build) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DTRANSITIVE_MODULES=1) + + set(test_suffix export-with-headers-build) + run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DWITH_HEADERS=1) endif () endif () @@ -305,9 +314,11 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(export-include-directories-old-cmake-install) run_cxx_module_test(export-usage-install) run_cxx_module_test(export-bmi-and-interface-install) + run_cxx_module_test(export-command-sepdir-install) run_cxx_module_test(export-transitive-targets-install) run_cxx_module_test(export-transitive-modules1-install) run_cxx_module_test(export-transitive-modules-install export-transitive-modules-install "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/export-transitive-modules1-install-install" ) + run_cxx_module_test(export-with-headers-install) if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND "bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION) @@ -324,11 +335,17 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) set(test_suffix export-bmi-and-interface-install) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DWITH_BMIS=1) + set(test_suffix export-command-sepdir-install) + run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DEXPORT_COMMAND_SEPDIR=1) + set(test_suffix export-transitive-targets-install) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DTRANSITIVE_TARGETS=1) set(test_suffix export-transitive-modules-install) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DTRANSITIVE_MODULES=1) + + set(test_suffix export-with-headers-install) + run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DWITH_HEADERS=1) set(RunCMake_CXXModules_INSTALL 1) endif () endif () diff --git a/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/CMakeLists.txt new file mode 100644 index 000000000..4f3fcf8a3 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.24...3.28) +project(cxx_modules_export_sepdir CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +add_subdirectory(subdir) + +install(TARGETS export_sepdir + EXPORT CXXModules + FILE_SET modules DESTINATION "lib/cxx/miu") +export(EXPORT CXXModules + NAMESPACE CXXModules:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/export_sepdir-targets.cmake") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_sepdir-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_sepdir-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") + +set(generator + -G "${CMAKE_GENERATOR}") +if (CMAKE_GENERATOR_TOOLSET) + list(APPEND generator + -T "${CMAKE_GENERATOR_TOOLSET}") +endif () +if (CMAKE_GENERATOR_PLATFORM) + list(APPEND generator + -A "${CMAKE_GENERATOR_PLATFORM}") +endif () + +add_test(NAME export_sepdir_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexpected_dir=${CMAKE_CURRENT_SOURCE_DIR}" + "-Dexport_sepdir_DIR=${CMAKE_CURRENT_BINARY_DIR}" + ${generator} + -S "${CMAKE_CURRENT_SOURCE_DIR}/test" + -B "${CMAKE_CURRENT_BINARY_DIR}/test") diff --git a/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/subdir/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/subdir/CMakeLists.txt new file mode 100644 index 000000000..cd571f694 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/subdir/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(export_sepdir STATIC) +target_sources(export_sepdir + PUBLIC + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}" + FILES + importable.cxx) +target_compile_features(export_sepdir PUBLIC cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/subdir/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/subdir/importable.cxx new file mode 100644 index 000000000..607680a07 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/subdir/importable.cxx @@ -0,0 +1,6 @@ +export module importable; + +export int from_import() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/test/CMakeLists.txt new file mode 100644 index 000000000..d39327158 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-build/test/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.24...3.28) +project(cxx_modules_library NONE) + +find_package(export_sepdir REQUIRED) + +if (NOT TARGET CXXModules::export_sepdir) + message(FATAL_ERROR + "Missing imported target") +endif () + +get_property(modules TARGET CXXModules::export_sepdir + PROPERTY "IMPORTED_CXX_MODULES_NOCONFIG") +if (modules STREQUAL "") + message(SEND_ERROR + "Expected non-empty property value for IMPORTED_CXX_MODULES_NOCONFIG") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/CMakeLists.txt new file mode 100644 index 000000000..de21a2e61 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.24...3.28) +project(cxx_modules_export_sepdir CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +add_subdirectory(subdir) + +install(TARGETS export_sepdir + EXPORT CXXModules + FILE_SET modules DESTINATION "lib/cxx/miu") +install(EXPORT CXXModules + NAMESPACE CXXModules:: + DESTINATION "lib/cmake/export_sepdir" + FILE "export_sepdir-targets.cmake") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_sepdir-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_sepdir-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/export_sepdir-config.cmake" + DESTINATION "lib/cmake/export_sepdir") + +set(generator + -G "${CMAKE_GENERATOR}") +if (CMAKE_GENERATOR_TOOLSET) + list(APPEND generator + -T "${CMAKE_GENERATOR_TOOLSET}") +endif () +if (CMAKE_GENERATOR_PLATFORM) + list(APPEND generator + -A "${CMAKE_GENERATOR_PLATFORM}") +endif () + +add_test(NAME export_sepdir_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexpected_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/miu" + "-Dexport_sepdir_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/export_sepdir" + ${generator} + -S "${CMAKE_CURRENT_SOURCE_DIR}/test" + -B "${CMAKE_CURRENT_BINARY_DIR}/test") diff --git a/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/subdir/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/subdir/CMakeLists.txt new file mode 100644 index 000000000..cd571f694 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/subdir/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(export_sepdir STATIC) +target_sources(export_sepdir + PUBLIC + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}" + FILES + importable.cxx) +target_compile_features(export_sepdir PUBLIC cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/subdir/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/subdir/importable.cxx new file mode 100644 index 000000000..607680a07 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/subdir/importable.cxx @@ -0,0 +1,6 @@ +export module importable; + +export int from_import() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/test/CMakeLists.txt new file mode 100644 index 000000000..d39327158 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-command-sepdir-install/test/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.24...3.28) +project(cxx_modules_library NONE) + +find_package(export_sepdir REQUIRED) + +if (NOT TARGET CXXModules::export_sepdir) + message(FATAL_ERROR + "Missing imported target") +endif () + +get_property(modules TARGET CXXModules::export_sepdir + PROPERTY "IMPORTED_CXX_MODULES_NOCONFIG") +if (modules STREQUAL "") + message(SEND_ERROR + "Expected non-empty property value for IMPORTED_CXX_MODULES_NOCONFIG") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/CMakeLists.txt new file mode 100644 index 000000000..e329189e3 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/CMakeLists.txt @@ -0,0 +1,49 @@ +cmake_minimum_required(VERSION 3.28) +project(export_with_headers CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +add_library(export_with_headers) +target_sources(export_with_headers + PUBLIC + FILE_SET headers TYPE HEADERS + BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" + FILES + "${CMAKE_CURRENT_SOURCE_DIR}/include/subdir/header.h" + PUBLIC + FILE_SET modules TYPE CXX_MODULES + FILES + importable.cxx) +target_compile_features(export_with_headers PUBLIC cxx_std_20) + +install(TARGETS export_with_headers + EXPORT CXXModules + FILE_SET headers + FILE_SET modules DESTINATION ${CMAKE_INSTALL_LIBDIR}/miu) +export(EXPORT CXXModules + NAMESPACE CXXModules:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-targets.cmake" + CXX_MODULES_DIRECTORY "export_with_headers-cxx-modules") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_with_headers-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") + +set(generator + -G "${CMAKE_GENERATOR}") +if (CMAKE_GENERATOR_TOOLSET) + list(APPEND generator + -T "${CMAKE_GENERATOR_TOOLSET}") +endif () +if (CMAKE_GENERATOR_PLATFORM) + list(APPEND generator + -A "${CMAKE_GENERATOR_PLATFORM}") +endif () + +add_test(NAME export_with_headers_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexport_with_headers_DIR=${CMAKE_CURRENT_BINARY_DIR}" + ${generator} + -S "${CMAKE_CURRENT_SOURCE_DIR}/test" + -B "${CMAKE_CURRENT_BINARY_DIR}/test") diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-build/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/importable.cxx new file mode 100644 index 000000000..83d5b5070 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/importable.cxx @@ -0,0 +1,14 @@ +module; + +#include + +#ifndef from_subdir_header_h +# error "Define from header found" +#endif + +export module importable; + +export int from_import() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-build/include/subdir/header.h b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/include/subdir/header.h new file mode 100644 index 000000000..81e821502 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/include/subdir/header.h @@ -0,0 +1,3 @@ +#pragma once + +#define from_subdir_header_h 1 diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-build/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/test/CMakeLists.txt new file mode 100644 index 000000000..11b0daeb0 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/test/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.28) +project(cxx_modules_library NONE) + +find_package(export_with_headers REQUIRED) + +if (NOT TARGET CXXModules::export_with_headers) + message(FATAL_ERROR + "Missing imported target") +endif () + +get_property(iface_includes TARGET CXXModules::export_with_headers + PROPERTY INTERFACE_INCLUDE_DIRECTORIES) +set(include_dir "${CMAKE_CURRENT_SOURCE_DIR}") +cmake_path(GET include_dir PARENT_PATH include_dir) +string(APPEND include_dir "/include") +if (NOT iface_includes STREQUAL "${include_dir};$") + message(FATAL_ERROR + "Incorrect include interface for CXXModules::export_with_headers:\n ${iface_includes}") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/CMakeLists.txt new file mode 100644 index 000000000..f6aefaf8e --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.28) +project(export_with_headers CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +add_library(export_with_headers) +target_sources(export_with_headers + PUBLIC + FILE_SET headers TYPE HEADERS + BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" + FILES + "${CMAKE_CURRENT_SOURCE_DIR}/include/subdir/header.h" + PUBLIC + FILE_SET modules TYPE CXX_MODULES + FILES + importable.cxx) +target_compile_features(export_with_headers PUBLIC cxx_std_20) + +install(TARGETS export_with_headers + EXPORT CXXModules + FILE_SET headers + FILE_SET modules DESTINATION lib/miu) +install(EXPORT CXXModules + NAMESPACE CXXModules:: + DESTINATION "lib/cmake/export_with_headers" + FILE "export_with_headers-targets.cmake") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_with_headers-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-config.cmake" + DESTINATION "lib/cmake/export_with_headers") + +set(generator + -G "${CMAKE_GENERATOR}") +if (CMAKE_GENERATOR_TOOLSET) + list(APPEND generator + -T "${CMAKE_GENERATOR_TOOLSET}") +endif () +if (CMAKE_GENERATOR_PLATFORM) + list(APPEND generator + -A "${CMAKE_GENERATOR_PLATFORM}") +endif () + +add_test(NAME export_with_headers_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexport_with_headers_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/export_with_headers" + ${generator} + -S "${CMAKE_CURRENT_SOURCE_DIR}/test" + -B "${CMAKE_CURRENT_BINARY_DIR}/test") diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-install/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/importable.cxx new file mode 100644 index 000000000..83d5b5070 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/importable.cxx @@ -0,0 +1,14 @@ +module; + +#include + +#ifndef from_subdir_header_h +# error "Define from header found" +#endif + +export module importable; + +export int from_import() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-install/include/subdir/header.h b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/include/subdir/header.h new file mode 100644 index 000000000..81e821502 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/include/subdir/header.h @@ -0,0 +1,3 @@ +#pragma once + +#define from_subdir_header_h 1 diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-install/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/test/CMakeLists.txt new file mode 100644 index 000000000..40d66cbcf --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/test/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.28) +project(cxx_modules_library NONE) + +find_package(export_with_headers REQUIRED) + +if (NOT TARGET CXXModules::export_with_headers) + message(FATAL_ERROR + "Missing imported target") +endif () + +get_property(iface_includes TARGET CXXModules::export_with_headers + PROPERTY INTERFACE_INCLUDE_DIRECTORIES) +set(include_dir "${export_with_headers_DIR}") +cmake_path(GET include_dir PARENT_PATH include_dir) +cmake_path(GET include_dir PARENT_PATH include_dir) +cmake_path(GET include_dir PARENT_PATH include_dir) +string(APPEND include_dir "/include") +if (NOT iface_includes STREQUAL "$") + message(FATAL_ERROR + "Incorrect include interface for CXXModules::export_with_headers:\n ${iface_includes}") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt index c2bbb2e9b..6796660ba 100644 --- a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt @@ -7,6 +7,8 @@ if (NO_PROPERTIES) set(package_name "export_interfaces_no_properties") elseif (WITH_BMIS) set(package_name "export_bmi_and_interfaces") +elseif (EXPORT_COMMAND_SEPDIR) + set(package_name "export_sepdir") elseif (INCLUDE_PROPERTIES) set(package_name "export_include_directories") elseif (FROM_NINJA) @@ -15,6 +17,8 @@ elseif (TRANSITIVE_TARGETS) set(package_name "export_transitive_targets") elseif (TRANSITIVE_MODULES) set(package_name "export_transitive_modules") +elseif (WITH_HEADERS) + set(package_name "export_with_headers") else () set(package_name "export_interfaces") endif () diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json index 61f8f6476..71b2b66e8 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json @@ -43,6 +43,7 @@ "destination" : "lib/cmake/export1", "export-name" : "with-private", "export-prefix" : "/CMakeFiles/Export/d2e2673818fd2bd8c45c0e3ed0e38fcd", + "filesystem-export-name" : "with-private", "install" : true, "namespace" : "export1::" }, @@ -51,6 +52,7 @@ "destination" : "lib/cmake/export2", "export-name" : "with-private", "export-prefix" : "/CMakeFiles/Export/28cd47cb4c96ad5cadaa3fb1b0201ae8", + "filesystem-export-name" : "with-private", "install" : true, "namespace" : "" }, @@ -59,6 +61,7 @@ "destination" : "/lib/cmake/export1", "export-name" : "with-private", "export-prefix" : "/lib/cmake/export1", + "filesystem-export-name" : "with-private", "install" : false, "namespace" : "export1::" }, @@ -67,6 +70,7 @@ "destination" : "/lib/cmake/export2", "export-name" : "with-private", "export-prefix" : "/lib/cmake/export2", + "filesystem-export-name" : "with-private", "install" : false, "namespace" : "" } diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json index d0263b0b9..a9cde991a 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json @@ -43,6 +43,7 @@ "destination" : "lib/cmake/export1", "export-name" : "with-public", "export-prefix" : "/CMakeFiles/Export/d2e2673818fd2bd8c45c0e3ed0e38fcd", + "filesystem-export-name" : "with-public", "install" : true, "namespace" : "export1::" }, @@ -51,6 +52,7 @@ "destination" : "lib/cmake/export2", "export-name" : "with-public", "export-prefix" : "/CMakeFiles/Export/28cd47cb4c96ad5cadaa3fb1b0201ae8", + "filesystem-export-name" : "with-public", "install" : true, "namespace" : "" }, @@ -59,6 +61,7 @@ "destination" : "/lib/cmake/export1", "export-name" : "with-public", "export-prefix" : "/lib/cmake/export1", + "filesystem-export-name" : "with-public", "install" : false, "namespace" : "export1::" }, @@ -67,6 +70,7 @@ "destination" : "/lib/cmake/export2", "export-name" : "with-public", "export-prefix" : "/lib/cmake/export2", + "filesystem-export-name" : "with-public", "install" : false, "namespace" : "" } diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json new file mode 100644 index 000000000..7905c535f --- /dev/null +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json @@ -0,0 +1,83 @@ +{ + "bmi-installation": null, + "compiler-id": "", + "compiler-frontend-variant": "", + "compiler-simulate-id": "", + "config": "", + "cxx-modules": { + "CMakeFiles/ninja-exports-private.dir/sources/module-internal-part.cxx": { + "bmi-only": false, + "destination": null, + "name": "internal_partitions", + "relative-directory": "sources", + "source": "/sources/module-internal-part.cxx", + "type": "CXX_MODULES", + "visibility": "PRIVATE" + }, + "CMakeFiles/ninja-exports-private.dir/sources/module-part.cxx": { + "bmi-only": false, + "destination": null, + "name": "modules", + "relative-directory": "", + "source": "/sources/module-part.cxx", + "type": "CXX_MODULES", + "visibility": "PRIVATE" + }, + "CMakeFiles/ninja-exports-private.dir/sources/module.cxx": { + "bmi-only": false, + "destination": null, + "name": "modules", + "relative-directory": "", + "source": "/sources/module.cxx", + "type": "CXX_MODULES", + "visibility": "PRIVATE" + } + }, + "dir-cur-bld": "", + "dir-cur-src": "", + "dir-top-bld": "", + "dir-top-src": "", + "exports": [ + { + "cxx-module-info-dir" : "cxx-modules", + "destination" : "lib/cmake/export1", + "export-name" : "with::private_", + "export-prefix" : "/CMakeFiles/Export/d2e2673818fd2bd8c45c0e3ed0e38fcd", + "filesystem-export-name" : "with_c_cprivate__", + "install" : true, + "namespace" : "export1::" + }, + { + "cxx-module-info-dir" : "cxx-modules", + "destination" : "lib/cmake/export2", + "export-name" : "with::private_", + "filesystem-export-name" : "with_c_cprivate__", + "export-prefix" : "/CMakeFiles/Export/28cd47cb4c96ad5cadaa3fb1b0201ae8", + "install" : true, + "namespace" : "" + }, + { + "cxx-module-info-dir" : "cxx-modules", + "destination" : "/lib/cmake/export1", + "export-name" : "with::private_", + "export-prefix" : "/lib/cmake/export1", + "filesystem-export-name" : "with_c_cprivate__", + "install" : false, + "namespace" : "export1::" + }, + { + "cxx-module-info-dir" : "cxx-modules", + "destination" : "/lib/cmake/export2", + "export-name" : "with::private_", + "export-prefix" : "/lib/cmake/export2", + "filesystem-export-name" : "with_c_cprivate__", + "install" : false, + "namespace" : "" + } + ], + "include-dirs": [], + "language": "CXX", + "forward-modules-from-target-dirs": [], + "linked-target-dirs": [], + "module-dir": "/CMakeFiles/ninja-exports-private.dir" +} diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json new file mode 100644 index 000000000..1734590a9 --- /dev/null +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json @@ -0,0 +1,83 @@ +{ + "bmi-installation": null, + "compiler-id": "", + "compiler-frontend-variant": "", + "compiler-simulate-id": "", + "config": "", + "cxx-modules": { + "CMakeFiles/ninja-exports-public.dir/sources/module-internal-part.cxx": { + "bmi-only": false, + "destination": "lib/cxx/internals", + "name": "internal_partitions", + "relative-directory": "sources", + "source": "/sources/module-internal-part.cxx", + "type": "CXX_MODULES", + "visibility": "PUBLIC" + }, + "CMakeFiles/ninja-exports-public.dir/sources/module-part.cxx": { + "bmi-only": false, + "destination": "lib/cxx", + "name": "modules", + "relative-directory": "", + "source": "/sources/module-part.cxx", + "type": "CXX_MODULES", + "visibility": "PUBLIC" + }, + "CMakeFiles/ninja-exports-public.dir/sources/module.cxx": { + "bmi-only": false, + "destination": "lib/cxx", + "name": "modules", + "relative-directory": "", + "source": "/sources/module.cxx", + "type": "CXX_MODULES", + "visibility": "PUBLIC" + } + }, + "dir-cur-bld": "", + "dir-cur-src": "", + "dir-top-bld": "", + "dir-top-src": "", + "exports": [ + { + "cxx-module-info-dir" : "cxx-modules", + "destination" : "lib/cmake/export1", + "export-name" : "with::public_", + "export-prefix" : "/CMakeFiles/Export/d2e2673818fd2bd8c45c0e3ed0e38fcd", + "filesystem-export-name" : "with_c_cpublic__", + "install" : true, + "namespace" : "export1::" + }, + { + "cxx-module-info-dir" : "cxx-modules", + "destination" : "lib/cmake/export2", + "export-name" : "with::public_", + "export-prefix" : "/CMakeFiles/Export/28cd47cb4c96ad5cadaa3fb1b0201ae8", + "filesystem-export-name" : "with_c_cpublic__", + "install" : true, + "namespace" : "" + }, + { + "cxx-module-info-dir" : "cxx-modules", + "destination" : "/lib/cmake/export1", + "export-name" : "with::public_", + "export-prefix" : "/lib/cmake/export1", + "filesystem-export-name" : "with_c_cpublic__", + "install" : false, + "namespace" : "export1::" + }, + { + "cxx-module-info-dir" : "cxx-modules", + "destination" : "/lib/cmake/export2", + "export-name" : "with::public_", + "export-prefix" : "/lib/cmake/export2", + "filesystem-export-name" : "with_c_cpublic__", + "install" : false, + "namespace" : "" + } + ], + "include-dirs": [], + "language": "CXX", + "forward-modules-from-target-dirs": [], + "linked-target-dirs": [], + "module-dir": "/CMakeFiles/ninja-exports-public.dir" +}