Now it's much more usable, you are forced to use a hosted shader compiler on a platform that needs it (for example, iOS) and now CMake will error when it's missing. Now every platform is very specific on which languages it needs to be translated to, and whether a hosted compiler is needed. No more manually copying over shaders!
127 lines
No EOL
3.1 KiB
CMake
Executable file
127 lines
No EOL
3.1 KiB
CMake
Executable file
cmake_minimum_required(VERSION 3.20)
|
|
project(PrismEngine)
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
|
|
|
|
# enable folders in IDEs that support this feature
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/cmake/Common.cmake)
|
|
include(${CMAKE_CURRENT_LIST_DIR}/cmake/AddPlatformExecutable.cmake)
|
|
include(FetchContent)
|
|
|
|
#set(SHADER_COMPILER_COMMAND $<TARGET_FILE:ShaderCompilerTool>)
|
|
# set(SHADER_COMPILER_COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/../build/bin/Debug/ShaderCompilerTool")
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
|
message("Linux build detected!")
|
|
|
|
find_package(SDL2 REQUIRED)
|
|
|
|
set(ENABLE_VULKAN TRUE)
|
|
set(ENABLE_LINUX TRUE)
|
|
|
|
set(NEEDS_HOSTED_SHADER_COMPILER FALSE)
|
|
set(REQUIRED_SHADER_LANGUAGE "spirv")
|
|
endif()
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" AND NOT IOS)
|
|
message("macOS build detected!")
|
|
|
|
find_package(SDL2 REQUIRED)
|
|
|
|
set(ENABLE_VULKAN TRUE)
|
|
set(ENABLE_DARWIN TRUE)
|
|
set(ENABLE_MACOS TRUE)
|
|
set(ENABLE_METAL TRUE)
|
|
|
|
set(CMAKE_XCODE_GENERATE_SCHEME OFF)
|
|
set(NEEDS_HOSTED_SHADER_COMPILER FALSE)
|
|
set(REQUIRED_SHADER_LANGUAGE "msl")
|
|
endif()
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
|
|
message("iOS build detected!")
|
|
|
|
#set(ENABLE_VULKAN TRUE)
|
|
set(ENABLE_DARWIN TRUE)
|
|
set(ENABLE_IOS TRUE)
|
|
set(ENABLE_METAL TRUE)
|
|
|
|
set(NEEDS_HOSTED_SHADER_COMPILER TRUE)
|
|
set(REQUIRED_SHADER_LANGUAGE "msl")
|
|
set(EXTRA_PLATFORM_ARG "mobile")
|
|
endif()
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "tvOS")
|
|
message("tvOS build detected!")
|
|
|
|
#set(ENABLE_VULKAN TRUE)
|
|
set(ENABLE_DARWIN TRUE)
|
|
set(ENABLE_TVOS TRUE)
|
|
set(ENABLE_METAL TRUE)
|
|
|
|
set(NEEDS_HOSTED_SHADER_COMPILER TRUE)
|
|
set(REQUIRED_SHADER_LANGUAGE "msl")
|
|
set(EXTRA_PLATFORM_ARG "mobile")
|
|
endif()
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
|
message("Windows build detected!")
|
|
|
|
find_package(SDL2 REQUIRED)
|
|
|
|
set(ENABLE_WINDOWS TRUE)
|
|
set(ENABLE_VULKAN TRUE)
|
|
|
|
set(NEEDS_HOSTED_SHADER_COMPILER FALSE)
|
|
set(REQUIRED_SHADER_LANGUAGE "spirv")
|
|
endif()
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
|
|
message("UWP build detected!")
|
|
|
|
set(ENABLE_UWP TRUE)
|
|
set(NEEDS_HOSTED_SHADER_COMPILER TRUE)
|
|
endif()
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
|
|
message("Web build detected!")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O0")
|
|
|
|
set(ENABLE_WEB TRUE)
|
|
set(ENABLE_WEBGPU TRUE)
|
|
|
|
set(NEEDS_HOSTED_SHADER_COMPILER TRUE)
|
|
set(REQUIRED_SHADER_LANGUAGE "wgsl")
|
|
endif()
|
|
|
|
if(NEEDS_HOSTED_SHADER_COMPILER AND (NOT DEFINED SHADER_COMPILER_LOCATION))
|
|
message(FATAL_ERROR "You are building for a platform that needs a hosted shader compiler. Please specify the path in SHADER_COMPILER_LOCATION!")
|
|
endif()
|
|
|
|
set(CROSS_LIBS
|
|
spirv-cross-core
|
|
spirv-cross-glsl
|
|
spirv-cross-msl
|
|
glslang
|
|
SPIRV
|
|
)
|
|
|
|
add_subdirectory(extern)
|
|
|
|
# enable lto
|
|
if (CMAKE_BUILD_TYPE EQUAL "Release")
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
endif ()
|
|
|
|
add_subdirectory(platforms)
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
|
|
|
source_group(Shaders shaders)
|
|
|
|
add_subdirectory(engine)
|
|
add_subdirectory(tools)
|
|
add_subdirectory(example) |