-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
134 lines (104 loc) · 4.2 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
cmake_minimum_required(VERSION 3.16)
include(cmake/functions.cmake)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set the project name
project(FunGame VERSION 0.1.0)
# add the executable
file(GLOB_RECURSE SOURCES1 "src/*.cpp")
# this is one json file and whereami
file(GLOB SOURCES4 "vendor/*.c*")
file(GLOB SOURCES6 "vendor/imgui/*.c*")
file(GLOB SOURCES7 "vendor/imgui/backends/imgui_impl_opengl3.cpp")
file(GLOB SOURCES8 "vendor/imgui/backends/imgui_impl_glfw.cpp")
add_executable(FunGame ${SOURCES1} ${SOURCES4} ${SOURCES6} ${SOURCES7} ${SOURCES8})
# Set standard version
set_property(TARGET FunGame PROPERTY CXX_STANDARD 23)
set_property(TARGET FunGame PROPERTY C_STANDARD 17)
# compile quill and sol2
block()
set(QUILL_BUILD_EXAMPLES OFF)
set(QUILL_BUILD_TESTS OFF)
set(QUILL_BUILD_BENCHMARKS OFF)
set(QUILL_DOCS_GEN OFF)
add_subdirectory("vendor/quill")
endblock()
add_subdirectory("vendor/sol2")
add_subdirectory("vendor/glaze")
# prefer newer OpenGL
# https://cmake.org/cmake/help/latest/policy/CMP0072.html
cmake_policy(SET CMP0072 NEW)
# Link against libdl for dlclose (used in latest IMGUI)
target_link_libraries(FunGame PRIVATE ${CMAKE_DL_LIBS})
# Find GL packages
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 REQUIRED)
find_package(glm REQUIRED)
find_package(PNG REQUIRED)
find_package(OpenMP REQUIRED)
target_link_libraries(FunGame PRIVATE glfw)
target_link_libraries(FunGame PRIVATE OpenGL::GL)
target_link_libraries(FunGame PRIVATE GLEW::GLEW)
target_link_libraries(FunGame PRIVATE PNG::PNG)
target_link_libraries(FunGame PRIVATE OpenMP::OpenMP_CXX)
if(WIN32)
target_link_libraries(FunGame PRIVATE glm)
else()
target_link_libraries(FunGame PRIVATE glm::glm)
endif()
# Lua 5.2 just uses the name "Lua" while 5.1, and 5.0 used "Lua51", and "Lua50"
# respectivly.
find_package(Lua REQUIRED)
include_directories(${LUA_INCLUDE_DIR})
# add quill and sol2
target_link_libraries_system(FunGame PRIVATE quill::quill)
target_link_libraries_system(FunGame PRIVATE sol2::sol2)
target_link_libraries(FunGame PRIVATE ${LUA_LIBRARIES})
# Add include dirs
target_include_directories(FunGame PRIVATE "vendor")
target_include_directories(FunGame PRIVATE "vendor/thread-pool/include")
target_include_directories(FunGame PRIVATE "vendor/glaze/include")
target_include_directories(FunGame PRIVATE "vendor/imgui")
target_include_directories(FunGame PRIVATE "src")
target_include_directories(FunGame PRIVATE "${PROJECT_BINARY_DIR}")
# this is for fmt included in quill
target_include_directories(FunGame PRIVATE "vendor/quill/quill/include/quill/bundled")
# Set warning options
if(MSVC)
target_compile_options(FunGame PRIVATE /W4 /WX)
else()
target_compile_options(FunGame PRIVATE -Wall -Wextra -Wpedantic -pedantic -fdiagnostics-color=always)
endif()
# Resource and data handling
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(DEBUG 1)
message(" Debug build, data will be loaded from repo root ")
else()
set(DEBUG 0)
message(" Debug build, data will be loaded from subdirs ")
target_compile_definitions(FunGame PUBLIC TILE_SET_TEST)
add_custom_target(resources
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/resources
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/resources ${CMAKE_BINARY_DIR}/resources
COMMENT " copying ${CMAKE_SOURCE_DIR}/resources to ${CMAKE_BINARY_DIR}/resources "
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_target(data
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/data
COMMENT " copying ${CMAKE_SOURCE_DIR}/data to ${CMAKE_BINARY_DIR}/data "
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_dependencies(FunGame resources)
add_dependencies(FunGame data)
endif()
configure_file(src/config.h.in config.h)
enable_testing()
add_test(NAME LuaTest COMMAND FunGame Test LuaTest)
add_test(NAME NoiseTest COMMAND FunGame Test NoiseTest)
add_test(NAME Logging COMMAND FunGame Test Logging)
add_test(NAME ChunkDataTest COMMAND FunGame Test ChunkDataTest)
add_test(NAME LoadManifest COMMAND FunGame Test LoadManifest)