fix: add support for C++20 modules for CMake 3.27.0/3.27.1 (#1632)
authorStephan Seitz <sseitz@nvidia.com>
Mon, 7 Aug 2023 06:56:36 +0000 (23:56 -0700)
committerGitHub <noreply@github.com>
Mon, 7 Aug 2023 06:56:36 +0000 (08:56 +0200)
When using VULKAN_HPP_ENABLE_EXPERIMENTAL_CPP20_MODULES=ON with CMake 3.27.0 or 3.27.1,
you will get a very confusing error message:
```
CMake Error at CMakeLists.txt:346 (target_sources):
  target_sources File set TYPE may only be "HEADERS"
```

This is because the value of `CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API`
is not update to the correct value, disabling all experimental CMake
features.

This PR adds the value for 3.27.X and triggers an error for higher CMake
versions where this feature needs to be revised and
CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API if the feature is still
experimental.

The error message will look similar to this one (simulated for CMake
3.27.1)
```
CMake Error at CMakeLists.txt:30 (message):
  VULKAN_HPP_ENABLE_EXPERIMENTAL_CPP20_MODULES is currently not supported for
  CMake version 3.27.1! To add support inform yourself about the state of the
  feature at
  https://github.com/Kitware/CMake/blob/master/Help/dev/experimental.rst and
  add the corresponding value of CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API to
  Vulkan-Hpp's CMakeLists.txt
```

CMakeLists.txt

index c7a2bd4..564e5f4 100644 (file)
 
 if( VULKAN_HPP_ENABLE_EXPERIMENTAL_CPP20_MODULES )
        cmake_minimum_required( VERSION 3.25 )
-       if ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.26 )
-               # CMake 3.26; need to handle future versions here
+       if ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.28 )
+               message(FATAL_ERROR "VULKAN_HPP_ENABLE_EXPERIMENTAL_CPP20_MODULES is currently not supported for CMake version ${CMAKE_VERSION}!"
+               " To add support inform yourself about the state of the feature at https://github.com/Kitware/CMake/blob/master/Help/dev/experimental.rst"
+               " and add the corresponding value of CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API to Vulkan-Hpp's CMakeLists.txt")
+       elseif ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.27 )
+               # CMake 3.27/3.27.1
+               set( CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API aa1f7df0-828a-4fcd-9afc-2dc80491aca7 )
+       elseif ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.26 )
+               # CMake 3.26
                set( CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 2182bf5c-ef0d-489a-91da-49dbc3090d2a )
        else()
                # CMake 3.25