blob: 537a103392872f51ac26d91f0313566704d7e951 [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)
Keir Mierle8ebb0732012-04-30 23:09:08 -070032
33IF (COMMAND cmake_policy)
34 CMAKE_POLICY(SET CMP0003 NEW)
35ENDIF (COMMAND cmake_policy)
36
37PROJECT(CERES C CXX)
38
Arnaud Gelasd2fb5ad2012-08-17 10:11:02 +020039# Set up the git hook to make Gerrit Change-Id: lines in commit messages.
40SET (LOCAL_GIT_DIRECTORY)
41IF (EXISTS ${CMAKE_SOURCE_DIR}/.git)
42 # .git directory can be found on Unix based system, or on Windows with
43 # Git Bash (shipped with msysgit)
44 SET (LOCAL_GIT_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)
45ELSE (EXISTS ${CMAKE_SOURCE_DIR}/.git)
Sameer Agarwal36f4cd22013-04-21 09:42:26 -070046 # TODO(keir) Add proper Windows support
Arnaud Gelasd2fb5ad2012-08-17 10:11:02 +020047ENDIF (EXISTS ${CMAKE_SOURCE_DIR}/.git)
48
49IF (EXISTS ${LOCAL_GIT_DIRECTORY})
50 IF (NOT EXISTS ${LOCAL_GIT_DIRECTORY}/hooks/commit-msg)
51 # Download the hook only if it is not already present
52 FILE(DOWNLOAD https://ceres-solver-review.googlesource.com/tools/hooks/commit-msg
53 ${CMAKE_BINARY_DIR}/commit-msg)
54
55 # Make the downloaded file executable, since it is not by default.
56 FILE(COPY ${CMAKE_BINARY_DIR}/commit-msg
57 DESTINATION ${LOCAL_GIT_DIRECTORY}/hooks/
58 FILE_PERMISSIONS
59 OWNER_READ OWNER_WRITE OWNER_EXECUTE
60 GROUP_READ GROUP_WRITE GROUP_EXECUTE
61 WORLD_READ WORLD_EXECUTE)
62 ENDIF (NOT EXISTS ${LOCAL_GIT_DIRECTORY}/hooks/commit-msg)
63ENDIF (EXISTS ${LOCAL_GIT_DIRECTORY})
64
Arnaud Gelasb3fa0092012-08-17 10:31:41 +020065SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
66SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
67SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
68
Keir Mierle05107ba2012-07-18 13:50:12 -070069# Important: Always bump the second number (e.g. 1.3.x to 1.4.0) for any
70# release that changes the ABI. The ABI changes for almost any modification to
71# include/ceres (e.g. the public API). If you are unsure about whether
72# something is an ABI change, please ask on the list.
73#
74# For versions without ABI changes, bump the smallest number in CERES_VERSION,
75# but leave the CERES_ABI_VERSION unchanged.
Pablo Specialec51b11c2013-03-12 00:56:56 -070076SET(CERES_VERSION_MAJOR 1)
77SET(CERES_VERSION_MINOR 5)
78SET(CERES_VERSION_PATCH 0)
79SET(CERES_VERSION
80 ${CERES_VERSION_MAJOR}.${CERES_VERSION_MINOR}.${CERES_VERSION_PATCH})
Sameer Agarwalfa21df82013-02-18 08:48:52 -080081SET(CERES_ABI_VERSION 1.5.0)
Keir Mierle05107ba2012-07-18 13:50:12 -070082
Sameer Agarwal30c5f932012-05-03 10:44:43 -070083ENABLE_TESTING()
Keir Mierle8ebb0732012-04-30 23:09:08 -070084
Sameer Agarwalaa9526d2012-05-08 21:22:09 -070085OPTION(BUILD_TESTING
86 "Enable tests"
87 ON)
88
Keir Mierleaefb8a82012-07-28 13:23:55 -070089OPTION(BUILD_ANDROID
90 "Build for Android. Use build_android.sh instead of setting this."
91 OFF)
92
Sameer Agarwalaa9526d2012-05-08 21:22:09 -070093# To get a more static build, try the following line on Mac and Linux:
94# SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
95
Sameer Agarwaldaa98242012-05-11 11:26:38 -070096# Default locations to search for on various platforms.
97LIST(APPEND SEARCH_LIBS /usr/lib)
98LIST(APPEND SEARCH_LIBS /usr/local/lib)
99LIST(APPEND SEARCH_LIBS /usr/local/homebrew/lib) # Mac OS X
100LIST(APPEND SEARCH_LIBS /opt/local/lib)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700101
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700102LIST(APPEND SEARCH_HEADERS /usr/include)
103LIST(APPEND SEARCH_HEADERS /usr/local/include)
104LIST(APPEND SEARCH_HEADERS /usr/local/homebrew/include) # Mac OS X
105LIST(APPEND SEARCH_HEADERS /opt/local/include)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700106
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700107# Locations to search for Eigen
108SET(EIGEN_SEARCH_HEADERS ${SEARCH_HEADERS})
109LIST(APPEND EIGEN_SEARCH_HEADERS /usr/include/eigen3) # Ubuntu 10.04's default location.
Sameer Agarwalb0518732012-05-29 00:27:57 -0700110LIST(APPEND EIGEN_SEARCH_HEADERS /usr/local/include/eigen3)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700111LIST(APPEND EIGEN_SEARCH_HEADERS /usr/local/homebrew/include/eigen3) # Mac OS X
112LIST(APPEND EIGEN_SEARCH_HEADERS /opt/local/var/macports/software/eigen3/opt/local/include/eigen3) # Mac OS X
113
114# Locations to search for SuiteSparse
115SET(SUITESPARSE_SEARCH_LIBS ${SEARCH_LIBS})
116LIST(APPEND SUITESPARSE_SEARCH_LIBS /usr/lib/suitesparse) # Ubuntu
Sameer Agarwalb0518732012-05-29 00:27:57 -0700117LIST(APPEND SUITESPARSE_SEARCH_LIBS /usr/local/lib/suitesparse)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700118LIST(APPEND SUITESPARSE_SEARCH_LIBS /opt/local/lib/ufsparse) # Mac OS X
119
120SET(SUITESPARSE_SEARCH_HEADERS ${SEARCH_HEADERS})
121LIST(APPEND SUITESPARSE_SEARCH_HEADERS /usr/include/suitesparse) # Ubuntu
Sameer Agarwalb0518732012-05-29 00:27:57 -0700122LIST(APPEND SUITESPARSE_SEARCH_HEADERS /usr/local/include/suitesparse)
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700123LIST(APPEND SUITESPARSE_SEARCH_HEADERS /opt/local/include/ufsparse) # Mac OS X
124
Sameer Agarwalb0518732012-05-29 00:27:57 -0700125SET(CXSPARSE_SEARCH_LIBS ${SEARCH_LIBS})
126SET(CXSPARSE_SEARCH_HEADERS ${SEARCH_HEADERS})
127LIST(APPEND CXSPARSE_SEARCH_HEADERS /usr/include/suitesparse) # Ubuntu
128
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700129IF ((NOT DEFINED SUITESPARSE) OR (DEFINED SUITESPARSE AND SUITESPARSE))
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700130# Check for SuiteSparse dependencies
131MESSAGE("-- Check for AMD")
132SET(AMD_FOUND TRUE)
133
134FIND_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 -0700150MESSAGE("-- Check for CAMD")
151SET(CAMD_FOUND TRUE)
152
153FIND_LIBRARY(CAMD_LIB NAMES camd PATHS ${SUITESPARSE_SEARCH_LIBS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700154IF (EXISTS ${CAMD_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700155 MESSAGE("-- Found CAMD library: ${CAMD_LIB}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700156ELSE (EXISTS ${CAMD_LIB})
157 MESSAGE("-- Did not find CAMD library")
158 SET(CAMD_FOUND FALSE)
159ENDIF (EXISTS ${CAMD_LIB})
160
161FIND_PATH(CAMD_INCLUDE NAMES camd.h PATHS ${SUITESPARSE_SEARCH_HEADERS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700162IF (EXISTS ${CAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700163 MESSAGE("-- Found CAMD header in: ${CAMD_INCLUDE}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700164ELSE (EXISTS ${CAMD_INCLUDE})
165 MESSAGE("-- Did not find CAMD header")
166 SET(CAMD_FOUND FALSE)
167ENDIF (EXISTS ${CAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700168
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700169MESSAGE("-- Check for COLAMD")
170SET(COLAMD_FOUND TRUE)
171
172FIND_LIBRARY(COLAMD_LIB NAMES colamd PATHS ${SUITESPARSE_SEARCH_LIBS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700173IF (EXISTS ${COLAMD_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700174 MESSAGE("-- Found COLAMD library: ${COLAMD_LIB}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700175ELSE (EXISTS ${COLAMD_LIB})
176 MESSAGE("-- Did not find COLAMD library")
177 SET(COLAMD_FOUND FALSE)
178ENDIF (EXISTS ${COLAMD_LIB})
179
180FIND_PATH(COLAMD_INCLUDE NAMES colamd.h PATHS ${SUITESPARSE_SEARCH_HEADERS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700181IF (EXISTS ${COLAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700182 MESSAGE("-- Found COLAMD header in: ${COLAMD_INCLUDE}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700183ELSE (EXISTS ${COLAMD_INCLUDE})
184 MESSAGE("-- Did not find COLAMD header")
185 SET(COLAMD_FOUND FALSE)
186ENDIF (EXISTS ${COLAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700187
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700188MESSAGE("-- Check for CCOLAMD")
189SET(CCOLAMD_FOUND TRUE)
190
191FIND_LIBRARY(CCOLAMD_LIB NAMES ccolamd PATHS ${SUITESPARSE_SEARCH_LIBS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700192IF (EXISTS ${CCOLAMD_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700193 MESSAGE("-- Found CCOLAMD library: ${CCOLAMD_LIB}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700194ELSE (EXISTS ${CCOLAMD_LIB})
195 MESSAGE("-- Did not find CCOLAMD library")
196 SET(CCOLAMD_FOUND FALSE)
197ENDIF (EXISTS ${CCOLAMD_LIB})
198
199FIND_PATH(CCOLAMD_INCLUDE NAMES ccolamd.h PATHS ${SUITESPARSE_SEARCH_HEADERS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700200IF (EXISTS ${CCOLAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700201 MESSAGE("-- Found CCOLAMD header in: ${CCOLAMD_INCLUDE}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700202ELSE (EXISTS ${CCOLAMD_INCLUDE})
203 MESSAGE("-- Did not find CCOLAMD header")
204 SET(CCOLAMD_FOUND FALSE)
205ENDIF (EXISTS ${CCOLAMD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700206
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700207MESSAGE("-- Check for CHOLMOD")
208SET(CHOLMOD_FOUND TRUE)
209
210FIND_LIBRARY(CHOLMOD_LIB NAMES cholmod PATHS ${SUITESPARSE_SEARCH_LIBS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700211IF (EXISTS ${CHOLMOD_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700212 MESSAGE("-- Found CHOLMOD library: ${CHOLMOD_LIB}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700213ELSE (EXISTS ${CHOLMOD_LIB})
214 MESSAGE("-- Did not find CHOLMOD library")
215 SET(CHOLMOD_FOUND FALSE)
216ENDIF (EXISTS ${CHOLMOD_LIB})
217
218FIND_PATH(CHOLMOD_INCLUDE NAMES cholmod.h PATHS ${SUITESPARSE_SEARCH_HEADERS})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700219IF (EXISTS ${CHOLMOD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700220 MESSAGE("-- Found CHOLMOD header in: ${CHOLMOD_INCLUDE}")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700221ELSE (EXISTS ${CHOLMOD_INCLUDE})
222 MESSAGE("-- Did not find CHOLMOD header")
223 SET(CHOLMOD_FOUND FALSE)
224ENDIF (EXISTS ${CHOLMOD_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700225
Markus Mollc497bd62012-08-17 14:40:13 +0200226# If SuiteSparse version is >= 4 then SuiteSparse_config is required.
227# For SuiteSparse 3, UFconfig.h is required.
228MESSAGE("-- Check for SuiteSparse_config (SuiteSparse v4)")
229SET(SUITESPARSE_CONFIG_FOUND TRUE)
230
231FIND_LIBRARY(SUITESPARSE_CONFIG_LIB
232 NAMES suitesparseconfig
233 PATHS ${SUITESPARSE_SEARCH_LIBS})
234IF (EXISTS ${SUITESPARSE_CONFIG_LIB})
235 MESSAGE("-- Found SuiteSparse_config library: ${SUITESPARSE_CONFIG_LIB}")
236ELSE (EXISTS ${SUITESPARSE_CONFIG_LIB})
237 MESSAGE("-- Did not find SuiteSparse_config library")
238ENDIF (EXISTS ${SUITESPARSE_CONFIG_LIB})
239
240FIND_PATH(SUITESPARSE_CONFIG_INCLUDE
241 NAMES SuiteSparse_config.h
Sameer Agarwal96f25dc2012-08-17 15:34:42 -0700242 PATHS ${SUITESPARSE_SEARCH_HEADERS})
Markus Mollc497bd62012-08-17 14:40:13 +0200243IF (EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
244 MESSAGE("-- Found SuiteSparse_config header in: ${SUITESPARSE_CONFIG_INCLUDE}")
245ELSE (EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
246 MESSAGE("-- Did not find SuiteSparse_config header")
247ENDIF (EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
248
249IF (NOT EXISTS ${SUITESPARSE_CONFIG_LIB} OR NOT EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
250 SET(SUITESPARSE_CONFIG_FOUND FALSE)
251ENDIF (NOT EXISTS ${SUITESPARSE_CONFIG_LIB} OR NOT EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
252
253MESSAGE("-- Check for UFconfig (SuiteSparse v3)")
254SET(UFCONFIG_FOUND TRUE)
255
256FIND_PATH(UFCONFIG_INCLUDE
257 NAMES UFconfig.h
Sameer Agarwale83f7872012-08-17 15:34:42 -0700258 PATHS ${SUITESPARSE_SEARCH_HEADERS})
Markus Mollc497bd62012-08-17 14:40:13 +0200259IF (EXISTS ${UFCONFIG_INCLUDE})
260 MESSAGE("-- Found UFconfig header in: ${UFCONFIG_INCLUDE}")
261ELSE (EXISTS ${UFCONFIG_INCLUDE})
262 MESSAGE("-- Did not find UFconfig header")
263 SET(UFCONFIG_FOUND FALSE)
264ENDIF (EXISTS ${UFCONFIG_INCLUDE})
265
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700266MESSAGE("-- Check for METIS (optional)")
267FIND_LIBRARY(METIS_LIB NAMES metis PATHS ${SUITESPARSE_SEARCH_LIBS})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700268
Sameer Agarwalb0518732012-05-29 00:27:57 -0700269IF (EXISTS ${METIS_LIB})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700270 MESSAGE("-- Found METIS library: ${METIS_LIB}")
271ELSE (EXISTS ${METIS_LIB})
272 MESSAGE("-- Did not find METIS library")
273ENDIF (EXISTS ${METIS_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700274
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700275SET(BLAS_AND_LAPACK_FOUND TRUE)
Sameer Agarwald1146902012-05-30 01:40:22 -0700276IF (${APPLE})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700277 # Mac OS X has LAPACK/BLAS bundled in a framework called
278 # "vecLib". Search for that instead of for the normal "lapack"
279 # library.
280 FIND_LIBRARY(LAPACK_LIB NAMES vecLib)
Sameer Agarwald1146902012-05-30 01:40:22 -0700281ELSE (${APPLE})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700282 FIND_LIBRARY(BLAS_LIB NAMES blas)
Sameer Agarwalb0518732012-05-29 00:27:57 -0700283 IF (EXISTS ${BLAS_LIB})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700284 MESSAGE("-- Found BLAS library: ${BLAS_LIB}")
285 ELSE (EXISTS ${BLAS_LIB})
286 MESSAGE("-- Did not find BLAS library")
287 SET(BLAS_AND_LAPACK_FOUND FALSE)
288 ENDIF (EXISTS ${BLAS_LIB})
289 FIND_LIBRARY(LAPACK_LIB NAMES lapack)
Sameer Agarwald1146902012-05-30 01:40:22 -0700290ENDIF (${APPLE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700291
Sameer Agarwalb0518732012-05-29 00:27:57 -0700292IF (EXISTS ${LAPACK_LIB})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700293 MESSAGE("-- Found LAPACK library: ${LAPACK_LIB}")
294ELSE (EXISTS ${LAPACK_LIB})
295 SET(BLAS_AND_LAPACK_FOUND FALSE)
296 MESSAGE("-- Did not find LAPACK library")
297ENDIF (EXISTS ${LAPACK_LIB})
Keir Mierle92d5ab52012-05-01 18:33:08 -0700298
Sameer Agarwalb0518732012-05-29 00:27:57 -0700299SET(SUITESPARSE_FOUND
Keir Mierleefe7ac62012-06-24 22:25:28 -0700300 ${AMD_FOUND} AND
301 ${CAMD_FOUND} AND
302 ${COLAMD_FOUND} AND
303 ${CCOLAMD_FOUND} AND
304 ${CHOLMOD_FOUND} AND
Markus Mollc497bd62012-08-17 14:40:13 +0200305 (${SUITESPARSE_CONFIG_FOUND} OR ${UFCONFIG_FOUND}) AND
Keir Mierleefe7ac62012-06-24 22:25:28 -0700306 ${BLAS_AND_LAPACK_FOUND})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700307
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700308ENDIF ((NOT DEFINED SUITESPARSE) OR (DEFINED SUITESPARSE AND SUITESPARSE))
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700309# By default, if all of SuiteSparse's dependencies are found, Ceres is
310# built with SuiteSparse support. -DSUITESPARSE=ON/OFF can be used to
311# enable/disable SuiteSparse explicitly.
312IF (DEFINED SUITESPARSE)
Sameer Agarwald1146902012-05-30 01:40:22 -0700313 IF (${SUITESPARSE})
314 IF (NOT ${SUITESPARSE_FOUND})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700315 MESSAGE(FATAL_ERROR "One or more of SuiteSparse's dependencies was not found")
Sameer Agarwald1146902012-05-30 01:40:22 -0700316 ENDIF (NOT ${SUITESPARSE_FOUND})
317 ELSE (${SUITESPARSE})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700318 ADD_DEFINITIONS(-DCERES_NO_SUITESPARSE)
Sameer Agarwald1146902012-05-30 01:40:22 -0700319 ENDIF (${SUITESPARSE})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700320ELSE (DEFINED SUITESPARSE)
Sameer Agarwald1146902012-05-30 01:40:22 -0700321 IF (${SUITESPARSE_FOUND})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700322 MESSAGE("-- Found all SuiteSparse dependencies. Building with SuiteSparse")
323 SET(SUITESPARSE ON)
Sameer Agarwald1146902012-05-30 01:40:22 -0700324 ELSE (${SUITESPARSE_FOUND})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700325 MESSAGE("-- Did not find all SuiteSparse dependencies. Building without SuiteSparse")
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700326 SET(SUITESPARSE OFF)
327 ADD_DEFINITIONS(-DCERES_NO_SUITESPARSE)
Sameer Agarwald1146902012-05-30 01:40:22 -0700328 ENDIF (${SUITESPARSE_FOUND})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700329ENDIF (DEFINED SUITESPARSE)
Keir Mierle8ebb0732012-04-30 23:09:08 -0700330
Sameer Agarwalb0518732012-05-29 00:27:57 -0700331# By default, if all of CXSparse's dependencies are found, Ceres is
332# built with CXSparse support. -DCXSPARSE=ON/OFF can be used to
333# enable/disable CXSparse explicitly.
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700334IF ((NOT DEFINED CXSPARSE) OR (DEFINED CXSPARSE AND CXSPARSE))
Sameer Agarwalb0518732012-05-29 00:27:57 -0700335MESSAGE("-- Check for CXSparse")
336SET(CXSPARSE_FOUND ON)
337
338FIND_LIBRARY(CXSPARSE_LIB NAMES cxsparse PATHS ${CXSPARSE_SEARCH_LIBS})
339IF (EXISTS ${CXSPARSE_LIB})
340 MESSAGE("-- Found CXSparse library in: ${CXSPARSE_LIB}")
341ELSE (EXISTS ${CXSPARSE_LIB})
342 MESSAGE("-- Did not find CXSparse header")
343 SET(CXSPARSE_FOUND FALSE)
344ENDIF (EXISTS ${CXSPARSE_LIB})
345
346FIND_PATH(CXSPARSE_INCLUDE NAMES cs.h PATHS ${CXSPARSE_SEARCH_HEADERS})
347IF (EXISTS ${CXSPARSE_INCLUDE})
348 MESSAGE("-- Found CXSparse header in: ${CXSPARSE_INCLUDE}")
349ELSE (EXISTS ${CXSPARSE_INCLUDE})
350 MESSAGE("-- Did not find CXSparse header")
351 SET(CXSPARSE_FOUND FALSE)
352ENDIF (EXISTS ${CXSPARSE_INCLUDE})
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700353ENDIF ((NOT DEFINED CXSPARSE) OR (DEFINED CXSPARSE AND CXSPARSE))
Sameer Agarwalb0518732012-05-29 00:27:57 -0700354
355IF (DEFINED CXSPARSE)
Sameer Agarwald1146902012-05-30 01:40:22 -0700356 IF (${CXSPARSE})
357 IF (NOT ${CXSPARSE_FOUND})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700358 MESSAGE(FATAL_ERROR "-- CXSparse not found.")
Sameer Agarwald1146902012-05-30 01:40:22 -0700359 ENDIF (NOT ${CXSPARSE_FOUND})
360 ELSE (${CXSPARSE})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700361 ADD_DEFINITIONS(-DCERES_NO_CXSPARSE)
Sameer Agarwald1146902012-05-30 01:40:22 -0700362 ENDIF (${CXSPARSE})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700363ELSE (DEFINED CXSPARSE)
Sameer Agarwald1146902012-05-30 01:40:22 -0700364 IF (${CXSPARSE_FOUND})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700365 MESSAGE("-- Building with CXSparse support.")
366 SET(CXSPARSE ON)
Sameer Agarwald1146902012-05-30 01:40:22 -0700367 ELSE (${CXSPARSE_FOUND})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700368 MESSAGE("-- Building without CXSparse.")
369 SET(CXSPARSE OFF)
370 ADD_DEFINITIONS(-DCERES_NO_CXSPARSE)
Sameer Agarwald1146902012-05-30 01:40:22 -0700371 ENDIF (${CXSPARSE_FOUND})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700372ENDIF (DEFINED CXSPARSE)
373
Keir Mierle8ebb0732012-04-30 23:09:08 -0700374# Google Flags
375OPTION(GFLAGS
376 "Enable Google Flags."
377 ON)
378
Sameer Agarwald1146902012-05-30 01:40:22 -0700379IF (${GFLAGS})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700380 MESSAGE("-- Check for Google Flags")
Sameer Agarwalaa9526d2012-05-08 21:22:09 -0700381 FIND_LIBRARY(GFLAGS_LIB NAMES gflags PATHS ${SEARCH_LIBS})
382 IF (NOT EXISTS ${GFLAGS_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700383 MESSAGE(FATAL_ERROR
384 "Can't find Google Flags. Please specify: "
Sameer Agarwalaa9526d2012-05-08 21:22:09 -0700385 "-DGFLAGS_LIB=...")
386 ENDIF (NOT EXISTS ${GFLAGS_LIB})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700387 MESSAGE("-- Found Google Flags library: ${GFLAGS_LIB}")
Sameer Agarwalaa9526d2012-05-08 21:22:09 -0700388 FIND_PATH(GFLAGS_INCLUDE NAMES gflags/gflags.h PATHS ${SEARCH_HEADERS})
389 IF (NOT EXISTS ${GFLAGS_INCLUDE})
390 MESSAGE(FATAL_ERROR
391 "Can't find Google Flags. Please specify: "
392 "-DGFLAGS_INCLUDE=...")
393 ENDIF (NOT EXISTS ${GFLAGS_INCLUDE})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700394 MESSAGE("-- Found Google Flags header in: ${GFLAGS_INCLUDE}")
Sameer Agarwald1146902012-05-30 01:40:22 -0700395ELSE (${GFLAGS})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700396 MESSAGE("-- Google Flags disabled; no tests or tools will be built!")
397 ADD_DEFINITIONS(-DCERES_NO_GFLAGS)
Sameer Agarwald1146902012-05-30 01:40:22 -0700398ENDIF (${GFLAGS})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700399
400# Google Logging
Keir Mierleaefb8a82012-07-28 13:23:55 -0700401IF (NOT ${BUILD_ANDROID})
402 MESSAGE("-- Check for Google Log")
403 FIND_LIBRARY(GLOG_LIB NAMES glog PATHS ${SEARCH_LIBS})
404 IF (NOT EXISTS ${GLOG_LIB})
405 MESSAGE(FATAL_ERROR
406 "Can't find Google Log. Please specify: "
407 "-DGLOG_LIB=...")
408 ENDIF (NOT EXISTS ${GLOG_LIB})
409 MESSAGE("-- Found Google Log library: ${GLOG_LIB}")
Sameer Agarwalaa9526d2012-05-08 21:22:09 -0700410
Keir Mierleaefb8a82012-07-28 13:23:55 -0700411 FIND_PATH(GLOG_INCLUDE NAMES glog/logging.h PATHS ${SEARCH_HEADERS})
412 IF (NOT EXISTS ${GLOG_INCLUDE})
413 MESSAGE(FATAL_ERROR
414 "Can't find Google Log. Please specify: "
415 "-DGLOG_INCLUDE=...")
416 ENDIF (NOT EXISTS ${GLOG_INCLUDE})
417 MESSAGE("-- Found Google Log header in: ${GLOG_INCLUDE}")
418ELSE (NOT ${BUILD_ANDROID})
419 SET(GLOG_LIB miniglog)
420 MESSAGE("-- Using minimal Glog substitute for Android (library): ${GLOG_LIB}")
421 SET(GLOG_INCLUDE internal/ceres/miniglog)
422 MESSAGE("-- Using minimal Glog substitute for Android (include): ${GLOG_INCLUDE}")
423ENDIF (NOT ${BUILD_ANDROID})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700424
425# Eigen
Pablo Speciale16dbf112013-03-11 14:44:02 -0700426MESSAGE("-- Check for Eigen 3.x")
Keir Mierlef477a382012-05-01 18:10:48 -0700427FIND_PATH(EIGEN_INCLUDE NAMES Eigen/Core PATHS ${EIGEN_SEARCH_HEADERS})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700428IF (NOT EXISTS ${EIGEN_INCLUDE})
Keir Mierlef477a382012-05-01 18:10:48 -0700429 MESSAGE(FATAL_ERROR "Can't find Eigen. Try passing -DEIGEN_INCLUDE=...")
Keir Mierle8ebb0732012-04-30 23:09:08 -0700430ENDIF (NOT EXISTS ${EIGEN_INCLUDE})
Pablo Speciale16dbf112013-03-11 14:44:02 -0700431MESSAGE("-- Found Eigen 3.x: ${EIGEN_INCLUDE}")
Keir Mierle8ebb0732012-04-30 23:09:08 -0700432
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700433# Template specializations for the Schur complement based solvers. If
434# compile time, binary size or compiler performance is an issue, you
435# may consider disabling this.
Keir Mierle8ebb0732012-04-30 23:09:08 -0700436OPTION(SCHUR_SPECIALIZATIONS
437 "Enable fixed-size schur specializations."
438 ON)
439
Sameer Agarwald1146902012-05-30 01:40:22 -0700440IF (NOT ${SCHUR_SPECIALIZATIONS})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700441 ADD_DEFINITIONS(-DCERES_RESTRICT_SCHUR_SPECIALIZATION)
Keir Mierlef10163a2012-05-04 21:33:53 -0700442 MESSAGE("-- Disabling Schur specializations (faster compiles)")
Sameer Agarwald1146902012-05-30 01:40:22 -0700443ENDIF (NOT ${SCHUR_SPECIALIZATIONS})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700444
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700445# Line search minimizer is useful for large scale problems or when
446# sparse linear algebra libraries are not available. If compile time,
447# binary size or compiler performance is an issue, consider disabling
448# this.
449OPTION(LINE_SEARCH_MINIMIZER
450 "Enable the line search minimizer."
451 ON)
452
453IF (NOT ${LINE_SEARCH_MINIMIZER})
Sameer Agarwal296fa9b2013-04-02 09:44:15 -0700454 ADD_DEFINITIONS(-DCERES_NO_LINE_SEARCH_MINIMIZER)
455 MESSAGE("-- Disabling line search minimizer")
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700456ENDIF (NOT ${LINE_SEARCH_MINIMIZER})
457
Sameer Agarwal296fa9b2013-04-02 09:44:15 -0700458OPTION(CUSTOM_BLAS
459 "Use handcoded BLAS routines (usually faster) instead of Eigen."
460 ON)
461
462IF (NOT ${CUSTOM_BLAS})
463 ADD_DEFINITIONS(-DCERES_NO_CUSTOM_BLAS)
464 MESSAGE("-- Disabling custom blas")
465ENDIF (NOT ${CUSTOM_BLAS})
466
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700467# Multithreading using OpenMP
Keir Mierle8ebb0732012-04-30 23:09:08 -0700468OPTION(OPENMP
469 "Enable threaded solving in Ceres (requires OpenMP)"
470 ON)
471
Sameer Agarwald1146902012-05-30 01:40:22 -0700472IF (${OPENMP})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700473 FIND_PACKAGE(OpenMP)
Sameer Agarwald1146902012-05-30 01:40:22 -0700474ENDIF (${OPENMP})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700475
Sameer Agarwal36f4cd22013-04-21 09:42:26 -0700476IF(${OPENMP_FOUND})
477 MESSAGE("-- Found OpenMP.")
478 ADD_DEFINITIONS(-DCERES_USE_OPENMP)
479 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
480 IF ("${UNIX}")
481 # At least on Linux, we need pthreads to be enabled for mutex to
482 # compile. This may not work on Windows or Android.
483 FIND_PACKAGE(Threads REQUIRED)
484 SET(STATIC_LIBRARY_FLAGS
485 "${STATIC_LIBRARY_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
486 SET(CMAKE_SHARED_LINKER_FLAGS
487 "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
488 ADD_DEFINITIONS(-DCERES_HAVE_PTHREAD)
489 ADD_DEFINITIONS(-DCERES_HAVE_RWLOCK)
490 ENDIF ("${UNIX}")
491ELSE(${OPENMP_FOUND})
492 MESSAGE("-- Can't find OpenMP. Disabling multithreading.")
493 ADD_DEFINITIONS(-DCERES_NO_THREADS)
494ENDIF(${OPENMP_FOUND})
495
496# Disable threads in mutex.h. Someday, after there is OpenMP support in
497# Android, this can get removed. Also turn on a workaround for an NDK bug.
498IF (${BUILD_ANDROID})
499 ADD_DEFINITIONS(-DCERES_NO_THREADS)
500 ADD_DEFINITIONS(-DCERES_WORK_AROUND_ANDROID_NDK_COMPILER_BUG)
501ENDIF (${BUILD_ANDROID})
502
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700503# Protocol buffers
Keir Mierle8ebb0732012-04-30 23:09:08 -0700504OPTION(PROTOBUF
505 "Enable protocol buffers support."
506 ON)
507
Sameer Agarwald1146902012-05-30 01:40:22 -0700508IF (${PROTOBUF})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700509 FIND_PACKAGE(Protobuf)
Sameer Agarwald1146902012-05-30 01:40:22 -0700510 IF (${PROTOBUF_FOUND})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700511 INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIRS})
512 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/internal)
Sameer Agarwald1146902012-05-30 01:40:22 -0700513 ELSE (${PROTOBUF_FOUND})
Sameer Agarwaldd2b17d2012-08-16 19:34:57 -0700514 ADD_DEFINITIONS(-DCERES_NO_PROTOCOL_BUFFERS)
Sameer Agarwald1146902012-05-30 01:40:22 -0700515 ENDIF (${PROTOBUF_FOUND})
516ELSE (${PROTOBUF})
Sameer Agarwaldd2b17d2012-08-16 19:34:57 -0700517 ADD_DEFINITIONS(-DCERES_NO_PROTOCOL_BUFFERS)
Sameer Agarwald1146902012-05-30 01:40:22 -0700518ENDIF (${PROTOBUF})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700519
Keir Mierled2164902012-08-15 19:04:50 -0700520OPTION(DISABLE_TR1
521 "Don't use TR1. This replaces some hash tables with sets. Slower."
522 OFF)
523
524IF (${DISABLE_TR1})
525 MESSAGE("-- Replacing unordered_map/set with map/set (warning: slower!)")
526 ADD_DEFINITIONS(-DCERES_NO_TR1)
527ELSE (${DISABLE_TR1})
528 MESSAGE("-- Using normal TR1 unordered_map/set")
529 # Use the std namespace for the hash<> and related templates. This may vary by
530 # system.
531 IF (MSVC)
532 # This is known to work with Visual Studio 2010 Express.
533 ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_START=namespace std {\"")
534 ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_END=}\"")
535 ELSE (MSVC)
536 # This is known to work with recent versions of Linux and Mac OS X.
537 ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_START=namespace std { namespace tr1 {\"")
538 ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_END=}}\"")
539 ENDIF (MSVC)
540ENDIF (${DISABLE_TR1})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700541
542INCLUDE_DIRECTORIES(
543 include
544 internal
545 internal/ceres
Keir Mierle8ebb0732012-04-30 23:09:08 -0700546 ${GLOG_INCLUDE}
Keir Mierle8ebb0732012-04-30 23:09:08 -0700547 ${EIGEN_INCLUDE}
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700548 )
549
Arnaud Gelas3d644b72012-08-16 17:33:21 +0200550FILE(GLOB CERES_HDRS ${CMAKE_SOURCE_DIR}/include/ceres/*.h)
551INSTALL(FILES ${CERES_HDRS} DESTINATION include/ceres)
552
553FILE(GLOB CERES_PUBLIC_INTERNAL_HDRS ${CMAKE_SOURCE_DIR}/include/ceres/internal/*.h)
554INSTALL(FILES ${CERES_PUBLIC_INTERNAL_HDRS} DESTINATION include/ceres/internal)
555
Sameer Agarwald1146902012-05-30 01:40:22 -0700556IF (${SUITESPARSE})
Markus Mollc497bd62012-08-17 14:40:13 +0200557 INCLUDE_DIRECTORIES(${AMD_INCLUDE})
558 INCLUDE_DIRECTORIES(${CAMD_INCLUDE})
559 INCLUDE_DIRECTORIES(${COLAMD_INCLUDE})
560 INCLUDE_DIRECTORIES(${CCOLAMD_INCLUDE})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700561 INCLUDE_DIRECTORIES(${CHOLMOD_INCLUDE})
Markus Mollc497bd62012-08-17 14:40:13 +0200562 IF (${SUITESPARSE_CONFIG_FOUND})
563 INCLUDE_DIRECTORIES(${SUITESPARSE_CONFIG_INCLUDE})
564 ENDIF (${SUITESPARSE_CONFIG_FOUND})
565 IF (${UFCONFIG_FOUND})
566 INCLUDE_DIRECTORIES(${UFCONFIG_INCLUDE})
567 ENDIF (${UFCONFIG_FOUND})
Sameer Agarwald1146902012-05-30 01:40:22 -0700568ENDIF(${SUITESPARSE})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700569
Sameer Agarwald1146902012-05-30 01:40:22 -0700570IF (${CXSPARSE})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700571 INCLUDE_DIRECTORIES(${CXSPARSE_INCLUDE})
Sameer Agarwald1146902012-05-30 01:40:22 -0700572ENDIF(${CXSPARSE})
Sameer Agarwalb0518732012-05-29 00:27:57 -0700573
Sameer Agarwald1146902012-05-30 01:40:22 -0700574IF (${GFLAGS})
Sameer Agarwaldaa98242012-05-11 11:26:38 -0700575 INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE})
Sameer Agarwald1146902012-05-30 01:40:22 -0700576ENDIF (${GFLAGS})
Keir Mierle8ebb0732012-04-30 23:09:08 -0700577
Sameer Agarwal8e2420e2012-05-31 17:00:58 -0700578# Change the default build type from Debug to Release, while still
579# supporting overriding the build type.
Sameer Agarwal4845bc42012-06-05 21:32:57 -0700580#
581# The CACHE STRING logic here and elsewhere is needed to force CMake
582# to pay attention to the value of these variables.
583IF (NOT CMAKE_BUILD_TYPE)
584 MESSAGE("-- No build type specified; defaulting to CMAKE_BUILD_TYPE=Release.")
585 SET(CMAKE_BUILD_TYPE Release CACHE STRING
586 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
587 FORCE)
588ELSE (NOT CMAKE_BUILD_TYPE)
Sameer Agarwal8e2420e2012-05-31 17:00:58 -0700589 IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
590 MESSAGE("\n=================================================================================")
591 MESSAGE("\n-- Build type: Debug. Performance will be terrible!")
592 MESSAGE("-- Add -DCMAKE_BUILD_TYPE=Release to the CMake command line to get an optimized build.")
593 MESSAGE("\n=================================================================================")
Sameer Agarwal8e2420e2012-05-31 17:00:58 -0700594 ENDIF (CMAKE_BUILD_TYPE STREQUAL "Debug")
Sameer Agarwal4845bc42012-06-05 21:32:57 -0700595ENDIF (NOT CMAKE_BUILD_TYPE)
596
597# Set the default Ceres flags to an empty string.
598SET (CERES_CXX_FLAGS)
599
600IF (CMAKE_BUILD_TYPE STREQUAL "Release")
601 IF (CMAKE_COMPILER_IS_GNUCXX)
Keir Mierleaefb8a82012-07-28 13:23:55 -0700602 IF (${BUILD_ANDROID})
603 # TODO(keir): Figure out what flags should go here to make an optimized
604 # native ARM binary for Android.
605 ELSE (${BUILD_ANDROID})
606 # Linux
607 IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
608 SET (CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -march=native -mtune=native")
609 ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
610 # Mac OS X
611 IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
612 SET (CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -fast -msse3")
613 ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
614 ENDIF (${BUILD_ANDROID})
Sameer Agarwal4845bc42012-06-05 21:32:57 -0700615 ENDIF (CMAKE_COMPILER_IS_GNUCXX)
Sameer Agarwal24fb32b2013-04-20 09:02:06 -0700616 IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
617 SET(CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -O4")
618 ENDIF()
Sameer Agarwal4845bc42012-06-05 21:32:57 -0700619ENDIF (CMAKE_BUILD_TYPE STREQUAL "Release")
Keir Mierleefe7ac62012-06-24 22:25:28 -0700620
Sameer Agarwal24fb32b2013-04-20 09:02:06 -0700621SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CERES_CXX_FLAGS}")
622
Keir Mierleefe7ac62012-06-24 22:25:28 -0700623# After the tweaks for the compile settings, disable some warnings on MSVC.
624IF (MSVC)
625 # Disable signed/unsigned int conversion warnings.
Keir Mierleaefb8a82012-07-28 13:23:55 -0700626 ADD_DEFINITIONS("/wd4018")
Keir Mierleefe7ac62012-06-24 22:25:28 -0700627 # Disable warning about using struct/class for the same symobl.
Keir Mierleaefb8a82012-07-28 13:23:55 -0700628 ADD_DEFINITIONS("/wd4099")
Keir Mierleefe7ac62012-06-24 22:25:28 -0700629 # Disable warning about the insecurity of using "std::copy".
630 ADD_DEFINITIONS("/wd4996")
631 # Disable performance warning about int-to-bool conversion.
632 ADD_DEFINITIONS("/wd4800")
633 # Disable performance warning about fopen insecurity.
634 ADD_DEFINITIONS("/wd4996")
635 # Disable warning about int64 to int32 conversion. Disabling
636 # this warning may not be correct; needs investigation.
637 # TODO(keir): Investigate these warnings in more detail.
638 ADD_DEFINITIONS("/wd4244")
639 # It's not possible to use STL types in DLL interfaces in a portable and
640 # reliable way. However, that's what happens with Google Log and Google Flags
641 # on Windows. MSVC gets upset about this and throws warnings that we can't do
642 # much about. The real solution is to link static versions of Google Log and
643 # Google Test, but that seems tricky on Windows. So, disable the warning.
644 ADD_DEFINITIONS("/wd4251")
645
646 # Google Flags doesn't have their DLL import/export stuff set up correctly,
647 # which results in linker warnings. This is irrelevant for Ceres, so ignore
648 # the warnings.
649 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4049")
Petter Strandmarkb7ba9342013-02-19 12:52:58 +0100650
651 # Tuple sizes of 10 are used by Gtest.
652 ADD_DEFINITIONS("-D_VARIADIC_MAX=10")
Keir Mierleefe7ac62012-06-24 22:25:28 -0700653ENDIF (MSVC)
654
Keir Mierle97ca0fb2012-09-18 15:52:36 -0700655# GCC is not strict enough by default, so enable most of the warnings.
656IF ("${UNIX}")
657 SET(CMAKE_CXX_FLAGS
Taylor Braun-Jonesb73148b2013-02-25 02:34:00 -0500658 "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter")
Keir Mierle97ca0fb2012-09-18 15:52:36 -0700659ENDIF ("${UNIX}")
660
Sameer Agarwal3d6eceb2013-04-02 21:45:48 -0700661# Use a larger inlining threshold for Clang, since it hobbles Eigen,
662# resulting in an unreasonably slow version of the blas routines. The
663# -Qunused-arguments is needed because CMake passes the inline
664# threshold to the linker and clang complains about it and dies.
Taylor Braun-Jonesb73148b2013-02-25 02:34:00 -0500665IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Sameer Agarwal3d6eceb2013-04-02 21:45:48 -0700666 SET(CMAKE_CXX_FLAGS
667 "${CMAKE_CXX_FLAGS} -Qunused-arguments -mllvm -inline-threshold=600 -Wno-return-type-c-linkage")
Taylor Braun-Jonesb73148b2013-02-25 02:34:00 -0500668ENDIF()
669
Keir Mierleefe7ac62012-06-24 22:25:28 -0700670ADD_SUBDIRECTORY(internal/ceres)
Arnaud Gelasb12b9062012-08-15 16:27:38 +0200671
672OPTION(BUILD_DOCUMENTATION
Pablo Specialec51b11c2013-03-12 00:56:56 -0700673 "Build User's Guide (html)"
Arnaud Gelasb12b9062012-08-15 16:27:38 +0200674 OFF)
675
676IF (${BUILD_DOCUMENTATION})
677 MESSAGE("-- Documentation building is enabled")
678
Pablo Specialec51b11c2013-03-12 00:56:56 -0700679 # Make CMake aware of the cmake folder, in order to find 'FindSphinx.cmake'
680 SET (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
681
682 # Generate the User's Guide (html).
Arnaud Gelasb12b9062012-08-15 16:27:38 +0200683 # The corresponding target is UserGuide, but is included in ALL.
684 ADD_SUBDIRECTORY(docs)
685ENDIF (${BUILD_DOCUMENTATION})
Arnaud Gelas73166092012-08-20 15:40:41 +0200686
687OPTION(BUILD_EXAMPLES "Build examples" ON)
688
689IF (${BUILD_EXAMPLES})
690 MESSAGE("-- Build the examples.")
691 ADD_SUBDIRECTORY(examples)
692ELSE (${BUILD_EXAMPLES})
693 MESSAGE("-- Do not build any example.")
694ENDIF (${BUILD_EXAMPLES})
Arnaud Gelas9ad27e82012-08-21 09:56:30 +0200695
696# Add an uninstall target to remove all installed files.
697CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in"
698 "${CMAKE_BINARY_DIR}/cmake/uninstall.cmake"
699 IMMEDIATE @ONLY)
700
701ADD_CUSTOM_TARGET(uninstall
702 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake/uninstall.cmake)
Pablo Speciale16dbf112013-03-11 14:44:02 -0700703
704# Set up install directories. INCLUDE_INSTALL_DIR and LIB_INSTALL_DIR
705# must not be absolute paths.
706SET(LIB_INSTALL_DIR_SUFFIX "" CACHE
707 STRING "The directories where to install libraries to")
708SET(LIB_INSTALL_DIR lib${LIB_INSTALL_DIR_SUFFIX} )
709SET(CMAKECONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/Ceres)
710SET(INCLUDE_INSTALL_DIR include)
711
712# This "exports" all targets which have been put into the export set
713# "CeresExport". This means that CMake generates a file with the given
714# filename, which can later on be loaded by projects using this package.
715# This file contains ADD_LIBRARY(bar IMPORTED) statements for each target
716# in the export set, so when loaded later on CMake will create "imported"
717# library targets from these, which can be used in many ways in the same way
718# as a normal library target created via a normal ADD_LIBRARY().
719INSTALL(EXPORT CeresExport
720 DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE CeresTargets.cmake)
721
722# Figure out the relative path from the installed Config.cmake file to the
723# install prefix (which may be at runtime different from the chosen
724# CMAKE_INSTALL_PREFIX if under Windows the package was installed anywhere)
725# This relative path will be configured into the CeresConfig.cmake.
726FILE(RELATIVE_PATH relInstallDir
727 ${CMAKE_INSTALL_PREFIX}/${CMAKECONFIG_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX})
728
729# Create a CeresConfig.cmake file. <name>Config.cmake files are searched by
730# FIND_PACKAGE() automatically. We configure that file so that we can put any
731# information we want in it, e.g. version numbers, include directories, etc.
732CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/CeresConfig.cmake.in"
733 "${CMAKE_CURRENT_BINARY_DIR}/CeresConfig.cmake" @ONLY)
734
735# Additionally, when CMake has found a CeresConfig.cmake, it can check for a
736# CeresConfigVersion.cmake in the same directory when figuring out the version
737# of the package when a version has been specified in the FIND_PACKAGE() call,
738# e.g. FIND_PACKAGE(Ceres [1.4.2] REQUIRED). The version argument is optional.
739CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/CeresConfigVersion.cmake.in"
740 "${CMAKE_CURRENT_BINARY_DIR}/CeresConfigVersion.cmake" @ONLY)
741
742# Install these two files into the same directory as the generated exports-file.
743INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/CeresConfig.cmake"
744 "${CMAKE_CURRENT_BINARY_DIR}/CeresConfigVersion.cmake"
745 "${CMAKE_SOURCE_DIR}/cmake/depend.cmake"
746 DESTINATION ${CMAKECONFIG_INSTALL_DIR})