-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
242 lines (194 loc) · 7.33 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# louis-work: a game
# Copyright (C) 2021 Mathew Topper
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# disallow macos for now
if (APPLE)
message( FATAL_ERROR "MacOS is not yet supported" )
endif()
cmake_minimum_required(VERSION 3.27)
# set the project name and version
project("Louis Work" VERSION 0.0.1
DESCRIPTION "A game about words and letters")
# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# options
option(ESPEAKNG_BUILD "Build espeak-ng" ON)
option(GCOVR_HTML "Generate HTML code coverage report" OFF)
option(GCOVR_XML "Generate XML code coverage report" OFF)
option(RPM "Create an RPM package" OFF)
option(INNO "Create a inno setup package" OFF)
# conan
find_package(argparse REQUIRED)
find_package(Boost REQUIRED)
find_package(GTest REQUIRED)
find_package(platform_folders REQUIRED)
find_package(SFML REQUIRED)
find_package(spdlog REQUIRED)
# vscode
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# testing
include(GoogleTest)
enable_testing()
# code coverage
find_program(GCOVR_PATH gcovr)
# install settings
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE)
# debug compiler flags
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall")
# boost_stacktrace
if (UNIX)
add_definitions(-DBOOST_STACKTRACE_USE_ADDR2LINE)
endif ()
# build output structure
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
# define asset and log path in pathconfig.h
set(DATA_DIR_TEST ${CMAKE_SOURCE_DIR})
set(LOGS_DIR_TEST ${CMAKE_SOURCE_DIR}/logs)
if (WIN32)
set(DATA_DIR_RELEASE ..)
set(LOGS_DIR_RELEASE "Louis Work")
elseif (UNIX)
set(DATA_DIR_RELEASE /usr/share/louis-work)
set(LOGS_DIR_RELEASE louis-work)
endif ()
configure_file(${CMAKE_SOURCE_DIR}/src/pathconfig.h.in
${CMAKE_SOURCE_DIR}/src/pathconfig.h)
# coverage target and compiler flags
if ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND
CMAKE_BUILD_TYPE STREQUAL "Debug" AND
GCOVR_PATH AND
(GCOVR_HTML OR GCOVR_XML))
include(CodeCoverage)
append_coverage_compiler_flags()
set(TEST_COMPILER_FLAGS "-O0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${TEST_COMPILER_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${TEST_COMPILER_FLAGS}")
if (GCOVR_HTML)
setup_target_for_coverage_gcovr_html(
NAME coverage-html
EXECUTABLE tests
DEPENDENCIES tests
EXCLUDE "${CMAKE_SOURCE_DIR}/app/*"
"${CMAKE_SOURCE_DIR}/build/_deps/*"
"${CMAKE_SOURCE_DIR}/src/adapters/*"
"${CMAKE_SOURCE_DIR}/test/*")
add_dependencies(coverage-html tests)
endif()
if (GCOVR_XML)
setup_target_for_coverage_gcovr_xml(
NAME coverage-xml
EXECUTABLE tests
DEPENDENCIES tests
EXCLUDE "${CMAKE_SOURCE_DIR}/app/*"
"${CMAKE_SOURCE_DIR}/build/_deps/*"
"${CMAKE_SOURCE_DIR}/src/adapters/*"
"${CMAKE_SOURCE_DIR}/test/*")
add_dependencies(coverage-xml tests)
endif()
file(GLOB_RECURSE GCOV_FILES CONFIGURE_DEPENDS ${PROJECT_BINARY_DIR}
*.gcda *.gcno)
add_custom_target(coverage-clean
COMMAND rm -f ${GCOV_FILES};
COMMAND ${CMAKE_MAKE_PROGRAM} clean WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR};
COMMENT "Removing build and gcov files."
)
endif ()
# RPATH handling
if (UNIX)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif ()
# path to source code
add_subdirectory(app)
add_subdirectory(src)
add_subdirectory(vendor)
# discover test files
file(GLOB test_SRC CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/test/*.cpp"
"${CMAKE_SOURCE_DIR}/test/*.h")
# add tests
add_executable(tests ${test_SRC})
#add_executable(tests "${CMAKE_SOURCE_DIR}/test/game_test.cpp"
# "${CMAKE_SOURCE_DIR}/test/mock.h")
target_link_libraries(tests
game
drawcomponents
soundcomponents
gtest::gtest)
gtest_discover_tests(tests)
# extra install commands
# Install libs
install(FILES $<TARGET_RUNTIME_DLLS:louis> TYPE BIN)
# Install assets
install(DIRECTORY ${CMAKE_SOURCE_DIR}/assets DESTINATION ${DATA_DIR_RELEASE})
# Install desktop entry
if (UNIX)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/data/louis.desktop.in
${CMAKE_CURRENT_BINARY_DIR}/louis.desktop)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/louis.desktop
DESTINATION share/applications/)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/l-key.svg
DESTINATION share/icons/hicolor/scalable/apps/)
SET(DESKTOP_INSTALL_PATH
"${CMAKE_INSTALL_PREFIX}/share/applications/louis.desktop")
SET(ICON_INSTALL_PATH
"${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps/l-key.svg")
endif()
# Install icon
if (WIN32)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/l-key.ico DESTINATION .)
endif()
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake)
endif()
if (RPM OR INNO)
# General CPack variables
SET(CPACK_VERBATIM_VARIABLES TRUE)
set(CPACK_PACKAGE_DESCRIPTION "\
A C++ project to create a game for my son to do his work on my computer")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/packages")
set(CPACK_PACKAGE_VENDOR "Mathew Topper")
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/COPYING)
# RPM
if (RPM AND UNIX)
set(CPACK_PACKAGE_NAME "louis-work")
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_RELEASE 1)
endif ()
if (INNO AND WIN32)
set(CPACK_PACKAGE_NAME "Louis Work")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Louis Work")
set(CPACK_GENERATOR "INNOSETUP")
set(CPACK_INNOSETUP_USE_CMAKE_BOOL_FORMAT ON)
set(CPACK_INNOSETUP_SETUP_ChangesEnvironment ON)
set(CPACK_INNOSETUP_EXTRA_SCRIPTS ${CMAKE_SOURCE_DIR}/cmake/icons.iss)
endif ()
include(CPack)
endif()