-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
501 lines (414 loc) · 19.1 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# Phaethon - A FLOSS resource explorer for BioWare's Aurora engine games
#
# Phaethon is the legal property of its developers, whose names
# can be found in the AUTHORS file distributed with this source
# distribution.
#
# Phaethon 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.
#
# Phaethon 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 Phaethon. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 3.1.0)
project(phaethon CXX)
set(phaethon_VERSION 0.0.6)
# -------------------------------------------------------------------------
# options!
option(Boost_USE_STATIC_LIBS "Use Boost static libraries" OFF)
option(PHAETHON_BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentation" OFF)
# -------------------------------------------------------------------------
# default build type
set(default_build_type "Debug")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# -------------------------------------------------------------------------
# load some cmake modules from cmake/ subfolder
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(GNUInstallDirs)
include(CheckIncludeFileCXX)
include(CMakeAM)
include(SetCheckCompilerFlag)
# -------------------------------------------------------------------------
# qt5 osx brew fix
if(APPLE AND EXISTS /usr/local/opt/qt5)
# Homebrew installs Qt5 (up to at least 5.9.1) in
# /usr/local/qt5, ensure it can be found by CMake since
# it is not in the default /usr/local prefix.
list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/qt5")
endif()
# -------------------------------------------------------------------------
# platform specific flags
if(CMAKE_HOST_APPLE)
add_definitions(-DUNIX -DMACOSX)
elseif(CMAKE_HOST_UNIX)
add_definitions(-DUNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections -fno-show-column")
# Wrap libraries in --start-group and --end-group to easily support static linking and symbol resolution, maybe useful on APPLE also, but I don't know
string(REPLACE "<LINK_LIBRARIES>" "-Wl,--gc-sections -Wl,--start-group <LINK_LIBRARIES> -Wl,--end-group" CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE}")
string(REPLACE "<LINK_LIBRARIES>" "-Wl,--start-group <LINK_LIBRARIES> -Wl,--end-group" CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
string(REPLACE "<LINK_LIBRARIES>" "-Wl,--start-group <LINK_LIBRARIES> -Wl,--end-group" CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE}")
elseif(CMAKE_HOST_WIN32)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:libcmt.lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
if(CMAKE_CL_64)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D FPM_64BIT")
endif()
else()
add_compile_options(-mwindows -municode)
endif()
else()
message(STATUS "Unknown platform, maybe not supported")
endif()
# C++ standard we're compiling against
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(CMAKE_HOST_WIN32 AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"))
# Needed by _wfopen in src/common/platform.cpp for mingw32 (but technically not for mingw-w64)
set(CMAKE_CXX_EXTENSIONS ON)
endif()
# Compiler warning flags, not for MSVC
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# Extra warnings valid for both C and C++
set_check_compiler_flag_cxx("-Wall")
set_check_compiler_flag_cxx("-Wignored-qualifiers")
set_check_compiler_flag_cxx("-Wpointer-arith")
set_check_compiler_flag_cxx("-Wshadow")
set_check_compiler_flag_cxx("-Wsign-compare")
set_check_compiler_flag_cxx("-Wtype-limits")
set_check_compiler_flag_cxx("-Wuninitialized")
set_check_compiler_flag_cxx("-Wunused-parameter")
set_check_compiler_flag_cxx("-Wunused-but-set-parameter")
set_check_compiler_flag_cxx("-Wdeprecated-declarations" "-Wno-deprecated-declarations")
set_check_compiler_flag_cxx("-Wduplicated-cond")
set_check_compiler_flag_cxx("-Wduplicated-branches")
set_check_compiler_flag_cxx("-Wlogical-op")
set_check_compiler_flag_cxx("-Wshift-negative-value")
set_check_compiler_flag_cxx("-Wshift-overflow=2")
set_check_compiler_flag_cxx("-Wimplicit-fallthrough")
set_check_compiler_flag_cxx("-Wvla")
set_check_compiler_flag_cxx("-Wcast-function-type")
set_check_compiler_flag_cxx("-Wnull-pointer-subtraction")
# Extra warnings valid for C++
set_check_compiler_flag_cxx("-Wnon-virtual-dtor")
set_check_compiler_flag_cxx("-Wredundant-move")
set_check_compiler_flag_cxx("-Wctad-maybe-unsupported")
# Disable warnings about hiding virtual functions from a base class. We don't care
set_check_compiler_flag_cxx("-Woverloaded-virtual" "-Wno-overloaded-virtual")
# Disable warnings about the long long type. We need it
set_check_compiler_flag_cxx("-Wlong-long" "-Wno-long-long")
set_check_compiler_flag_cxx("-Wc++11-long-long" "-Wno-c++11-long-long")
# clang is far too trigger-happy on this warning, so let's disable it
set_check_compiler_flag_cxx("-Wundefined-var-template" "-Wno-undefined-var-template")
# We do not yet mark any of our overrides. Let's disable this for now
set_check_compiler_flag_cxx("-Winconsistent-missing-override" "-Wno-inconsistent-missing-override")
# Disable warnings about unused static const variables
set_check_compiler_flag_cxx("-Wunused-const-variable" "-Wno-unused-const-variable")
# Disable warnings about >= 0 comparisons on enums
set_check_compiler_flag_cxx("-Wtautological-unsigned-enum-zero-compare" "-Wno-tautological-unsigned-enum-zero-compare")
endif()
# platform specific warning settings
if(CMAKE_HOST_WIN32)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
endif()
set(WARNINGS_DISABLE
# ignore
4250 # 'class1' : inherits 'class2::member' via dominance
#4101 # 'identifier' : unreferenced local variable
4100 # 'identifier' : unreferenced formal parameter
4127 # conditional expression is constant (template parameter already evaluated)
4189 # 'identifier' : local variable is initialized but not referenced
4245 # 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch
4435 # 'class1' : Object layout under /vd2 will change due to virtual base 'class2'
4510 # 'class' : default constructor could not be generated
4512 # 'class' : assignment operator could not be generated
4610 # object 'class' can never be instantiated - user-defined constructor required
#4702 # unreachable code
4706 # assignment within conditional expression
4710 # 'function' : function not inlined
4714 # function 'function' marked as __forceinline not inlined
# investigate later
4305 # 'identifier' : truncation from 'type1' to 'type2'
4244 # 'argument' : conversion from 'type1' to 'type2', possible loss of data
4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data
4996 # 'function': was declared deprecated
# investigate now
#4005 # 'identifier' : macro redefinition
#4800 # 'type' : forcing value to bool 'true' or 'false' (performance warning)
#4146 # unary minus operator applied to unsigned type, result still unsigned
)
foreach(d ${WARNINGS_DISABLE})
set(WARNINGS "${WARNINGS} /wd${d}")
endforeach(d)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS} ${MT_BUILD}")
endif()
endif()
# header detection, could get rid of it, but it is used by lua as well
include(CheckIncludeFileCXX)
function(check_has_header FILE_NAME PP_NAME)
check_include_file_cxx(${FILE_NAME} ${PP_NAME})
if(${PP_NAME})
add_definitions(-D${PP_NAME}=1)
endif()
endfunction()
check_has_header("stdint.h" HAVE_STDINT_H)
check_has_header("inttypes.h" HAVE_INTTYPES_H)
check_has_header("sys/types.h" HAVE_SYS_TYPES_H)
# type size checks
include(CheckTypeSize)
check_type_size("char" SIZEOF_CHAR LANGUAGE CXX)
check_type_size("short" SIZEOF_SHORT LANGUAGE CXX)
check_type_size("int" SIZEOF_INT LANGUAGE CXX)
check_type_size("long" SIZEOF_LONG LANGUAGE CXX)
check_type_size("long long" SIZEOF_LONG_LONG LANGUAGE CXX)
check_type_size("void *" SIZEOF_VOID_P LANGUAGE CXX)
check_type_size("intptr_t" SIZEOF_INTPTR_T LANGUAGE CXX)
check_type_size("uintptr_t" SIZEOF_UINTPTR_T LANGUAGE CXX)
if(HAVE_SIZEOF_CHAR AND SIZEOF_CHAR)
add_definitions(-DSIZEOF_CHAR=${SIZEOF_CHAR})
endif()
if(HAVE_SIZEOF_SHORT AND SIZEOF_SHORT)
add_definitions(-DSIZEOF_SHORT=${SIZEOF_SHORT})
endif()
if(HAVE_SIZEOF_INT AND SIZEOF_INT)
add_definitions(-DSIZEOF_INT=${SIZEOF_INT})
endif()
if(HAVE_SIZEOF_LONG AND SIZEOF_LONG)
add_definitions(-DSIZEOF_LONG=${SIZEOF_LONG})
endif()
if(HAVE_SIZEOF_LONG_LONG AND SIZEOF_LONG_LONG)
add_definitions(-DSIZEOF_LONG_LONG=${SIZEOF_LONG_LONG})
endif()
if(HAVE_SIZEOF_VOID_P AND SIZEOF_VOID_P)
add_definitions(-DSIZEOF_VOID_P=${SIZEOF_VOID_P})
endif()
if(HAVE_SIZEOF_INTPTR_T AND SIZEOF_INTPTR_T)
add_definitions(-DHAVE_INTPTR_T=1)
endif()
if(HAVE_SIZEOF_UINTPTR_T AND SIZEOF_UINTPTR_T)
add_definitions(-DHAVE_UINTPTR_T=1)
endif()
# function detection
include(CheckCXXSymbolExists)
function(check_has_function FUNCTION_NAME FILE_NAME PP_NAME)
check_cxx_symbol_exists(${FUNCTION_NAME} "${FILE_NAME}" ${PP_NAME})
if(${PP_NAME})
add_definitions(-D${PP_NAME}=1)
endif()
endfunction()
check_has_function(strtof "cstdlib" HAVE_STRTOF)
check_has_function(strtoll "cstdlib" HAVE_STRTOLL)
check_has_function(strtoull "cstdlib" HAVE_STRTOULL)
# endianess detection, could be replaced by including Boost.Config
include(TestBigEndian)
# CMake's endian check needs C and won't work with just CXX...
enable_language(C)
test_big_endian(PHAETHON_BIG_ENDIAN)
if(PHAETHON_BIG_ENDIAN)
add_definitions(-DPHAETHON_BIG_ENDIAN=1)
else()
add_definitions(-DPHAETHON_LITTLE_ENDIAN=1)
endif()
# -------------------------------------------------------------------------
# subfolders where built binaries and libraries will be located, relative to the build folder
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# -------------------------------------------------------------------------
# find the required libraries
set(PHAETHON_LIBRARIES "")
find_package(Iconv REQUIRED)
include_directories(${Iconv_INCLUDE_DIRS})
list(APPEND PHAETHON_LIBRARIES ${Iconv_LIBRARIES})
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
list(APPEND PHAETHON_LIBRARIES ${ZLIB_LIBRARIES})
find_package(Boost COMPONENTS system filesystem date_time locale chrono REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
list(APPEND PHAETHON_LIBRARIES ${Boost_LIBRARIES})
find_package(OpenAL REQUIRED)
include_directories(${OPENAL_INCLUDE_DIR})
list(APPEND PHAETHON_LIBRARIES ${OPENAL_LIBRARY})
find_package(Mad REQUIRED)
include_directories(${MAD_INCLUDE_DIRS})
list(APPEND PHAETHON_LIBRARIES ${MAD_LIBRARIES})
find_package(Faad REQUIRED)
include_directories(${FAAD_INCLUDE_DIRS})
list(APPEND PHAETHON_LIBRARIES ${FAAD_LIBRARIES})
find_package(Ogg REQUIRED)
include_directories(${OGG_INCLUDE_DIRS})
list(APPEND PHAETHON_LIBRARIES ${OGG_LIBRARIES})
find_package(Vorbis REQUIRED)
include_directories(${VORBIS_INCLUDE_DIRS})
list(APPEND PHAETHON_LIBRARIES ${VORBIS_LIBRARIES})
find_package(LibLZMA REQUIRED)
include_directories(${LIBLZMA_INCLUDE_DIRS})
list(APPEND PHAETHON_LIBRARIES ${LIBLZMA_LIBRARIES})
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Concurrent REQUIRED)
include_directories(${Qt5Widgets_INCLUDE_DIRS} ${Qt5Concurrent_INCLUDE_DIRS})
list(APPEND PHAETHON_LIBRARIES Qt5::Widgets Qt5::Concurrent)
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
if(ICONV_SECOND_ARGUMENT_IS_CONST)
add_definitions(-DICONV_CONST=const)
else(ICONV_SECOND_ARGUMENT_IS_CONST)
add_definitions(-DICONV_CONST=)
endif(ICONV_SECOND_ARGUMENT_IS_CONST)
# pthreads
if(NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "MinGW")
find_package(Threads)
endif()
set(HAVE_PTHREAD ${CMAKE_USE_PTHREADS_INIT})
if(CMAKE_USE_PTHREADS_INIT)
set(PTHREAD_LIBS ${CMAKE_THREAD_LIBS_INIT})
list(APPEND PHAETHON_LIBRARIES ${PTHREAD_LIBS})
endif()
# libmspack
parse_automake(external/mspack/rules.mk)
# -------------------------------------------------------------------------
# custom unit testing target, because CMake's make test is pretty useless
add_custom_target(check ${CMAKE_COMMAND} -E echo CWD=${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E echo CMD=${CMAKE_CTEST_COMMAND} -C $<CONFIG>
COMMAND ${CMAKE_COMMAND} -E echo ----------------------------------
COMMAND ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1 ${CMAKE_CTEST_COMMAND} -C $<CONFIG>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# -------------------------------------------------------------------------
# phaethon main targets, parsed from the Automake rules.mk files
include_directories(${PROJECT_SOURCE_DIR})
add_definitions(-DPACKAGE_STRING="phaethon ${phaethon_VERSION}")
parse_automake(src/rules.mk)
# unit tests depend on Phaethon proper
foreach(AM_TARGET ${AM_TARGETS})
add_dependencies(check ${AM_TARGET})
endforeach()
foreach(AM_PROGRAM ${AM_PROGRAMS})
target_link_libraries(${AM_PROGRAM} ${PHAETHON_LIBRARIES})
endforeach()
# install programs to bin dir
install(
TARGETS ${AM_PROGRAMS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# -------------------------------------------------------------------------
# unit tests, parsed from the Automake rules.mk files
enable_testing()
parse_automake(tests/rules.mk)
# they should be build on make check, but not make all
foreach(AM_TARGET ${AM_TARGETS})
set_target_properties(${AM_TARGET} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE EXCLUDE_FROM_ALL TRUE)
add_dependencies(check ${AM_TARGET})
# ctest counts skipped tests as failed... -.-
get_target_property(TARGET_SOURCES ${AM_TARGET} SOURCES)
foreach(TARGET_SOURCE ${TARGET_SOURCES})
set_source_files_properties(${TARGET_SOURCE} PROPERTIES APPEND PROPERTY COMPILE_DEFINITIONS "SKIP_RETURN_CODE=0")
endforeach()
endforeach()
foreach(AM_PROGRAM ${AM_PROGRAMS})
target_link_libraries(${AM_PROGRAM} ${PHAETHON_LIBRARIES})
add_test(NAME ${AM_PROGRAM} COMMAND ${AM_PROGRAM})
endforeach()
# -------------------------------------------------------------------------
# phaethon man pages and docs
parse_automake(man/rules.mk)
# install man pages
install(
FILES ${AM_MAN1_MANS}
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
)
install(
FILES ${AM_MAN6_MANS}
DESTINATION ${CMAKE_INSTALL_MANDIR}/man6
)
parse_automake(doc/rules.mk)
# install docs
install(
FILES ${AM_DOCS}
DESTINATION ${CMAKE_INSTALL_DOCDIR}
)
# -------------------------------------------------------------------------
# uninstall target
# Code taken from https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake
if(NOT TARGET uninstall)
configure_file("${CMAKE_SOURCE_DIR}/cmake/CMakeUninstall.cmake" "${CMAKE_BINARY_DIR}/CMakeUninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake)
endif()
# -------------------------------------------------------------------------
# try to add version information from git to src/version/version.cpp
# this is not 100% clean, and doesn't reconfigure when there's only a local change since last
# build (so it does not always add the .dirty suffix)
# get build timestamp, but heed SOURCE_DATE_EPOCH
set(DATE_FMT "%Y-%m-%dT%H:%M:%SZ")
if(DEFINED ENV{SOURCE_DATE_EPOCH})
execute_process(COMMAND "date" "-u" "-d" "@$ENV{SOURCE_DATE_EPOCH}" "+${DATE_FMT}" OUTPUT_VARIABLE PHAETHON_BUILDDATE OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE DATE_RETCODE ERROR_QUIET)
if(NOT "${DATE_RETCODE}" STREQUAL "0")
execute_process(COMMAND "date" "-u" "-r" "$ENV{SOURCE_DATE_EPOCH}" "+${DATE_FMT}" OUTPUT_VARIABLE PHAETHON_BUILDDATE OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE DATE_RETCODE ERROR_QUIET)
if(NOT "${DATE_RETCODE}" STREQUAL "0")
string(TIMESTAMP PHAETHON_BUILDDATE "${DATE_FMT}" UTC)
endif()
endif()
else()
string(TIMESTAMP PHAETHON_BUILDDATE "${DATE_FMT}" UTC)
endif()
set_property(SOURCE src/version/version.cpp APPEND PROPERTY COMPILE_DEFINITIONS PHAETHON_BUILDDATE="${PHAETHON_BUILDDATE}")
find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} -C ${CMAKE_CURRENT_SOURCE_DIR} describe --long --match desc/* OUTPUT_VARIABLE PHAETHON_REVDESC OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "desc/(.*)-([^-]*)-([^-]*)" "\\1+\\2.\\3" PHAETHON_REVDESC "${PHAETHON_REVDESC}")
execute_process(
COMMAND ${GIT_EXECUTABLE} -C ${CMAKE_CURRENT_SOURCE_DIR} update-index --refresh --unmerged
COMMAND ${GIT_EXECUTABLE} -C ${CMAKE_CURRENT_SOURCE_DIR} diff-index --quiet HEAD
OUTPUT_QUIET ERROR_QUIET
RESULT_VARIABLE PHAETHON_REVDIRT
)
if(NOT PHAETHON_REVDIRT EQUAL 0)
set(PHAETHON_REVDESC "${PHAETHON_REVDESC}.dirty")
endif()
string(REGEX REPLACE "^[^+]*\\+" "" PHAETHON_REV "${PHAETHON_REVDESC}")
message(STATUS "Building version: ${PHAETHON_REVDESC}")
set_property(SOURCE src/version/version.cpp APPEND PROPERTY COMPILE_DEFINITIONS PHAETHON_REVDESC="${PHAETHON_REVDESC}")
set_property(SOURCE src/version/version.cpp APPEND PROPERTY COMPILE_DEFINITIONS PHAETHON_REV="${PHAETHON_REV}")
# use .git/logs/HEAD to track if git state has changed and if we need to reconfigure
if(EXISTS ${CMAKE_SOURCE_DIR}/.git/logs/HEAD)
configure_file(${CMAKE_SOURCE_DIR}/.git/logs/HEAD .dirstamp)
endif()
endif()
# -------------------------------------------------------------------------
# documentation
if(PHAETHON_BUILD_DOCUMENTATION)
find_package(Doxygen)
if (NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation. Please install it correctly")
endif()
add_custom_target(doxygen
COMMAND ${DOXYGEN_EXECUTABLE}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/Doxyfile
)
add_custom_target(doxygen-clean
COMMAND rm -rf doc/doxygen/html/
COMMAND rm -rf doc/doxygen/latex/
COMMAND rm -rf doc/doxygen/man/
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
endif()