-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
166 lines (133 loc) · 5.78 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
cmake_minimum_required(VERSION 3.18)
project(little_game)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(WITH_OPENGL "Use OpenGL as the graphics API" ON)
option(WITH_VULKAN "Use Vulkan as the graphics API" ON)
if(WITH_OPENGL)
find_package(glad CONFIG REQUIRED)
endif()
if(WITH_VULKAN)
find_package(VulkanHeaders REQUIRED)
endif()
find_package(glm CONFIG REQUIRED)
find_package(RapidJSON CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(EnTT CONFIG REQUIRED)
find_package(SDL2 CONFIG REQUIRED)
find_package(Boost CONFIG REQUIRED)
find_package(SDL2_image CONFIG REQUIRED)
find_package(range-v3 CONFIG REQUIRED)
add_subdirectory(external)
add_executable(little_game)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR(CMAKE_CXX_COMPILER_ID MATCHES "Clang*" AND NOT MSVC))
target_link_libraries(little_game PRIVATE -static-libgcc -static-libstdc++)
message(STATUS "Using static libstdc++ & libgcc_s")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(little_game PRIVATE -Wl,--push-state,-Bstatic -lstdc++ -lpthread -Wl,--pop-state)
message(STATUS "Using static libwinpthread")
endif()
target_link_libraries(little_game PRIVATE -Wl,--as-needed)
endif()
if(MSVC)
target_compile_options(little_game PRIVATE "/W4")
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang*")
target_compile_options(little_game PRIVATE "-Werror=all" "-Werror=extra" "-Weverything" "-Wno-pedantic")
else() # assume GCC style compiler
target_compile_options(little_game PRIVATE "-Werror=all" "-Werror=extra")
endif()
file(GLOB_RECURSE VGAME_PRIVATE_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/src/*")
file(GLOB_RECURSE VGAME_PUBLIC_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/include/*")
file(GLOB_RECURSE VGAME_OPENGL_PRIVATE_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/src/engine/rendering/opengl/*")
file(GLOB_RECURSE VGAME_OPENGL_PUBLIC_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/include/engine/rendering/opengl/*")
file(GLOB_RECURSE VGAME_VULKAN_PRIVATE_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/src/engine/rendering/vulkan/*")
file(GLOB_RECURSE VGAME_VULKAN_PUBLIC_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/include/engine/rendering/vulkan/*")
file(GLOB_RECURSE VGAME_WIN32_PRIVATE_SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/win32/*")
file(GLOB_RECURSE VGAME_UNIX_PRIVATE_SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/unix/*")
list(REMOVE_ITEM VGAME_PRIVATE_SOURCES ${VGAME_OPENGL_PRIVATE_SOURCES} ${VGAME_VULKAN_PRIVATE_SOURCES} ${VGAME_WIN32_PRIVATE_SOURCES} ${VGAME_UNIX_PRIVATE_SOURCES})
list(REMOVE_ITEM VGAME_PUBLIC_SOURCES ${VGAME_OPENGL_PUBLIC_SOURCES} ${VGAME_VULKAN_PUBLIC_SOURCES})
target_sources(little_game
PRIVATE
${VGAME_PRIVATE_SOURCES}
PUBLIC
${VGAME_PUBLIC_SOURCES}
)
if(WITH_OPENGL)
target_sources(little_game
PRIVATE
${VGAME_OPENGL_PRIVATE_SOURCES}
PUBLIC
${VGAME_OPENGL_PUBLIC_SOURCES})
target_link_libraries(little_game
PRIVATE
glad::glad
imgui_impl_opengl3)
target_compile_definitions(little_game
PRIVATE
ENGINE_WITH_OPENGL)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_sources(little_game PRIVATE ${VGAME_WIN32_PRIVATE_SOURCES})
else()
target_sources(little_game PRIVATE ${VGAME_UNIX_PRIVATE_SOURCES})
endif()
if(WITH_VULKAN)
find_package(Vulkan MODULE)
find_package(volk CONFIG REQUIRED)
target_sources(little_game PRIVATE
PRIVATE
${VGAME_VULKAN_PRIVATE_SOURCES}
PUBLIC
${VGAME_VULKAN_PUBLIC_SOURCES})
target_link_libraries(little_game
PRIVATE
Vulkan::Headers
volk::volk
imgui_impl_vulkan)
target_compile_definitions(little_game
PRIVATE
ENGINE_WITH_VULKAN
VK_NO_PROTOTYPES
VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1)
endif()
find_program(RESOURCE_COMPILER resource_compiler.py PATHS "${CMAKE_CURRENT_LIST_DIR}/tools/bin" REQUIRED NO_DEFAULT_PATH)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/resources_generated.hpp"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/include/"
COMMAND "${RESOURCE_COMPILER}" "${CMAKE_CURRENT_LIST_DIR}/res" -o "${CMAKE_CURRENT_BINARY_DIR}/include/resources_generated.hpp"
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/res"
VERBATIM
)
target_sources(little_game PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include/resources_generated.hpp)
target_include_directories(little_game PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include/)
target_link_libraries(little_game
PRIVATE
SDL2::SDL2 glm::glm imgui_impl_sdl2 rapidjson SDL2_image::SDL2_image
fmt::fmt spdlog::spdlog EnTT::EnTT Boost::boost range-v3::range-v3)
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(little_game PRIVATE Boost::stacktrace_backtrace)
endif()
set_target_properties(little_game PROPERTIES CXX_STANDARD 23 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON)
target_compile_features(little_game PUBLIC cxx_std_23)
target_include_directories(little_game PRIVATE "${CMAKE_CURRENT_LIST_DIR}/include")
target_compile_definitions(little_game
PUBLIC
GLM_FORCE_XYZW_ONLY
GLM_ENABLE_EXPERIMENTAL
)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND NOT(MINGW OR CYGWIN))
message(STATUS "Linking with SDL2main")
target_link_libraries(little_game PRIVATE SDL2::SDL2main)
else()
target_compile_definitions(little_game PRIVATE SDL_MAIN_HANDLED)
endif()
if(UNIX AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}" CACHE PATH "" FORCE)
endif()
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set_target_properties(little_game PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")
endif()
include(GNUInstallDirs)
install(TARGETS little_game
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)