Skip to content

Commit

Permalink
fix: add support for C++20 modules for CMake 3.27.0/3.27.1 (#1632)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
theHamsta authored Aug 7, 2023
1 parent 68052d9 commit cf70eb8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@

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
Expand Down

0 comments on commit cf70eb8

Please sign in to comment.