-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
196 lines (151 loc) · 6.86 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
cmake_minimum_required(VERSION 3.1)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -DCMAKE_OSX_ARCHITECTURES=x86_64")
set(CMAKE_OSX_ARCHITECTURES x86_64)
set( COMPILER_BIN /usr/bin/)
set( CMAKE_C_COMPILER ${COMPILER_BIN}/clang CACHE PATH "clang" FORCE )
set( CMAKE_CXX_COMPILER ${COMPILER_BIN}/clang++ CACHE PATH "clang++" FORCE )
enable_language( C CXX )
set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/third_party/entityx/cmake")
set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/third_party/bullet3")
set (CMAKE_PREFIX_PATH lib_directory ${CMAKE_PREFIX_PATH})
# Disabled cotire due to issues with GL includes, renable later if needed
# set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/third_party/cotire/CMake")
# include(cotire)
project(LeagueOfDwarves)
set(LeagueOfDwarves_VERSION_MAJOR 0)
set(LeagueOfDwarves_VERSION_MINOR 1)
set(LeagueOfDwarves_VERSION_PATCH 0)
set(LeagueOfDwarves_VERSION "${LeagueOfDwarves_VERSION_MAJOR}.${LeagueOfDwarves_VERSION_MINOR}.${LeagueOfDwarves_VERSION_PATCH}")
set(PROJ_NAME "\"League Of Dwarves\"") # PROJECT_NAME is a predefined variable
set(PROJECT_DESCRIPTION "\"A cross-platform C++14 project template\"")
configure_file(src/league-of-dwarves/config.hpp.in
${CMAKE_BINARY_DIR}/src/league-of-dwarves/config.hpp
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Options
option(BUILD_TESTS "Build test executable" OFF)
option(GEN_DOCS "Generate documentation" ON)
option(ENABLE_COVERAGE "Enable code coverage" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as no build type was specified")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the build type (Debug/Release)" FORCE)
endif (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
if (ENABLE_COVERAGE AND NOT CMAKE_CONFIGURATION_TYPES)
if (NOT BUILD_TESTS)
message(FATAL_ERROR "Tests must be enabled for code coverage!")
endif (NOT BUILD_TESTS)
include(CodeCoverage)
append_coverage_compiler_flags()
set(COVERAGE_EXCLUDES "/usr/include/\\*;${CMAKE_SOURCE_DIR}/src/league-of-dwarves/main.cpp;${CMAKE_SOURCE_DIR}/test/*;${CMAKE_SOURCE_DIR}/third_party/doctest/*")
setup_target_for_coverage(NAME coverage EXECUTABLE ctest DEPENDENCIES coverage)
else (ENABLE_COVERAGE AND NOT CMAKE_CONFIGURATION_TYPES)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
endif (ENABLE_COVERAGE AND NOT CMAKE_CONFIGURATION_TYPES)
file(GLOB_RECURSE ENGINE_SOURCE_FILES
"src/boundless-engine/*.cpp"
)
file(GLOB_RECURSE LOD_SOURCE_FILES
"src/league-of-dwarves/*.cpp"
)
set(LIBRARY_SOURCES
${ENGINE_SOURCE_FILES}
)
set(GAME_SOURCES
${LOD_SOURCE_FILES}
)
# Add boost, glew, glfw, glm
FIND_PACKAGE( Boost 1.75 COMPONENTS system thread filesystem REQUIRED )
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif()
FIND_PACKAGE( GLEW 2.2 REQUIRED)
if (GLEW_FOUND)
include_directories(${GLEW_INCLUDE_DIRS})
endif()
FIND_PACKAGE( GLFW3 3.3 REQUIRED)
if (GLFW3_FOUND)
include_directories(${GLFW3_INCLUDE_DIRS})
endif()
FIND_PACKAGE( GLM REQUIRED)
if (GLM_FOUND)
include_directories(${GLM_INCLUDE_DIRS})
endif()
find_package(OpenCL REQUIRED)
find_package(OpenGL REQUIRED)
include_directories( ${OPENCL_INCLUDE_DIR})
find_package(OpenAL REQUIRED)
if(APPLE)
set(ENV{OPENALDIR} "/usr/local/opt/openal-soft")
include_directories( "/usr/local/opt/openal-soft/include")
else()
include_directories( ${OpenAL_INCLUDE_DIR})
endif()
find_package(FastNoise2 REQUIRED)
find_package(FastNoise2 CONFIG REQUIRED)
find_package(spdlog REQUIRED)
FIND_PACKAGE( entityx REQUIRED)
if (entityx_FOUND)
include_directories(${ENTITYX_INCLUDE_DIRS})
endif()
FIND_PACKAGE( Bullet REQUIRED)
if (Bullet_FOUND)
include_directories(${Bullet_INCLUDE_DIRS})
endif()
#set(FASTNOISE2_NOISETOOL OFF CACHE BOOL "Build Noise Tool" FORCE) #example if don't need the graph tool
#add_subdirectory("third_party/FastNoise2")
# Add third party libaries
include_directories("third_party/eventpp/include")
#include_directories("third_party/ThreadPool")
include_directories("third_party/SimplexNoise/src")
include_directories("third_party/OpenCL-Registry/api/2.1")
include_directories("third_party/FastNoise2/include")
include_directories("third_party/boost_threadpool/boost")
set(SIMPLEX_NOISE
"third_party/SimplexNoise/src/SimplexNoise.cpp"
)
add_library(BoundlessEngine ${LIBRARY_SOURCES} ${SIMPLEX_NOISE}) # A library
set_target_properties(BoundlessEngine PROPERTIES PREFIX "") # Remove the lib prefix
target_include_directories(BoundlessEngine PUBLIC ${CMAKE_SOURCE_DIR}/src/boundless-engine ${CMAKE_BINARY_DIR}/src/boundless-engine)
if(APPLE)
target_link_libraries(BoundlessEngine LINK_PUBLIC ${GLM_LIBRARIES}
${GLFW3_LIBRARIES} ${GLEW_LIBRARIES} ${Boost_LIBRARIES} ${OpenAL_LIBRARIES} GLEW::GLEW glfw OpenCL::OpenCL
"-framework OpenCL" spdlog::spdlog ${ENTITYX_LIBRARIES} ${Bullet_LIBRARIES} FastNoise2::FastNoise)
else()
target_link_libraries(BoundlessEngine LINK_PUBLIC ${GLM_LIBRARIES}
${GLFW3_LIBRARIES} ${GLEW_LIBRARIES} ${Boost_LIBRARIES} ${OpenAL_LIBRARIES} GLEW::GLEW glfw OpenCL::OpenCL
spdlog::spdlog ${ENTITYX_LIBRARIES} ${Bullet_LIBRARIES} FastNoise2::FastNoise)
endif()
# cotire(BoundlessEngine)
add_executable(LeagueOfDwarves ${GAME_SOURCES}) # The main game executable
target_link_libraries(LeagueOfDwarves LINK_PUBLIC BoundlessEngine)
# cotire(LeagueOfDwarves)
if (BUILD_TESTS)
include(CTest)
enable_testing()
add_subdirectory(test)
endif (BUILD_TESTS)
if (GEN_DOCS)
add_subdirectory(doc)
endif (GEN_DOCS)
# Install the built library and executable into the appropriate directory
install(TARGETS LeagueOfDwarves DESTINATION bin)
install(TARGETS BoundlessEngine
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# Install the project header files into the appropriate directory
install(DIRECTORY src/ DESTINATION src PATTERN "config.hpp.in" EXCLUDE) # Install our main header files
install(FILES ${CMAKE_BINARY_DIR}/src/league-of-dwarves/config.hpp DESTINATION src/league-of-dwarves) # Install our configuration file
# Install the project's extra files
install(FILES README.md LICENSE DESTINATION share/league-of-dwarves)