-
Notifications
You must be signed in to change notification settings - Fork 75
/
CMakeLists.txt
79 lines (66 loc) · 2.72 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
cmake_minimum_required(VERSION 3.14)
project(niagara)
option(USE_WAYLAND "Use Wayland instead of X11" OFF)
file(GLOB_RECURSE GLSL_SOURCE_FILES "src/shaders/*.glsl")
file(GLOB_RECURSE GLSL_HEADER_FILES "src/shaders/*.h" "src/config.h")
file(GLOB_RECURSE CPP_SOURCE_FILES "src/*.h" "src/*.cpp")
add_executable(niagara
${CPP_SOURCE_FILES}
${GLSL_SOURCE_FILES}
${GLSL_HEADER_FILES})
set_target_properties(niagara PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)
target_compile_definitions(niagara PRIVATE GLFW_INCLUDE_NONE GLM_FORCE_XYZW_ONLY GLM_FORCE_QUAT_DATA_XYZW)
target_include_directories(niagara PRIVATE extern/fast_obj)
if(UNIX)
if(USE_WAYLAND)
target_compile_definitions(niagara PRIVATE VK_USE_PLATFORM_WAYLAND_KHR)
target_compile_definitions(niagara PRIVATE GLFW_EXPOSE_NATIVE_WAYLAND)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WAYLAND_KHR)
else()
target_compile_definitions(niagara PRIVATE VK_USE_PLATFORM_XLIB_KHR)
target_compile_definitions(niagara PRIVATE GLFW_EXPOSE_NATIVE_X11)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_XLIB_KHR)
endif()
elseif(WIN32)
target_compile_definitions(niagara PRIVATE VK_USE_PLATFORM_WIN32_KHR GLFW_EXPOSE_NATIVE_WIN32)
target_compile_definitions(niagara PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
set(VOLK_STATIC_DEFINES "VK_USE_PLATFORM_WIN32_KHR")
endif()
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(extern/glfw)
add_subdirectory(extern/glm)
add_subdirectory(extern/volk)
add_subdirectory(extern/meshoptimizer)
target_link_libraries(niagara
PRIVATE
glfw
glm::glm
volk
meshoptimizer)
if(UNIX)
if(DEFINED ENV{VULKAN_SDK})
set(GLSL_VALIDATOR "$ENV{VULKAN_SDK}/bin/glslangValidator")
else()
set(GLSL_VALIDATOR "glslangValidator")
endif()
elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "AMD64")
set(GLSL_VALIDATOR "$ENV{VULKAN_SDK}/Bin/glslangValidator.exe")
else()
set(GLSL_VALIDATOR "$ENV{VULKAN_SDK}/Bin32/glslangValidator.exe")
endif()
# Thanks to: https://gist.github.com/evilactually/a0d191701cb48f157b05be7f74d79396
set(SPIRV_OUTPUT_DIR "${PROJECT_BINARY_DIR}/src/shaders/")
foreach(GLSL ${GLSL_SOURCE_FILES})
get_filename_component(STEM ${GLSL} NAME_WLE)
set(SPIRV "${SPIRV_OUTPUT_DIR}${STEM}.spv")
add_custom_command(
OUTPUT ${SPIRV}
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/src/shaders/"
COMMAND ${GLSL_VALIDATOR} -V --target-env vulkan1.3 --quiet ${GLSL} -o ${SPIRV}
DEPENDS ${GLSL} ${GLSL_HEADER_FILES})
list(APPEND SPIRV_BINARY_FILES ${SPIRV})
endforeach()
add_custom_target(compile_shaders DEPENDS ${SPIRV_BINARY_FILES})
add_dependencies(niagara compile_shaders)