Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 1 | # 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 Agarwal | d114690 | 2012-05-30 01:40:22 -0700 | [diff] [blame] | 31 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 32 | CMAKE_POLICY(VERSION 2.8) |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 33 | |
| 34 | IF (COMMAND cmake_policy) |
| 35 | CMAKE_POLICY(SET CMP0003 NEW) |
| 36 | ENDIF (COMMAND cmake_policy) |
| 37 | |
| 38 | PROJECT(CERES C CXX) |
| 39 | |
Arnaud Gelas | d2fb5ad | 2012-08-17 10:11:02 +0200 | [diff] [blame] | 40 | # Set up the git hook to make Gerrit Change-Id: lines in commit messages. |
| 41 | SET (LOCAL_GIT_DIRECTORY) |
| 42 | IF (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) |
| 46 | ELSE (EXISTS ${CMAKE_SOURCE_DIR}/.git) |
Sameer Agarwal | 36f4cd2 | 2013-04-21 09:42:26 -0700 | [diff] [blame] | 47 | # TODO(keir) Add proper Windows support |
Arnaud Gelas | d2fb5ad | 2012-08-17 10:11:02 +0200 | [diff] [blame] | 48 | ENDIF (EXISTS ${CMAKE_SOURCE_DIR}/.git) |
| 49 | |
| 50 | IF (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) |
| 64 | ENDIF (EXISTS ${LOCAL_GIT_DIRECTORY}) |
| 65 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 66 | # Make CMake aware of the cmake folder for local FindXXX scripts. |
| 67 | SET (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") |
| 68 | |
Arnaud Gelas | b3fa009 | 2012-08-17 10:31:41 +0200 | [diff] [blame] | 69 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 70 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 71 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 72 | # Set postfixes for generated libraries based on buildtype. |
| 73 | SET(CMAKE_RELEASE_POSTFIX "") |
| 74 | SET(CMAKE_DEBUG_POSTFIX "-debug") |
Arnaud Gelas | b3fa009 | 2012-08-17 10:31:41 +0200 | [diff] [blame] | 75 | |
Keir Mierle | 05107ba | 2012-07-18 13:50:12 -0700 | [diff] [blame] | 76 | # Important: Always bump the second number (e.g. 1.3.x to 1.4.0) for any |
| 77 | # release that changes the ABI. The ABI changes for almost any modification to |
| 78 | # include/ceres (e.g. the public API). If you are unsure about whether |
| 79 | # something is an ABI change, please ask on the list. |
| 80 | # |
| 81 | # For versions without ABI changes, bump the smallest number in CERES_VERSION, |
| 82 | # but leave the CERES_ABI_VERSION unchanged. |
Pablo Speciale | c51b11c | 2013-03-12 00:56:56 -0700 | [diff] [blame] | 83 | SET(CERES_VERSION_MAJOR 1) |
Sameer Agarwal | c71085e | 2013-10-31 13:56:38 -0700 | [diff] [blame] | 84 | SET(CERES_VERSION_MINOR 8) |
Pablo Speciale | c51b11c | 2013-03-12 00:56:56 -0700 | [diff] [blame] | 85 | SET(CERES_VERSION_PATCH 0) |
| 86 | SET(CERES_VERSION |
| 87 | ${CERES_VERSION_MAJOR}.${CERES_VERSION_MINOR}.${CERES_VERSION_PATCH}) |
Sameer Agarwal | c71085e | 2013-10-31 13:56:38 -0700 | [diff] [blame] | 88 | SET(CERES_ABI_VERSION 1.8.0) |
Keir Mierle | 05107ba | 2012-07-18 13:50:12 -0700 | [diff] [blame] | 89 | |
Sameer Agarwal | 30c5f93 | 2012-05-03 10:44:43 -0700 | [diff] [blame] | 90 | ENABLE_TESTING() |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 91 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 92 | OPTION(MINIGLOG "Use a stripped down version of glog." OFF) |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 93 | OPTION(GFLAGS "Enable Google Flags." ON) |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 94 | OPTION(SUITESPARSE "Enable SuiteSparse." ON) |
| 95 | OPTION(CXSPARSE "Enable CXSparse." ON) |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 96 | OPTION(LAPACK "Enable use of LAPACK." ON) |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 97 | # Template specializations for the Schur complement based solvers. If |
| 98 | # compile time, binary size or compiler performance is an issue, you |
| 99 | # may consider disabling this. |
| 100 | OPTION(SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ON) |
| 101 | OPTION(CUSTOM_BLAS |
| 102 | "Use handcoded BLAS routines (usually faster) instead of Eigen." |
Sameer Agarwal | aa9526d | 2012-05-08 21:22:09 -0700 | [diff] [blame] | 103 | ON) |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 104 | # Multithreading using OpenMP |
| 105 | OPTION(OPENMP "Enable threaded solving in Ceres (requires OpenMP)" ON) |
Sameer Agarwal | f6b67df | 2013-10-25 06:24:19 -0700 | [diff] [blame] | 106 | |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 107 | OPTION(BUILD_TESTING "Enable tests" ON) |
| 108 | OPTION(BUILD_DOCUMENTATION "Build User's Guide (html)" OFF) |
| 109 | OPTION(BUILD_EXAMPLES "Build examples" ON) |
Alex Stewart | 835ae9a | 2013-10-02 17:52:16 +0100 | [diff] [blame] | 110 | OPTION(BUILD_SHARED_LIBS "Build Ceres as a shared library." OFF) |
Alex Stewart | 21e7c0f | 2013-10-18 19:50:19 +0100 | [diff] [blame] | 111 | IF (MSVC) |
| 112 | OPTION(MSVC_USE_STATIC_CRT |
| 113 | "MS Visual Studio: Use static C-Run Time Library in place of shared." OFF) |
| 114 | ENDIF (MSVC) |
Sameer Agarwal | aa9526d | 2012-05-08 21:22:09 -0700 | [diff] [blame] | 115 | |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 116 | # Prior to October 2013, Ceres used some non-CMake standardised variables to |
| 117 | # hold user-specified (as opposed to FindPackage found) include directory and |
| 118 | # library paths for Ceres dependencies. These were were of the form: |
| 119 | # <DEPENDENCY>_LIB / <DEPENDENCY>_INCLUDE. Since then, Ceres now has |
| 120 | # FindPackage() scripts for all of its dependencies which obey the standard |
| 121 | # CMake variables: <DEPENDENCY>_LIBRARIES & <DEPENDENCY>_INCLUDE_DIRS. In order |
| 122 | # to ensure backwards compatibility, we use convert any legacy variables to |
| 123 | # _directory_ hints for the FindPackage() scripts. |
| 124 | MACRO(HANDLE_LEGACY_INCLUDE_DEPENDENCY_HINT |
| 125 | LEGACY_VAR DIRECTORY_HINT_VAR) |
| 126 | IF (DEFINED ${LEGACY_VAR}) |
| 127 | # Get the dependency name (all caps) from the hint directory variable |
| 128 | # for the warning message. |
| 129 | STRING(REGEX MATCH "^[^_]*" DEPENDENCY_NAME ${DIRECTORY_HINT_VAR}) |
| 130 | MESSAGE(WARNING "You are defining a legacy variable ${LEGACY_VAR} " |
| 131 | "to specify the include directory for ${DEPENDENCY_NAME}. This is " |
| 132 | "deprecated and support for it will be removed in a future release. " |
| 133 | "Please use either the search directory hints variable: " |
| 134 | "${DIRECTORY_HINT_VAR} or ${DEPENDENCY_NAME}_INCLUDE_DIR to specify " |
| 135 | "exactly the directory used (no search performed), see: " |
| 136 | "http://homes.cs.washington.edu/~sagarwal/ceres-solver/dev/building.html " |
| 137 | "for more information.") |
| 138 | LIST(APPEND ${DIRECTORY_HINT_VAR} ${${LEGACY_VAR}}) |
| 139 | ENDIF (DEFINED ${LEGACY_VAR}) |
| 140 | ENDMACRO(HANDLE_LEGACY_INCLUDE_DEPENDENCY_HINT) |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 141 | |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 142 | MACRO(HANDLE_LEGACY_LIBRARY_DEPENDENCY_HINT |
| 143 | LEGACY_VAR DIRECTORY_HINT_VAR) |
| 144 | IF (DEFINED ${LEGACY_VAR}) |
| 145 | # Get the dependency name (all caps) from the hint directory variable |
| 146 | # for the warning message. |
| 147 | STRING(REGEX MATCH "^[^_]*" DEPENDENCY_NAME ${DIRECTORY_HINT_VAR}) |
| 148 | MESSAGE(WARNING "You are defining a legacy variable ${LEGACY_VAR} " |
| 149 | "to specify the library for ${DEPENDENCY_NAME}. This is " |
| 150 | "deprecated and support for it will be removed in a future release. " |
| 151 | "Please use either the search directory hints variable: " |
| 152 | "${DIRECTORY_HINT_VAR} or ${DEPENDENCY_NAME}_LIBRARY to specify " |
| 153 | "exactly the library used (no search performed), see: " |
| 154 | "http://homes.cs.washington.edu/~sagarwal/ceres-solver/dev/building.html " |
| 155 | "for more information.") |
| 156 | IF (EXISTS ${${LEGACY_VAR}} AND |
| 157 | NOT IS_DIRECTORY ${${LEGACY_VAR}}) |
| 158 | # User specified an explicit (library) file using the legacy variable |
| 159 | # interface, hints to FindPackage() scripts are directories so add the |
| 160 | # parent directory of the specified file. |
| 161 | GET_FILENAME_COMPONENT(DIR_HINT ${${LEGACY_VAR}} PATH) |
| 162 | LIST(APPEND ${DIRECTORY_HINT_VAR} ${DIR_HINT}) |
| 163 | ELSEIF (EXISTS ${${LEGACY_VAR}} AND |
| 164 | IS_DIRECTORY ${${LEGACY_VAR}}) |
| 165 | # User specified a directory hint using the legacy variable, use it. |
| 166 | LIST(APPEND ${DIRECTORY_HINT_VAR} ${${LEGACY_VAR}}) |
| 167 | ENDIF() |
| 168 | ENDIF (DEFINED ${LEGACY_VAR}) |
| 169 | ENDMACRO(HANDLE_LEGACY_LIBRARY_DEPENDENCY_HINT) |
Sameer Agarwal | daa9824 | 2012-05-11 11:26:38 -0700 | [diff] [blame] | 170 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 171 | # Eigen. |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 172 | HANDLE_LEGACY_INCLUDE_DEPENDENCY_HINT(EIGEN_INCLUDE EIGEN_INCLUDE_DIR_HINTS) |
| 173 | FIND_PACKAGE(Eigen REQUIRED) |
| 174 | IF (EIGEN_FOUND) |
| 175 | MESSAGE("-- Found Eigen version ${EIGEN_VERSION}: ${EIGEN_INCLUDE_DIRS}") |
| 176 | ENDIF (EIGEN_FOUND) |
Sameer Agarwal | b051873 | 2012-05-29 00:27:57 -0700 | [diff] [blame] | 177 | |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 178 | # LAPACK (& BLAS). |
| 179 | IF (LAPACK) |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 180 | FIND_PACKAGE(LAPACK QUIET) |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 181 | IF (LAPACK_FOUND) |
| 182 | MESSAGE("-- Found LAPACK library: ${LAPACK_LIBRARIES}") |
| 183 | ELSE (LAPACK_FOUND) |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 184 | MESSAGE("-- Did not find LAPACK library, disabling LAPACK support.") |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 185 | ENDIF (LAPACK_FOUND) |
Sameer Agarwal | 367b65e | 2013-08-09 10:35:37 -0700 | [diff] [blame] | 186 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 187 | FIND_PACKAGE(BLAS QUIET) |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 188 | IF (BLAS_FOUND) |
| 189 | MESSAGE("-- Found BLAS library: ${BLAS_LIBRARIES}") |
| 190 | ELSE (BLAS_FOUND) |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 191 | MESSAGE("-- Did not find BLAS library, disabling LAPACK support.") |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 192 | ENDIF (BLAS_FOUND) |
Sameer Agarwal | 367b65e | 2013-08-09 10:35:37 -0700 | [diff] [blame] | 193 | |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 194 | IF (NOT (LAPACK_FOUND AND BLAS_FOUND)) |
| 195 | # Retain the help string associated with the LAPACK option |
| 196 | # when updating it to disable use of LAPACK. |
| 197 | GET_PROPERTY(HELP_STRING CACHE LAPACK PROPERTY HELPSTRING) |
| 198 | SET(LAPACK OFF CACHE BOOL "${HELP_STRING}" FORCE) |
| 199 | ADD_DEFINITIONS(-DCERES_NO_LAPACK) |
| 200 | ENDIF (NOT (LAPACK_FOUND AND BLAS_FOUND)) |
| 201 | ELSE (LAPACK) |
| 202 | MESSAGE("-- Building without LAPACK.") |
Sameer Agarwal | 367b65e | 2013-08-09 10:35:37 -0700 | [diff] [blame] | 203 | ADD_DEFINITIONS(-DCERES_NO_LAPACK) |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 204 | ENDIF (LAPACK) |
Sameer Agarwal | 367b65e | 2013-08-09 10:35:37 -0700 | [diff] [blame] | 205 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 206 | # SuiteSparse. |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 207 | IF (SUITESPARSE AND NOT LAPACK) |
| 208 | # If user has disabled LAPACK, but left SUITESPARSE ON, turn it OFF, |
| 209 | # LAPACK controls whether Ceres will be linked, directly or indirectly |
| 210 | # via SuiteSparse to LAPACK. |
| 211 | MESSAGE("-- Disabling SuiteSparse as use of LAPACK has been disabled, " |
| 212 | "turn ON LAPACK to enable (optional) building with SuiteSparse.") |
| 213 | # Retain the help string associated with the SUITESPARSE option |
| 214 | # when updating it to disable use of SuiteSparse. |
| 215 | GET_PROPERTY(HELP_STRING CACHE SUITESPARSE PROPERTY HELPSTRING) |
| 216 | SET(SUITESPARSE OFF CACHE BOOL "${HELP_STRING}" FORCE) |
| 217 | ENDIF (SUITESPARSE AND NOT LAPACK) |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 218 | IF (SUITESPARSE) |
| 219 | # By default, if SuiteSparse and all dependencies are found, Ceres is |
| 220 | # built with SuiteSparse support. |
Sameer Agarwal | daa9824 | 2012-05-11 11:26:38 -0700 | [diff] [blame] | 221 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 222 | # Check for SuiteSparse and dependencies. |
Alex Stewart | 6fed9fe | 2013-11-04 18:33:05 +0000 | [diff] [blame] | 223 | FIND_PACKAGE(SuiteSparse) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 224 | IF (SUITESPARSE_FOUND) |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 225 | # On Ubuntu the system install of SuiteSparse (v3.4.0) up to at least |
| 226 | # Ubuntu 13.10 cannot be used to link shared libraries. |
| 227 | IF (BUILD_SHARED_LIBS AND |
| 228 | SUITESPARSE_IS_BROKEN_SHARED_LINKING_UBUNTU_SYSTEM_VERSION) |
| 229 | MESSAGE(FATAL_ERROR "You are attempting to build Ceres as a shared " |
| 230 | "library on Ubuntu using a system package install of SuiteSparse " |
| 231 | "3.4.0. This package is broken and does not support the " |
| 232 | "construction of shared libraries (you can still build Ceres as " |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 233 | "a static library). If you wish to build a shared version of Ceres " |
| 234 | "you should uninstall the system install of SuiteSparse " |
| 235 | "(libsuitesparse-dev) and perform a source install of SuiteSparse " |
| 236 | "(we recommend that you use the latest version), " |
| 237 | "see: http://homes.cs.washington.edu/~sagarwal" |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 238 | "/ceres-solver/dev/building.html for more information.") |
| 239 | ENDIF (BUILD_SHARED_LIBS AND |
| 240 | SUITESPARSE_IS_BROKEN_SHARED_LINKING_UBUNTU_SYSTEM_VERSION) |
| 241 | |
| 242 | # By default, if all of SuiteSparse's dependencies are found, Ceres is |
| 243 | # built with SuiteSparse support. |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 244 | MESSAGE("-- Found SuiteSparse ${SUITESPARSE_VERSION}, " |
| 245 | "building with SuiteSparse.") |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 246 | ELSE (SUITESPARSE_FOUND) |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 247 | # Disable use of SuiteSparse if it cannot be found and continue. |
| 248 | MESSAGE("-- Did not find all SuiteSparse dependencies, disabling " |
| 249 | "SuiteSparse support.") |
| 250 | # Retain the help string associated with the SUITESPARSE option |
| 251 | # when updating it to disable use of SuiteSparse. |
| 252 | GET_PROPERTY(HELP_STRING CACHE SUITESPARSE PROPERTY HELPSTRING) |
| 253 | SET(SUITESPARSE OFF CACHE BOOL "${HELP_STRING}" FORCE) |
Sameer Agarwal | daa9824 | 2012-05-11 11:26:38 -0700 | [diff] [blame] | 254 | ADD_DEFINITIONS(-DCERES_NO_SUITESPARSE) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 255 | ENDIF (SUITESPARSE_FOUND) |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 256 | ELSE (SUITESPARSE) |
| 257 | MESSAGE("-- Building without SuiteSparse.") |
| 258 | ADD_DEFINITIONS(-DCERES_NO_SUITESPARSE) |
| 259 | ENDIF (SUITESPARSE) |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 260 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 261 | # CXSparse. |
| 262 | IF (CXSPARSE) |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 263 | # Don't search with REQUIRED as we can continue without CXSparse. |
| 264 | FIND_PACKAGE(CXSparse) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 265 | IF (CXSPARSE_FOUND) |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 266 | # By default, if CXSparse and all dependencies are found, Ceres is |
| 267 | # built with CXSparse support. |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 268 | MESSAGE("-- Found CXSparse version: ${CXSPARSE_VERSION}, " |
| 269 | "building with CXSparse.") |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 270 | ELSE (CXSPARSE_FOUND) |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 271 | # Disable use of CXSparse if it cannot be found and continue. |
| 272 | MESSAGE("-- Did not find CXSparse, Building without CXSparse.") |
| 273 | # Retain the help string associated with the CXSPARSE option |
| 274 | # when updating it to disable use of CXSparse. |
| 275 | GET_PROPERTY(HELP_STRING CACHE CXSPARSE PROPERTY HELPSTRING) |
| 276 | SET(CXSPARSE OFF CACHE BOOL "${HELP_STRING}" FORCE) |
Sameer Agarwal | b051873 | 2012-05-29 00:27:57 -0700 | [diff] [blame] | 277 | ADD_DEFINITIONS(-DCERES_NO_CXSPARSE) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 278 | ENDIF (CXSPARSE_FOUND) |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 279 | ELSE (CXSPARSE) |
| 280 | MESSAGE("-- Building without CXSparse.") |
| 281 | ADD_DEFINITIONS(-DCERES_NO_CXSPARSE) |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 282 | # Mark as advanced (remove from default GUI view) the CXSparse search |
| 283 | # variables in case user enabled CXSPARSE, FindCXSparse did not find it, so |
| 284 | # made search variables visible in GUI for user to set, but then user disables |
| 285 | # CXSPARSE instead of setting them. |
| 286 | MARK_AS_ADVANCED(FORCE CXSPARSE_INCLUDE_DIR |
| 287 | CXSPARSE_LIBRARY) |
Sameer Agarwal | 35ee1f7 | 2013-10-09 10:12:43 -0700 | [diff] [blame] | 288 | ENDIF (CXSPARSE) |
Sameer Agarwal | b051873 | 2012-05-29 00:27:57 -0700 | [diff] [blame] | 289 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 290 | # GFlags. |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 291 | IF (GFLAGS) |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 292 | HANDLE_LEGACY_INCLUDE_DEPENDENCY_HINT(GFLAGS_INCLUDE GFLAGS_INCLUDE_DIR_HINTS) |
| 293 | HANDLE_LEGACY_LIBRARY_DEPENDENCY_HINT(GFLAGS_LIB GFLAGS_LIBRARY_DIR_HINTS) |
| 294 | |
| 295 | # Don't search with REQUIRED as we can continue without gflags. |
| 296 | FIND_PACKAGE(Gflags) |
| 297 | IF (GFLAGS_FOUND) |
| 298 | MESSAGE("-- Found Google Flags header in: ${GFLAGS_INCLUDE_DIRS}") |
| 299 | ELSE (GFLAGS_FOUND) |
| 300 | MESSAGE("-- Did not find Google Flags (gflags), Building without gflags " |
| 301 | "- no tests or tools will be built!") |
| 302 | # Retain the help string associated with the GFLAGS option |
| 303 | # when updating it to disable use of gflags. |
| 304 | GET_PROPERTY(HELP_STRING CACHE GFLAGS PROPERTY HELPSTRING) |
| 305 | SET(GFLAGS OFF CACHE BOOL "${HELP_STRING}" FORCE) |
| 306 | ADD_DEFINITIONS(-DCERES_NO_GFLAGS) |
| 307 | ENDIF (GFLAGS_FOUND) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 308 | ELSE (GFLAGS) |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 309 | MESSAGE("-- Google Flags disabled; no tests or tools will be built!") |
| 310 | ADD_DEFINITIONS(-DCERES_NO_GFLAGS) |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 311 | # Mark as advanced (remove from default GUI view) the gflags search |
| 312 | # variables in case user enabled GFLAGS, FindGflags did not find it, so |
| 313 | # made search variables visible in GUI for user to set, but then user disables |
| 314 | # GFLAGS instead of setting them. |
| 315 | MARK_AS_ADVANCED(FORCE GFLAGS_INCLUDE_DIR |
| 316 | GFLAGS_LIBRARY) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 317 | ENDIF (GFLAGS) |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 318 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 319 | # MiniGLog. |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 320 | IF (MINIGLOG) |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 321 | SET(GLOG_LIBRARIES miniglog) |
| 322 | MESSAGE("-- Using minimal Glog substitute (library): ${GLOG_LIBRARIES}") |
| 323 | SET(GLOG_INCLUDE_DIRS internal/ceres/miniglog) |
| 324 | MESSAGE("-- Using minimal Glog substitute (include): ${GLOG_INCLUDE_DIRS}") |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 325 | |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 326 | # Mark as advanced (remove from default GUI view) the glog search |
| 327 | # variables in case user disables MINIGLOG, FindGlog did not find it, so |
| 328 | # made search variables visible in GUI for user to set, but then user enables |
| 329 | # MINIGLOG instead of setting them. |
| 330 | MARK_AS_ADVANCED(FORCE GLOG_INCLUDE_DIR |
| 331 | GLOG_LIBRARY) |
| 332 | ELSE (MINIGLOG) |
| 333 | HANDLE_LEGACY_INCLUDE_DEPENDENCY_HINT(GLOG_INCLUDE GLOG_INCLUDE_DIR_HINTS) |
| 334 | HANDLE_LEGACY_LIBRARY_DEPENDENCY_HINT(GLOG_LIB GLOG_LIBRARY_DIR_HINTS) |
| 335 | |
| 336 | # Don't search with REQUIRED so that configuration continues if not found and |
| 337 | # we can output an error messages explaining MINIGLOG option. |
| 338 | FIND_PACKAGE(Glog) |
| 339 | IF (GLOG_FOUND) |
| 340 | MESSAGE("-- Found Google Log header in: ${GLOG_INCLUDE_DIRS}") |
| 341 | ELSE (GLOG_FOUND) |
| 342 | MESSAGE(FATAL_ERROR "Can't find Google Log. Please set GLOG_INCLUDE_DIR & " |
| 343 | "GLOG_LIBRARY or enable MINIGLOG option to use minimal glog " |
| 344 | "implementation.") |
| 345 | ENDIF (GLOG_FOUND) |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 346 | ENDIF (MINIGLOG) |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 347 | |
Sergey Sharybin | 72cc457 | 2013-06-19 20:59:08 +0600 | [diff] [blame] | 348 | IF (NOT SCHUR_SPECIALIZATIONS) |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 349 | ADD_DEFINITIONS(-DCERES_RESTRICT_SCHUR_SPECIALIZATION) |
Keir Mierle | f10163a | 2012-05-04 21:33:53 -0700 | [diff] [blame] | 350 | MESSAGE("-- Disabling Schur specializations (faster compiles)") |
Sergey Sharybin | 72cc457 | 2013-06-19 20:59:08 +0600 | [diff] [blame] | 351 | ENDIF (NOT SCHUR_SPECIALIZATIONS) |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 352 | |
Sergey Sharybin | 72cc457 | 2013-06-19 20:59:08 +0600 | [diff] [blame] | 353 | IF (NOT CUSTOM_BLAS) |
Sameer Agarwal | 296fa9b | 2013-04-02 09:44:15 -0700 | [diff] [blame] | 354 | ADD_DEFINITIONS(-DCERES_NO_CUSTOM_BLAS) |
| 355 | MESSAGE("-- Disabling custom blas") |
Sergey Sharybin | 72cc457 | 2013-06-19 20:59:08 +0600 | [diff] [blame] | 356 | ENDIF (NOT CUSTOM_BLAS) |
Sameer Agarwal | 296fa9b | 2013-04-02 09:44:15 -0700 | [diff] [blame] | 357 | |
Alex Stewart | 9cded61 | 2013-10-23 14:39:21 +0100 | [diff] [blame] | 358 | IF (OPENMP) |
| 359 | # Clang does not (yet) support OpenMP. |
| 360 | IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 361 | # Retain the help string associated with the OPENMP option |
| 362 | # when updating it to disable use of OPENMP. |
| 363 | GET_PROPERTY(HELP_STRING CACHE OPENMP PROPERTY HELPSTRING) |
| 364 | SET(OPENMP OFF CACHE BOOL "${HELP_STRING}" FORCE) |
| 365 | MESSAGE("-- Compiler is Clang, disabling OpenMP.") |
| 366 | ADD_DEFINITIONS(-DCERES_NO_THREADS) |
| 367 | ELSE (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 368 | # Find quietly s/t as we can continue without OpenMP if it is not found. |
| 369 | FIND_PACKAGE(OpenMP QUIET) |
| 370 | IF (OPENMP_FOUND) |
| 371 | MESSAGE("-- Building with OpenMP.") |
| 372 | ADD_DEFINITIONS(-DCERES_USE_OPENMP) |
| 373 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") |
| 374 | IF (UNIX) |
| 375 | # At least on Linux, we need pthreads to be enabled for mutex to |
| 376 | # compile. This may not work on Windows or Android. |
| 377 | FIND_PACKAGE(Threads REQUIRED) |
Alex Stewart | 9cded61 | 2013-10-23 14:39:21 +0100 | [diff] [blame] | 378 | ADD_DEFINITIONS(-DCERES_HAVE_PTHREAD) |
| 379 | ADD_DEFINITIONS(-DCERES_HAVE_RWLOCK) |
| 380 | ENDIF (UNIX) |
| 381 | ELSE (OPENMP_FOUND) |
| 382 | MESSAGE("-- Failed to find OpenMP, disabling.") |
| 383 | # Retain the help string associated with the OPENMP option |
| 384 | # when updating it to disable use of OPENMP. |
| 385 | GET_PROPERTY(HELP_STRING CACHE OPENMP PROPERTY HELPSTRING) |
| 386 | SET(OPENMP OFF CACHE BOOL "${HELP_STRING}" FORCE) |
| 387 | ADD_DEFINITIONS(-DCERES_NO_THREADS) |
| 388 | ENDIF (OPENMP_FOUND) |
| 389 | ENDIF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 390 | ELSE (OPENMP) |
| 391 | MESSAGE("-- Building without OpenMP (disabling multithreading).") |
Sameer Agarwal | 36f4cd2 | 2013-04-21 09:42:26 -0700 | [diff] [blame] | 392 | ADD_DEFINITIONS(-DCERES_NO_THREADS) |
Alex Stewart | 9cded61 | 2013-10-23 14:39:21 +0100 | [diff] [blame] | 393 | ENDIF (OPENMP) |
Sameer Agarwal | 36f4cd2 | 2013-04-21 09:42:26 -0700 | [diff] [blame] | 394 | |
Sergey Sharybin | d1cf320 | 2013-11-28 23:11:11 +0600 | [diff] [blame] | 395 | INCLUDE(CheckIncludeFileCXX) |
| 396 | CHECK_INCLUDE_FILE_CXX(unordered_map HAVE_STD_UNORDERED_MAP_HEADER) |
| 397 | IF (HAVE_STD_UNORDERED_MAP_HEADER) |
| 398 | # Even so we've found unordered_map header file it doesn't |
| 399 | # mean unordered_map and unordered_set will be declared in |
| 400 | # std namespace. |
| 401 | # |
| 402 | # Namely, MSVC 2008 have unordered_map header which declares |
| 403 | # unordered_map class in std::tr1 namespace. In order to support |
| 404 | # this, we do extra check to see which exactly namespace is |
| 405 | # to be used. |
| 406 | |
| 407 | INCLUDE(CheckCXXSourceCompiles) |
| 408 | CHECK_CXX_SOURCE_COMPILES("#include <unordered_map> |
| 409 | int main() { |
| 410 | std::unordered_map<int, int> map; |
| 411 | return 0; |
| 412 | }" |
| 413 | HAVE_UNORDERED_MAP_IN_STD_NAMESPACE) |
| 414 | IF (HAVE_UNORDERED_MAP_IN_STD_NAMESPACE) |
| 415 | ADD_DEFINITIONS(-DCERES_STD_UNORDERED_MAP) |
| 416 | MESSAGE("-- Found unordered_map/set in std namespace.") |
| 417 | ELSE (HAVE_UNORDERED_MAP_IN_STD_NAMESPACE) |
| 418 | CHECK_CXX_SOURCE_COMPILES("#include <unordered_map> |
| 419 | int main() { |
| 420 | std::tr1::unordered_map<int, int> map; |
| 421 | return 0; |
| 422 | }" |
| 423 | HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE) |
| 424 | IF (HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE) |
| 425 | ADD_DEFINITIONS(-DCERES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE) |
| 426 | MESSAGE("-- Found unordered_map/set in std::tr1 namespace.") |
| 427 | ELSE (HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE) |
| 428 | MESSAGE("-- Found <unordered_map> but cannot find either std::unordered_map " |
| 429 | "or std::tr1::unordered_map.") |
| 430 | MESSAGE("-- Replacing unordered_map/set with map/set (warning: slower!)") |
| 431 | ADD_DEFINITIONS(-DCERES_NO_UNORDERED_MAP) |
| 432 | ENDIF (HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE) |
| 433 | ENDIF (HAVE_UNORDERED_MAP_IN_STD_NAMESPACE) |
| 434 | ELSE (HAVE_STD_UNORDERED_MAP_HEADER) |
Sameer Agarwal | f6b67df | 2013-10-25 06:24:19 -0700 | [diff] [blame] | 435 | CHECK_INCLUDE_FILE_CXX("tr1/unordered_map" UNORDERED_MAP_IN_TR1_NAMESPACE) |
| 436 | IF (UNORDERED_MAP_IN_TR1_NAMESPACE) |
| 437 | ADD_DEFINITIONS(-DCERES_TR1_UNORDERED_MAP) |
Sergey Sharybin | d1cf320 | 2013-11-28 23:11:11 +0600 | [diff] [blame] | 438 | MESSAGE("-- Found tr1/unordered_map/set in std::tr1 namespace.") |
Sameer Agarwal | f6b67df | 2013-10-25 06:24:19 -0700 | [diff] [blame] | 439 | ELSE (UNORDERED_MAP_IN_TR1_NAMESPACE) |
| 440 | MESSAGE("-- Unable to find <unordered_map> or <tr1/unordered_map>. ") |
| 441 | MESSAGE("-- Replacing unordered_map/set with map/set (warning: slower!)") |
| 442 | ADD_DEFINITIONS(-DCERES_NO_UNORDERED_MAP) |
| 443 | ENDIF (UNORDERED_MAP_IN_TR1_NAMESPACE) |
Sergey Sharybin | d1cf320 | 2013-11-28 23:11:11 +0600 | [diff] [blame] | 444 | ENDIF (HAVE_STD_UNORDERED_MAP_HEADER) |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 445 | |
| 446 | INCLUDE_DIRECTORIES( |
| 447 | include |
| 448 | internal |
| 449 | internal/ceres |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 450 | ${GLOG_INCLUDE_DIRS} |
| 451 | ${EIGEN_INCLUDE_DIRS}) |
Arnaud Gelas | 3d644b7 | 2012-08-16 17:33:21 +0200 | [diff] [blame] | 452 | |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 453 | IF (SUITESPARSE) |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 454 | INCLUDE_DIRECTORIES(${SUITESPARSE_INCLUDE_DIRS}) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 455 | ENDIF (SUITESPARSE) |
Sameer Agarwal | daa9824 | 2012-05-11 11:26:38 -0700 | [diff] [blame] | 456 | |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 457 | IF (CXSPARSE) |
Alex Stewart | cada337 | 2013-11-04 18:08:24 +0000 | [diff] [blame] | 458 | INCLUDE_DIRECTORIES(${CXSPARSE_INCLUDE_DIRS}) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 459 | ENDIF (CXSPARSE) |
Sameer Agarwal | b051873 | 2012-05-29 00:27:57 -0700 | [diff] [blame] | 460 | |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 461 | IF (GFLAGS) |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 462 | INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE_DIRS}) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 463 | ENDIF (GFLAGS) |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 464 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 465 | IF (BUILD_SHARED_LIBS) |
| 466 | MESSAGE("-- Building Ceres as a shared library.") |
| 467 | ELSE (BUILD_SHARED_LIBS) |
| 468 | MESSAGE("-- Building Ceres as a static library.") |
| 469 | ENDIF (BUILD_SHARED_LIBS) |
| 470 | |
Sameer Agarwal | 8e2420e | 2012-05-31 17:00:58 -0700 | [diff] [blame] | 471 | # Change the default build type from Debug to Release, while still |
| 472 | # supporting overriding the build type. |
Sameer Agarwal | 4845bc4 | 2012-06-05 21:32:57 -0700 | [diff] [blame] | 473 | # |
| 474 | # The CACHE STRING logic here and elsewhere is needed to force CMake |
| 475 | # to pay attention to the value of these variables. |
| 476 | IF (NOT CMAKE_BUILD_TYPE) |
| 477 | MESSAGE("-- No build type specified; defaulting to CMAKE_BUILD_TYPE=Release.") |
| 478 | SET(CMAKE_BUILD_TYPE Release CACHE STRING |
| 479 | "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." |
| 480 | FORCE) |
| 481 | ELSE (NOT CMAKE_BUILD_TYPE) |
Sameer Agarwal | 8e2420e | 2012-05-31 17:00:58 -0700 | [diff] [blame] | 482 | IF (CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 483 | MESSAGE("\n=================================================================================") |
| 484 | MESSAGE("\n-- Build type: Debug. Performance will be terrible!") |
| 485 | MESSAGE("-- Add -DCMAKE_BUILD_TYPE=Release to the CMake command line to get an optimized build.") |
| 486 | MESSAGE("\n=================================================================================") |
Sameer Agarwal | 8e2420e | 2012-05-31 17:00:58 -0700 | [diff] [blame] | 487 | ENDIF (CMAKE_BUILD_TYPE STREQUAL "Debug") |
Sameer Agarwal | 4845bc4 | 2012-06-05 21:32:57 -0700 | [diff] [blame] | 488 | ENDIF (NOT CMAKE_BUILD_TYPE) |
| 489 | |
| 490 | # Set the default Ceres flags to an empty string. |
| 491 | SET (CERES_CXX_FLAGS) |
| 492 | |
| 493 | IF (CMAKE_BUILD_TYPE STREQUAL "Release") |
| 494 | IF (CMAKE_COMPILER_IS_GNUCXX) |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 495 | # Linux |
| 496 | IF (CMAKE_SYSTEM_NAME MATCHES "Linux") |
Sameer Agarwal | 74727f5 | 2013-09-19 10:03:03 -0700 | [diff] [blame] | 497 | IF (NOT GCC_VERSION VERSION_LESS 4.2) |
| 498 | SET (CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -march=native -mtune=native") |
| 499 | ENDIF (NOT GCC_VERSION VERSION_LESS 4.2) |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 500 | ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux") |
| 501 | # Mac OS X |
| 502 | IF (CMAKE_SYSTEM_NAME MATCHES "Darwin") |
| 503 | SET (CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -msse3") |
| 504 | # Use of -fast only applicable for Apple's GCC |
| 505 | # Assume this is being used if GCC version < 4.3 on OSX |
Alex Stewart | f5f21b5 | 2013-10-10 19:22:31 +0100 | [diff] [blame] | 506 | EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} |
| 507 | ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion |
| 508 | OUTPUT_VARIABLE GCC_VERSION |
| 509 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
Sameer Agarwal | c24a4ec | 2013-08-23 06:49:22 -0700 | [diff] [blame] | 510 | IF (GCC_VERSION VERSION_LESS 4.3) |
| 511 | SET (CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -fast") |
| 512 | ENDIF (GCC_VERSION VERSION_LESS 4.3) |
| 513 | ENDIF (CMAKE_SYSTEM_NAME MATCHES "Darwin") |
Sameer Agarwal | 4845bc4 | 2012-06-05 21:32:57 -0700 | [diff] [blame] | 514 | ENDIF (CMAKE_COMPILER_IS_GNUCXX) |
Sergey Sharybin | 72cc457 | 2013-06-19 20:59:08 +0600 | [diff] [blame] | 515 | IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
Johannes Schönberger | 8956f56 | 2014-03-10 22:39:20 -0400 | [diff] [blame] | 516 | # Use of -flto requires use of gold linker & LLVM-gold plugin, which might |
Sameer Agarwal | 395b4e9 | 2013-05-23 11:01:16 -0700 | [diff] [blame] | 517 | # well not be present / in use and without which files will compile, but |
Alex Stewart | 3702068 | 2013-05-12 20:06:04 +0100 | [diff] [blame] | 518 | # not link ('file not recognized') so explicitly check for support |
| 519 | INCLUDE(CheckCXXCompilerFlag) |
Johannes Schönberger | 8956f56 | 2014-03-10 22:39:20 -0400 | [diff] [blame] | 520 | CHECK_CXX_COMPILER_FLAG("-flto" HAVE_LTO_SUPPORT) |
Alex Stewart | 3702068 | 2013-05-12 20:06:04 +0100 | [diff] [blame] | 521 | IF (HAVE_LTO_SUPPORT) |
Johannes Schönberger | 8956f56 | 2014-03-10 22:39:20 -0400 | [diff] [blame] | 522 | MESSAGE(STATUS "Enabling link-time optimization (-flto)") |
| 523 | SET(CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -flto") |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 524 | ELSE () |
Johannes Schönberger | 8956f56 | 2014-03-10 22:39:20 -0400 | [diff] [blame] | 525 | MESSAGE(STATUS "Compiler/linker does not support link-time optimization (-flto), disabling.") |
Alex Stewart | 3702068 | 2013-05-12 20:06:04 +0100 | [diff] [blame] | 526 | ENDIF (HAVE_LTO_SUPPORT) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 527 | ENDIF () |
Sameer Agarwal | 4845bc4 | 2012-06-05 21:32:57 -0700 | [diff] [blame] | 528 | ENDIF (CMAKE_BUILD_TYPE STREQUAL "Release") |
Keir Mierle | efe7ac6 | 2012-06-24 22:25:28 -0700 | [diff] [blame] | 529 | |
Sameer Agarwal | 24fb32b | 2013-04-20 09:02:06 -0700 | [diff] [blame] | 530 | SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CERES_CXX_FLAGS}") |
| 531 | |
Keir Mierle | efe7ac6 | 2012-06-24 22:25:28 -0700 | [diff] [blame] | 532 | # After the tweaks for the compile settings, disable some warnings on MSVC. |
| 533 | IF (MSVC) |
| 534 | # Disable signed/unsigned int conversion warnings. |
Keir Mierle | aefb8a8 | 2012-07-28 13:23:55 -0700 | [diff] [blame] | 535 | ADD_DEFINITIONS("/wd4018") |
Keir Mierle | efe7ac6 | 2012-06-24 22:25:28 -0700 | [diff] [blame] | 536 | # Disable warning about using struct/class for the same symobl. |
Keir Mierle | aefb8a8 | 2012-07-28 13:23:55 -0700 | [diff] [blame] | 537 | ADD_DEFINITIONS("/wd4099") |
Keir Mierle | efe7ac6 | 2012-06-24 22:25:28 -0700 | [diff] [blame] | 538 | # Disable warning about the insecurity of using "std::copy". |
| 539 | ADD_DEFINITIONS("/wd4996") |
| 540 | # Disable performance warning about int-to-bool conversion. |
| 541 | ADD_DEFINITIONS("/wd4800") |
| 542 | # Disable performance warning about fopen insecurity. |
| 543 | ADD_DEFINITIONS("/wd4996") |
| 544 | # Disable warning about int64 to int32 conversion. Disabling |
| 545 | # this warning may not be correct; needs investigation. |
| 546 | # TODO(keir): Investigate these warnings in more detail. |
| 547 | ADD_DEFINITIONS("/wd4244") |
| 548 | # It's not possible to use STL types in DLL interfaces in a portable and |
| 549 | # reliable way. However, that's what happens with Google Log and Google Flags |
| 550 | # on Windows. MSVC gets upset about this and throws warnings that we can't do |
| 551 | # much about. The real solution is to link static versions of Google Log and |
| 552 | # Google Test, but that seems tricky on Windows. So, disable the warning. |
| 553 | ADD_DEFINITIONS("/wd4251") |
| 554 | |
| 555 | # Google Flags doesn't have their DLL import/export stuff set up correctly, |
| 556 | # which results in linker warnings. This is irrelevant for Ceres, so ignore |
| 557 | # the warnings. |
| 558 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4049") |
Petter Strandmark | b7ba934 | 2013-02-19 12:52:58 +0100 | [diff] [blame] | 559 | |
Alex Stewart | 21e7c0f | 2013-10-18 19:50:19 +0100 | [diff] [blame] | 560 | # Update the C/CXX flags for MSVC to use either the static or shared |
| 561 | # C-Run Time (CRT) library based on the user option: MSVC_USE_STATIC_CRT. |
| 562 | LIST(APPEND C_CXX_FLAGS |
| 563 | CMAKE_CXX_FLAGS |
| 564 | CMAKE_CXX_FLAGS_DEBUG |
| 565 | CMAKE_CXX_FLAGS_RELEASE |
| 566 | CMAKE_CXX_FLAGS_MINSIZEREL |
| 567 | CMAKE_CXX_FLAGS_RELWITHDEBINFO) |
| 568 | |
| 569 | FOREACH(FLAG_VAR ${C_CXX_FLAGS}) |
| 570 | IF (MSVC_USE_STATIC_CRT) |
| 571 | # Use static CRT. |
| 572 | IF (${FLAG_VAR} MATCHES "/MD") |
| 573 | STRING(REGEX REPLACE "/MD" "/MT" ${FLAG_VAR} "${${FLAG_VAR}}") |
| 574 | ENDIF (${FLAG_VAR} MATCHES "/MD") |
| 575 | ELSE (MSVC_USE_STATIC_CRT) |
| 576 | # Use shared, not static, CRT. |
| 577 | IF (${FLAG_VAR} MATCHES "/MT") |
| 578 | STRING(REGEX REPLACE "/MT" "/MD" ${FLAG_VAR} "${${FLAG_VAR}}") |
| 579 | ENDIF (${FLAG_VAR} MATCHES "/MT") |
| 580 | ENDIF (MSVC_USE_STATIC_CRT) |
| 581 | ENDFOREACH() |
| 582 | |
Petter Strandmark | b7ba934 | 2013-02-19 12:52:58 +0100 | [diff] [blame] | 583 | # Tuple sizes of 10 are used by Gtest. |
| 584 | ADD_DEFINITIONS("-D_VARIADIC_MAX=10") |
Keir Mierle | efe7ac6 | 2012-06-24 22:25:28 -0700 | [diff] [blame] | 585 | ENDIF (MSVC) |
| 586 | |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 587 | IF (UNIX) |
Sameer Agarwal | 395b4e9 | 2013-05-23 11:01:16 -0700 | [diff] [blame] | 588 | # GCC is not strict enough by default, so enable most of the warnings. |
Keir Mierle | 97ca0fb | 2012-09-18 15:52:36 -0700 | [diff] [blame] | 589 | SET(CMAKE_CXX_FLAGS |
Sameer Agarwal | 1ab7fde | 2013-07-08 10:03:49 -0700 | [diff] [blame] | 590 | "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers") |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 591 | ENDIF (UNIX) |
Keir Mierle | 97ca0fb | 2012-09-18 15:52:36 -0700 | [diff] [blame] | 592 | |
Sameer Agarwal | 3d6eceb | 2013-04-02 21:45:48 -0700 | [diff] [blame] | 593 | # Use a larger inlining threshold for Clang, since it hobbles Eigen, |
| 594 | # resulting in an unreasonably slow version of the blas routines. The |
| 595 | # -Qunused-arguments is needed because CMake passes the inline |
| 596 | # threshold to the linker and clang complains about it and dies. |
Sergey Sharybin | 72cc457 | 2013-06-19 20:59:08 +0600 | [diff] [blame] | 597 | IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
Sameer Agarwal | 3d6eceb | 2013-04-02 21:45:48 -0700 | [diff] [blame] | 598 | SET(CMAKE_CXX_FLAGS |
Alex Stewart | fc409e0 | 2013-10-01 18:25:55 +0100 | [diff] [blame] | 599 | "${CMAKE_CXX_FLAGS} -Qunused-arguments -mllvm -inline-threshold=600") |
| 600 | # Older versions of Clang (<= 2.9) do not support the 'return-type-c-linkage' |
| 601 | # option, so check for its presence before adding it to the default flags set. |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 602 | INCLUDE(CheckCXXCompilerFlag) |
Alex Stewart | fc409e0 | 2013-10-01 18:25:55 +0100 | [diff] [blame] | 603 | CHECK_CXX_COMPILER_FLAG("-Wno-return-type-c-linkage" |
| 604 | HAVE_RETURN_TYPE_C_LINKAGE) |
| 605 | IF (HAVE_RETURN_TYPE_C_LINKAGE) |
| 606 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type-c-linkage") |
| 607 | ENDIF(HAVE_RETURN_TYPE_C_LINKAGE) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 608 | ENDIF () |
Taylor Braun-Jones | b73148b | 2013-02-25 02:34:00 -0500 | [diff] [blame] | 609 | |
Alex Stewart | f5f21b5 | 2013-10-10 19:22:31 +0100 | [diff] [blame] | 610 | # Xcode 4.5.x used Clang 4.1 (Apple version), this has a bug that prevents |
| 611 | # compilation of Ceres. |
| 612 | IF (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 613 | EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} |
| 614 | ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion |
| 615 | OUTPUT_VARIABLE CLANG_VERSION |
| 616 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 617 | # Use version > 4.0 & < 4.2 to catch all 4.1(.x) versions. |
| 618 | IF (CLANG_VERSION VERSION_GREATER 4.0 AND |
| 619 | CLANG_VERSION VERSION_LESS 4.2) |
| 620 | MESSAGE(FATAL_ERROR "You are attempting to build Ceres on OS X using Xcode " |
| 621 | "4.5.x (Clang version: ${CLANG_VERSION}). This version of Clang has a " |
| 622 | "bug that prevents compilation of Ceres, please update to " |
| 623 | "Xcode >= 4.6.3.") |
| 624 | ENDIF (CLANG_VERSION VERSION_GREATER 4.0 AND |
| 625 | CLANG_VERSION VERSION_LESS 4.2) |
| 626 | ENDIF (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 627 | |
Keir Mierle | efe7ac6 | 2012-06-24 22:25:28 -0700 | [diff] [blame] | 628 | ADD_SUBDIRECTORY(internal/ceres) |
Arnaud Gelas | b12b906 | 2012-08-15 16:27:38 +0200 | [diff] [blame] | 629 | |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 630 | IF (BUILD_DOCUMENTATION) |
Arnaud Gelas | b12b906 | 2012-08-15 16:27:38 +0200 | [diff] [blame] | 631 | MESSAGE("-- Documentation building is enabled") |
| 632 | |
Pablo Speciale | c51b11c | 2013-03-12 00:56:56 -0700 | [diff] [blame] | 633 | # Generate the User's Guide (html). |
Arnaud Gelas | b12b906 | 2012-08-15 16:27:38 +0200 | [diff] [blame] | 634 | # The corresponding target is UserGuide, but is included in ALL. |
| 635 | ADD_SUBDIRECTORY(docs) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 636 | ENDIF (BUILD_DOCUMENTATION) |
Arnaud Gelas | 7316609 | 2012-08-20 15:40:41 +0200 | [diff] [blame] | 637 | |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 638 | IF (BUILD_EXAMPLES) |
Arnaud Gelas | 7316609 | 2012-08-20 15:40:41 +0200 | [diff] [blame] | 639 | MESSAGE("-- Build the examples.") |
| 640 | ADD_SUBDIRECTORY(examples) |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 641 | ELSE (BUILD_EXAMPLES) |
Arnaud Gelas | 7316609 | 2012-08-20 15:40:41 +0200 | [diff] [blame] | 642 | MESSAGE("-- Do not build any example.") |
Joydeep Biswas | aa20a6d | 2013-05-15 09:38:03 -0400 | [diff] [blame] | 643 | ENDIF (BUILD_EXAMPLES) |
Arnaud Gelas | 9ad27e8 | 2012-08-21 09:56:30 +0200 | [diff] [blame] | 644 | |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 645 | # Setup installation of Ceres public headers. |
| 646 | FILE(GLOB CERES_HDRS ${CMAKE_SOURCE_DIR}/include/ceres/*.h) |
| 647 | INSTALL(FILES ${CERES_HDRS} DESTINATION include/ceres) |
| 648 | |
| 649 | FILE(GLOB CERES_PUBLIC_INTERNAL_HDRS ${CMAKE_SOURCE_DIR}/include/ceres/internal/*.h) |
| 650 | INSTALL(FILES ${CERES_PUBLIC_INTERNAL_HDRS} DESTINATION include/ceres/internal) |
| 651 | |
| 652 | IF (MINIGLOG) |
| 653 | # Install miniglog header if being used as logging #includes appear in |
| 654 | # installed public Ceres headers. |
| 655 | INSTALL(FILES ${CMAKE_SOURCE_DIR}/internal/ceres/miniglog/glog/logging.h |
| 656 | DESTINATION include/ceres/internal/miniglog/glog) |
| 657 | ENDIF (MINIGLOG) |
| 658 | |
Arnaud Gelas | 9ad27e8 | 2012-08-21 09:56:30 +0200 | [diff] [blame] | 659 | # Add an uninstall target to remove all installed files. |
| 660 | CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in" |
| 661 | "${CMAKE_BINARY_DIR}/cmake/uninstall.cmake" |
| 662 | IMMEDIATE @ONLY) |
| 663 | |
| 664 | ADD_CUSTOM_TARGET(uninstall |
| 665 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake/uninstall.cmake) |
Pablo Speciale | 16dbf11 | 2013-03-11 14:44:02 -0700 | [diff] [blame] | 666 | |
Alex Stewart | 54fc942 | 2013-11-14 11:42:00 +0000 | [diff] [blame] | 667 | # Set relative install paths, which are appended to CMAKE_INSTALL_PREFIX to |
| 668 | # generate the absolute install paths. |
Pablo Speciale | f519ff7 | 2013-09-05 00:51:37 +0200 | [diff] [blame] | 669 | IF (WIN32) |
Alex Stewart | 54fc942 | 2013-11-14 11:42:00 +0000 | [diff] [blame] | 670 | SET(RELATIVE_CMAKECONFIG_INSTALL_DIR CMake) |
Pablo Speciale | f519ff7 | 2013-09-05 00:51:37 +0200 | [diff] [blame] | 671 | ELSE () |
Alex Stewart | 54fc942 | 2013-11-14 11:42:00 +0000 | [diff] [blame] | 672 | SET(RELATIVE_CMAKECONFIG_INSTALL_DIR share/Ceres) |
Pablo Speciale | f519ff7 | 2013-09-05 00:51:37 +0200 | [diff] [blame] | 673 | ENDIF () |
Pablo Speciale | 16dbf11 | 2013-03-11 14:44:02 -0700 | [diff] [blame] | 674 | |
| 675 | # This "exports" all targets which have been put into the export set |
| 676 | # "CeresExport". This means that CMake generates a file with the given |
| 677 | # filename, which can later on be loaded by projects using this package. |
| 678 | # This file contains ADD_LIBRARY(bar IMPORTED) statements for each target |
| 679 | # in the export set, so when loaded later on CMake will create "imported" |
| 680 | # library targets from these, which can be used in many ways in the same way |
| 681 | # as a normal library target created via a normal ADD_LIBRARY(). |
| 682 | INSTALL(EXPORT CeresExport |
Alex Stewart | 54fc942 | 2013-11-14 11:42:00 +0000 | [diff] [blame] | 683 | DESTINATION ${RELATIVE_CMAKECONFIG_INSTALL_DIR} FILE CeresTargets.cmake) |
Pablo Speciale | 16dbf11 | 2013-03-11 14:44:02 -0700 | [diff] [blame] | 684 | |
| 685 | # Figure out the relative path from the installed Config.cmake file to the |
| 686 | # install prefix (which may be at runtime different from the chosen |
| 687 | # CMAKE_INSTALL_PREFIX if under Windows the package was installed anywhere) |
| 688 | # This relative path will be configured into the CeresConfig.cmake. |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 689 | FILE(RELATIVE_PATH INSTALL_ROOT_REL_CONFIG_INSTALL_DIR |
Alex Stewart | 54fc942 | 2013-11-14 11:42:00 +0000 | [diff] [blame] | 690 | ${CMAKE_INSTALL_PREFIX}/${RELATIVE_CMAKECONFIG_INSTALL_DIR} |
| 691 | ${CMAKE_INSTALL_PREFIX}) |
Pablo Speciale | 16dbf11 | 2013-03-11 14:44:02 -0700 | [diff] [blame] | 692 | |
| 693 | # Create a CeresConfig.cmake file. <name>Config.cmake files are searched by |
| 694 | # FIND_PACKAGE() automatically. We configure that file so that we can put any |
| 695 | # information we want in it, e.g. version numbers, include directories, etc. |
| 696 | CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/CeresConfig.cmake.in" |
| 697 | "${CMAKE_CURRENT_BINARY_DIR}/CeresConfig.cmake" @ONLY) |
| 698 | |
| 699 | # Additionally, when CMake has found a CeresConfig.cmake, it can check for a |
| 700 | # CeresConfigVersion.cmake in the same directory when figuring out the version |
| 701 | # of the package when a version has been specified in the FIND_PACKAGE() call, |
| 702 | # e.g. FIND_PACKAGE(Ceres [1.4.2] REQUIRED). The version argument is optional. |
| 703 | CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/CeresConfigVersion.cmake.in" |
| 704 | "${CMAKE_CURRENT_BINARY_DIR}/CeresConfigVersion.cmake" @ONLY) |
| 705 | |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 706 | # Install these files into the same directory as the generated exports-file, |
| 707 | # we include the FindPackage scripts for libraries whose headers are included |
| 708 | # in the public API of Ceres and should thus be present in CERES_INCLUDE_DIRS. |
Pablo Speciale | 16dbf11 | 2013-03-11 14:44:02 -0700 | [diff] [blame] | 709 | INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/CeresConfig.cmake" |
| 710 | "${CMAKE_CURRENT_BINARY_DIR}/CeresConfigVersion.cmake" |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 711 | "${CMAKE_SOURCE_DIR}/cmake/FindEigen.cmake" |
| 712 | "${CMAKE_SOURCE_DIR}/cmake/FindGlog.cmake" |
Alex Stewart | 54fc942 | 2013-11-14 11:42:00 +0000 | [diff] [blame] | 713 | DESTINATION ${RELATIVE_CMAKECONFIG_INSTALL_DIR}) |