-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
195 lines (164 loc) · 5.05 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
cmake_minimum_required(VERSION 3.2)
#
# Project settings
#
project(finFoil)
set(PROJECT_BRIEF "${PROJECT_NAME} is a foil design tool optimized for surfboard fins.")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin/)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib/)
# Version
set(MAJOR_VERSION "1")
set(MINOR_VERSION "2")
set(REVISION "0")
#
# Build flags & compiler settings
#
# Define the Build flags
option(Shared "Build shared libararies where possible." OFF)
option(CCache "Build using ccache." OFF)
option(Tests "Build the tests executable" OFF)
option(Web "Include the web components" ON)
# Build flags
set(CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(DEBUG_FLAGS "-g -O0 -Wall -Wextra -pedantic")
set(RELEASE_FLAGS "-O3 -fomit-frame-pointer -finline-functions")
# Assign the build flags
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS_RELEASE ${RELEASE_FLAGS})
set(CMAKE_C_FLAGS_RELEASE ${RELEASE_FLAGS})
set(CMAKE_CXX_FLAGS_DEBUG ${DEBUG_FLAGS})
#set(CMAKE_CXX_FLAGS_DEBUG ${GCOV_FLAGS})
set(CMAKE_C_FLAGS_DEBUG ${DEBUG_FLAGS})
#set(CMAKE_C_FLAGS_DEBUG ${GCOV_FLAGS})
#set(CMAKE_EXE_LINKER_FLAGS_DEBUG ${GCOV_FLAGS})
# TODO OP check how this works on multiple configurations generators
# available configurations in multiple configurations enabled generators
set(CMAKE_CONFIGURATION_TYPES Debug Release)
#message("CMAKE_CFG_INTDIR = ${CMAKE_CFG_INTDIR}")
# Linking and dependency options
add_definitions(-DJENSON_QPTR) # Definition to make jenson serialize to qunique_ptr
if(Shared)
set(FINFOIL_LIB_TYPE SHARED)
set(JENSON_SHARED ON)
set(QTUNITS_SHARED ON)
else()
set(FINFOIL_LIB_TYPE STATIC)
add_definitions(-DJENSON_STATIC)
add_definitions(-DQTUNITS_STATIC)
endif()
# Optionally enable ccache
if(CCache)
SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
endif()
# Optionally enable Web
if(Web)
else()
add_definitions(-DWEB_DISABLED)
endif()
#
# Find and include external dependencies
#
# Qt
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
if(Web)
find_package(Qt5Network REQUIRED)
find_package(Qt5WebEngineWidgets REQUIRED)
endif()
set(CMAKE_AUTOMOC ON)
# Boost
find_package(Boost COMPONENTS iostreams REQUIRED)
if(Boost_FOUND)
message(STATUS "Including Boost from: ${Boost_INCLUDE_DIRS}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
if (WIN32)
# disable autolinking in boost
add_definitions( -DBOOST_ALL_NO_LIB )
# force all boost libraries to dynamic link (we already disabled
# autolinking, so I don't know why we need this, but we do!)
add_definitions( -DBOOST_ALL_DYN_LINK )
endif()
#
# Try to set build number and commit hash
#
# Get the build number
execute_process(
COMMAND git rev-list HEAD --count
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BUILD_NUMBER
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the commit hash
execute_process(
COMMAND git rev-parse --verify HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(${GIT_BUILD_NUMBER})
configure_file(
${CMAKE_SOURCE_DIR}/src/version_template.hpp
${CMAKE_SOURCE_DIR}/src/version_autogen.hpp
)
message(STATUS "GIT_BUILD_NUMBER: ${GIT_BUILD_NUMBER} GIT_COMMIT_HASH: ${GIT_COMMIT_HASH}")
else()
message(WARNING "Not building from a git repository, the build number cannot be updated.")
endif()
#
# Include subdirectories
#
# Include header files
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src/app")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/submodules/jenson/src")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/submodules/qtunits/src")
add_subdirectory(src/app)
if(Tests)
find_package(Qt5Test REQUIRED)
add_subdirectory(tests/unittests)
file(COPY tests/testdata DESTINATION ${CMAKE_BINARY_DIR}/bin/)
endif()
# Install header files
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/.
DESTINATION include/finfoil
COMPONENT headers
)
# Install JenSON header files
file(GLOB_RECURSE JENSON_H ${CMAKE_SOURCE_DIR}/submodules/jenson/src/*.h)
file(GLOB_RECURSE JENSON_HPP ${CMAKE_SOURCE_DIR}/submodules/jenson/src/*.hpp)
install(FILES
${JENSON_H}
${JENSON_HPP}
DESTINATION include/finfoil/jenson
COMPONENT headers
)
# Install QtUnits header files
file(GLOB_RECURSE QTUNITS_H ${CMAKE_SOURCE_DIR}/submodules/qtunits/src/*.h)
file(GLOB_RECURSE QTUNITS_HPP ${CMAKE_SOURCE_DIR}/submodules/qtunits/src/*.hpp)
install(FILES
${QTUNITS_H}
${QTUNITS_HPP}
DESTINATION include/finfoil/qtunits
COMPONENT headers
)
# Install qtestrunner header file
install(FILES
${CMAKE_SOURCE_DIR}/submodules/qtestrunner/qtestrunner.hpp
DESTINATION include/finfoil/qtestrunner
COMPONENT headers
)
# Install readme and license files
install(FILES
${PROJECT_SOURCE_DIR}/README
${PROJECT_SOURCE_DIR}/LICENSE.BSD
${PROJECT_SOURCE_DIR}/LICENSE.LGPLv2
DESTINATION include/finfoil
)
install(TARGETS ${LIB_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static
)
# Note: executable and library installation is configured in dedicated CMakeLists.txt