-
Notifications
You must be signed in to change notification settings - Fork 58
/
CMakeLists.txt
214 lines (164 loc) · 7.56 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
CMAKE_MINIMUM_REQUIRED( VERSION 2.8.4 )
project (easykf)
SET(PACKAGE_VERSION "2.11")
SET(PACKAGE_LICENSE "GPL")
SET(CMAKE_BUILD_TYPE Release)
SET(PROJECT_DESCRIPTION_SUMMARY "C++ library for Kalman filtering (linear, EKF, UKF)")
#######################################
# Get the libs/inc for the dependencies
#######################################
find_package(PkgConfig)
pkg_check_modules(GSL gsl REQUIRED)
pkg_check_modules(PYTHON python REQUIRED)
set(PKG_CONFIG_DEPENDS "gsl python")
#######################################
# Setting the compilation flags
#######################################
# cflags added by the package
#SET(PROJECT_CFLAGS "-std=c++0x")
# cflags added by the pkg-config dependencies contains ';' as separator. This is a fix.
string(REPLACE ";" " " GSL_CFLAGS "${GSL_CFLAGS}")
string(REPLACE ";" " " PYTHON_CFLAGS "${PYTHON_CFLAGS}")
# lib flags added by the package
SET(PROJECT_LIBS "-Wl,--no-as-needed -leasykf")
# libs added by the pkg-config dependencies contains ';' as separator. This is a fix.
string(REPLACE ";" " " GSL_LDFLAGS "${GSL_LDFLAGS}")
string(REPLACE ";" " " PYTHON_LDFLAGS "${PYTHON_LDFLAGS}")
# ldflags required, but not provided by pkg-config
SET(PROJECT_LDFLAGS "")
# Gathering of all flags
# (e.g. for compiling examples)
SET(PROJECT_ALL_CFLAGS "${PROJECT_CFLAGS} ${GSL_CFLAGS} ${PYTHON_CFLAGS}")
SET(PROJECT_ALL_LDFLAGS "${PROJECT_LIBS} ${PROJECT_LDFLAGS} -L${CMAKE_BINARY_DIR}/src ${GSL_LDFLAGS} ${PYTHON_LDFLAGS}")
# Gathering of all flags from dependancies flags
# (e.g. for compiling libraries)
SET(PROJECT_ALL_DEP_LDFLAGS "${PROJECT_LDFLAGS} ${GSL_LDFLAGS} ${PYTHON_LDFLAGS}")
###################################
# Some prefix definitions
###################################
# Define the prefix where libs are going to be installed
SET(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE STRING "Library directory name")
# Define the path to install the headers
SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}/" CACHE PATH "The subdirectory to the header prefix")
# Define the path to install the documentation
SET(DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${CMAKE_PROJECT_NAME}" CACHE PATH "The subdirectory to the documentation prefix")
# Define the path to install the pc pkg-config file
SET(PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig/" CACHE STRING "Base directory for pkgconfig files")
###################################
# Pkg-config stuff
###################################
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.pc
"
Name: ${CMAKE_PROJECT_NAME}
Description: ${PROJECT_DESCRIPTION_SUMMARY}
Version: ${PACKAGE_VERSION}
Requires: ${PKG_CONFIG_DEPENDS}
Libs: -L${LIB_INSTALL_DIR} ${PROJECT_LDFLAGS} ${PROJECT_LIBS}
Cflags: -I${INCLUDE_INSTALL_DIR} ${PROJECT_CFLAGS}
"
)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.pc
DESTINATION ${PKGCONFIG_INSTALL_DIR}
COMPONENT devel)
###################################
# Subdirectories
###################################
add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(doc)
###################################
# Custom command for source tgz
###################################
SET(DIST_DIR "${CMAKE_PROJECT_NAME}-${PACKAGE_VERSION}")
ADD_CUSTOM_TARGET(dist
COMMAND rm -rf ${DIST_DIR}
COMMAND mkdir ${DIST_DIR}
COMMAND cp -r ${CMAKE_SOURCE_DIR}/* ${DIST_DIR} || true
COMMAND rm -rf ${DIST_DIR}/build
COMMAND mkdir ${DIST_DIR}/build
COMMAND tar --exclude="*~" --exclude="._*" --exclude=".svn" -zcvf ${DIST_DIR}.tar.gz ${DIST_DIR}
COMMAND rm -rf ${DIST_DIR}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
###################################
# For building packages
###################################
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_DESCRIPTION_SUMMARY})
SET(CPACK_PACKAGE_VENDOR "Jeremy Fix")
SET(CPACK_PACKAGE_CONTACT "[email protected]")
SET(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
SET(CPACK_PACKAGE_LICENSE "${PACKAGE_LICENSE}")
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
SET(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README)
SET(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_SOURCE_DIR}/README)
SET(CPACK_RESOURCE_FILE_INSTALL ${CMAKE_SOURCE_DIR}/INSTALL)
IF(MYBUILDTYPE STREQUAL "binary")
SET(CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME}-binaries;binary;/")
ELSEIF(MYBUILDTYPE STREQUAL "devel")
SET(CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME}-headers;devel;/")
ENDIF()
# Custom target for building the packages
# we do it inside
execute_process(COMMAND getconf _NPROCESSORS_ONLN
OUTPUT_VARIABLE NB_PROCESSOR)
ADD_CUSTOM_TARGET(packages
COMMAND rm -rf build
COMMAND mkdir build
COMMAND cd build && cmake ${CMAKE_SOURCE_DIR} -DCMAKE_INSTALL_PREFIX=/usr -DLIB_SUFFIX=${LIB_SUFFIX} -DMYBUILDTYPE="binary" && make package -j${NB_PROCESSOR}
COMMAND cp build/*.rpm build/*.deb . || true
COMMAND rm -rf build
COMMAND mkdir build
COMMAND cd build && cmake ${CMAKE_SOURCE_DIR} -DCMAKE_INSTALL_PREFIX=/usr -DLIB_SUFFIX=${LIB_SUFFIX} -DMYBUILDTYPE="devel" && make package -j${NB_PROCESSOR}
COMMAND cp build/*.rpm build/*.deb . || true
COMMAND rm -rf build
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
###############################################
# For RPMs
###############################################
find_program( RPMBUILD
NAMES rpmbuild
PATHS "/usr/bin"
)
IF(NOT RPMBUILD STREQUAL "RPMBUILD-NOTFOUND")
MESSAGE("Set up for building RPM")
IF(MYBUILDTYPE STREQUAL "binary")
SET(CPACK_RPM_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
ENDIF()
IF(MYBUILDTYPE STREQUAL "binary")
SET(CPACK_RPM_PACKAGE_REQUIRES "gsl, python2.7")
ENDIF()
IF(MYBUILDTYPE STREQUAL "devel")
SET(CPACK_RPM_PACKAGE_NAME ${CMAKE_PROJECT_NAME}-devel)
SET(CPACK_RPM_PACKAGE_REQUIRES "gsl-devel, python2.7-devel, ${CMAKE_PROJECT_NAME}")
ENDIF()
SET(CPACK_PACKAGE_FILE_NAME ${CPACK_RPM_PACKAGE_NAME}-${PACKAGE_VERSION}-${CMAKE_SYSTEM_PROCESSOR})
SET(CPACK_RPM_SPEC_MORE_DEFINE "%define ignore \#")
SET(CPACK_RPM_USER_FILELIST "%ignore /usr" "%ignore /usr/bin" "%ignore /usr/lib64" "%ignore /usr/lib" "%ignore /usr/lib64/pkgconfig" "%ignore /usr/lib/pkgconfig" "%ignore /usr/include" "%ignore /usr/share" "%ignore /usr/share/doc" "%ignore /usr/share/pixmaps" "%ignore /usr/share/applications" "%ignore /usr/lib/gstreamer-0.10" "%ignore /usr/lib64/gstreamer-0.10")
SET(CPACK_RPM_PACKAGE_LICENSE "${PACKAGE_LICENSE}")
SET(CPACK_GENERATOR "RPM")
ENDIF(NOT RPMBUILD STREQUAL "RPMBUILD-NOTFOUND")
###############################################
# For DEBs
###############################################
find_program( DPKGDEB
NAMES dpkg-deb
PATHS "/usr/bin"
)
IF(NOT DPKGDEB STREQUAL "DPKGDEB-NOTFOUND")
MESSAGE("Set up for building DEB")
IF(MYBUILDTYPE STREQUAL "binary")
SET(CPACK_DEBIAN_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
ENDIF()
IF(MYBUILDTYPE STREQUAL "binary")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libgsl23, libpython2.7")
ENDIF()
IF(MYBUILDTYPE STREQUAL "devel")
SET(CPACK_DEBIAN_PACKAGE_NAME ${CMAKE_PROJECT_NAME}-dev)
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libgsl-dev, libpython2.7-dev, ${CMAKE_PROJECT_NAME}")
ENDIF()
SET(CPACK_PACKAGE_FILE_NAME ${CPACK_DEBIAN_PACKAGE_NAME}-${PACKAGE_VERSION}-${CMAKE_SYSTEM_PROCESSOR})
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
SET(CPACK_GENERATOR "DEB")
ENDIF(NOT DPKGDEB STREQUAL "DPKGDEB-NOTFOUND")
###############################################
INCLUDE(CPack)