-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
267 lines (217 loc) · 9.79 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
PROJECT(__PROJECTNAME__)
# require at least cmake 2.8
cmake_minimum_required(VERSION 2.8)
#############################################################################
# include cmake scripts
#############################################################################
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros)
# require out-of-source build
INCLUDE(require_out_of_src_build)
MACRO_REQUIRE_OUT_OF_SRC_BUILD("__PROJECTNAME__ requires out-of-source builds.")
# Git revision saved in variable __PROJECTNAME___VERSION
INCLUDE(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC __PROJECTNAME___VERSION)
#############################################################################
# Varaibles to upper string for easier comparisions
#############################################################################
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "RelWithDebInfo")
ENDIF(NOT CMAKE_BUILD_TYPE)
STRING(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
#############################################################################
# build libraries
#############################################################################
# require boost
#SET(Boost_USE_STATIC_LIBS OFF)
#SET(Boost_USE_MULTITHREAD OFF)
#make sure that at least version 1.46.0 is used
#SET(BOOST_MIN_VERSION "1.46.0")
#FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} COMPONENTS thread REQUIRED)
#INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
#LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
#############################################################################
# compiler Flags
#############################################################################
# Set default compile flags for GCC
if(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -Wall -Wconversion -ggdb3")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -ftree-vectorize -msse2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3")
endif(CMAKE_COMPILER_IS_GNUCXX)
#############################################################################
# Cmake generated header files
#############################################################################
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/include/__targetname__/config.hpp.cmake
${__PROJECTNAME___BINARY_DIR}/include/__targetname__/config.hpp
)
#############################################################################
# Cmake Options
#############################################################################
OPTION(ENABLE_TESTING "Compile tests" ON)
OPTION(ENABLE_COVERAGE "Enable GCov coverage analysis (defines a 'coverage' target and enforces static build of __projectname__)" OFF)
OPTION(ENABLE_EXAMPLES "Compile examples" OFF)
OPTION(ENABLE_THREADING "Enable threading" FALSE)
#############################################################################
# global include dirs
#############################################################################
INCLUDE_DIRECTORIES(
${__PROJECTNAME___SOURCE_DIR}/include
${__PROJECTNAME___BINARY_DIR}/include
)
#############################################################################
# messages and error handling
#############################################################################
MESSAGE(STATUS "__projectname__ Git Commit: "${__PROJECTNAME___VERSION})
MESSAGE(STATUS "Build type: "${CMAKE_BUILD_TYPE})
MESSAGE(STATUS "CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}")
IF(ENABLE_THREADING)
MESSAGE(STATUS "Threading enabled")
ELSE()
MESSAGE(STATUS "Threading disabled")
ENDIF()
IF(ENABLE_TESTING)
MESSAGE(STATUS "Testing enabled")
ELSE()
MESSAGE(STATUS "Testing disabled")
ENDIF()
IF(ENABLE_EXAMPLES)
MESSAGE(STATUS "Examples enabled")
ELSE()
MESSAGE(STATUS "Examples disabled")
ENDIF()
IF (ENABLE_COVERAGE)
IF(CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND ENABLE_TESTING)
MESSAGE(STATUS "Coverage enabled")
ELSEIF(NOT ENABLE_TESTING)
MESSAGE(FATAL_ERROR "Coverage analysis requires Testing Enabled")
ELSE()
MESSAGE(FATAL_ERROR "Coverage analysis requires DEBUG build")
ENDIF()
ELSE()
MESSAGE(STATUS "Coverage disabled")
ENDIF()
#############################################################################
# code coverage analysis
#############################################################################
IF (ENABLE_COVERAGE)
IF(CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND ENABLE_TESTING)
SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
CONFIGURE_FILE(${__PROJECTNAME___SOURCE_DIR}/cmake/scripts/coverage.sh.in
${__PROJECTNAME___BINARY_DIR}/cmake/scripts/coverage.sh
@ONLY IMMEDIATE
)
ADD_CUSTOM_TARGET(
coverage COMMAND /bin/bash ${__PROJECTNAME___BINARY_DIR}/cmake/scripts/coverage.sh
)
ENDIF()
ENDIF(ENABLE_COVERAGE)
#############################################################################
# tests
#############################################################################
IF (ENABLE_TESTING)
INCLUDE(CTest)
ENABLE_TESTING()
ADD_SUBDIRECTORY(test)
ENDIF (ENABLE_TESTING)
#############################################################################
# build __projectname__
#############################################################################
ADD_SUBDIRECTORY(src)
############################################################################
# examples
############################################################################
#
#IF (ENABLE_EXAMPLES)
# ADD_SUBDIRECTORY(examples)
#ENDIF (ENABLE_EXAMPLES)
#############################################################################
# documentation
#############################################################################
# doxygen support
CONFIGURE_FILE(${__PROJECTNAME___SOURCE_DIR}/doc/Doxyfile.cmake
${__PROJECTNAME___BINARY_DIR}/doc/Doxyfile
@ONLY IMMEDIATE
)
CONFIGURE_FILE(${__PROJECTNAME___SOURCE_DIR}/doc/__projectname__.png
${__PROJECTNAME___BINARY_DIR}/doc/__projectname__.png
COPYONLY
)
FIND_PACKAGE(Doxygen)
# target for doxygen
ADD_CUSTOM_TARGET(doc COMMAND ${DOXYGEN} ${__PROJECTNAME___BINARY_DIR}/doc/Doxyfile)
#############################################################################
# installation
#############################################################################
# location, location, location
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX
"/usr/local" CACHE PATH "__projectname__ install prefix" FORCE
)
ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# so that the dmg works also to the given location
SET(CPACK_PACKAGE_DEFAULT_LOCATION ${CMAKE_INSTALL_PREFIX})
# headers
INSTALL(DIRECTORY ${__PROJECTNAME___SOURCE_DIR}/include/__projectname__
DESTINATION include
COMPONENT headers
REGEX "/.git$" EXCLUDE
PATTERN "config.hpp.cmake" EXCLUDE)
# config.h
INSTALL(FILES ${__PROJECTNAME___BINARY_DIR}/include/__projectname__/config.hpp
DESTINATION include/__projectname__
COMPONENT headers)
# documentation
INSTALL(DIRECTORY ${__PROJECTNAME___BINARY_DIR}/doc
DESTINATION share/__projectname__
COMPONENT documentation
PATTERN "Doxyfile" EXCLUDE)
##############################################################################
## exporting __projectname__
##############################################################################
get_target_property(__PROJECTNAME___LIBRARY __targetname__ LOCATION)
get_filename_component(__PROJECTNAME___INSTALL_LIBRARY ${__PROJECTNAME___LIBRARY} NAME)
set (__PROJECTNAME___LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/${__PROJECTNAME___INSTALL_LIBRARY})
set (__PROJECTNAME___INCLUDE ${CMAKE_INSTALL_PREFIX}/include)
configure_file(
"${PROJECT_SOURCE_DIR}/cmake/macros/__projectname__Config.cmake.in"
"${PROJECT_BINARY_DIR}/InstallFiles/__projectname__Config.cmake")
export(TARGETS __targetname__
FILE "${PROJECT_BINARY_DIR}/InstallFiles/__projectname__LibraryDepends.cmake")
export(PACKAGE __targetname__)
if (UNIX)
INSTALL(FILES "${PROJECT_BINARY_DIR}/InstallFiles/__projectname__Config.cmake" DESTINATION /lib/__projectname__/)
INSTALL(FILES "${PROJECT_BINARY_DIR}/InstallFiles/__projectname__LibraryDepends.cmake" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/__projectname__/cmake/)
elseif(WIN32)
INSTALL(FILES "${PROJECT_BINARY_DIR}/InstallFiles/__projectname__Config.cmake" DESTINATION /cmake/)
INSTALL(FILES "${PROJECT_BINARY_DIR}/InstallFiles/__projectname__LibraryDepends.cmake" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/__projectname__/cmake/)
endif()
##############################################################################
## packaging
##############################################################################
## FIXME: make sure that the documentation is compiled and pdfs are
## generated prior to packaging!
#
set(CPACK_PACKAGE_NAME "__projectname__")
set(CPACK_PACKAGE_VENDOR "kirchnerlab.org")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The __targetname__ library; version "$__PROJECTNAME___VERSION)
# CPack version strings
SET(CPACK_PACKAGE_VERSION_MAJOR 2)
SET(CPACK_PACKAGE_VERSION_MINOR 1)
SET(CPACK_PACKAGE_VERSION_PATCH 0)
SET(CPACK_RESOURCE_FILE_README "${__PROJECTNAME___SOURCE_DIR}/README.txt")
SET(CPACK_RESOURCE_FILE_LICENSE "${__PROJECTNAME___SOURCE_DIR}/LICENSE.txt")
set(CPACK_COMPONENTS_ALL libraries headers documentation examples)
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Development Headers")
set(CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "C++ Interface Documentation")
set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Compiled Examples")
set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
"Compiled libraries.")
set(CPACK_COMPONENT_HEADERS_DESCRIPTION
"C++ header files for __projectname__ development.")
set(CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION
"The C++ __projectname__ interface documentation (Doxygen).")
set(CPACK_COMPONENT_EXAMPLES_DESCRIPTION
"Compiled examples.")
INCLUDE(CPack)