11cmake_minimum_required (VERSION 3.29)
22
3- # Enable C++ module dependency scanning
4- set (CMAKE_CXX_SCAN_FOR_MODULES ON )
5-
63project (SimpleEngine VERSION 1.0.0 LANGUAGES CXX C)
74
5+ # Option to enable/disable Vulkan C++20 module support for this standalone project
6+ option (ENABLE_CPP20_MODULE "Enable C++ 20 module support for Vulkan in SimpleEngine" OFF )
7+
8+ # Enable C++ module dependency scanning only when modules are enabled
9+ if (ENABLE_CPP20_MODULE)
10+ set (CMAKE_CXX_SCAN_FOR_MODULES ON )
11+ endif ()
12+
813# Add CMake module path for custom find modules
9- list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR} /../ CMake" )
14+ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR} /CMake" )
1015
1116# Find required packages
1217find_package (glfw3 REQUIRED)
@@ -16,32 +21,52 @@ find_package (tinygltf REQUIRED)
1621find_package (KTX REQUIRED)
1722find_package (OpenAL REQUIRED)
1823
19- # set up Vulkan C++ module
20- add_library (VulkanCppModule)
21- add_library (Vulkan::cppm ALIAS VulkanCppModule)
24+ if (ENABLE_CPP20_MODULE)
25+ # Set up Vulkan C++ module for this standalone project
26+ add_library (VulkanCppModule)
27+ add_library (Vulkan::cppm ALIAS VulkanCppModule)
2228
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- )
29+ target_compile_definitions (VulkanCppModule
30+ PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1
31+ )
32+ target_include_directories (VulkanCppModule
33+ PUBLIC
34+ "${Vulkan_INCLUDE_DIR} "
35+ )
36+ target_link_libraries (VulkanCppModule
37+ PUBLIC
38+ Vulkan::Vulkan
39+ )
3440
35- set_target_properties (VulkanCppModule PROPERTIES CXX_STANDARD 20)
41+ set_target_properties (VulkanCppModule PROPERTIES CXX_STANDARD 20)
3642
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- )
43+ target_sources (VulkanCppModule
44+ PUBLIC
45+ FILE_SET cxx_modules TYPE CXX_MODULES
46+ BASE_DIRS
47+ "${Vulkan_INCLUDE_DIR} "
48+ FILES
49+ "${Vulkan_INCLUDE_DIR} /vulkan/vulkan.cppm"
50+ )
51+
52+ # MSVC-specific options to improve module support
53+ if (MSVC )
54+ target_compile_options (VulkanCppModule PRIVATE
55+ /std:c++latest
56+ /permissive-
57+ /Zc:__cplusplus
58+ /EHsc
59+ /Zc:preprocessor
60+ )
61+ endif ()
62+ else ()
63+ add_library (VulkanCppModule INTERFACE )
64+ add_library (Vulkan::cppm ALIAS VulkanCppModule)
65+ target_link_libraries (VulkanCppModule INTERFACE Vulkan::Vulkan)
66+ target_compile_definitions (VulkanCppModule
67+ INTERFACE VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1
68+ )
69+ endif ()
4570
4671
4772
5580endif ()
5681
5782# Shader compilation
58- # Find Slang shaders
83+ # Find Slang shaders (exclude utility modules that are imported, not compiled standalone)
5984file (GLOB SLANG_SHADER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR} /shaders/*.slang)
85+ list (FILTER SLANG_SHADER_SOURCES EXCLUDE REGEX ".*/(common_types|pbr_utils|lighting_utils|tonemapping_utils)\\ .slang$" )
6086
6187# Find slangc executable (optional)
6288find_program (SLANGC_EXECUTABLE slangc HINTS $ENV{VULKAN_SDK} /bin)
@@ -97,13 +123,15 @@ set(SOURCES
97123 renderer_compute.cpp
98124 renderer_utils.cpp
99125 renderer_resources.cpp
126+ renderer_ray_query.cpp
100127 memory_pool.cpp
101128 resource_manager.cpp
102129 entity.cpp
103130 component .cpp
104131 transform_component.cpp
105132 mesh_component.cpp
106133 camera_component.cpp
134+ animation_component.cpp
107135 model_loader.cpp
108136 audio_system.cpp
109137 physics_system.cpp
@@ -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
@@ -135,6 +178,33 @@ if(NOT ANDROID)
135178 target_link_libraries (SimpleEngine PRIVATE glfw)
136179endif ()
137180
181+ # Windows/MSVC portability and build settings
182+ if (MSVC )
183+ # Avoid Windows.h macro pollution and CRT warnings; improve conformance and build perf
184+ target_compile_definitions (SimpleEngine PRIVATE
185+ NOMINMAX
186+ WIN32_LEAN_AND_MEAN
187+ _CRT_SECURE_NO_WARNINGS
188+ )
189+ target_compile_options (SimpleEngine PRIVATE
190+ /permissive-
191+ /Zc:__cplusplus
192+ /EHsc
193+ /W3
194+ /MP
195+ /bigobj
196+ )
197+ # Crash reporter uses Dbghelp; pragma should suffice, but make it explicit for clarity
198+ target_link_libraries (SimpleEngine PRIVATE Dbghelp)
199+ elseif (WIN32 )
200+ # Non-MSVC Windows toolchains (e.g., MinGW)
201+ target_compile_definitions (SimpleEngine PRIVATE
202+ NOMINMAX
203+ WIN32_LEAN_AND_MEAN
204+ _CRT_SECURE_NO_WARNINGS
205+ )
206+ endif ()
207+
138208# Copy model and texture files if they exist
139209if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /models)
140210 add_custom_command (TARGET SimpleEngine POST_BUILD
0 commit comments