@@ -5,6 +5,14 @@ set(CMAKE_CXX_SCAN_FOR_MODULES ON)
55
66project (SimpleEngine VERSION 1.0.0 LANGUAGES CXX C)
77
8+ # Option to enable/disable Vulkan C++20 module support for this standalone project
9+ option (ENABLE_CPP20_MODULE "Enable C++ 20 module support for Vulkan in SimpleEngine" OFF )
10+
11+ # Enable C++ module dependency scanning only when modules are enabled
12+ if (ENABLE_CPP20_MODULE)
13+ set (CMAKE_CXX_SCAN_FOR_MODULES ON )
14+ endif ()
15+
816# Add CMake module path for custom find modules
917list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR} /../CMake" )
1018
@@ -16,32 +24,52 @@ find_package (tinygltf REQUIRED)
1624find_package (KTX REQUIRED)
1725find_package (OpenAL REQUIRED)
1826
19- # set up Vulkan C++ module
20- add_library (VulkanCppModule)
21- add_library (Vulkan::cppm ALIAS VulkanCppModule)
27+ if (ENABLE_CPP20_MODULE)
28+ # Set up Vulkan C++ module for this standalone project
29+ add_library (VulkanCppModule)
30+ add_library (Vulkan::cppm ALIAS VulkanCppModule)
2231
23- target_compile_definitions (VulkanCppModule
24- PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1
25- )
26- target_include_directories (VulkanCppModule
27- PRIVATE
28- "${Vulkan_INCLUDE_DIR} "
29- )
30- target_link_libraries (VulkanCppModule
31- PUBLIC
32- Vulkan::Vulkan
33- )
32+ target_compile_definitions (VulkanCppModule
33+ PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1
34+ )
35+ target_include_directories (VulkanCppModule
36+ PUBLIC
37+ "${Vulkan_INCLUDE_DIR} "
38+ )
39+ target_link_libraries (VulkanCppModule
40+ PUBLIC
41+ Vulkan::Vulkan
42+ )
3443
35- set_target_properties (VulkanCppModule PROPERTIES CXX_STANDARD 20)
44+ set_target_properties (VulkanCppModule PROPERTIES CXX_STANDARD 20)
3645
37- target_sources (VulkanCppModule
38- PUBLIC
39- FILE_SET cxx_modules TYPE CXX_MODULES
40- BASE_DIRS
41- "${Vulkan_INCLUDE_DIR} "
42- FILES
43- "${Vulkan_INCLUDE_DIR} /vulkan/vulkan.cppm"
44- )
46+ target_sources (VulkanCppModule
47+ PUBLIC
48+ FILE_SET cxx_modules TYPE CXX_MODULES
49+ BASE_DIRS
50+ "${Vulkan_INCLUDE_DIR} "
51+ FILES
52+ "${Vulkan_INCLUDE_DIR} /vulkan/vulkan.cppm"
53+ )
54+
55+ # MSVC-specific options to improve module support
56+ if (MSVC )
57+ target_compile_options (VulkanCppModule PRIVATE
58+ /std:c++latest
59+ /permissive-
60+ /Zc:__cplusplus
61+ /EHsc
62+ /Zc:preprocessor
63+ )
64+ endif ()
65+ else ()
66+ add_library (VulkanCppModule INTERFACE )
67+ add_library (Vulkan::cppm ALIAS VulkanCppModule)
68+ target_link_libraries (VulkanCppModule INTERFACE Vulkan::Vulkan)
69+ target_compile_definitions (VulkanCppModule
70+ INTERFACE VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1
71+ )
72+ endif ()
4573
4674
4775
@@ -122,9 +150,24 @@ add_executable(SimpleEngine ${SOURCES})
122150add_dependencies (SimpleEngine shaders)
123151set_target_properties (SimpleEngine PROPERTIES CXX_STANDARD 20)
124152
153+ # Enable required defines for GLM experimental extensions and MSVC math constants
154+ target_compile_definitions (SimpleEngine PRIVATE
155+ GLM_ENABLE_EXPERIMENTAL
156+ _USE_MATH_DEFINES
157+ VULKAN_HPP_NO_STRUCT_CONSTRUCTORS
158+ VULKAN_HPP_DISPATCH_LOADER_DYNAMIC
159+ )
160+
125161# Link libraries
162+ # Prefer the Vulkan C++ module target when available (configured at the parent level),
163+ # but fall back to the standard Vulkan library otherwise.
164+ if (TARGET Vulkan::cppm)
165+ target_link_libraries (SimpleEngine PRIVATE Vulkan::cppm)
166+ else ()
167+ target_link_libraries (SimpleEngine PRIVATE Vulkan::Vulkan)
168+ endif ()
169+
126170target_link_libraries (SimpleEngine PRIVATE
127- Vulkan::cppm
128171 glm::glm
129172 tinygltf::tinygltf
130173 KTX::ktx
0 commit comments