-
Notifications
You must be signed in to change notification settings - Fork 22
/
CMakeLists.txt
147 lines (124 loc) · 5.09 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
##########################################################################
# Evoplex <https://evoplex.org>
# Copyright (C) 2018 - Marcos Cardinot <marcos@cardinot.net>
##########################################################################
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
set(EVOPLEX_VERSION 0.2.2)
set(EVOPLEX_RELEASE "development")
if(EVOPLEX_RELEASE STREQUAL "")
set(EVOPLEX_VERSION_RELEASE "${EVOPLEX_VERSION}")
else()
set(EVOPLEX_VERSION_RELEASE "${EVOPLEX_VERSION}-${EVOPLEX_RELEASE}")
endif()
project(evoplex VERSION ${EVOPLEX_VERSION})
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
if(POLICY CMP0071)
cmake_policy(SET CMP0071 NEW) # process generated files
endif()
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
# Generate the commands
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# c++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# clang-3.8 and 3.9 need to be linked against libc++ to make c++14 work
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND
${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 3.7.1 AND
${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/src/cmake)
option(TESTS "Turn on tests" OFF)
option(CODE_COVERAGE "Turn on code coverage" OFF)
if(CODE_COVERAGE)
set(TESTS ON)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_BUILD_TYPE Debug) # coverage must be in debug mode
include(CodeCoverage) # codecov.io
include(Coveralls) # coveralls.io
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra")
append_coverage_compiler_flags()
setup_target_for_coverage(NAME "${PROJECT_NAME}_coverage" EXECUTABLE ctest --parallel 4)
else()
message("CODE_COVERAGE cannot be ON for this compiler!")
set(CODE_COVERAGE OFF)
endif()
endif()
if(TESTS)
enable_testing() # Tests must be enabled from root
endif()
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE EVOPLEX_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE EVOPLEX_GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_definitions("-DGIT_COMMIT_HASH=${EVOPLEX_GIT_COMMIT_HASH}")
add_definitions("-DGIT_BRANCH=${EVOPLEX_GIT_BRANCH}")
# http://doc.qt.io/qt-5/qmessagelogcontext.html
# By default QMessageLogContext only works in Debug mode.
# To make it permanent for all modes, we need to define QT_MESSAGELOGCONTEXT
add_definitions("-DQT_MESSAGELOGCONTEXT")
# pass some of the CMake settings to the source code
configure_file("${CMAKE_SOURCE_DIR}/src/config.h.in" "${CMAKE_BINARY_DIR}/src/config.h")
# Find qt5 packages
find_package(Qt5Core 5.8.0 REQUIRED)
find_package(Qt5Concurrent 5.8.0 REQUIRED)
find_package(Qt5Network 5.8.0 REQUIRED)
find_package(Qt5Charts 5.8.0 REQUIRED)
find_package(Qt5Widgets 5.8.0 REQUIRED)
find_package(Qt5Test 5.8.0 REQUIRED)
find_package(Qt5Svg 5.8.0 REQUIRED)
# set compilation and installation directories
if(APPLE)
set(CMAKE_INSTALL_PREFIX "/Applications")
set(EVOPLEX_OUTPUT_PREFIX "${CMAKE_BINARY_DIR}/bin/")
set(EVOPLEX_INSTALL_PREFIX "${PROJECT_NAME}.app/Contents/MacOS/")
set(EVOPLEX_OUTPUT_RUNTIME "${EVOPLEX_OUTPUT_PREFIX}")
set(EVOPLEX_OUTPUT_RESOURCES "${EVOPLEX_OUTPUT_PREFIX}${PROJECT_NAME}.app/Contents/Resources/")
set(EVOPLEX_OUTPUT_LIBRARY "${EVOPLEX_OUTPUT_PREFIX}${PROJECT_NAME}.app/Contents/MacOS/lib/evoplex/")
set(EVOPLEX_INSTALL_RUNTIME "${EVOPLEX_INSTALL_PREFIX}")
set(EVOPLEX_INSTALL_RESOURCES "${EVOPLEX_INSTALL_PREFIX}../Resources/")
elseif(WIN32)
set(EVOPLEX_OUTPUT_PREFIX "${CMAKE_BINARY_DIR}/releases/")
set(EVOPLEX_OUTPUT_RUNTIME "${EVOPLEX_OUTPUT_PREFIX}")
set(EVOPLEX_OUTPUT_RESOURCES "${EVOPLEX_OUTPUT_PREFIX}")
set(EVOPLEX_OUTPUT_LIBRARY "${EVOPLEX_OUTPUT_PREFIX}lib/evoplex/")
set(EVOPLEX_INSTALL_RUNTIME ".")
set(EVOPLEX_INSTALL_RESOURCES ".")
else()
set(EVOPLEX_OUTPUT_PREFIX "${CMAKE_BINARY_DIR}/")
set(EVOPLEX_OUTPUT_RUNTIME "${EVOPLEX_OUTPUT_PREFIX}bin/")
set(EVOPLEX_OUTPUT_RESOURCES "${EVOPLEX_OUTPUT_PREFIX}share/evoplex/")
set(EVOPLEX_OUTPUT_LIBRARY "${EVOPLEX_OUTPUT_PREFIX}lib/evoplex/")
set(EVOPLEX_INSTALL_RUNTIME "bin/")
set(EVOPLEX_INSTALL_RESOURCES "share/evoplex/")
endif()
set(EVOPLEX_OUTPUT_ARCHIVE "${EVOPLEX_OUTPUT_LIBRARY}")
set(EVOPLEX_INSTALL_LIBRARY "${EVOPLEX_INSTALL_PREFIX}lib/evoplex/")
set(EVOPLEX_INSTALL_ARCHIVE "${EVOPLEX_INSTALL_PREFIX}lib/evoplex/")
set(EVOPLEX_INSTALL_INCLUDES "${EVOPLEX_INSTALL_PREFIX}include/evoplex/")
# Compile source
add_subdirectory(src)
# copy text files
foreach(TXTFILE README.md CHANGELOG.md)
configure_file(${TXTFILE} "${EVOPLEX_OUTPUT_RESOURCES}${TXTFILE}" COPYONLY)
install(FILES ${TXTFILE} DESTINATION "${EVOPLEX_INSTALL_RESOURCES}")
endforeach(TXTFILE)
# Packaging
include(EvoplexCPack)