-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
199 lines (171 loc) · 6.6 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
cmake_minimum_required(VERSION 3.10)
# Project Configuration
project(BloodFarmers VERSION 1.0.0 LANGUAGES CXX C)
# Detect compiler
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# using Clang
set(USING_CLANG 1)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC
set(USING_GCC 1)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
# using Intel C++
set(USING_ICC 1)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
set(USING_MSVC 1)
endif()
# Dependencies that get included into projects sources directly
add_library(FastNoiseSIMD OBJECT
deps/FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_sse41.cpp
deps/FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_internal.cpp
deps/FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD.cpp
deps/FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_sse2.cpp
deps/FastNoiseSIMD/FastNoiseSIMD/FastNoiseSIMD_avx2.cpp
)
set(PHYSICSFS_SOURCES
deps/physfs/src/physfs.c
deps/physfs/src/physfs_archiver_7z.c
deps/physfs/src/physfs_archiver_dir.c
deps/physfs/src/physfs_archiver_grp.c
deps/physfs/src/physfs_archiver_hog.c
deps/physfs/src/physfs_archiver_iso9660.c
deps/physfs/src/physfs_archiver_mvl.c
deps/physfs/src/physfs_archiver_qpak.c
deps/physfs/src/physfs_archiver_slb.c
deps/physfs/src/physfs_archiver_unpacked.c
deps/physfs/src/physfs_archiver_vdf.c
deps/physfs/src/physfs_archiver_wad.c
deps/physfs/src/physfs_archiver_zip.c
deps/physfs/src/physfs_byteorder.c
deps/physfs/src/physfs_miniz.h
deps/physfs/src/physfs_platform_haiku.cpp
deps/physfs/src/physfs_platform_os2.c
deps/physfs/src/physfs_platform_posix.c
deps/physfs/src/physfs_platform_qnx.c
deps/physfs/src/physfs_platform_unix.c
deps/physfs/src/physfs_platform_windows.c
deps/physfs/src/physfs_platform_winrt.cpp
deps/physfs/src/physfs_unicode.c
)
if(APPLE)
list(APPEND PHYSICS_FS_SOURCES deps/physfs/src/physfs_platform_apple.m)
endif()
# Sources
set(SOURCES
${PHYSICSFS_SOURCES}
src/main.cpp
src/graphics/shader.cpp
src/graphics/textures.cpp
src/graphics/imagesets.cpp
src/graphics/spritepool.cpp
src/graphics/renderer.cpp
src/util/logging.cpp
src/util/helpers.cpp
src/services/core/resources.cpp
src/services/core/physics.cpp
src/services/scene.cpp
)
add_executable(BloodFarmers ${SOURCES} $<TARGET_OBJECTS:FastNoiseSIMD>)
# Packaged dependencies
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
find_package(SDL2 2.0.10)
if (SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIR})
target_link_libraries(BloodFarmers ${SDL2_LIBRARY})
endif()
find_package(GLEW REQUIRED)
if (GLEW_FOUND)
include_directories(${GLEW_INCLUDE_DIRS})
target_link_libraries(BloodFarmers ${GLEW_LIBRARIES})
endif()
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
if (OPENGL_FOUND)
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(BloodFarmers ${OPENGL_LIBRARIES})
endif()
find_package(BULLET REQUIRED)
if (BULLET_FOUND)
include_directories(${BULLET_INCLUDE_DIRS})
target_link_libraries(BloodFarmers ${BULLET_LIBRARIES})
endif()
# Included dependencies
add_subdirectory(deps/cpptoml)
target_include_directories (cpptoml INTERFACE $<BUILD_INTERFACE:${CPPTOML_SOURCE_DIR}/include>)
target_link_libraries(BloodFarmers cpptoml)
target_include_directories(BloodFarmers
PRIVATE
# Project include files
${PROJECT_SOURCE_DIR}/include
# Source dependencies' includes
${PROJECT_SOURCE_DIR}/deps/FastNoiseSIMD/FastNoiseSIMD
${PROJECT_SOURCE_DIR}/deps/physfs/src # Includes the header file...
# Include header-only dependencies
${PROJECT_SOURCE_DIR}/deps/stb
${PROJECT_SOURCE_DIR}/deps/spdlog/include
${PROJECT_SOURCE_DIR}/deps/entt/src
${PROJECT_SOURCE_DIR}/deps/glm
${PROJECT_SOURCE_DIR}/deps/semimap
${PROJECT_SOURCE_DIR}/deps/physfs-hpp/include
${PROJECT_SOURCE_DIR}/deps/cxxopts/include
)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
target_compile_definitions(BloodFarmers PUBLIC $<$<CONFIG:DEBUG>:DEBUG_BUILD>)
target_compile_definitions(BloodFarmers PUBLIC $<$<CONFIG:DEBUG>:SPDLOG_DEBUG_ON>)
target_compile_definitions(BloodFarmers PUBLIC $<$<CONFIG:DEBUG>:SPDLOG_TRACE_ON>)
set(SETTINGS_ORGANIZATION "Dan Kersten")
set(SETTINGS_APPLICATION ${PROJECT_NAME})
set(PROJECT_AUTHOR "Dan Kersten")
set(PROJECT_AUTHOR_EMAIL "[email protected]")
message("*")
message("* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
message("* Copyright (c) 2018 ${PROJECT_AUTHOR} <${PROJECT_AUTHOR_EMAIL}>")
message("* Building with ${CMAKE_CXX_COMPILER_ID}")
message("*")
option(USE_ASAN "Use address sanitizer by adding -fsanitize=address -fno-omit-frame-pointer flags" OFF)
if(USE_ASAN)
target_compile_options(BloodFarmers PUBLIC $<$<AND:$<CONFIG:Debug>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-fsanitize=address -fno-omit-frame-pointer>)
target_link_libraries(BloodFarmers PUBLIC $<$<AND:$<CONFIG:Debug>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-fsanitize=address -fno-omit-frame-pointer>)
endif()
target_compile_options(
BloodFarmers
PUBLIC $<$<AND:$<CONFIG:Debug>,$<NOT:$<BOOL:USING_MSVC>>>:-O0 -g>
# it seems that -O3 ruins a bit the performance when using clang ...
PUBLIC $<$<AND:$<CONFIG:Release>,$<BOOL:USING_CLANG>>:-O2 -flto=thin>
# ... on the other side, GCC is incredibly comfortable with it.
PUBLIC $<$<AND:$<CONFIG:Release>,$<BOOL:USING_GCC>>:-O3>
)
# Platform specific compile options
if(USING_MSVC)
target_compile_options(BloodFarmers PUBLIC /arch:SSE4.1 /fp:fast)
target_compile_options(FastNoiseSIMD PUBLIC /arch:SSE4.1 /arch:AVX2 /fp:fast)
else()
target_compile_options(BloodFarmers PUBLIC -msse4.1 -mfma)
target_compile_options(FastNoiseSIMD PUBLIC -msse4.1 -mavx2 -mfma)
if(USING_CLANG)
target_compile_options(BloodFarmers PUBLIC -ffp-contract=fast)
target_compile_options(FastNoiseSIMD PUBLIC -ffp-contract=fast)
endif()
if(APPLE)
# Foundation and IOKit are needed by PhysicsFS on OSX
target_link_libraries(BloodFarmers
"-framework Foundation"
"-framework IOKit"
"-framework OpenGL"
)
endif()
endif()
#target_compile_options(BloodFarmers PUBLIC -Werror)
target_compile_features(BloodFarmers PRIVATE cxx_std_17)
target_compile_features(FastNoiseSIMD PRIVATE cxx_std_11)
# Place compiled binary into project root directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})
if (NOT DEFINED BUILD_TESTS)
set(BUILD_TESTS OFF CACHE BOOL "Build Tests ?")
endif()
if (BUILD_TESTS)
add_subdirectory(tests)
endif()