-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
96 lines (72 loc) · 3.07 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
cmake_minimum_required(VERSION 3.16)
project(pathfinder
VERSION 0.1
LANGUAGES C CXX)
# Set binary output directory.
# (Using CMAKE_CURRENT_SOURCE_DIR is necessary.)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
# Options.
option(PATHFINDER_VULKAN_SUPPORT "Use Vulkan instead of OpenGL" OFF)
option(PATHFINDER_BUILD_DEMO "Build demo" OFF)
# Identify Linux.
if (UNIX AND NOT APPLE AND NOT ANDROID)
set(LINUX ON)
endif ()
# Should handle EMSCRIPTEN before other platforms.
if (EMSCRIPTEN)
message("[Pathfinder] Build for Web")
# No Vulkan support for web.
set(PATHFINDER_VULKAN_SUPPORT OFF)
elseif (APPLE)
# No GL support for Mac.
set(PATHFINDER_VULKAN_SUPPORT ON)
elseif (LINUX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
endif ()
add_subdirectory(pathfinder)
target_compile_features(pathfinder PUBLIC cxx_std_14)
if (PATHFINDER_VULKAN_SUPPORT)
message("[Pathfinder] Use Vulkan")
find_package(Vulkan REQUIRED)
# Don't use add_compile_definitions, which doesn't propagate to parent projects.
target_compile_definitions(pathfinder PUBLIC PATHFINDER_USE_VULKAN)
target_link_libraries(pathfinder PUBLIC Vulkan::Vulkan)
# This is to please GitHub Actions.
target_include_directories(pathfinder PUBLIC "${Vulkan_INCLUDE_DIRS}")
else ()
message("[Pathfinder] Use OpenGL")
endif ()
# Include third_party headers.
target_include_directories(pathfinder PUBLIC "third_party" "third_party/glad/include")
# We don't need GLFW on Android, and Emscripten has its own version of GLFW.
if ((WIN32 OR LINUX OR APPLE) AND NOT (EMSCRIPTEN OR ANDROID))
include(FetchContent)
FetchContent_Declare(glfw
GIT_REPOSITORY https://github.com/floppyhammer/glfw.git
GIT_TAG master
)
message("[Pathfinder] Fetching external git repositories")
FetchContent_MakeAvailable(glfw)
target_include_directories(pathfinder PUBLIC "${glfw_SOURCE_DIR}/include")
target_link_libraries(pathfinder PUBLIC glfw)
endif ()
if (PATHFINDER_BUILD_DEMO)
message("[Pathfinder] Build demo")
# target_compile_definitions only added PATHFINDER_USE_VULKAN to the Pathfinder library.
# We need to define PATHFINDER_USE_VULKAN for the demo as well.
if (PATHFINDER_VULKAN_SUPPORT)
add_compile_definitions(PATHFINDER_USE_VULKAN)
endif ()
# Demo common library.
add_subdirectory(demo/common)
if ((WIN32 OR LINUX OR APPLE) AND NOT (EMSCRIPTEN OR ANDROID))
add_subdirectory(demo/native)
elseif (EMSCRIPTEN)
# Set output directory to the web demo, so we don't have to copy output files manually.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/demo/web")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_GLFW=3 -s USE_WEBGL2=1 -s FULL_ES3=1")
# For debugging. Enable this to obtain detailed call stack.
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gsource-map -s ASSERTIONS=2 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=1 --source-map-base http://127.0.0.1:8000/")
add_subdirectory(demo/web)
endif ()
endif ()