blob: c4c89bc018af93200c5c9c5997bde4b7da782db4 [file] [log] [blame]
Keir Mierle8ebb0732012-04-30 23:09:08 -07001# Ceres Solver - A fast non-linear least squares minimizer
2# Copyright 2010, 2011, 2012 Google Inc. All rights reserved.
3# http://code.google.com/p/ceres-solver/
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
7#
8# * Redistributions of source code must retain the above copyright notice,
9# this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above copyright notice,
11# this list of conditions and the following disclaimer in the documentation
12# and/or other materials provided with the distribution.
13# * Neither the name of Google Inc. nor the names of its contributors may be
14# used to endorse or promote products derived from this software without
15# specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28#
29# Author: keir@google.com (Keir Mierle)
30
Sameer Agarwald1146902012-05-30 01:40:22 -070031CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -040032CMAKE_POLICY(VERSION 2.8)
Keir Mierle8ebb0732012-04-30 23:09:08 -070033
34IF (COMMAND cmake_policy)
35 CMAKE_POLICY(SET CMP0003 NEW)
36ENDIF (COMMAND cmake_policy)
37
38PROJECT(CERES C CXX)
39
Arnaud Gelasd2fb5ad2012-08-17 10:11:02 +020040# Set up the git hook to make Gerrit Change-Id: lines in commit messages.
41SET (LOCAL_GIT_DIRECTORY)
42IF (EXISTS ${CMAKE_SOURCE_DIR}/.git)
43 # .git directory can be found on Unix based system, or on Windows with
44 # Git Bash (shipped with msysgit)
45 SET (LOCAL_GIT_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)
46ELSE (EXISTS ${CMAKE_SOURCE_DIR}/.git)
Sameer Agarwal36f4cd22013-04-21 09:42:26 -070047 # TODO(keir) Add proper Windows support
Arnaud Gelasd2fb5ad2012-08-17 10:11:02 +020048ENDIF (EXISTS ${CMAKE_SOURCE_DIR}/.git)
49
50IF (EXISTS ${LOCAL_GIT_DIRECTORY})
51 IF (NOT EXISTS ${LOCAL_GIT_DIRECTORY}/hooks/commit-msg)
52 # Download the hook only if it is not already present
53 FILE(DOWNLOAD https://ceres-solver-review.googlesource.com/tools/hooks/commit-msg
54 ${CMAKE_BINARY_DIR}/commit-msg)
55
56 # Make the downloaded file executable, since it is not by default.
57 FILE(COPY ${CMAKE_BINARY_DIR}/commit-msg
58 DESTINATION ${LOCAL_GIT_DIRECTORY}/hooks/
59 FILE_PERMISSIONS
60 OWNER_READ OWNER_WRITE OWNER_EXECUTE
61 GROUP_READ GROUP_WRITE GROUP_EXECUTE
62 WORLD_READ WORLD_EXECUTE)
63 ENDIF (NOT EXISTS ${LOCAL_GIT_DIRECTORY}/hooks/commit-msg)
64ENDIF (EXISTS ${LOCAL_GIT_DIRECTORY})
65
Arnaud Gelasb3fa0092012-08-17 10:31:41 +020066SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
67SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
68SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
69
Keir Mierle05107ba2012-07-18 13:50:12 -070070# Important: Always bump the second number (e.g. 1.3.x to 1.4.0) for any
71# release that changes the ABI. The ABI changes for almost any modification to
72# include/ceres (e.g. the public API). If you are unsure about whether
73# something is an ABI change, please ask on the list.
74#
75# For versions without ABI changes, bump the smallest number in CERES_VERSION,
76# but leave the CERES_ABI_VERSION unchanged.
Pablo Specialec51b11c2013-03-12 00:56:56 -070077SET(CERES_VERSION_MAJOR 1)
Sameer Agarwal937777a2013-04-29 13:57:28 -070078SET(CERES_VERSION_MINOR 6)
Pablo Specialec51b11c2013-03-12 00:56:56 -070079SET(CERES_VERSION_PATCH 0)
80SET(CERES_VERSION
81 ${CERES_VERSION_MAJOR}.${CERES_VERSION_MINOR}.${CERES_VERSION_PATCH})
Sameer Agarwal937777a2013-04-29 13:57:28 -070082SET(CERES_ABI_VERSION 1.6.0)
Keir Mierle05107ba2012-07-18 13:50:12 -070083
Sameer Agarwal30c5f932012-05-03 10:44:43 -070084ENABLE_TESTING()
Keir Mierle8ebb0732012-04-30 23:09:08 -070085
Sameer Agarwalaa9526d2012-05-08 21:22:09 -070086OPTION(BUILD_TESTING
87 "Enable tests"
88 ON)
89
Keir Mierleaefb8a82012-07-28 13:23:55 -070090OPTION(BUILD_ANDROID
91 "Build for Android. Use build_android.sh instead of setting this."
92 OFF)
93
Sameer Agarwalaa9526d2012-05-08 21:22:09 -070094# To get a more static build, try the following line on Mac and Linux:
95# SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
96
Sameer Agarwaldaa98242012-05-11 11:26:38 -070097# Default locations to search for on various platforms.
98LIST(APPEND SEARCH_LIBS /usr/lib)
99LIST(APPEND SEARCH_LIBS /usr/local/lib)
100LIST(APPEND SEARCH_LIBS /usr/local/homebrew/lib) # Mac OS X
101LIST(APPEND SEARCH_LIBS /opt/local/lib)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700102
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700103LIST(APPEND SEARCH_HEADERS /usr/include)
104LIST(APPEND SEARCH_HEADERS /usr/local/include)
105LIST(APPEND SEARCH_HEADERS /usr/local/homebrew/include) # Mac OS X
106LIST(APPEND SEARCH_HEADERS /opt/local/include)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700107
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700108# Locations to search for Eigen
109SET(EIGEN_SEARCH_HEADERS ${SEARCH_HEADERS})
110LIST(APPEND EIGEN_SEARCH_HEADERS /usr/include/eigen3) # Ubuntu 10.04's default location.
Sameer Agarwalb0518732012-05-29 00:27:57 -0700111LIST(APPEND EIGEN_SEARCH_HEADERS /usr/local/include/eigen3)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700112LIST(APPEND EIGEN_SEARCH_HEADERS /usr/local/homebrew/include/eigen3) # Mac OS X
113LIST(APPEND EIGEN_SEARCH_HEADERS /opt/local/var/macports/software/eigen3/opt/local/include/eigen3) # Mac OS X
114
115# Locations to search for SuiteSparse
116SET(SUITESPARSE_SEARCH_LIBS ${SEARCH_LIBS})
117LIST(APPEND SUITESPARSE_SEARCH_LIBS /usr/lib/suitesparse) # Ubuntu
Sameer Agarwalb0518732012-05-29 00:27:57 -0700118LIST(APPEND SUITESPARSE_SEARCH_LIBS /usr/local/lib/suitesparse)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700119LIST(APPEND SUITESPARSE_SEARCH_LIBS /opt/local/lib/ufsparse) # Mac OS X
120
121SET(SUITESPARSE_SEARCH_HEADERS ${SEARCH_HEADERS})
122LIST(APPEND SUITESPARSE_SEARCH_HEADERS /usr/include/suitesparse) # Ubuntu
Sameer Agarwalb0518732012-05-29 00:27:57 -0700123LIST(APPEND SUITESPARSE_SEARCH_HEADERS /usr/local/include/suitesparse)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700124LIST(APPEND SUITESPARSE_SEARCH_HEADERS /opt/local/include/ufsparse) # Mac OS X
125
Sameer Agarwalb0518732012-05-29 00:27:57 -0700126SET(CXSPARSE_SEARCH_LIBS ${SEARCH_LIBS})
127SET(CXSPARSE_SEARCH_HEADERS ${SEARCH_HEADERS})
128LIST(APPEND CXSPARSE_SEARCH_HEADERS /usr/include/suitesparse) # Ubuntu
129
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700130IF ((NOT DEFINED SUITESPARSE) OR (DEFINED SUITESPARSE AND SUITESPARSE))
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700131# Check for SuiteSparse dependencies
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700132
Sameer Agarwalbd82f822013-07-09 23:19:09 -0700133SET(AMD_FOUND TRUE)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700134FIND_LIBRARY(AMD_LIB NAMES amd PATHS ${SUITESPARSE_SEARCH_LIBS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700135IF (EXISTS ${AMD_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700136 MESSAGE("-- Found AMD library: ${AMD_LIB}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700137ELSE (EXISTS ${AMD_LIB})
138 MESSAGE("-- Did not find AMD library")
139 SET(AMD_FOUND FALSE)
140ENDIF (EXISTS ${AMD_LIB})
141
142FIND_PATH(AMD_INCLUDE NAMES amd.h PATHS ${SUITESPARSE_SEARCH_HEADERS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700143IF (EXISTS ${AMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700144 MESSAGE("-- Found AMD header in: ${AMD_INCLUDE}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700145ELSE (EXISTS ${AMD_INCLUDE})
146 MESSAGE("-- Did not find AMD header")
147 SET(AMD_FOUND FALSE)
148ENDIF (EXISTS ${AMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700149
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700150SET(CAMD_FOUND TRUE)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700151FIND_LIBRARY(CAMD_LIB NAMES camd PATHS ${SUITESPARSE_SEARCH_LIBS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700152IF (EXISTS ${CAMD_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700153 MESSAGE("-- Found CAMD library: ${CAMD_LIB}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700154ELSE (EXISTS ${CAMD_LIB})
155 MESSAGE("-- Did not find CAMD library")
156 SET(CAMD_FOUND FALSE)
157ENDIF (EXISTS ${CAMD_LIB})
158
159FIND_PATH(CAMD_INCLUDE NAMES camd.h PATHS ${SUITESPARSE_SEARCH_HEADERS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700160IF (EXISTS ${CAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700161 MESSAGE("-- Found CAMD header in: ${CAMD_INCLUDE}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700162ELSE (EXISTS ${CAMD_INCLUDE})
163 MESSAGE("-- Did not find CAMD header")
164 SET(CAMD_FOUND FALSE)
165ENDIF (EXISTS ${CAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700166
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700167SET(COLAMD_FOUND TRUE)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700168FIND_LIBRARY(COLAMD_LIB NAMES colamd PATHS ${SUITESPARSE_SEARCH_LIBS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700169IF (EXISTS ${COLAMD_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700170 MESSAGE("-- Found COLAMD library: ${COLAMD_LIB}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700171ELSE (EXISTS ${COLAMD_LIB})
172 MESSAGE("-- Did not find COLAMD library")
173 SET(COLAMD_FOUND FALSE)
174ENDIF (EXISTS ${COLAMD_LIB})
175
176FIND_PATH(COLAMD_INCLUDE NAMES colamd.h PATHS ${SUITESPARSE_SEARCH_HEADERS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700177IF (EXISTS ${COLAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700178 MESSAGE("-- Found COLAMD header in: ${COLAMD_INCLUDE}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700179ELSE (EXISTS ${COLAMD_INCLUDE})
180 MESSAGE("-- Did not find COLAMD header")
181 SET(COLAMD_FOUND FALSE)
182ENDIF (EXISTS ${COLAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700183
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700184SET(CCOLAMD_FOUND TRUE)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700185FIND_LIBRARY(CCOLAMD_LIB NAMES ccolamd PATHS ${SUITESPARSE_SEARCH_LIBS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700186IF (EXISTS ${CCOLAMD_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700187 MESSAGE("-- Found CCOLAMD library: ${CCOLAMD_LIB}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700188ELSE (EXISTS ${CCOLAMD_LIB})
189 MESSAGE("-- Did not find CCOLAMD library")
190 SET(CCOLAMD_FOUND FALSE)
191ENDIF (EXISTS ${CCOLAMD_LIB})
192
193FIND_PATH(CCOLAMD_INCLUDE NAMES ccolamd.h PATHS ${SUITESPARSE_SEARCH_HEADERS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700194IF (EXISTS ${CCOLAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700195 MESSAGE("-- Found CCOLAMD header in: ${CCOLAMD_INCLUDE}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700196ELSE (EXISTS ${CCOLAMD_INCLUDE})
197 MESSAGE("-- Did not find CCOLAMD header")
198 SET(CCOLAMD_FOUND FALSE)
199ENDIF (EXISTS ${CCOLAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700200
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700201SET(CHOLMOD_FOUND TRUE)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700202FIND_LIBRARY(CHOLMOD_LIB NAMES cholmod PATHS ${SUITESPARSE_SEARCH_LIBS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700203IF (EXISTS ${CHOLMOD_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700204 MESSAGE("-- Found CHOLMOD library: ${CHOLMOD_LIB}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700205ELSE (EXISTS ${CHOLMOD_LIB})
206 MESSAGE("-- Did not find CHOLMOD library")
207 SET(CHOLMOD_FOUND FALSE)
208ENDIF (EXISTS ${CHOLMOD_LIB})
209
210FIND_PATH(CHOLMOD_INCLUDE NAMES cholmod.h PATHS ${SUITESPARSE_SEARCH_HEADERS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700211IF (EXISTS ${CHOLMOD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700212 MESSAGE("-- Found CHOLMOD header in: ${CHOLMOD_INCLUDE}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700213ELSE (EXISTS ${CHOLMOD_INCLUDE})
214 MESSAGE("-- Did not find CHOLMOD header")
215 SET(CHOLMOD_FOUND FALSE)
216ENDIF (EXISTS ${CHOLMOD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700217
Sameer Agarwal5a974712013-06-07 22:38:30 -0700218SET(SUITESPARSEQR_FOUND TRUE)
219FIND_LIBRARY(SUITESPARSEQR_LIB NAMES spqr PATHS ${SUITESPARSE_SEARCH_LIBS})
220IF (EXISTS ${SUITESPARSEQR_LIB})
221 MESSAGE("-- Found SUITESPARSEQR library: ${SUITESPARSEQR_LIB}")
222ELSE (EXISTS ${SUITESPARSEQR_LIB})
223 MESSAGE("-- Did not find SUITESPARSEQR library")
224 SET(SUITESPARSEQR_FOUND FALSE)
225ENDIF (EXISTS ${SUITESPARSEQR_LIB})
226
227FIND_PATH(SUITESPARSEQR_INCLUDE NAMES SuiteSparseQR.hpp PATHS ${SUITESPARSE_SEARCH_HEADERS})
228IF (EXISTS ${SUITESPARSEQR_INCLUDE})
229 MESSAGE("-- Found SUITESPARSEQR header in: ${SUITESPARSEQR_INCLUDE}")
230ELSE (EXISTS ${SUITESPARSEQR_INCLUDE})
231 MESSAGE("-- Did not find SUITESPARSEQR header")
232 SET(SUITESPARSEQR_FOUND FALSE)
233ENDIF (EXISTS ${SUITESPARSEQR_INCLUDE})
234
Markus Mollc497bd62012-08-17 14:40:13 +0200235# If SuiteSparse version is >= 4 then SuiteSparse_config is required.
236# For SuiteSparse 3, UFconfig.h is required.
Markus Mollc497bd62012-08-17 14:40:13 +0200237SET(SUITESPARSE_CONFIG_FOUND TRUE)
Sameer Agarwalbd82f822013-07-09 23:19:09 -0700238SET(UFCONFIG_FOUND TRUE)
Markus Mollc497bd62012-08-17 14:40:13 +0200239
240FIND_LIBRARY(SUITESPARSE_CONFIG_LIB
241 NAMES suitesparseconfig
242 PATHS ${SUITESPARSE_SEARCH_LIBS})
243IF (EXISTS ${SUITESPARSE_CONFIG_LIB})
244 MESSAGE("-- Found SuiteSparse_config library: ${SUITESPARSE_CONFIG_LIB}")
245ELSE (EXISTS ${SUITESPARSE_CONFIG_LIB})
246 MESSAGE("-- Did not find SuiteSparse_config library")
247ENDIF (EXISTS ${SUITESPARSE_CONFIG_LIB})
248
249FIND_PATH(SUITESPARSE_CONFIG_INCLUDE
250 NAMES SuiteSparse_config.h
Sameer Agarwal96f25dc2012-08-17 15:34:42 -0700251 PATHS ${SUITESPARSE_SEARCH_HEADERS})
Markus Mollc497bd62012-08-17 14:40:13 +0200252IF (EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
253 MESSAGE("-- Found SuiteSparse_config header in: ${SUITESPARSE_CONFIG_INCLUDE}")
Sameer Agarwalbd82f822013-07-09 23:19:09 -0700254 SET(UFCONFIG_FOUND FALSE)
Markus Mollc497bd62012-08-17 14:40:13 +0200255ELSE (EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
256 MESSAGE("-- Did not find SuiteSparse_config header")
257ENDIF (EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
258
259IF (NOT EXISTS ${SUITESPARSE_CONFIG_LIB} OR NOT EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
260 SET(SUITESPARSE_CONFIG_FOUND FALSE)
Sameer Agarwalbd82f822013-07-09 23:19:09 -0700261 FIND_PATH(UFCONFIG_INCLUDE
262 NAMES UFconfig.h
263 PATHS ${SUITESPARSE_SEARCH_HEADERS})
264 IF (EXISTS ${UFCONFIG_INCLUDE})
265 MESSAGE("-- Found UFconfig header in: ${UFCONFIG_INCLUDE}")
266 ELSE (EXISTS ${UFCONFIG_INCLUDE})
267 MESSAGE("-- Did not find UFconfig header")
268 SET(UFCONFIG_FOUND FALSE)
269 ENDIF (EXISTS ${UFCONFIG_INCLUDE})
Markus Mollc497bd62012-08-17 14:40:13 +0200270ENDIF (NOT EXISTS ${SUITESPARSE_CONFIG_LIB} OR NOT EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
271
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700272FIND_LIBRARY(METIS_LIB NAMES metis PATHS ${SUITESPARSE_SEARCH_LIBS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700273IF (EXISTS ${METIS_LIB})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700274 MESSAGE("-- Found METIS library: ${METIS_LIB}")
275ELSE (EXISTS ${METIS_LIB})
276 MESSAGE("-- Did not find METIS library")
277ENDIF (EXISTS ${METIS_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700278
Sameer Agarwal5a974712013-06-07 22:38:30 -0700279# SuiteSparseQR may be compiled with Intel Threading Building Blocks.
280SET(TBB_FOUND TRUE)
281FIND_LIBRARY(TBB_LIB NAMES tbb PATHS ${SEARCH_LIBS})
282IF (EXISTS ${TBB_LIB})
283 MESSAGE("-- Found TBB library: ${TBB_LIB}")
284ELSE (EXISTS ${TBB_LIB})
285 MESSAGE("-- Did not find TBB library")
286 SET(TBB_FOUND FALSE)
287ENDIF (EXISTS ${TBB_LIB})
288
289FIND_LIBRARY(TBB_MALLOC_LIB NAMES tbbmalloc PATHS ${SEARCH_LIBS})
290IF (EXISTS ${TBB_MALLOC_LIB})
291 MESSAGE("-- Found TBB Malloc library: ${TBB_MALLOC_LIB}")
292ELSE (EXISTS ${TBB_MALLOC_LIB})
293 MESSAGE("-- Did not find TBB library")
294 SET(TBB_FOUND FALSE)
295ENDIF (EXISTS ${TBB_MALLOC_LIB})
296
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700297SET(BLAS_AND_LAPACK_FOUND TRUE)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400298IF (APPLE)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700299 # Mac OS X has LAPACK/BLAS bundled in a framework called
300 # "vecLib". Search for that instead of for the normal "lapack"
301 # library.
302 FIND_LIBRARY(LAPACK_LIB NAMES vecLib)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400303ELSE (APPLE)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700304 FIND_LIBRARY(BLAS_LIB NAMES blas)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700305 IF (EXISTS ${BLAS_LIB})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700306 MESSAGE("-- Found BLAS library: ${BLAS_LIB}")
307 ELSE (EXISTS ${BLAS_LIB})
308 MESSAGE("-- Did not find BLAS library")
309 SET(BLAS_AND_LAPACK_FOUND FALSE)
310 ENDIF (EXISTS ${BLAS_LIB})
311 FIND_LIBRARY(LAPACK_LIB NAMES lapack)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400312ENDIF (APPLE)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700313
Sameer Agarwalb0518732012-05-29 00:27:57 -0700314IF (EXISTS ${LAPACK_LIB})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700315 MESSAGE("-- Found LAPACK library: ${LAPACK_LIB}")
316ELSE (EXISTS ${LAPACK_LIB})
317 SET(BLAS_AND_LAPACK_FOUND FALSE)
318 MESSAGE("-- Did not find LAPACK library")
319ENDIF (EXISTS ${LAPACK_LIB})
Keir Mierle92d5ab52012-05-01 18:33:08 -0700320
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600321# We don't use SET(SUITESPARSE_FOUND ${AMD_FOUND} ...) in order to
322# be able to check whether SuiteSparse is available withou expanding
323# SUITESPARSE_FOUND with ${}. This means further checks could be:
324#
325# IF (SUITESPARSE_FOUND)
326#
327# and not:
328#
329# IF (${SUITESPARSE_FOUND})
330#
331IF (${AMD_FOUND} AND
Keir Mierleefe7ac62012-06-24 22:25:28 -0700332 ${CAMD_FOUND} AND
333 ${COLAMD_FOUND} AND
334 ${CCOLAMD_FOUND} AND
335 ${CHOLMOD_FOUND} AND
Markus Mollc497bd62012-08-17 14:40:13 +0200336 (${SUITESPARSE_CONFIG_FOUND} OR ${UFCONFIG_FOUND}) AND
Keir Mierleefe7ac62012-06-24 22:25:28 -0700337 ${BLAS_AND_LAPACK_FOUND})
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600338 SET(SUITESPARSE_FOUND TRUE)
339ELSE ()
340 SET(SUITESPARSE_FOUND FALSE)
341ENDIF ()
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700342
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700343ENDIF ((NOT DEFINED SUITESPARSE) OR (DEFINED SUITESPARSE AND SUITESPARSE))
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700344# By default, if all of SuiteSparse's dependencies are found, Ceres is
345# built with SuiteSparse support. -DSUITESPARSE=ON/OFF can be used to
346# enable/disable SuiteSparse explicitly.
347IF (DEFINED SUITESPARSE)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400348 IF (SUITESPARSE)
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600349 IF (NOT SUITESPARSE_FOUND)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700350 MESSAGE(FATAL_ERROR "One or more of SuiteSparse's dependencies was not found")
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600351 ENDIF (NOT SUITESPARSE_FOUND)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400352 ELSE (SUITESPARSE)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700353 ADD_DEFINITIONS(-DCERES_NO_SUITESPARSE)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400354 ENDIF (SUITESPARSE)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700355ELSE (DEFINED SUITESPARSE)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400356 IF (SUITESPARSE_FOUND)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700357 MESSAGE("-- Found all SuiteSparse dependencies. Building with SuiteSparse")
358 SET(SUITESPARSE ON)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400359 ELSE (SUITESPARSE_FOUND)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700360 MESSAGE("-- Did not find all SuiteSparse dependencies. Building without SuiteSparse")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700361 SET(SUITESPARSE OFF)
362 ADD_DEFINITIONS(-DCERES_NO_SUITESPARSE)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400363 ENDIF (SUITESPARSE_FOUND)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700364ENDIF (DEFINED SUITESPARSE)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700365
Sameer Agarwalb0518732012-05-29 00:27:57 -0700366# By default, if all of CXSparse's dependencies are found, Ceres is
367# built with CXSparse support. -DCXSPARSE=ON/OFF can be used to
368# enable/disable CXSparse explicitly.
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700369IF ((NOT DEFINED CXSPARSE) OR (DEFINED CXSPARSE AND CXSPARSE))
Sameer Agarwalb0518732012-05-29 00:27:57 -0700370
Sameer Agarwalbd82f822013-07-09 23:19:09 -0700371SET(CXSPARSE_FOUND ON)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700372FIND_LIBRARY(CXSPARSE_LIB NAMES cxsparse PATHS ${CXSPARSE_SEARCH_LIBS})
373IF (EXISTS ${CXSPARSE_LIB})
374 MESSAGE("-- Found CXSparse library in: ${CXSPARSE_LIB}")
375ELSE (EXISTS ${CXSPARSE_LIB})
376 MESSAGE("-- Did not find CXSparse header")
377 SET(CXSPARSE_FOUND FALSE)
378ENDIF (EXISTS ${CXSPARSE_LIB})
379
380FIND_PATH(CXSPARSE_INCLUDE NAMES cs.h PATHS ${CXSPARSE_SEARCH_HEADERS})
381IF (EXISTS ${CXSPARSE_INCLUDE})
382 MESSAGE("-- Found CXSparse header in: ${CXSPARSE_INCLUDE}")
383ELSE (EXISTS ${CXSPARSE_INCLUDE})
384 MESSAGE("-- Did not find CXSparse header")
385 SET(CXSPARSE_FOUND FALSE)
386ENDIF (EXISTS ${CXSPARSE_INCLUDE})
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700387ENDIF ((NOT DEFINED CXSPARSE) OR (DEFINED CXSPARSE AND CXSPARSE))
Sameer Agarwalb0518732012-05-29 00:27:57 -0700388
389IF (DEFINED CXSPARSE)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400390 IF (CXSPARSE)
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600391 IF (NOT CXSPARSE_FOUND)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700392 MESSAGE(FATAL_ERROR "-- CXSparse not found.")
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600393 ENDIF (NOT CXSPARSE_FOUND)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400394 ELSE (CXSPARSE)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700395 ADD_DEFINITIONS(-DCERES_NO_CXSPARSE)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400396 ENDIF (CXSPARSE)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700397ELSE (DEFINED CXSPARSE)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400398 IF (CXSPARSE_FOUND)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700399 MESSAGE("-- Building with CXSparse support.")
400 SET(CXSPARSE ON)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400401 ELSE (CXSPARSE_FOUND)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700402 MESSAGE("-- Building without CXSparse.")
403 SET(CXSPARSE OFF)
404 ADD_DEFINITIONS(-DCERES_NO_CXSPARSE)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400405 ENDIF (CXSPARSE_FOUND)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700406ENDIF (DEFINED CXSPARSE)
407
Keir Mierle8ebb0732012-04-30 23:09:08 -0700408# Google Flags
409OPTION(GFLAGS
410 "Enable Google Flags."
411 ON)
412
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400413IF (GFLAGS)
Sameer Agarwalaa9526d2012-05-08 21:22:09 -0700414 FIND_LIBRARY(GFLAGS_LIB NAMES gflags PATHS ${SEARCH_LIBS})
415 IF (NOT EXISTS ${GFLAGS_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700416 MESSAGE(FATAL_ERROR
417 "Can't find Google Flags. Please specify: "
Sameer Agarwalaa9526d2012-05-08 21:22:09 -0700418 "-DGFLAGS_LIB=...")
419 ENDIF (NOT EXISTS ${GFLAGS_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700420 MESSAGE("-- Found Google Flags library: ${GFLAGS_LIB}")
Sameer Agarwalaa9526d2012-05-08 21:22:09 -0700421 FIND_PATH(GFLAGS_INCLUDE NAMES gflags/gflags.h PATHS ${SEARCH_HEADERS})
422 IF (NOT EXISTS ${GFLAGS_INCLUDE})
423 MESSAGE(FATAL_ERROR
424 "Can't find Google Flags. Please specify: "
425 "-DGFLAGS_INCLUDE=...")
426 ENDIF (NOT EXISTS ${GFLAGS_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700427 MESSAGE("-- Found Google Flags header in: ${GFLAGS_INCLUDE}")
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400428ELSE (GFLAGS)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700429 MESSAGE("-- Google Flags disabled; no tests or tools will be built!")
430 ADD_DEFINITIONS(-DCERES_NO_GFLAGS)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400431ENDIF (GFLAGS)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700432
433# Google Logging
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600434IF (NOT BUILD_ANDROID)
Keir Mierleaefb8a82012-07-28 13:23:55 -0700435 FIND_LIBRARY(GLOG_LIB NAMES glog PATHS ${SEARCH_LIBS})
436 IF (NOT EXISTS ${GLOG_LIB})
437 MESSAGE(FATAL_ERROR
438 "Can't find Google Log. Please specify: "
439 "-DGLOG_LIB=...")
440 ENDIF (NOT EXISTS ${GLOG_LIB})
441 MESSAGE("-- Found Google Log library: ${GLOG_LIB}")
Sameer Agarwalaa9526d2012-05-08 21:22:09 -0700442
Keir Mierleaefb8a82012-07-28 13:23:55 -0700443 FIND_PATH(GLOG_INCLUDE NAMES glog/logging.h PATHS ${SEARCH_HEADERS})
444 IF (NOT EXISTS ${GLOG_INCLUDE})
445 MESSAGE(FATAL_ERROR
446 "Can't find Google Log. Please specify: "
447 "-DGLOG_INCLUDE=...")
448 ENDIF (NOT EXISTS ${GLOG_INCLUDE})
449 MESSAGE("-- Found Google Log header in: ${GLOG_INCLUDE}")
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600450ELSE (NOT BUILD_ANDROID)
Keir Mierleaefb8a82012-07-28 13:23:55 -0700451 SET(GLOG_LIB miniglog)
452 MESSAGE("-- Using minimal Glog substitute for Android (library): ${GLOG_LIB}")
453 SET(GLOG_INCLUDE internal/ceres/miniglog)
454 MESSAGE("-- Using minimal Glog substitute for Android (include): ${GLOG_INCLUDE}")
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600455ENDIF (NOT BUILD_ANDROID)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700456
457# Eigen
Keir Mierlef477a382012-05-01 18:10:48 -0700458FIND_PATH(EIGEN_INCLUDE NAMES Eigen/Core PATHS ${EIGEN_SEARCH_HEADERS})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700459IF (NOT EXISTS ${EIGEN_INCLUDE})
Keir Mierlef477a382012-05-01 18:10:48 -0700460 MESSAGE(FATAL_ERROR "Can't find Eigen. Try passing -DEIGEN_INCLUDE=...")
Sameer Agarwalbd82f822013-07-09 23:19:09 -0700461ELSE (NOT EXISTS ${EIGEN_INCLUDE})
462 MESSAGE("-- Found Eigen 3.x: ${EIGEN_INCLUDE}")
Keir Mierle8ebb0732012-04-30 23:09:08 -0700463ENDIF (NOT EXISTS ${EIGEN_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700464
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700465# Template specializations for the Schur complement based solvers. If
466# compile time, binary size or compiler performance is an issue, you
467# may consider disabling this.
Keir Mierle8ebb0732012-04-30 23:09:08 -0700468OPTION(SCHUR_SPECIALIZATIONS
469 "Enable fixed-size schur specializations."
470 ON)
471
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600472IF (NOT SCHUR_SPECIALIZATIONS)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700473 ADD_DEFINITIONS(-DCERES_RESTRICT_SCHUR_SPECIALIZATION)
Keir Mierlef10163a2012-05-04 21:33:53 -0700474 MESSAGE("-- Disabling Schur specializations (faster compiles)")
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600475ENDIF (NOT SCHUR_SPECIALIZATIONS)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700476
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700477# Line search minimizer is useful for large scale problems or when
478# sparse linear algebra libraries are not available. If compile time,
479# binary size or compiler performance is an issue, consider disabling
480# this.
481OPTION(LINE_SEARCH_MINIMIZER
482 "Enable the line search minimizer."
483 ON)
484
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600485IF (NOT LINE_SEARCH_MINIMIZER)
Sameer Agarwal296fa9b2013-04-02 09:44:15 -0700486 ADD_DEFINITIONS(-DCERES_NO_LINE_SEARCH_MINIMIZER)
487 MESSAGE("-- Disabling line search minimizer")
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600488ENDIF (NOT LINE_SEARCH_MINIMIZER)
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700489
Sameer Agarwal296fa9b2013-04-02 09:44:15 -0700490OPTION(CUSTOM_BLAS
491 "Use handcoded BLAS routines (usually faster) instead of Eigen."
492 ON)
493
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600494IF (NOT CUSTOM_BLAS)
Sameer Agarwal296fa9b2013-04-02 09:44:15 -0700495 ADD_DEFINITIONS(-DCERES_NO_CUSTOM_BLAS)
496 MESSAGE("-- Disabling custom blas")
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600497ENDIF (NOT CUSTOM_BLAS)
Sameer Agarwal296fa9b2013-04-02 09:44:15 -0700498
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700499# Multithreading using OpenMP
Keir Mierle8ebb0732012-04-30 23:09:08 -0700500OPTION(OPENMP
501 "Enable threaded solving in Ceres (requires OpenMP)"
502 ON)
503
Sameer Agarwal9f4552b2013-07-09 00:10:08 -0700504IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
505 SET(OPENMP_FOUND FALSE)
506ELSE (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
507 IF (OPENMP)
508 FIND_PACKAGE(OpenMP)
509 ENDIF (OPENMP)
510ENDIF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Keir Mierle8ebb0732012-04-30 23:09:08 -0700511
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400512IF (OPENMP_FOUND)
Sameer Agarwal36f4cd22013-04-21 09:42:26 -0700513 MESSAGE("-- Found OpenMP.")
514 ADD_DEFINITIONS(-DCERES_USE_OPENMP)
515 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600516 IF (UNIX)
Sameer Agarwal36f4cd22013-04-21 09:42:26 -0700517 # At least on Linux, we need pthreads to be enabled for mutex to
518 # compile. This may not work on Windows or Android.
519 FIND_PACKAGE(Threads REQUIRED)
520 SET(STATIC_LIBRARY_FLAGS
521 "${STATIC_LIBRARY_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
522 SET(CMAKE_SHARED_LINKER_FLAGS
523 "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
524 ADD_DEFINITIONS(-DCERES_HAVE_PTHREAD)
525 ADD_DEFINITIONS(-DCERES_HAVE_RWLOCK)
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600526 ENDIF (UNIX)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400527ELSE (OPENMP_FOUND)
Sameer Agarwal36f4cd22013-04-21 09:42:26 -0700528 MESSAGE("-- Can't find OpenMP. Disabling multithreading.")
529 ADD_DEFINITIONS(-DCERES_NO_THREADS)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400530ENDIF (OPENMP_FOUND)
Sameer Agarwal36f4cd22013-04-21 09:42:26 -0700531
532# Disable threads in mutex.h. Someday, after there is OpenMP support in
533# Android, this can get removed. Also turn on a workaround for an NDK bug.
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400534IF (BUILD_ANDROID)
Sameer Agarwal36f4cd22013-04-21 09:42:26 -0700535 ADD_DEFINITIONS(-DCERES_NO_THREADS)
536 ADD_DEFINITIONS(-DCERES_WORK_AROUND_ANDROID_NDK_COMPILER_BUG)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400537ENDIF (BUILD_ANDROID)
Sameer Agarwal36f4cd22013-04-21 09:42:26 -0700538
Keir Mierled2164902012-08-15 19:04:50 -0700539OPTION(DISABLE_TR1
540 "Don't use TR1. This replaces some hash tables with sets. Slower."
541 OFF)
542
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400543IF (DISABLE_TR1)
Keir Mierled2164902012-08-15 19:04:50 -0700544 MESSAGE("-- Replacing unordered_map/set with map/set (warning: slower!)")
545 ADD_DEFINITIONS(-DCERES_NO_TR1)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400546ELSE (DISABLE_TR1)
Keir Mierled2164902012-08-15 19:04:50 -0700547 MESSAGE("-- Using normal TR1 unordered_map/set")
548 # Use the std namespace for the hash<> and related templates. This may vary by
549 # system.
550 IF (MSVC)
Sergey Sharybinf8065762013-05-31 23:48:06 +0600551 IF (MSVC90)
552 # Special case for Visual Studio 2008.
553 # Newer versions have got tr1 symbols in another namespace,
554 # and this is being handled in Else branch of this condition.
555 # Probably Visual studio 2003 and 2005 also shall be handled here,
556 # but don't have by hand to verify and most likely they're not
557 # used by Ceres users anyway.
558 ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_START=namespace std { namespace tr1 {\"")
559 ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_END=}}\"")
560 ELSE (MSVC90)
561 # This is known to work with Visual Studio 2010 Express.
562 # Further, for as long Visual Studio 2012 didn't move tr1 to
563 # just another namespace, the same define will work for it as well.
564 # Hopefully all further versions will also keep working with this define.
565 ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_START=namespace std {\"")
566 ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_END=}\"")
567 ENDIF(MSVC90)
Keir Mierled2164902012-08-15 19:04:50 -0700568 ELSE (MSVC)
569 # This is known to work with recent versions of Linux and Mac OS X.
570 ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_START=namespace std { namespace tr1 {\"")
571 ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_END=}}\"")
572 ENDIF (MSVC)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400573ENDIF (DISABLE_TR1)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700574
575INCLUDE_DIRECTORIES(
576 include
577 internal
578 internal/ceres
Keir Mierle8ebb0732012-04-30 23:09:08 -0700579 ${GLOG_INCLUDE}
Keir Mierle8ebb0732012-04-30 23:09:08 -0700580 ${EIGEN_INCLUDE}
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700581 )
582
Arnaud Gelas3d644b72012-08-16 17:33:21 +0200583FILE(GLOB CERES_HDRS ${CMAKE_SOURCE_DIR}/include/ceres/*.h)
584INSTALL(FILES ${CERES_HDRS} DESTINATION include/ceres)
585
586FILE(GLOB CERES_PUBLIC_INTERNAL_HDRS ${CMAKE_SOURCE_DIR}/include/ceres/internal/*.h)
587INSTALL(FILES ${CERES_PUBLIC_INTERNAL_HDRS} DESTINATION include/ceres/internal)
588
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400589IF (SUITESPARSE)
Markus Mollc497bd62012-08-17 14:40:13 +0200590 INCLUDE_DIRECTORIES(${AMD_INCLUDE})
591 INCLUDE_DIRECTORIES(${CAMD_INCLUDE})
592 INCLUDE_DIRECTORIES(${COLAMD_INCLUDE})
593 INCLUDE_DIRECTORIES(${CCOLAMD_INCLUDE})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700594 INCLUDE_DIRECTORIES(${CHOLMOD_INCLUDE})
Sameer Agarwal5a974712013-06-07 22:38:30 -0700595 INCLUDE_DIRECTORIES(${SUITESPARSEQR_INCLUDE})
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400596 IF (SUITESPARSE_CONFIG_FOUND)
Markus Mollc497bd62012-08-17 14:40:13 +0200597 INCLUDE_DIRECTORIES(${SUITESPARSE_CONFIG_INCLUDE})
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400598 ENDIF (SUITESPARSE_CONFIG_FOUND)
599 IF (UFCONFIG_FOUND)
Markus Mollc497bd62012-08-17 14:40:13 +0200600 INCLUDE_DIRECTORIES(${UFCONFIG_INCLUDE})
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400601 ENDIF (UFCONFIG_FOUND)
602ENDIF (SUITESPARSE)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700603
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400604IF (CXSPARSE)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700605 INCLUDE_DIRECTORIES(${CXSPARSE_INCLUDE})
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400606ENDIF (CXSPARSE)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700607
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400608IF (GFLAGS)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700609 INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE})
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400610ENDIF (GFLAGS)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700611
Sameer Agarwal8e2420e2012-05-31 17:00:58 -0700612# Change the default build type from Debug to Release, while still
613# supporting overriding the build type.
Sameer Agarwal4845bc42012-06-05 21:32:57 -0700614#
615# The CACHE STRING logic here and elsewhere is needed to force CMake
616# to pay attention to the value of these variables.
617IF (NOT CMAKE_BUILD_TYPE)
618 MESSAGE("-- No build type specified; defaulting to CMAKE_BUILD_TYPE=Release.")
619 SET(CMAKE_BUILD_TYPE Release CACHE STRING
620 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
621 FORCE)
622ELSE (NOT CMAKE_BUILD_TYPE)
Sameer Agarwal8e2420e2012-05-31 17:00:58 -0700623 IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
624 MESSAGE("\n=================================================================================")
625 MESSAGE("\n-- Build type: Debug. Performance will be terrible!")
626 MESSAGE("-- Add -DCMAKE_BUILD_TYPE=Release to the CMake command line to get an optimized build.")
627 MESSAGE("\n=================================================================================")
Sameer Agarwal8e2420e2012-05-31 17:00:58 -0700628 ENDIF (CMAKE_BUILD_TYPE STREQUAL "Debug")
Sameer Agarwal4845bc42012-06-05 21:32:57 -0700629ENDIF (NOT CMAKE_BUILD_TYPE)
630
631# Set the default Ceres flags to an empty string.
632SET (CERES_CXX_FLAGS)
633
634IF (CMAKE_BUILD_TYPE STREQUAL "Release")
635 IF (CMAKE_COMPILER_IS_GNUCXX)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400636 IF (BUILD_ANDROID)
Keir Mierleaefb8a82012-07-28 13:23:55 -0700637 # TODO(keir): Figure out what flags should go here to make an optimized
638 # native ARM binary for Android.
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400639 ELSE (BUILD_ANDROID)
Keir Mierleaefb8a82012-07-28 13:23:55 -0700640 # Linux
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600641 IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
Keir Mierleaefb8a82012-07-28 13:23:55 -0700642 SET (CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -march=native -mtune=native")
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600643 ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")
Keir Mierleaefb8a82012-07-28 13:23:55 -0700644 # Mac OS X
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600645 IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
Keir Mierleaefb8a82012-07-28 13:23:55 -0700646 SET (CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -fast -msse3")
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600647 ENDIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400648 ENDIF (BUILD_ANDROID)
Sameer Agarwal4845bc42012-06-05 21:32:57 -0700649 ENDIF (CMAKE_COMPILER_IS_GNUCXX)
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600650 IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Sameer Agarwal395b4e92013-05-23 11:01:16 -0700651 # Use of -O4 requires use of gold linker & LLVM-gold plugin, which might
652 # well not be present / in use and without which files will compile, but
Alex Stewart37020682013-05-12 20:06:04 +0100653 # not link ('file not recognized') so explicitly check for support
654 INCLUDE(CheckCXXCompilerFlag)
655 CHECK_CXX_COMPILER_FLAG("-O4" HAVE_LTO_SUPPORT)
656 IF (HAVE_LTO_SUPPORT)
657 MESSAGE(STATUS "Enabling link-time optimization (-O4)")
658 SET(CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -O4")
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400659 ELSE ()
Alex Stewart37020682013-05-12 20:06:04 +0100660 MESSAGE(STATUS "Compiler/linker does not support link-time optimization (-O4), disabling.")
661 ENDIF (HAVE_LTO_SUPPORT)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400662 ENDIF ()
Sameer Agarwal4845bc42012-06-05 21:32:57 -0700663ENDIF (CMAKE_BUILD_TYPE STREQUAL "Release")
Keir Mierleefe7ac62012-06-24 22:25:28 -0700664
Sameer Agarwal24fb32b2013-04-20 09:02:06 -0700665SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CERES_CXX_FLAGS}")
666
Keir Mierleefe7ac62012-06-24 22:25:28 -0700667# After the tweaks for the compile settings, disable some warnings on MSVC.
668IF (MSVC)
669 # Disable signed/unsigned int conversion warnings.
Keir Mierleaefb8a82012-07-28 13:23:55 -0700670 ADD_DEFINITIONS("/wd4018")
Keir Mierleefe7ac62012-06-24 22:25:28 -0700671 # Disable warning about using struct/class for the same symobl.
Keir Mierleaefb8a82012-07-28 13:23:55 -0700672 ADD_DEFINITIONS("/wd4099")
Keir Mierleefe7ac62012-06-24 22:25:28 -0700673 # Disable warning about the insecurity of using "std::copy".
674 ADD_DEFINITIONS("/wd4996")
675 # Disable performance warning about int-to-bool conversion.
676 ADD_DEFINITIONS("/wd4800")
677 # Disable performance warning about fopen insecurity.
678 ADD_DEFINITIONS("/wd4996")
679 # Disable warning about int64 to int32 conversion. Disabling
680 # this warning may not be correct; needs investigation.
681 # TODO(keir): Investigate these warnings in more detail.
682 ADD_DEFINITIONS("/wd4244")
683 # It's not possible to use STL types in DLL interfaces in a portable and
684 # reliable way. However, that's what happens with Google Log and Google Flags
685 # on Windows. MSVC gets upset about this and throws warnings that we can't do
686 # much about. The real solution is to link static versions of Google Log and
687 # Google Test, but that seems tricky on Windows. So, disable the warning.
688 ADD_DEFINITIONS("/wd4251")
689
690 # Google Flags doesn't have their DLL import/export stuff set up correctly,
691 # which results in linker warnings. This is irrelevant for Ceres, so ignore
692 # the warnings.
693 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4049")
Petter Strandmarkb7ba9342013-02-19 12:52:58 +0100694
695 # Tuple sizes of 10 are used by Gtest.
696 ADD_DEFINITIONS("-D_VARIADIC_MAX=10")
Keir Mierleefe7ac62012-06-24 22:25:28 -0700697ENDIF (MSVC)
698
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400699IF (UNIX)
Sameer Agarwal395b4e92013-05-23 11:01:16 -0700700 # GCC is not strict enough by default, so enable most of the warnings.
Keir Mierle97ca0fb2012-09-18 15:52:36 -0700701 SET(CMAKE_CXX_FLAGS
Sameer Agarwal1ab7fde2013-07-08 10:03:49 -0700702 "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers")
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400703ENDIF (UNIX)
Keir Mierle97ca0fb2012-09-18 15:52:36 -0700704
Sameer Agarwal3d6eceb2013-04-02 21:45:48 -0700705# Use a larger inlining threshold for Clang, since it hobbles Eigen,
706# resulting in an unreasonably slow version of the blas routines. The
707# -Qunused-arguments is needed because CMake passes the inline
708# threshold to the linker and clang complains about it and dies.
Sergey Sharybin72cc4572013-06-19 20:59:08 +0600709IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Sameer Agarwal3d6eceb2013-04-02 21:45:48 -0700710 SET(CMAKE_CXX_FLAGS
711 "${CMAKE_CXX_FLAGS} -Qunused-arguments -mllvm -inline-threshold=600 -Wno-return-type-c-linkage")
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400712ENDIF ()
Taylor Braun-Jonesb73148b2013-02-25 02:34:00 -0500713
Keir Mierleefe7ac62012-06-24 22:25:28 -0700714ADD_SUBDIRECTORY(internal/ceres)
Arnaud Gelasb12b9062012-08-15 16:27:38 +0200715
716OPTION(BUILD_DOCUMENTATION
Pablo Specialec51b11c2013-03-12 00:56:56 -0700717 "Build User's Guide (html)"
Arnaud Gelasb12b9062012-08-15 16:27:38 +0200718 OFF)
719
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400720IF (BUILD_DOCUMENTATION)
Arnaud Gelasb12b9062012-08-15 16:27:38 +0200721 MESSAGE("-- Documentation building is enabled")
722
Pablo Specialec51b11c2013-03-12 00:56:56 -0700723 # Make CMake aware of the cmake folder, in order to find 'FindSphinx.cmake'
724 SET (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
725
726 # Generate the User's Guide (html).
Arnaud Gelasb12b9062012-08-15 16:27:38 +0200727 # The corresponding target is UserGuide, but is included in ALL.
728 ADD_SUBDIRECTORY(docs)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400729ENDIF (BUILD_DOCUMENTATION)
Arnaud Gelas73166092012-08-20 15:40:41 +0200730
731OPTION(BUILD_EXAMPLES "Build examples" ON)
732
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400733IF (BUILD_EXAMPLES)
Arnaud Gelas73166092012-08-20 15:40:41 +0200734 MESSAGE("-- Build the examples.")
735 ADD_SUBDIRECTORY(examples)
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400736ELSE (BUILD_EXAMPLES)
Arnaud Gelas73166092012-08-20 15:40:41 +0200737 MESSAGE("-- Do not build any example.")
Joydeep Biswasaa20a6d2013-05-15 09:38:03 -0400738ENDIF (BUILD_EXAMPLES)
Arnaud Gelas9ad27e82012-08-21 09:56:30 +0200739
740# Add an uninstall target to remove all installed files.
741CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in"
742 "${CMAKE_BINARY_DIR}/cmake/uninstall.cmake"
743 IMMEDIATE @ONLY)
744
745ADD_CUSTOM_TARGET(uninstall
746 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake/uninstall.cmake)
Pablo Speciale16dbf112013-03-11 14:44:02 -0700747
Pablo Speciale0ff3bb32013-05-23 17:52:21 -0700748# Set up install directories. INCLUDE_INSTALL_DIR, LIB_INSTALL_DIR and
749# CMAKECONFIG_INSTALL_DIR must not be absolute paths.
Pablo Speciale16dbf112013-03-11 14:44:02 -0700750SET(INCLUDE_INSTALL_DIR include)
Pablo Speciale0ff3bb32013-05-23 17:52:21 -0700751SET(LIB_INSTALL_DIR lib)
752SET(CMAKECONFIG_INSTALL_DIR share/Ceres)
Pablo Speciale16dbf112013-03-11 14:44:02 -0700753
754# This "exports" all targets which have been put into the export set
755# "CeresExport". This means that CMake generates a file with the given
756# filename, which can later on be loaded by projects using this package.
757# This file contains ADD_LIBRARY(bar IMPORTED) statements for each target
758# in the export set, so when loaded later on CMake will create "imported"
759# library targets from these, which can be used in many ways in the same way
760# as a normal library target created via a normal ADD_LIBRARY().
761INSTALL(EXPORT CeresExport
762 DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE CeresTargets.cmake)
763
764# Figure out the relative path from the installed Config.cmake file to the
765# install prefix (which may be at runtime different from the chosen
766# CMAKE_INSTALL_PREFIX if under Windows the package was installed anywhere)
767# This relative path will be configured into the CeresConfig.cmake.
768FILE(RELATIVE_PATH relInstallDir
769 ${CMAKE_INSTALL_PREFIX}/${CMAKECONFIG_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX})
770
771# Create a CeresConfig.cmake file. <name>Config.cmake files are searched by
772# FIND_PACKAGE() automatically. We configure that file so that we can put any
773# information we want in it, e.g. version numbers, include directories, etc.
774CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/CeresConfig.cmake.in"
775 "${CMAKE_CURRENT_BINARY_DIR}/CeresConfig.cmake" @ONLY)
776
777# Additionally, when CMake has found a CeresConfig.cmake, it can check for a
778# CeresConfigVersion.cmake in the same directory when figuring out the version
779# of the package when a version has been specified in the FIND_PACKAGE() call,
780# e.g. FIND_PACKAGE(Ceres [1.4.2] REQUIRED). The version argument is optional.
781CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/CeresConfigVersion.cmake.in"
782 "${CMAKE_CURRENT_BINARY_DIR}/CeresConfigVersion.cmake" @ONLY)
783
784# Install these two files into the same directory as the generated exports-file.
785INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/CeresConfig.cmake"
786 "${CMAKE_CURRENT_BINARY_DIR}/CeresConfigVersion.cmake"
787 "${CMAKE_SOURCE_DIR}/cmake/depend.cmake"
788 DESTINATION ${CMAKECONFIG_INSTALL_DIR})