-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
111 lines (94 loc) · 3.79 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Need 3.7 for FindVulkan
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
project(engine)
### Set compilation options ###
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
add_compile_options(
-Wall
-Wextra
-pedantic
-Werror=format-security
-Werror=format
)
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -D_DEBUG -O0 -ggdb")
string(APPEND CMAKE_CXX_FLAGS_RELEASE
" -03 -ffast-math -fno-unsafe-math-optimizations -fomit-frame-pointer")
endif()
if(MSVC)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# temporary fix
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10000000")
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -D_DEBUG")
endif()
# Add after setting options
add_executable(${CMAKE_PROJECT_NAME})
# https://stackoverflow.com/a/40947954/15620835
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
add_compile_definitions("SOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}")
# use glfw
add_compile_definitions(USE_GLFW)
# Search for vulkan
find_package(Vulkan)
if(!Vulkan_FOUND)
message(FATAL_ERROR "Vulkan library not found.")
endif()
message(STATUS "Found vulkan library and headers")
### Compile shaders ###
add_subdirectory(shaders)
add_dependencies(engine shaders)
### Copy resource files into build folder ###
add_custom_command(TARGET engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_LIST_DIR}/resources/" "$<TARGET_FILE_DIR:engine>/resources/")
### Add sources ###
file(GLOB SOURCES src/*.cpp)
get_directory_property(CURRENT_DEFINITIONS COMPILE_DEFINITIONS)
message(STATUS "Compile definitions " ${CURRENT_DEFINITIONS})
list(FIND CURRENT_DEFINITIONS "USE_GLFW" USING_GLFW)
if (NOT USING_GLFW EQUAL -1)
message(STATUS "USING GLFW")
list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/input.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/window.cpp)
else()
message(STATUS "NOT USING GLFW")
list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/glfw_input.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/glfw_window.cpp)
endif()
target_include_directories(engine PRIVATE ${Vulkan_INCLUDE_DIRS})
target_sources(engine PRIVATE ${SOURCES})
### stb_image, tinyobj, spir_reflect and vma ###
file(GLOB EXTERNAL_SOURCES external/*.c external/*.cpp)
add_library(ext_lib STATIC ${EXTERNAL_SOURCES})
target_include_directories(ext_lib INTERFACE "${PROJECT_SOURCE_DIR}/external")
### Compile GLFW ###
### Add Dear ImGui ###
if (NOT USING_GLFW EQUAL -1)
set( GLFW_BUILD_DOCS OFF CACHE BOOL "GLFW lib only" )
set( GLFW_INSTALL OFF CACHE BOOL "GLFW lib only" )
add_subdirectory(external/glfw)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE glfw)
add_library(imgui STATIC)
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/external/imgui" ${Vulkan_INCLUDE_DIRS})
target_sources(imgui PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/imgui.h"
"${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/imgui.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/imgui_demo.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/imgui_draw.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/imgui_widgets.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/imgui_tables.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/backends/imgui_impl_vulkan.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/external/imgui/backends/imgui_impl_glfw.cpp"
)
target_link_libraries(imgui PUBLIC ${Vulkan_LIBRARY} glfw)
endif()
### Link external libraries ###
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${Vulkan_LIBRARY} ext_lib imgui)
if(UNIX)
find_package(PkgConfig)
pkg_check_modules(XCB REQUIRED xcb xcb-icccm)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${XCB_LIBRARIES})
endif()