-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
217 lines (184 loc) · 7 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
cmake_minimum_required(VERSION 3.15.0)
project(flectron VERSION 0.1.0)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/GetDependencies.cmake")
if(MSVC)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
# elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_USE_MATH_DEFINES")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_USE_MATH_DEFINES")
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
file(GLOB_RECURSE FLECTRON_SRC_FILES ./src/*.cpp)
add_library(flectron STATIC ${FLECTRON_SRC_FILES})
target_include_directories(flectron
PUBLIC include
PUBLIC ${GLFW_INCLUDE_DIR}
PUBLIC ${GLEW_INCLUDE_DIR}
PUBLIC ${GLM_INCLUDE_DIR}
PUBLIC ${STB_IMAGE_INCLUDE_DIR}
PUBLIC ${OPTICK_INCLUDE_DIR}
PUBLIC ${ENTT_INCLUDE_DIR}
PUBLIC ${SPDLOG_INCLUDE_DIR}
)
target_link_libraries(flectron
glfw
libglew_static
glm
stb_image
EnTT
spdlog::spdlog
)
if(MSVC)
target_link_libraries(flectron OptickCore)
endif()
EMBED_INTO(flectron "./src/renderer/shaders/*.*" FLECTRON_SHADER)
find_package(Git)
if (Git_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
target_compile_definitions(flectron PUBLIC "-DFLECTRON_GIT_HASH=\"${GIT_HASH}\"")
execute_process(
COMMAND ${GIT_EXECUTABLE} status --porcelain
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if("${GIT_STATUS}" STREQUAL "")
target_compile_definitions(flectron PUBLIC "-DFLECTRON_GIT_STATUS_IS_DIRTY=false")
else()
target_compile_definitions(flectron PUBLIC "-DFLECTRON_GIT_STATUS_IS_DIRTY=true")
endif()
else()
target_compile_definitions(flectron PUBLIC "-DFLECTRON_GIT_HASH=\"\"")
target_compile_definitions(flectron PUBLIC "-DFLECTRON_GIT_STATUS_IS_DIRTY=false")
endif()
target_compile_definitions(flectron PUBLIC "-DFLECTRON_VERSION=\"${PROJECT_VERSION}\"")
target_compile_definitions(flectron PUBLIC "-DFLECTRON_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}")
target_compile_definitions(flectron PUBLIC "-DFLECTRON_VERSION_MINOR=${PROJECT_VERSION_MINOR}")
target_compile_definitions(flectron PUBLIC "-DFLECTRON_VERSION_PATCH=${PROJECT_VERSION_PATCH}")
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(FLECTRON_STANDALONE TRUE)
endif()
option(FLECTRON_BUILD_TESTS "Build flectron tests" ${FLECTRON_STANDALONE})
option(FLECTRON_BUILD_EXAMPLES "Build flectron examples" ${FLECTRON_STANDALONE})
option(FLECTRON_BUILD_DOCS "Build flectron documentation" ON)
option(FLECTRON_INSTALL "Install the flectron library" ON)
option(FLECTRON_COVERAGE "Enable coverage reporting" OFF)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_NAME "Flectron")
set(CPACK_PACKAGE_VENDOR "Patryk Janiak")
set(CPACK_PACKAGE_DESCRIPTION "Flectron is a 2D engine written in C++")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/morswin22/flectron")
# set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/flectron.png")
if(FLECTRON_BUILD_TESTS)
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_EXECUTABLES "flectron-demo;Flectron Demo" "flectron-terrain;Flectron Terrain Generator" "flectron-piday;Flectron Pi Day")
# set(CPACK_CREATE_DESKTOP_LINKS "flectron-demo;Flectron Demo" "flectron-terrain;Terrain Generator")
endif()
set(CPACK_THREADS 0)
include(CPack)
cpack_add_component_group(flectron_core DISPLAY_NAME "Flectron" DESCRIPTION "Flectron core library")
if (FLECTRON_INSTALL)
set_target_properties(flectron PROPERTIES PUBLIC_HEADER "include/flectron.hpp")
install(DIRECTORY include/
DESTINATION include/
FILES_MATCHING PATTERN "*.hpp"
PATTERN "include/flectron.hpp" EXCLUDE
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE DESTINATION include/flectron)
install(TARGETS flectron
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/flectron
COMPONENT flectron_lib
)
cpack_add_component(flectron_lib DISPLAY_NAME "Library" DESCRIPTION "Flectron library" GROUP flectron_core)
endif()
if(FLECTRON_BUILD_DOCS)
find_package(Doxygen)
if(DOXYGEN_FOUND)
include(FetchContent)
FetchContent_Declare(
doxygen_awesome_css
GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css.git
GIT_TAG v2.0.3
)
FetchContent_GetProperties(doxygen_awesome_css)
if(NOT doxygen_awesome_css_POPULATED)
FetchContent_Populate(doxygen_awesome_css)
endif()
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/README.md readme_contents)
list(POP_FRONT readme_contents)
list(PREPEND readme_contents "![Flectron](flectron.png)")
list(PREPEND readme_contents "# Flectron")
list(JOIN readme_contents "\n" readme_contents)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/README.md ${readme_contents})
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
add_custom_target(flectron-docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generate flectron documentation"
)
if(FLECTRON_INSTALL)
include(GNUInstallDirs)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs/
DESTINATION ${CMAKE_INSTALL_DOCDIR}
COMPONENT flectron_docs
)
cpack_add_component(flectron_docs DISPLAY_NAME "Documentation" DESCRIPTION "Flectron documentation" GROUP flectron_core)
endif()
else()
message(FATAL_ERROR "Doxygen needs to be installed to generate flectron documentation")
endif()
endif()
function(flectron_copy_all dir)
file(GLOB files "${dir}/*")
foreach(filepath ${files})
get_filename_component(filename ${filepath} NAME)
foreach(mode IN LISTS ARGN)
configure_file("${dir}/${filename}" "${mode}/${dir}/${filename}" COPYONLY)
endforeach()
configure_file("${dir}/${filename}" "${dir}/${filename}" COPYONLY)
configure_file("${dir}/${filename}" "${PROJECT_BINARY_DIR}/${dir}/${filename}" COPYONLY)
install(FILES "${PROJECT_BINARY_DIR}/${dir}/${filename}" DESTINATION "${dir}")
endforeach()
endfunction()
set(flectron_MODES Debug Release RelWithDebInfo MinSizeRel)
if(FLECTRON_BUILD_TESTS)
add_subdirectory(tests)
endif()
if(FLECTRON_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# this results in "No tests found"
if (FLECTRON_COVERAGE AND NOT MSVC)
enable_coverage()
enable_coverage_for(flectron)
enable_coverage_for(flectron-tests)
enable_coverage_for(flectron-tests-main)
add_coverage(
NAME flectron-tests-coverage
EXECUTABLE flectron-tests
DEPENDENCIES
flectron
flectron-tests
flectron-tests-main
SOURCE ${CMAKE_CURRENT_SOURCE_DIR}
XML ON
HTML ON
)
endif()