Skip to content
This repository has been archived by the owner on Oct 26, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…solver

# By Sameer Agarwal (6) and others
# Via Sameer Agarwal
* 'master' of https://ceres-solver.googlesource.com/ceres-solver:
  Fixes swapped verboselevel and condition.
  Fixed warning : 'va_copy' : macro redefinition MSVC 2013 has got va_copy Compare http://msdn.microsoft.com/en-us/library/kb57fad8(v=vs.110).aspx and http://msdn.microsoft.com/en-us/library/kb57fad8.aspx.
  Removed MSVC warnings These are warnings which show up when using Ceres.
  Remove BlockRandomAccessCRSMatrix.
  Fix some 80col violations and reflow the comments in cmake.in file.
  Remove some errant tabs.
  Lazily initialize the bounds arrays in ParameterBlock.
  Add the (2,4,8) template specialization.
  Export Ceres compile definitions to targets compiled against Ceres.
  Fix a bug in Minimizer::RunCallbacks.
  • Loading branch information
Yuliy Schwartzburg committed May 9, 2014
2 parents c204174 + cbf9554 commit fbc880f
Show file tree
Hide file tree
Showing 23 changed files with 372 additions and 527 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,23 @@ IF (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
CLANG_VERSION VERSION_LESS 4.2)
ENDIF (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

# Get the complete list of any added compile definitions so that we can
# export them. Currently we export all Ceres compile definitions to users
# of Ceres via FindPackage() except CERES_BUILDING_SHARED_LIBRARY (if present)
# which controls the behaviour of the CERES_EXPORT macro for MSVC, which
# we substitute for CERES_USING_SHARED_LIBRARY, which is what users of
# Ceres should call in MSVC.
GET_DIRECTORY_PROPERTY(CERES_INTERFACE_COMPILE_DEFINITIONS
DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
# Substitute CERES_BUILDING_SHARED_LIBRARY with CERES_USING_SHARED_LIBRARY
# if building Ceres as a shared library.
IF (BUILD_SHARED_LIBS)
LIST(REMOVE_ITEM CERES_INTERFACE_COMPILE_DEFINITIONS
CERES_BUILDING_SHARED_LIBRARY)
LIST(APPEND CERES_INTERFACE_COMPILE_DEFINITIONS
CERES_USING_SHARED_LIBRARY)
ENDIF()

ADD_SUBDIRECTORY(internal/ceres)

IF (BUILD_DOCUMENTATION)
Expand Down
111 changes: 75 additions & 36 deletions cmake/CeresConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,60 @@
#
# This module defines the following variables:
#
# Ceres_FOUND / CERES_FOUND: True iff Ceres has been successfully found. Both
# variables are set as although FindPackage() only
# references Ceres_FOUND in Config mode, given the
# conventions for <package>_FOUND when FindPackage()
# is called in Module mode, users could reasonably
# expect to use CERES_FOUND instead.
# Ceres_FOUND / CERES_FOUND: True iff Ceres has been successfully
# found. Both variables are set as although
# FindPackage() only references Ceres_FOUND
# in Config mode, given the conventions for
# <package>_FOUND when FindPackage() is
# called in Module mode, users could
# reasonably expect to use CERES_FOUND
# instead.
#
# CERES_VERSION: Version of Ceres found.
# CERES_INCLUDE_DIRS: Include directories for Ceres and the dependencies which
# appear in the Ceres public API and are thus required to
# use Ceres.
# CERES_LIBRARIES: Libraries for Ceres and all dependencies against which Ceres
# was compiled. This will not include any optional dependencies
# that were disabled when Ceres was compiled.
#
# The following variables are also defined for legacy compatibility only.
# Any new code should not use them as they do not conform to the standard CMake
# FindPackage naming conventions.
# CERES_INCLUDE_DIRS: Include directories for Ceres and the
# dependencies which appear in the Ceres public
# API and are thus required to use Ceres.
# CERES_LIBRARIES: Libraries for Ceres and all
# dependencies against which Ceres was
# compiled. This will not include any optional
# dependencies that were disabled when Ceres was
# compiled.
#
# CERES_INTERFACE_COMPILE_DEFINITIONS: List of compile definitions
# which should be used when
# compiling a target that uses Ceres
# Note that these variables will NOT
# have a -D prefix appended.
#
# IMPORTANT: The contents of CERES_INTERFACE_COMPILE_DEFINITIONS will
# be AUTOMATICALLY added for you, either via the CMake
# function target_compile_definitions() in CMake >= 2.8.11,
# or via a call to add_definitions() in CMake < 2.8.11.
#
# The following variables are also defined for legacy compatibility
# only. Any new code should not use them as they do not conform to
# the standard CMake FindPackage naming conventions.
#
# CERES_INCLUDES = ${CERES_INCLUDE_DIRS}.

# Called if we failed to find Ceres or any of it's required dependencies,
# unsets all public (designed to be used externally) variables and reports
# error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
MACRO(CERES_REPORT_NOT_FOUND REASON_MSG)
# FindPackage() only references Ceres_FOUND, and requires it to be explicitly
# set FALSE to denote not found (not merely undefined).
# FindPackage() only references Ceres_FOUND, and requires it to be
# explicitly set FALSE to denote not found (not merely undefined).
SET(Ceres_FOUND FALSE)
SET(CERES_FOUND FALSE)
UNSET(CERES_INCLUDE_DIRS)
UNSET(CERES_LIBRARIES)
UNSET(CERES_INTERFACE_COMPILE_DEFINITIONS)

# Reset the CMake module path to its state when this script was called.
SET(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH})

# Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage()
# use the camelcase library name, not uppercase.
# Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by
# FindPackage() use the camelcase library name, not uppercase.
IF (Ceres_FIND_QUIETLY)
MESSAGE(STATUS "Failed to find Ceres - " ${REASON_MSG} ${ARGN})
ELSE (Ceres_FIND_REQUIRED)
Expand All @@ -89,20 +107,20 @@ ENDMACRO(CERES_REPORT_NOT_FOUND)
GET_FILENAME_COMPONENT(CURRENT_CONFIG_INSTALL_DIR
"${CMAKE_CURRENT_LIST_FILE}" PATH)

# Record the state of the CMake module path when this script was called so
# that we can ensure that we leave it in the same state on exit as it was
# on entry, but modify it locally.
# Record the state of the CMake module path when this script was
# called so that we can ensure that we leave it in the same state on
# exit as it was on entry, but modify it locally.
SET(CALLERS_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
# Reset CMake module path to the installation directory of this script,
# thus we will use the FindPackage() scripts shipped with Ceres to find
# Ceres' dependencies, even if the user has equivalently named FindPackage()
# scripts in their project.
# Reset CMake module path to the installation directory of this
# script, thus we will use the FindPackage() scripts shipped with
# Ceres to find Ceres' dependencies, even if the user has equivalently
# named FindPackage() scripts in their project.
SET(CMAKE_MODULE_PATH ${CURRENT_CONFIG_INSTALL_DIR})

# Build the absolute root install directory as a relative path (determined when
# Ceres was configured & built) from the current install directory for this
# this file. This allows for the install tree to be relocated, after Ceres was
# built, outside of CMake.
# Build the absolute root install directory as a relative path
# (determined when Ceres was configured & built) from the current
# install directory for this this file. This allows for the install
# tree to be relocated, after Ceres was built, outside of CMake.
GET_FILENAME_COMPONENT(CURRENT_ROOT_INSTALL_DIR
${CURRENT_CONFIG_INSTALL_DIR}/@INSTALL_ROOT_REL_CONFIG_INSTALL_DIR@ ABSOLUTE)
IF (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR})
Expand All @@ -128,9 +146,10 @@ IF (NOT EXISTS ${CERES_INCLUDE_DIR}/ceres/ceres.h)
"partially relocated outside of CMake after Ceres was built.")
ENDIF (NOT EXISTS ${CERES_INCLUDE_DIR}/ceres/ceres.h)

# Append the include directories for all (potentially optional) dependencies
# with which Ceres was compiled, the libraries themselves come in via
# CeresTargets-<release/debug>.cmake as link libraries for Ceres target.
# Append the include directories for all (potentially optional)
# dependencies with which Ceres was compiled, the libraries themselves
# come in via CeresTargets-<release/debug>.cmake as link libraries for
# Ceres target.
SET(CERES_INCLUDE_DIRS ${CERES_INCLUDE_DIR})

# Eigen.
Expand Down Expand Up @@ -190,6 +209,24 @@ ENDIF (NOT TARGET ceres AND NOT Ceres_BINARY_DIR)
# Set the expected XX_LIBRARIES variable for FindPackage().
SET(CERES_LIBRARIES ceres)

# If Ceres was compiled with CMake < 2.8.11, we were not able to use
# the new (in 2.8.11) target_compile_definitions() function to append
# the required compile definitions to use when compiling a target that
# uses Ceres to the Ceres library target. As such, we need to use
# add_definitions() to ensure that they will be present. This is a
# blunt instrument, as it will add the Ceres definitions to _all_
# targets declared from this point on in the caller's project.
# Hoever, without requiring the user to explicitly set the flags
# themselves, this is the only way in CMake versions < 2.8.11.
SET (CERES_COMPILED_CMAKE_VERSION @CMAKE_VERSION@)
SET (CERES_INTERFACE_COMPILE_DEFINITIONS @CERES_INTERFACE_COMPILE_DEFINITIONS@)
IF (CERES_COMPILED_CMAKE_VERSION VERSION_LESS 2.8.11)
# The definitions will have been stripped of -D, add it back.
FOREACH(DEF ${CERES_INTERFACE_COMPILE_DEFINITIONS})
ADD_DEFINITIONS("-D${DEF}")
ENDFOREACH()
ENDIF()

# Set legacy include directories variable for backwards compatibility.
SET(CERES_INCLUDES ${CERES_INCLUDE_DIRS})

Expand All @@ -200,7 +237,9 @@ SET(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH})
# found Ceres and all required dependencies.
MESSAGE(STATUS "Found Ceres version: ${CERES_VERSION} "
"installed in: ${CURRENT_ROOT_INSTALL_DIR}")
# Set CERES_FOUND to be equivalent to Ceres_FOUND, which is set to TRUE by
# FindPackage() if this file is found and run, and after which Ceres_FOUND
# is not (explicitly, i.e. undefined does not count) set to FALSE.

# Set CERES_FOUND to be equivalent to Ceres_FOUND, which is set to
# TRUE by FindPackage() if this file is found and run, and after which
# Ceres_FOUND is not (explicitly, i.e. undefined does not count) set
# to FALSE.
SET(CERES_FOUND TRUE)
6 changes: 3 additions & 3 deletions include/ceres/fpclassify.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ namespace ceres {

#if defined(_MSC_VER)

inline bool IsFinite (double x) { return _finite(x); }
inline bool IsInfinite(double x) { return !_finite(x) && !_isnan(x); }
inline bool IsNaN (double x) { return _isnan(x); }
inline bool IsFinite (double x) { return _finite(x) != 0; }
inline bool IsInfinite(double x) { return _finite(x) == 0 && _isnan(x) == 0; }
inline bool IsNaN (double x) { return _isnan(x) != 0; }
inline bool IsNormal (double x) {
int classification = _fpclass(x);
return classification == _FPCLASS_NN ||
Expand Down
2 changes: 1 addition & 1 deletion include/ceres/local_parameterization.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class CERES_EXPORT SubsetParameterization : public LocalParameterization {
double* x_plus_delta) const;
virtual bool ComputeJacobian(const double* x,
double* jacobian) const;
virtual int GlobalSize() const { return constancy_mask_.size(); }
virtual int GlobalSize() const { return static_cast<int>(constancy_mask_.size()); }
virtual int LocalSize() const { return local_size_; }

private:
Expand Down
18 changes: 16 additions & 2 deletions internal/ceres/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ SET(CERES_INTERNAL_SRC
block_evaluate_preparer.cc
block_jacobi_preconditioner.cc
block_jacobian_writer.cc
block_random_access_crs_matrix.cc
block_random_access_dense_matrix.cc
block_random_access_diagonal_matrix.cc
block_random_access_matrix.cc
Expand Down Expand Up @@ -177,6 +176,22 @@ SET_TARGET_PROPERTIES(ceres PROPERTIES
VERSION ${CERES_VERSION}
SOVERSION ${CERES_VERSION_MAJOR}
)

# If we are using CMake >= 2.8.11, make use of the target_compile_definitions()
# function to append the compile definitions to the exported ceres target, thus
# any library that finds Ceres via CMake, then adds Ceres to one of its own
# targets will be compiled with the Ceres compile definitions defined. This
# is important for any defines that appear in the installed Ceres header files
# e.g those related to shared_ptr.
#
# If we are using CMake < 2.8.11, then we will have added an add_definitions()
# call in the CeresConfig.cmake file, which whilst achieving a similar effect,
# is more of a blunt instrument, as the Ceres definitions will also be added
# to targets in the users project that do not use Ceres.
IF (CMAKE_VERSION VERSION_EQUAL 2.8.11 OR
CMAKE_VERSION VERSION_GREATER 2.8.11)
TARGET_COMPILE_DEFINITIONS(ceres INTERFACE ${CERES_INTERFACE_COMPILE_DEFINITIONS})
ENDIF()
TARGET_LINK_LIBRARIES(ceres ${CERES_LIBRARY_DEPENDENCIES})

INSTALL(TARGETS ceres
Expand Down Expand Up @@ -208,7 +223,6 @@ IF (BUILD_TESTING AND GFLAGS)
CERES_TEST(autodiff)
CERES_TEST(autodiff_cost_function)
CERES_TEST(autodiff_local_parameterization)
CERES_TEST(block_random_access_crs_matrix)
CERES_TEST(block_random_access_dense_matrix)
CERES_TEST(block_random_access_diagonal_matrix)
CERES_TEST(block_random_access_sparse_matrix)
Expand Down
Loading

0 comments on commit fbc880f

Please sign in to comment.