Skip to content

Commit

Permalink
Adjust module support handling with CMake version 3.28 and above.
Browse files Browse the repository at this point in the history
  • Loading branch information
asuessenbach committed Oct 17, 2023
1 parent 962979c commit e06fe0f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 58 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_STANDARD=${{matrix.cxx_standard}}
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DENABLE_OPT=0

- name: Build
run: cmake --build ${{github.workspace}}/build --parallel
43 changes: 14 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,19 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

if( VULKAN_HPP_ENABLE_EXPERIMENTAL_CPP20_MODULES )
cmake_minimum_required( VERSION 3.25 )
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
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
set( CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 3c375311-a3c9-4396-a187-3227ef642046 )
endif()
set( CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1 )
# all the options for this project
option( VULKAN_HPP_PRECOMPILE "Precompile vulkan.hpp and vulkan_raii.hpp for sample builds" ON )
option( VULKAN_HPP_RUN_GENERATOR "Run the HPP generator" OFF )
option( VULKAN_HPP_SAMPLES_BUILD "Build samples" OFF )
option( VULKAN_HPP_TESTS_BUILD "Build tests" OFF )
option( VULKAN_HPP_SAMPLES_BUILD_ONLY_DYNAMIC "Build only dynamic. Required in case the Vulkan SDK is not available" OFF )
option( VULKAN_HPP_TESTS_BUILD_ONLY_DYNAMIC "Build only dynamic" OFF )
option( VULKAN_HPP_BUILD_WITH_LOCAL_VULKAN_HPP "Build with local Vulkan headers" ON )
option( VULKAN_HPP_ENABLE_CPP20_MODULES "Build Vulkan-Hpp as C++20 module; requires minimum CMake version 3.28" OFF )
option( VULKAN_HPP_CPP20_MODULE_DYNAMIC_DISPATCHER "Build C++20 module with dynamic Dispatcher" ON )

if ( VULKAN_HPP_ENABLE_CPP20_MODULES )
cmake_minimum_required( VERSION 3.28 )
else()
cmake_minimum_required( VERSION 3.12 )
endif()
Expand Down Expand Up @@ -316,17 +312,6 @@ else()
message( WARNING " Could not find clang-format. Generated vulkan.hpp and vulkan_raii.hpp will not be nicely formatted." )
endif()

# all the options for this project
option( VULKAN_HPP_PRECOMPILE "Precompile vulkan.hpp and vulkan_raii.hpp for sample builds" ON )
option( VULKAN_HPP_RUN_GENERATOR "Run the HPP generator" OFF )
option( VULKAN_HPP_SAMPLES_BUILD "Build samples" OFF )
option( VULKAN_HPP_TESTS_BUILD "Build tests" OFF )
option( VULKAN_HPP_SAMPLES_BUILD_ONLY_DYNAMIC "Build only dynamic. Required in case the Vulkan SDK is not available" OFF )
option( VULKAN_HPP_TESTS_BUILD_ONLY_DYNAMIC "Build only dynamic" OFF )
option( VULKAN_HPP_BUILD_WITH_LOCAL_VULKAN_HPP "Build with local Vulkan headers" ON )
option( VULKAN_HPP_ENABLE_EXPERIMENTAL_CPP20_MODULES "Build Vulkan-Hpp as C++20 module" OFF )
option( VULKAN_HPP_CPP20_MODULE_DYNAMIC_DISPATCHER "Build C++20 module with dynamic Dispatcher" ON )

# look for the file vk.xml, the ultimate source of truth for vulkan, to generate the headers from
if( NOT DEFINED VulkanRegistry_DIR )
if( DEFINED VULKAN_HPP_VULKAN_HEADERS_SRC_DIR )
Expand All @@ -347,7 +332,7 @@ set( TINYXML2_HEADERS ${VULKAN_HPP_TINYXML2_SRC_DIR}/tinyxml2.h )
source_group( TinyXML2 FILES ${TINYXML2_HEADERS} ${TINYXML2_SOURCES} )

# Build Vulkan-Hpp as a module
if( VULKAN_HPP_ENABLE_EXPERIMENTAL_CPP20_MODULES )
if ( VULKAN_HPP_ENABLE_CPP20_MODULES )
# create a target to provide VulkanHpp as C++20 module
add_library( VulkanHppModule )
set_target_properties( VulkanHppModule PROPERTIES
Expand Down
33 changes: 6 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,9 @@ The current version of MS Visual Studio 2022 is not able to handle the vulkan.cp
#### Overview
<!-- todo: add a link to the file -->
Vulkan-Hpp now provides a [C++ standard module](https://en.cppreference.com/w/cpp/language/modules) in [`vulkan.cppm`](vulkan/vulkan.cppm).
Vulkan-Hpp provides a [C++ standard module](https://en.cppreference.com/w/cpp/language/modules) in [`vulkan.cppm`](vulkan/vulkan.cppm).
C++ modules are intended to supersede headers so that declarations and definitions may be easily shared across translation units without repeatedly parsing headers; therefore, they can potentially drastically improve compile times for large projects.
In particular, Vulkan-Hpp has some extremely long headers (e.g. [`vulkan_structs.hpp`](vulkan/vulkan_structs.hpp)), and it is hoped that the C++ module will shorten compile times for projects currently using it.
In particular, Vulkan-Hpp has some extremely long headers (e.g. [`vulkan_structs.hpp`](vulkan/vulkan_structs.hpp)), and the C++ module will shorten compile times for projects currently using it.
#### Compiler support
Expand All @@ -693,47 +693,26 @@ This feature requires a recent compiler with complete C++20 support:
* Visual Studio 2019 16.10 or later (providing `cl.exe` 19.28 or later)
* Clang 15.0.0 or later
If you intend to use CMake's [experimental C++ module support](https://www.kitware.com/import-cmake-c20-modules/) (and possibly Ninja), then more recent tools are required:
If you intend to use CMake's C++ module support (and possibly Ninja), then more recent tools are required:
* Visual Studio 17.4 or later (providing `cl.exe` 19.34 or later)
* Clang 16.0.0 or later
* CMake 3.25 or later
* CMake 3.28 or later
* Ninja 1.10.2 or later
Either way, GCC does not completely support C++ modules, is therefore not recommended for use.
##### Usage with CMake
CMake is recommended for use with the Vulkan C++ module, as it provides a convenient platform-agnostic way to configure your project.
As mentioned above, note that CMake's module support is experimental, and usage may change in the future.
Consult the blog post at the link above for more information.
CMake version 3.28 or later is required to support C++ modules.
CMake provides the [FindVulkan module](https://cmake.org/cmake/help/latest/module/FindVulkan.html), which may be used to source the Vulkan SDK and Vulkan headers on your system.
**Note that this module does not yet provide an IMPORTED target for the Vulkan C++ module, so you must set it up manually.**
To use CMake with C++ modules, you must first enable its experimental support, set up `vulkan.cppm` as the source for a library target with `FILE_SET` configured `TYPE = CXX_MODULES`, and then link it into your project.
To use CMake with C++ modules, you must first set up `vulkan.cppm` as the source for a library target with `FILE_SET` configured `TYPE = CXX_MODULES`, and then link it into your project.
```cmake
# enable C++ module support
cmake_minimum_required( VERSION 3.25 )
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
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
set( CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 3c375311-a3c9-4396-a187-3227ef642046 )
endif()
set( CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1 )
...
# find Vulkan SDK
find_package( Vulkan REQUIRED )
Expand Down
2 changes: 1 addition & 1 deletion glslang
Submodule glslang updated 1152 files
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ add_subdirectory( StridedArrayProxy )
add_subdirectory( StructureChain )
add_subdirectory( UniqueHandle )
add_subdirectory( UniqueHandleDefaultArguments )
if( VULKAN_HPP_ENABLE_EXPERIMENTAL_CPP20_MODULES )
if( VULKAN_HPP_ENABLE_CPP20_MODULES )
add_subdirectory( Cpp20Modules )
endif()

0 comments on commit e06fe0f

Please sign in to comment.