Squashed 'third_party/ceres/' changes from e51e9b46f..399cda773
399cda773 Update build documentation to reflect detection of Eigen via config mode
bb127272f Fix typos.
a0ec5c32a Update version history for 2.0.0RC2
3f6d27367 Unify symbol visibility configuration for all compilers
29c2912ee Unbreak the bazel build some more
bf47e1a36 Fix the Bazel build.
600e8c529 fix minor typos
bdcdcc78a update docs for changed cmake usage
3f69e5b36 Corrections from William Rucklidge
8bfdb02fb Rewrite uses of VLOG_IF and LOG_IF.
d1b35ffc1 Corrections from William Rucklidge
f34e80e91 Add dividers between licenses.
65c397dae Fix formatting
f63b1fea9 Add the MIT license text corresponding to the libmv derived files.
542613c13 minor formatting fix for trust_region_minimizer.cc
6d9e9843d Remove inclusion of ceres/eigen.h
eafeca5dc Fix a logging bug in TrustRegionMinimizer.
1fd0be916 Fix default initialisation of IterationCallback::cost
137bbe845 add info about clang-format to contributing docs
d3f66d77f fix formatting generated files (best effort)
a9c7361c8 minor formatting fix (wrongly updated in earlier commit)
7b8f675bf fix formatting for (non-generated) internal source files
921368ce3 Fix a number of typos in covariance.h
7b6b2491c fix formatting for examples
82275d8a4 some fixes for Linux and macOS install docs
9d762d74f fix formatting for public header files
c76478c48 gitignore *.pyc
4e69a475c Fix potential for mismatched release/debug TBB libraries
8e1d8e32a A number of small changes.
368a738e5 AutoDiffCostFunction: optional ownership
8cbd721c1 Add erf and erfc to jet.h, including tests in jet_test.cc
31366cff2 Benchmarks for dynamic autodiff.
29fb08aea Use CMAKE_PREFIX_PATH to pass Homebrew install location
242c703b5 Minor fixes to the documentation
79bbf9510 Add changelog for 2.0.0
41d05f13d Fix lint errors in evaluation_callback_test.cc
4b67903c1 Remove unused variables from problem_test.cc
10449fc36 Add Apache license to the LICENSE file for FixedArray
8c3ecec6d Fix some minor errors in IterationCallback docs
7d3ffcb42 Remove forced CONFIG from find_package(Eigen3)
a029fc0f9 Use latest FindTBB.cmake from VTK project
aa1abbc57 Replace use of GFLAGS_LIBRARIES with export gflags target
db2af1be8 Add Problem::EvaluateResidualBlockAssumingParametersUnchanged
ab4ed32cd Replace NULL with nullptr in the documentation.
ee280e27a Allow SubsetParameterization to accept an empty vector of constant parameters.
4b8c731d8 Fix a bug in DynamicAutoDiffCostFunction
5cb5b35a9 Fixed incorrect argument name in RotationMatrixToQuaternion()
e39d9ed1d Add a missing term and remove a superfluous word
27cab77b6 Reformulate some sentences
8ac6655ce Fix documentation formatting issues
7ef83e075 Update minimum required C++ version for Ceres to C++14
1d75e7568 Improve documentation for LocalParameterization
763398ca4 Update the section on Preconditioners
a614f788a Call EvaluationCallback before evaluating the fixed cost.
70308f7bb Simplify documentation generation.
e886d7e65 Reduce the number of minimizer iterations in evaluation_callback_test.cc
9483e6f2f Simplify DynamicCompressedRowJacobianWriter::Write
323cc55bb Update the version in package.xml to 2.0.0.
303b078b5 Fix few typos and alter a NULL to nullptr.
cca93fed6 Bypass Ceres' FindGlog.cmake in CeresConfig.cmake if possible
77fc1d0fc Use build_depend for private dependencies in Catkin package.xml
a09682f00 Fix MSVC version check to support use of clang-cl front-end
b70687fcc Add namespace qualified Ceres::ceres CMake target
99efa54bd Replace type aliases deprecated/removed in C++17/C++20 from FixedArray
adb973e4a NULL -> nullptr
27b717951 Respect FIND_QUIETLY flag in cmake config file
646959ef1 Do not export class template LineParameterization
1f128d070 Change the type of parameter index/offset to match their getter/setter
072c8f070 Initialize integer variables with integer instead of double
8c36bcc81 Use inline & -inlinehint-threshold in auto-diff benchmarks
57cf20aa5 static const -> static constexpr where we can.
40b27482a Add std::numeric_limit specialization for Jets
e751d6e4f Remove AutodiffCodegen
e9eb76f8e Remove AutodiffCodegen CMake integration
9435e08a7 More clang-tidy and wjr@ comment fixes
d93fac4b7 Remove AutodiffCodegen Tests
2281c6ed2 Fixes for comments from William Rucklidge
d797a87a4 Use Ridders' method in GradientChecker.
41675682d Fix a MSVC type deduction bug in ComputeHouseholderVector
947ec0c1f Remove AutodiffCodegen autodiff benchmarks
27183d661 Allow LocalParameterizations to have zero local size.
7ac7d79dc Remove HelloWorldCodegen example
8c8738bf8 Add photometric and relative-pose residuals to autodiff benchmarks
9f7fb66d6 Add a constant cost function to the autodiff benchmarks
ab0d373e4 Fix a comment in autodiff.h
27bb99714 Change SVD algorithm in covariance computation.
84fdac38e Add const to GetCovarianceMatrix*
6bde61d6b Add line local parameterization.
2c1c0932e Update documentation in autodiff.h
8904fa488 Inline Jet initialization in Autodiff
18a464d4e Remove an errant CR from local_parameterization.cc
5c85f2179 Use ArraySelector in Autodiff
80477ff07 Add class ArraySelector
e7a30359e Pass kNumResiduals to Autodiff
f339d71dd Refactor the automatic differentiation benchmarks.
d37b4cb15 Fix some include headers in codegen/test_utils.cc/h
550766e6d Add Autodiff Brdf Benchmark
8da9876e7 Add more autodiff benchmarks
6da364713 Fix Tukey loss function
cf4185c4e Add Codegen BA Benchmark
75dd30fae Simplify GenerateCodeForFunctor
9049688c6 Default Initialize ExpressionRef to Zero
bf1aff2f0 Fix 3+ nested Jet constructor
92d6541c7 Move Codegen files into codegen/ directory
8e962f37d Add Autodiff Codegen Tests
13c7a22ce Codegen Optimizer API
90799e29e Fix install and unnecessary string copy
032d5844c AutoDiff Code Generation - CMake Integration
d82de91b8 Add ExpressionGraph::Erase(ExpressionId)
c8e35e19f Add namespaces to generated functions and constants
75e575cae Fix use of incomplete type in defaulted Problem methods
8def19616 Remove ExpressionRef Move Constructor
f26f95410 Fix windows MSVC build.
fdf9cfd32 Add functions to find the matching ELSE, ENDIF expressions
678c05b28 Fix invert PSD matrix.
a384a7e96 Remove not used using declaration
a60136b7a Add COMMENT ExpressionType
f212c9295 Let Problem::SetParameterization be called more than once.
a3696835b use CMake function to create CeresConfigVersion
67fcff918 Make Problem movable.
19728e72d Add documentation for Problem::IsParameterBlockConstant
ba6e5fb4a Make the custom uninstall target optional
8547cbd55 Make EventLogger more efficient.
edb8322bd Update the minimum required version of Eigen to 3.3.
aa6ef417f Specify Eigen3_DIR in iOS and Android Travis CI builds
4655f2549 Use find_package() instead of find_dependency() in CeresConfig.cmake
a548766d1 Use glfags target
33dd469a5 Use Eigen3::Eigen target
47e784bb4 NULL-jacobians are handled correctly in generated autodiff code
edd54b83e Update Jet.h and rotation.h to use the new IF/ELSE macros
848c1f90c Update return type in code generator and add tests for logical functions
5010421bb Add the expression return type as a member to Expression
f4dc670ee Improve testing of the codegen system
572ec4a5a Rework Expression creation and insertion
c7337154e Disable the code generation module by default
7fa0f3db4 Explicitly state PUBLIC/PRIVATE when linking
4362a2169 Run clang-format on the public headers. Also update copyright year.
c56702aac Fix installation of codegen headers
0d03e74dc Fix the include in the autodiff codegen example
d16026440 Autodiff Codegen Part 4: Public API
d1703db45 Moved AutoDiffCodeGen macros to a separate (public) header
5ce6c063d Fix ExpressionRef copy constructor and add a move constructor
a90b5a12c Pass ExpressionRef by const reference instead of by value
ea057678c Remove MakeFunctionCall() and add test for Ternary
1084c5460 Quote all configure-expanded paths
3d756b07c Test Expressions with 'insert' instead of a macro
486d81812 Add ExpressionGraph::InsertExpression
3831a1dd3 Expression and ExpressionGraph comparison
9bb1dcb84 Remove definition of ExpressionRef::ExpressionRef(double&);
5be2e4883 Autodiff Codegen Part 3: CodeGenerator
6cd633043 Remove unused ExpressionTypes
7d0d69a4d Fix ExpressionRef
6ba8c57d2 Fix expression_test IsArithmetic
2b494cfb3 Update Travis CI to Bionic & Xcode 11.2
a3dde6877 Require Xcode >= 11.2 on macOS 10.15 (Catalina)
6fd4f072d Autodiff Codegen Part 2: Conditionals
52d6477a4 Detect and disable -fstack-check on macOS 10.15 with Xcode 11
46ca461b7 Fix `gradient_check_relative_precision` docs typo
4247d420f Autodiff Codegen Part 1: Expressions
ba62397d8 Run clang-format on jet.h
667062dcc Introduce BlockSparseMatrixData
17becf461 Remove a CHECK failure from covariance_impl.cc
d7f428e5c Add a missing cast in rotation.h
ea4d66e7e clang-tidy fixes.
be15b842a Integrate the SchurEliminatorForOneFBlock for the case <2,3,6>
087b28f1b Remove use of SetUsage as it creates compilation problems.
573046d7f Protect declarations of lapack functions under CERES_NO_LAPACK
71d638ef3 Add a specialized schur eliminator.
2ffddaccf Use override & final instead of just using virtual.
e4577dd6d Use override instead of virtual for subclasses.
3e5db5bc2 Fixing documentation typo.
82d325b73 Avoid memory allocations in Accelerate Sparse[Refactor/Solve]().
f66b51382 Fix some clang-tidy warnings.
0428e2dd0 Fix missing #include of <memory>
487c1aa51 Expose SubsetPreconditioner in the API
bf709ecac Move EvaluationCallback from Solver::Options to Problem::Options.
059bcb7f8 Drop ROS dependency on catkin
c4dbc927d Default to any other sparse libraries over Accelerate
db1f5b57a Allow some methods in Problem to use const double*.
a60c14525 Explicitly delete the copy constructor and copy assignment operator
084042c25 Lint changes from William Rucklidge
93d869020 Use selfAdjoingView<Upper> in InvertPSDMatrix.
a0cd0854a Speed up InvertPSDMatrix
7b53262b7 Allow Solver::Options::max_num_line_search_step_size_iterations = 0.
3e2cdca54 Make LineSearchMinizer work correctly with negative valued functions.
3ff12a878 Fix a clang-tidy warning in problem_test.cc
57441fe90 Fix two bugs.
1b852c57e Add Problem::EvaluateResidualBlock.
54ba6c27b Fix missing declaration warnings in Ceres code
fac46d50e Modernize ProductParameterization.
53dc6213f Add some missing string-to-enum-to-string convertors.
c0aa9a263 Add checks in rotation.h for inplace operations.
0f57fa82d Update Bazel WORKSPACE for newest Bazel
f8e5fba7b TripletSparseMatrix: guard against self-assignment
939253c20 Fix Eigen alignment issues.
bf67daf79 Add the missing <array> header to fixed_array.h
25e1cdbb6 Switch to FixedArray implementation from abseil.
d467a627b IdentityTransformation -> IdentityParameterization
eaec6a9d0 Fix more typos in CostFunctionToFunctor documentation.
99b5aa4aa Fix typos in CostFunctionToFunctor documentation.
ee7e2cb3c Set Homebrew paths via HINTS not CMAKE_PREFIX_PATH
4f8a01853 Revert "Fix custom Eigen on macos (EIGEN_INCLUDE_DIR_HINTS)"
e6c5c7226 Fix custom Eigen on macos (EIGEN_INCLUDE_DIR_HINTS)
5a56d522e Add the 3,3,3 template specialization.
df5c23116 Reorder initializer list to make -Wreorder happy
0fcfdb0b4 Fix the build breakage caused by the last commit.
9b9e9f0dc Reduce machoness of macro definition in cost_functor_to_function_test.cc
21d40daa0 Remove UTF-8 chars
9350e57a4 Enable optional use of sanitizers
0456edffb Update Travis CI Linux distro to 16.04 (Xenial)
bef0dfe35 Fix a typo in cubic_interpolation.h
056ba9bb1 Add AutoDiffFirstOrderFunction
6e527392d Update googletest/googlemock to db9b85e2.
1b2940749 Clarify documentation of BiCubicInterpolator::Evaluate for out-of-bounds values
Change-Id: Id61dd832e8fbe286deb0799aa1399d4017031dae
git-subtree-dir: third_party/ceres
git-subtree-split: 399cda773035d99eaf1f4a129a666b3c4df9d1b1
diff --git a/cmake/AddCompileFlagsIfSupported.cmake b/cmake/AddCompileFlagsIfSupported.cmake
new file mode 100644
index 0000000..1af9ee8
--- /dev/null
+++ b/cmake/AddCompileFlagsIfSupported.cmake
@@ -0,0 +1,51 @@
+# Ceres Solver - A fast non-linear least squares minimizer
+# Copyright 2017 Google Inc. All rights reserved.
+# http://ceres-solver.org/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# * Neither the name of Google Inc. nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# Author: sergey.vfx@gmail.com (Sergey Sharybin)
+
+function(add_cxx_compiler_flag_if_supported
+ AGGREGATED_CXX_FLAGS_VAR
+ FLAG_TO_ADD_IF_SUPPORTED)
+ include(CheckCXXCompilerFlag)
+ # Use of whitespace or '-' in variable names (used by CheckCXXSourceCompiles
+ # as #defines) will trigger errors.
+ string(STRIP "${FLAG_TO_ADD_IF_SUPPORTED}" FLAG_TO_ADD_IF_SUPPORTED)
+ # Build an informatively named test result variable so that it will be evident
+ # which tests were performed/succeeded in the CMake output, e.g for -Wall:
+ #
+ # -- Performing Test CHECK_CXX_FLAG_Wall - Success
+ #
+ # NOTE: This variable is also used to cache test result.
+ string(REPLACE "-" "_" CHECK_CXX_FLAG
+ "CHECK_CXX_FLAG${FLAG_TO_ADD_IF_SUPPORTED}")
+ check_cxx_compiler_flag(${FLAG_TO_ADD_IF_SUPPORTED} ${CHECK_CXX_FLAG})
+ if (${CHECK_CXX_FLAG})
+ set(${AGGREGATED_CXX_FLAGS_VAR}
+ "${${AGGREGATED_CXX_FLAGS_VAR}} ${FLAG_TO_ADD_IF_SUPPORTED}" PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/cmake/CeresCompileOptionsToComponents.cmake b/cmake/CeresCompileOptionsToComponents.cmake
index ccf0fa2..5be0fb2 100644
--- a/cmake/CeresCompileOptionsToComponents.cmake
+++ b/cmake/CeresCompileOptionsToComponents.cmake
@@ -84,6 +84,8 @@
CERES_RESTRICT_SCHUR_SPECIALIZATION "SchurSpecializations")
add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
CERES_USE_OPENMP "OpenMP;Multithreading")
+ add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
+ CERES_USE_CXX_THREADS "Multithreading")
# Remove duplicates of SparseLinearAlgebraLibrary if multiple sparse backends
# are present.
list(REMOVE_DUPLICATES ${CERES_COMPONENTS_VAR})
diff --git a/cmake/CeresConfig.cmake.in b/cmake/CeresConfig.cmake.in
index 0ef7021..e5e2976 100644
--- a/cmake/CeresConfig.cmake.in
+++ b/cmake/CeresConfig.cmake.in
@@ -60,6 +60,8 @@
# CMake target already includes the definition of its public
# include directories.
+include(CMakeFindDependencyMacro)
+
# Called if we failed to find Ceres or any of its required dependencies,
# unsets all public (designed to be used externally) variables and reports
# error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
@@ -89,6 +91,18 @@
return()
endmacro(CERES_REPORT_NOT_FOUND)
+
+# ceres_message([mode] "message text")
+#
+# Wraps the standard cmake 'message' command, but suppresses output
+# if the QUIET flag was passed to the find_package(Ceres ...) call.
+function(ceres_message)
+ if (NOT Ceres_FIND_QUIETLY)
+ message(${ARGN})
+ endif()
+endfunction()
+
+
# ceres_pretty_print_cmake_list( OUTPUT_VAR [item1 [item2 ... ]] )
#
# Sets ${OUTPUT_VAR} in the caller's scope to a human-readable string
@@ -127,7 +141,7 @@
# 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
- ${CERES_CURRENT_CONFIG_DIR}/@INSTALL_ROOT_REL_CONFIG_INSTALL_DIR@
+ "${CERES_CURRENT_CONFIG_DIR}/@INSTALL_ROOT_REL_CONFIG_INSTALL_DIR@"
ABSOLUTE)
if (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR})
ceres_report_not_found(
@@ -142,7 +156,7 @@
# Ceres was exported from the build tree.
set(CERES_EXPORTED_BUILD_DIR ${CERES_CURRENT_CONFIG_DIR})
get_filename_component(CERES_EXPORTED_SOURCE_DIR
- ${CERES_EXPORTED_BUILD_DIR}/@INSTALL_ROOT_REL_CONFIG_INSTALL_DIR@
+ "${CERES_EXPORTED_BUILD_DIR}/@INSTALL_ROOT_REL_CONFIG_INSTALL_DIR@"
ABSOLUTE)
if (NOT EXISTS ${CERES_EXPORTED_SOURCE_DIR})
ceres_report_not_found(
@@ -164,98 +178,87 @@
include(CMakeFindDependencyMacro)
find_dependency(Threads)
+# As imported CMake targets are not re-exported when a dependent target is
+# exported, we must invoke find_package(XXX) here to reload the definition
+# of their targets. Without this, the dependency target names (e.g.
+# 'gflags-shared') which will be present in the ceres target would not be
+# defined, and so CMake will assume that they refer to a library name and
+# fail to link correctly.
+
# Eigen.
# Flag set during configuration and build of Ceres.
-set(CERES_EIGEN_VERSION @EIGEN_VERSION@)
-set(EIGEN_WAS_BUILT_WITH_CMAKE @FOUND_INSTALLED_EIGEN_CMAKE_CONFIGURATION@)
-# Append the locations of Eigen when Ceres was built to the search path hints.
-if (EIGEN_WAS_BUILT_WITH_CMAKE)
- set(Eigen3_DIR @Eigen3_DIR@)
- set(EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION TRUE)
-else()
- list(APPEND EIGEN_INCLUDE_DIR_HINTS @EIGEN_INCLUDE_DIR@)
-endif()
+set(CERES_EIGEN_VERSION @EIGEN3_VERSION_STRING@)
# Search quietly to control the timing of the error message if not found. The
# search should be for an exact match, but for usability reasons do a soft
# match and reject with an explanation below.
-find_package(Eigen ${CERES_EIGEN_VERSION} QUIET)
-if (EIGEN_FOUND)
- if (NOT EIGEN_VERSION VERSION_EQUAL CERES_EIGEN_VERSION)
+find_package(Eigen3 ${CERES_EIGEN_VERSION} QUIET)
+if (EIGEN3_FOUND)
+ if (NOT EIGEN3_VERSION_STRING VERSION_EQUAL CERES_EIGEN_VERSION)
# CMake's VERSION check in FIND_PACKAGE() will accept any version >= the
# specified version. However, only version = is supported. Improve
# usability by explaining why we don't accept non-exact version matching.
ceres_report_not_found("Found Eigen dependency, but the version of Eigen "
- "found (${EIGEN_VERSION}) does not exactly match the version of Eigen "
+ "found (${EIGEN3_VERSION_STRING}) does not exactly match the version of Eigen "
"Ceres was compiled with (${CERES_EIGEN_VERSION}). This can cause subtle "
"bugs by triggering violations of the One Definition Rule. See the "
"Wikipedia article http://en.wikipedia.org/wiki/One_Definition_Rule "
"for more details")
endif ()
- message(STATUS "Found required Ceres dependency: "
- "Eigen version ${CERES_EIGEN_VERSION} in ${EIGEN_INCLUDE_DIRS}")
-else (EIGEN_FOUND)
+ ceres_message(STATUS "Found required Ceres dependency: "
+ "Eigen version ${CERES_EIGEN_VERSION} in ${EIGEN3_INCLUDE_DIRS}")
+else (EIGEN3_FOUND)
ceres_report_not_found("Missing required Ceres "
"dependency: Eigen version ${CERES_EIGEN_VERSION}, please set "
- "EIGEN_INCLUDE_DIR.")
-endif (EIGEN_FOUND)
+ "Eigen3_DIR.")
+endif (EIGEN3_FOUND)
-# Glog.
-# Flag set during configuration and build of Ceres.
+# glog (and maybe gflags).
+#
+# Flags set during configuration and build of Ceres.
set(CERES_USES_MINIGLOG @MINIGLOG@)
+set(CERES_GLOG_VERSION @glog_VERSION@)
+set(CERES_GLOG_WAS_BUILT_WITH_CMAKE @FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION@)
+
set(CERES_USES_GFLAGS @GFLAGS@)
+set(CERES_GFLAGS_VERSION @gflags_VERSION@)
+
if (CERES_USES_MINIGLOG)
# Output message at standard log level (not the lower STATUS) so that
# the message is output in GUI during configuration to warn user.
- message("-- Found Ceres compiled with miniglog substitute "
+ ceres_message("-- Found Ceres compiled with miniglog substitute "
"for glog, beware this will likely cause problems if glog is later linked.")
else(CERES_USES_MINIGLOG)
- # As imported CMake targets are not re-exported when a dependent target is
- # exported, we must invoke find_package(XXX) here to reload the definition
- # of their targets. Without this, the dependency target names (e.g.
- # 'gflags-shared') which will be present in the ceres target would not be
- # defined, and so CMake will assume that they refer to a library name and
- # fail to link correctly.
-
- # Append the locations of glog when Ceres was built to the search path hints.
- set(GLOG_WAS_BUILT_WITH_CMAKE @FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION@)
- if (GLOG_WAS_BUILT_WITH_CMAKE)
- set(glog_DIR @glog_DIR@)
- set(GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION TRUE)
+ if (CERES_GLOG_WAS_BUILT_WITH_CMAKE)
+ find_package(glog ${CERES_GLOG_VERSION} CONFIG QUIET)
+ set(GLOG_FOUND ${glog_FOUND})
else()
- list(APPEND GLOG_INCLUDE_DIR_HINTS @GLOG_INCLUDE_DIR@)
- get_filename_component(CERES_BUILD_GLOG_LIBRARY_DIR @GLOG_LIBRARY@ PATH)
+ # Version of glog against which Ceres was built was not built with CMake,
+ # use the exported glog find_package() module from Ceres to find it again.
+ # Append the locations of glog when Ceres was built to the search path hints.
+ list(APPEND GLOG_INCLUDE_DIR_HINTS "@GLOG_INCLUDE_DIR@")
+ get_filename_component(CERES_BUILD_GLOG_LIBRARY_DIR "@GLOG_LIBRARY@" PATH)
list(APPEND GLOG_LIBRARY_DIR_HINTS ${CERES_BUILD_GLOG_LIBRARY_DIR})
+
+ # Search quietly s/t we control the timing of the error message if not found.
+ find_package(Glog QUIET)
endif()
- # Search quietly s/t we control the timing of the error message if not found.
- find_package(Glog QUIET)
+
if (GLOG_FOUND)
- message(STATUS "Found required Ceres dependency: glog")
+ ceres_message(STATUS "Found required Ceres dependency: glog")
else()
- ceres_report_not_found("Missing required Ceres "
- "dependency: glog. Searched using GLOG_INCLUDE_DIR_HINTS: "
- "${GLOG_INCLUDE_DIR_HINTS} and glog_DIR: ${glog_DIR}.")
+ ceres_report_not_found("Missing required Ceres dependency: glog.")
endif()
# gflags is only a public dependency of Ceres via glog, thus is not required
# if Ceres was built with MINIGLOG.
if (CERES_USES_GFLAGS)
- set(GFLAGS_WAS_BUILT_WITH_CMAKE @FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION@)
- if (GFLAGS_WAS_BUILT_WITH_CMAKE)
- set(gflags_DIR @gflags_DIR@)
- set(GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION TRUE)
- else()
- list(APPEND GFLAGS_INCLUDE_DIR_HINTS @GFLAGS_INCLUDE_DIR@)
- get_filename_component(CERES_BUILD_GFLAGS_LIBRARY_DIR @GFLAGS_LIBRARY@ PATH)
- list(APPEND GFLAGS_LIBRARY_DIR_HINTS ${CERES_BUILD_GFLAGS_LIBRARY_DIR})
- endif()
# Search quietly s/t we control the timing of the error message if not found.
- find_package(Gflags QUIET)
- if (GFLAGS_FOUND)
- message(STATUS "Found required Ceres dependency: gflags")
+ find_package(gflags ${CERES_GFLAGS_VERSION} QUIET)
+ if (gflags_FOUND AND TARGET gflags)
+ ceres_message(STATUS "Found required Ceres dependency: gflags")
else()
ceres_report_not_found("Missing required Ceres "
- "dependency: gflags. Searched using GFLAGS_INCLUDE_DIR_HINTS: "
- "${GFLAGS_INCLUDE_DIR_HINTS} and gflags_DIR: ${gflags_DIR}.")
+ "dependency: gflags (not found, or not found as exported CMake target).")
endif()
endif()
endif(CERES_USES_MINIGLOG)
@@ -265,7 +268,7 @@
include(${CERES_CURRENT_CONFIG_DIR}/CeresTargets.cmake)
endif (NOT TARGET ceres AND NOT Ceres_BINARY_DIR)
# Set the expected XX_LIBRARIES variable for FindPackage().
-set(CERES_LIBRARIES ceres)
+set(CERES_LIBRARIES Ceres::ceres)
# Reset CMake module path to its state when this script was called.
set(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH})
@@ -316,10 +319,18 @@
# As we use CERES_REPORT_NOT_FOUND() to abort, if we reach this point we have
# found Ceres and all required dependencies.
-message(STATUS "Found " ${CERES_DETECTED_VERSION_STRING})
+ceres_message(STATUS "Found " ${CERES_DETECTED_VERSION_STRING})
# 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)
+
+if (NOT TARGET ceres)
+ # For backwards compatibility, create a local 'alias' target with the
+ # non-namespace-qualified Ceres target name. Note that this is not a
+ # true ALIAS library in CMake terms as they cannot point to imported targets.
+ add_library(ceres INTERFACE IMPORTED)
+ set_target_properties(ceres PROPERTIES INTERFACE_LINK_LIBRARIES Ceres::ceres)
+endif()
diff --git a/cmake/CeresConfigVersion.cmake.in b/cmake/CeresConfigVersion.cmake.in
deleted file mode 100644
index 5ff36eb..0000000
--- a/cmake/CeresConfigVersion.cmake.in
+++ /dev/null
@@ -1,50 +0,0 @@
-# Ceres Solver - A fast non-linear least squares minimizer
-# Copyright 2015 Google Inc. All rights reserved.
-# http://ceres-solver.org/
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * Neither the name of Google Inc. nor the names of its contributors may be
-# used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-# Author: pablo.speciale@gmail.com (Pablo Speciale)
-#
-# FIND_PACKAGE() searches for a <package>Config.cmake file and an associated
-# <package>Version.cmake file, which it loads to check the version number.
-#
-# This file can be used with CONFIGURE_FILE() to generate such a file for a
-# project with very basic logic.
-#
-# It sets PACKAGE_VERSION_EXACT if the current version string and the requested
-# version string are exactly the same and it sets PACKAGE_VERSION_COMPATIBLE
-# if the current version is >= requested version.
-
-set(PACKAGE_VERSION @CERES_VERSION@)
-
-if ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
- set(PACKAGE_VERSION_COMPATIBLE FALSE)
-else ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
- set(PACKAGE_VERSION_COMPATIBLE TRUE)
- if ("${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
- set(PACKAGE_VERSION_EXACT TRUE)
- endif ("${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
-endif ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
diff --git a/cmake/CeresThreadingModels.cmake b/cmake/CeresThreadingModels.cmake
index 24e8aab..571dd7d 100644
--- a/cmake/CeresThreadingModels.cmake
+++ b/cmake/CeresThreadingModels.cmake
@@ -29,7 +29,7 @@
# Author: alexs.mac@gmail.com (Alex Stewart)
# Ordered by expected preference.
-set(CERES_THREADING_MODELS "CXX11_THREADS;OPENMP;NO_THREADS")
+set(CERES_THREADING_MODELS "CXX_THREADS;OPENMP;NO_THREADS")
function(find_available_ceres_threading_models CERES_THREADING_MODELS_AVAILABLE_VAR)
set(CERES_THREADING_MODELS_AVAILABLE ${CERES_THREADING_MODELS})
@@ -48,7 +48,7 @@
endfunction()
macro(set_ceres_threading_model_to_cxx11_threads)
- list(APPEND CERES_COMPILE_OPTIONS CERES_USE_CXX11_THREADS)
+ list(APPEND CERES_COMPILE_OPTIONS CERES_USE_CXX_THREADS)
endmacro()
macro(set_ceres_threading_model_to_openmp)
@@ -63,7 +63,7 @@
endmacro()
macro(set_ceres_threading_model CERES_THREADING_MODEL_TO_SET)
- if ("${CERES_THREADING_MODEL_TO_SET}" STREQUAL "CXX11_THREADS")
+ if ("${CERES_THREADING_MODEL_TO_SET}" STREQUAL "CXX_THREADS")
set_ceres_threading_model_to_cxx11_threads()
elseif ("${CERES_THREADING_MODEL_TO_SET}" STREQUAL "OPENMP")
set_ceres_threading_model_to_openmp()
diff --git a/cmake/DetectBrokenStackCheckMacOSXcodePairing.cmake b/cmake/DetectBrokenStackCheckMacOSXcodePairing.cmake
new file mode 100644
index 0000000..151e28c
--- /dev/null
+++ b/cmake/DetectBrokenStackCheckMacOSXcodePairing.cmake
@@ -0,0 +1,83 @@
+# Ceres Solver - A fast non-linear least squares minimizer
+# Copyright 2019 Google Inc. All rights reserved.
+# http://ceres-solver.org/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# * Neither the name of Google Inc. nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# Author: alexs.mac@gmail.com (Alex Stewart)
+
+# As detailed in [1] the combination of macOS 10.15.x (Catalina) and
+# Xcode 11.0-1 enables by default a broken version of -fstack-check which
+# can break the alignment requirements for SIMD instructions resulting in
+# segfaults from within Eigen. This issue was apparently fixed in Xcode 11.2
+# despite not appearing in the official release notes.
+#
+# Although this can be worked around by compiling with -fno-stack-check, we
+# instead prevent generation as the update to Xcode 11.2 is free and failing
+# to include -fno-stack-check *everywhere* could still result in random
+# segfaults.
+#
+# [1]: https://forums.developer.apple.com/thread/121887
+function(detect_broken_stack_check_macos_xcode_pairing)
+ if (NOT APPLE)
+ return()
+ endif()
+
+ execute_process(COMMAND sw_vers -productVersion
+ OUTPUT_VARIABLE MACOS_VERSION
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if (MACOS_VERSION VERSION_LESS 10.15)
+ # Only 10.15 (Catalina) is likely to be affected, irrespective of the Xcode
+ # version. Although it is possible to recreate the issue on 10.14 (Mojave)
+ # and Xcode 11.0-1 if -fstack-check is forced on, this is not the default.
+ return()
+ endif()
+
+ execute_process(COMMAND xcodebuild -version
+ OUTPUT_VARIABLE XCODE_VERSION
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}")
+ string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}")
+
+ if ((XCODE_VERSION VERSION_EQUAL 11.0) OR
+ (XCODE_VERSION VERSION_EQUAL 11.1))
+ message(FATAL_ERROR "Detected macOS version: ${MACOS_VERSION} and "
+ "Xcode version: ${XCODE_VERSION} which combined exhibit an "
+ "-fstack-check bug which can break alignment requirements for at least "
+ "AVX instructions as detailed here [1]."
+ "\n"
+ "This bug affected Xcode 11.0 and 11.1 but only when used with 10.15 "
+ "(Catalina), and was fixed in Xcode 11.2. Without the fix in place, "
+ "random segfaults will occur in Eigen operations used by Ceres that use "
+ "AVX instructions."
+ "\n"
+ "Please update to at least Xcode 11.2."
+ "\n"
+ "[1]: https://forums.developer.apple.com/thread/121887")
+ endif()
+endfunction()
diff --git a/cmake/EnableSanitizer.cmake b/cmake/EnableSanitizer.cmake
new file mode 100644
index 0000000..1ef68c3
--- /dev/null
+++ b/cmake/EnableSanitizer.cmake
@@ -0,0 +1,98 @@
+# Ceres Solver - A fast non-linear least squares minimizer
+# Copyright 2019 Google Inc. All rights reserved.
+# http://ceres-solver.org/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# * Neither the name of Google Inc. nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# Author: alexs.mac@gmail.com (Alex Stewart)
+
+# Usage: enable_sanitizer(REQUIRED_SANITIZERS) where REQUIRED_SANITIZERS should
+# contain the list of sanitizers to enable by updating CMAKE_CXX_FLAGS and
+# CMAKE_EXE_LINKER_FLAGS.
+#
+# The specified sanitizers will be checked both for compatibility with the
+# current compiler and with each other as some sanitizers are mutually
+# exclusive.
+macro(enable_sanitizer)
+ # According to the Clang documentation [1] the following sanitizers are
+ # mututally exclusive.
+ # [1]: https://clang.llvm.org/docs/UsersManual.html#controlling-code-generation
+ set(INCOMPATIBLE_SANITIZERS address thread memory)
+ # Set the recommended additional common compile flags for any sanitizer to
+ # get the best possible output, e.g [2] but make them visible in the cache
+ # so that the user can edit them if required.
+ # [2]: https://clang.llvm.org/docs/AddressSanitizer.html#usage
+ set(COMMON_SANITIZER_COMPILE_OPTIONS
+ "-g -fno-omit-frame-pointer -fno-optimize-sibling-calls"
+ CACHE STRING "Common compile flags enabled for any sanitizer")
+
+ # Check that the specified list of sanitizers to enable does not include
+ # multiple entries from the incompatible list.
+ set(MERGED_SANITIZERS ${ARGN} ${INCOMPATIBLE_SANITIZERS})
+ list(LENGTH MERGED_SANITIZERS COMBINED_LENGTH)
+ list(REMOVE_DUPLICATES MERGED_SANITIZERS)
+ list(LENGTH MERGED_SANITIZERS COMBINED_LENGTH_NO_DUPLICATES)
+ math(EXPR VALID_LENGTH "${COMBINED_LENGTH} - 1")
+ if (COMBINED_LENGTH_NO_DUPLICATES LESS VALID_LENGTH)
+ include(PrettyPrintCMakeList)
+ pretty_print_cmake_list(REQUESTED_SANITIZERS ${ARGN})
+ pretty_print_cmake_list(
+ PRETTY_INCOMPATIBLE_SANITIZERS ${INCOMPATIBLE_SANITIZERS})
+ message(FATAL_ERROR "Found incompatible sanitizers in requested set: "
+ "${REQUESTED_SANITIZERS}. The following sanitizers are mutually "
+ "exclusive: ${PRETTY_INCOMPATIBLE_SANITIZERS}")
+ endif()
+
+ # Until CMake 3.14 and CMAKE_REQUIRED_LINK_OPTIONS there was no equivalent to
+ # CMAKE_REQUIRED_FLAGS for try_compile() for linker flags. However, in CMake
+ # 3.2 CMP0056 was introduced that when enabled passes CMAKE_EXE_LINKER_FLAGS
+ # to try_compile() which allows us to achieve the same effect.
+ cmake_policy(SET CMP0056 NEW)
+ include(CheckCXXCompilerFlag)
+
+ unset(ADDED_SANITIZER)
+ foreach(REQUESTED_SANITIZER ${ARGN})
+ set(SANITIZER_FLAG -fsanitize=${REQUESTED_SANITIZER})
+ # Save the current CMAKE_EXE_LINKER_FLAGS before modifying it to test for
+ # the existence of the sanitizer flag so that we can revert after the test.
+ set(INITIAL_CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAG}")
+ check_cxx_compiler_flag(${SANITIZER_FLAG} HAVE_SANITIZER)
+ set(CMAKE_EXE_LINKER_FLAGS "${INITIAL_CMAKE_EXE_LINKER_FLAGS}")
+ if (NOT HAVE_SANITIZER)
+ message(FATAL_ERROR "Specified sanitizer: ${REQUESTED_SANITIZER} is not "
+ "supported by the compiler.")
+ endif()
+ message(STATUS "Enabling sanitizer: ${REQUESTED_SANITIZER}")
+ set(ADDED_SANITIZER TRUE)
+ # As per the Clang documentation, the sanitizer flags must be added to both
+ # the compiler and linker flags.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAG}")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAG}")
+ endforeach()
+ if (ADDED_SANITIZER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_SANITIZER_COMPILE_OPTIONS}")
+ endif()
+endmacro()
diff --git a/cmake/FindCXSparse.cmake b/cmake/FindCXSparse.cmake
index 3f4b015..8b380c9 100644
--- a/cmake/FindCXSparse.cmake
+++ b/cmake/FindCXSparse.cmake
@@ -120,6 +120,27 @@
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "" "${CMAKE_FIND_LIBRARY_PREFIXES}")
endif (MSVC)
+# On macOS, add the Homebrew prefix (with appropriate suffixes) to the
+# respective HINTS directories (after any user-specified locations). This
+# handles Homebrew installations into non-standard locations (not /usr/local).
+# We do not use CMAKE_PREFIX_PATH for this as given the search ordering of
+# find_xxx(), doing so would override any user-specified HINTS locations with
+# the Homebrew version if it exists.
+if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ find_program(HOMEBREW_EXECUTABLE brew)
+ mark_as_advanced(FORCE HOMEBREW_EXECUTABLE)
+ if (HOMEBREW_EXECUTABLE)
+ # Detected a Homebrew install, query for its install prefix.
+ execute_process(COMMAND ${HOMEBREW_EXECUTABLE} --prefix
+ OUTPUT_VARIABLE HOMEBREW_INSTALL_PREFIX
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ message(STATUS "Detected Homebrew with install prefix: "
+ "${HOMEBREW_INSTALL_PREFIX}, adding to CMake search paths.")
+ list(APPEND CXSPARSE_INCLUDE_DIR_HINTS "${HOMEBREW_INSTALL_PREFIX}/include")
+ list(APPEND CXSPARSE_LIBRARY_DIR_HINTS "${HOMEBREW_INSTALL_PREFIX}/lib")
+ endif()
+endif()
+
# Search user-installed locations first, so that we prefer user installs
# to system installs where both exist.
#
diff --git a/cmake/FindEigen.cmake b/cmake/FindEigen.cmake
deleted file mode 100644
index f6d2664..0000000
--- a/cmake/FindEigen.cmake
+++ /dev/null
@@ -1,263 +0,0 @@
-# Ceres Solver - A fast non-linear least squares minimizer
-# Copyright 2015 Google Inc. All rights reserved.
-# http://ceres-solver.org/
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * Neither the name of Google Inc. nor the names of its contributors may be
-# used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-# Author: alexs.mac@gmail.com (Alex Stewart)
-#
-
-# FindEigen.cmake - Find Eigen library, version >= 3.
-#
-# This module defines the following variables:
-#
-# EIGEN_FOUND: TRUE iff Eigen is found.
-# EIGEN_INCLUDE_DIRS: Include directories for Eigen.
-# EIGEN_VERSION: Extracted from Eigen/src/Core/util/Macros.h
-# EIGEN_WORLD_VERSION: Equal to 3 if EIGEN_VERSION = 3.2.0
-# EIGEN_MAJOR_VERSION: Equal to 2 if EIGEN_VERSION = 3.2.0
-# EIGEN_MINOR_VERSION: Equal to 0 if EIGEN_VERSION = 3.2.0
-# FOUND_INSTALLED_EIGEN_CMAKE_CONFIGURATION: True iff the version of Eigen
-# found was built & installed /
-# exported as a CMake package.
-#
-# The following variables control the behaviour of this module:
-#
-# EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION: TRUE/FALSE, iff TRUE then
-# then prefer using an exported CMake configuration
-# generated by Eigen over searching for the
-# Eigen components manually. Otherwise (FALSE)
-# ignore any exported Eigen CMake configurations and
-# always perform a manual search for the components.
-# Default: TRUE iff user does not define this variable
-# before we are called, and does NOT specify
-# EIGEN_INCLUDE_DIR_HINTS, otherwise FALSE.
-# EIGEN_INCLUDE_DIR_HINTS: List of additional directories in which to
-# search for eigen includes, e.g: /timbuktu/eigen3.
-#
-# The following variables are also defined by this module, but in line with
-# CMake recommended FindPackage() module style should NOT be referenced directly
-# by callers (use the plural variables detailed above instead). These variables
-# do however affect the behaviour of the module via FIND_[PATH/LIBRARY]() which
-# are NOT re-called (i.e. search for library is not repeated) if these variables
-# are set with valid values _in the CMake cache_. This means that if these
-# variables are set directly in the cache, either by the user in the CMake GUI,
-# or by the user passing -DVAR=VALUE directives to CMake when called (which
-# explicitly defines a cache variable), then they will be used verbatim,
-# bypassing the HINTS variables and other hard-coded search locations.
-#
-# EIGEN_INCLUDE_DIR: Include directory for CXSparse, not including the
-# include directory of any dependencies.
-
-# Called if we failed to find Eigen 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(EIGEN_REPORT_NOT_FOUND REASON_MSG)
- unset(EIGEN_FOUND)
- unset(EIGEN_INCLUDE_DIRS)
- unset(FOUND_INSTALLED_EIGEN_CMAKE_CONFIGURATION)
- # Make results of search visible in the CMake GUI if Eigen has not
- # been found so that user does not have to toggle to advanced view.
- mark_as_advanced(CLEAR EIGEN_INCLUDE_DIR)
- # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage()
- # use the camelcase library name, not uppercase.
- if (Eigen_FIND_QUIETLY)
- message(STATUS "Failed to find Eigen - " ${REASON_MSG} ${ARGN})
- elseif (Eigen_FIND_REQUIRED)
- message(FATAL_ERROR "Failed to find Eigen - " ${REASON_MSG} ${ARGN})
- else()
- # Neither QUIETLY nor REQUIRED, use no priority which emits a message
- # but continues configuration and allows generation.
- message("-- Failed to find Eigen - " ${REASON_MSG} ${ARGN})
- endif ()
- return()
-endmacro(EIGEN_REPORT_NOT_FOUND)
-
-# Protect against any alternative find_package scripts for this library having
-# been called previously (in a client project) which set EIGEN_FOUND, but not
-# the other variables we require / set here which could cause the search logic
-# here to fail.
-unset(EIGEN_FOUND)
-
-# -----------------------------------------------------------------
-# By default, if the user has expressed no preference for using an exported
-# Eigen CMake configuration over performing a search for the installed
-# components, and has not specified any hints for the search locations, then
-# prefer an exported configuration if available.
-if (NOT DEFINED EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION
- AND NOT EIGEN_INCLUDE_DIR_HINTS)
- message(STATUS "No preference for use of exported Eigen CMake configuration "
- "set, and no hints for include directory provided. "
- "Defaulting to preferring an installed/exported Eigen CMake configuration "
- "if available.")
- set(EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION TRUE)
-endif()
-
-if (EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION)
- # Try to find an exported CMake configuration for Eigen.
- #
- # We search twice, s/t we can invert the ordering of precedence used by
- # find_package() for exported package build directories, and installed
- # packages (found via CMAKE_SYSTEM_PREFIX_PATH), listed as items 6) and 7)
- # respectively in [1].
- #
- # By default, exported build directories are (in theory) detected first, and
- # this is usually the case on Windows. However, on OS X & Linux, the install
- # path (/usr/local) is typically present in the PATH environment variable
- # which is checked in item 4) in [1] (i.e. before both of the above, unless
- # NO_SYSTEM_ENVIRONMENT_PATH is passed). As such on those OSs installed
- # packages are usually detected in preference to exported package build
- # directories.
- #
- # To ensure a more consistent response across all OSs, and as users usually
- # want to prefer an installed version of a package over a locally built one
- # where both exist (esp. as the exported build directory might be removed
- # after installation), we first search with NO_CMAKE_PACKAGE_REGISTRY which
- # means any build directories exported by the user are ignored, and thus
- # installed directories are preferred. If this fails to find the package
- # we then research again, but without NO_CMAKE_PACKAGE_REGISTRY, so any
- # exported build directories will now be detected.
- #
- # To prevent confusion on Windows, we also pass NO_CMAKE_BUILDS_PATH (which
- # is item 5) in [1]), to not preferentially use projects that were built
- # recently with the CMake GUI to ensure that we always prefer an installed
- # version if available.
- #
- # [1] http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:find_package
- find_package(Eigen3 QUIET
- NO_MODULE
- NO_CMAKE_PACKAGE_REGISTRY
- NO_CMAKE_BUILDS_PATH)
- if (EIGEN3_FOUND)
- message(STATUS "Found installed version of Eigen: ${Eigen3_DIR}")
- else()
- # Failed to find an installed version of Eigen, repeat search allowing
- # exported build directories.
- message(STATUS "Failed to find installed Eigen CMake configuration, "
- "searching for Eigen build directories exported with CMake.")
- # Again pass NO_CMAKE_BUILDS_PATH, as we know that Eigen is exported and
- # do not want to treat projects built with the CMake GUI preferentially.
- find_package(Eigen3 QUIET
- NO_MODULE
- NO_CMAKE_BUILDS_PATH)
- if (EIGEN3_FOUND)
- message(STATUS "Found exported Eigen build directory: ${Eigen3_DIR}")
- endif()
- endif()
- if (EIGEN3_FOUND)
- set(FOUND_INSTALLED_EIGEN_CMAKE_CONFIGURATION TRUE)
- set(EIGEN_FOUND ${EIGEN3_FOUND})
- set(EIGEN_INCLUDE_DIR "${EIGEN3_INCLUDE_DIR}" CACHE STRING
- "Eigen include directory" FORCE)
- else()
- message(STATUS "Failed to find an installed/exported CMake configuration "
- "for Eigen, will perform search for installed Eigen components.")
- endif()
-endif()
-
-if (NOT EIGEN_FOUND)
- # Search user-installed locations first, so that we prefer user installs
- # to system installs where both exist.
- list(APPEND EIGEN_CHECK_INCLUDE_DIRS
- /usr/local/include
- /usr/local/homebrew/include # Mac OS X
- /opt/local/var/macports/software # Mac OS X.
- /opt/local/include
- /usr/include)
- # Additional suffixes to try appending to each search path.
- list(APPEND EIGEN_CHECK_PATH_SUFFIXES
- eigen3 # Default root directory for Eigen.
- Eigen/include/eigen3 # Windows (for C:/Program Files prefix) < 3.3
- Eigen3/include/eigen3 ) # Windows (for C:/Program Files prefix) >= 3.3
-
- # Search supplied hint directories first if supplied.
- find_path(EIGEN_INCLUDE_DIR
- NAMES Eigen/Core
- HINTS ${EIGEN_INCLUDE_DIR_HINTS}
- PATHS ${EIGEN_CHECK_INCLUDE_DIRS}
- PATH_SUFFIXES ${EIGEN_CHECK_PATH_SUFFIXES})
-
- if (NOT EIGEN_INCLUDE_DIR OR
- NOT EXISTS ${EIGEN_INCLUDE_DIR})
- eigen_report_not_found(
- "Could not find eigen3 include directory, set EIGEN_INCLUDE_DIR to "
- "path to eigen3 include directory, e.g. /usr/local/include/eigen3.")
- endif (NOT EIGEN_INCLUDE_DIR OR
- NOT EXISTS ${EIGEN_INCLUDE_DIR})
-
- # Mark internally as found, then verify. EIGEN_REPORT_NOT_FOUND() unsets
- # if called.
- set(EIGEN_FOUND TRUE)
-endif()
-
-# Extract Eigen version from Eigen/src/Core/util/Macros.h
-if (EIGEN_INCLUDE_DIR)
- set(EIGEN_VERSION_FILE ${EIGEN_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h)
- if (NOT EXISTS ${EIGEN_VERSION_FILE})
- eigen_report_not_found(
- "Could not find file: ${EIGEN_VERSION_FILE} "
- "containing version information in Eigen install located at: "
- "${EIGEN_INCLUDE_DIR}.")
- else (NOT EXISTS ${EIGEN_VERSION_FILE})
- file(READ ${EIGEN_VERSION_FILE} EIGEN_VERSION_FILE_CONTENTS)
-
- string(REGEX MATCH "#define EIGEN_WORLD_VERSION [0-9]+"
- EIGEN_WORLD_VERSION "${EIGEN_VERSION_FILE_CONTENTS}")
- string(REGEX REPLACE "#define EIGEN_WORLD_VERSION ([0-9]+)" "\\1"
- EIGEN_WORLD_VERSION "${EIGEN_WORLD_VERSION}")
-
- string(REGEX MATCH "#define EIGEN_MAJOR_VERSION [0-9]+"
- EIGEN_MAJOR_VERSION "${EIGEN_VERSION_FILE_CONTENTS}")
- string(REGEX REPLACE "#define EIGEN_MAJOR_VERSION ([0-9]+)" "\\1"
- EIGEN_MAJOR_VERSION "${EIGEN_MAJOR_VERSION}")
-
- string(REGEX MATCH "#define EIGEN_MINOR_VERSION [0-9]+"
- EIGEN_MINOR_VERSION "${EIGEN_VERSION_FILE_CONTENTS}")
- string(REGEX REPLACE "#define EIGEN_MINOR_VERSION ([0-9]+)" "\\1"
- EIGEN_MINOR_VERSION "${EIGEN_MINOR_VERSION}")
-
- # This is on a single line s/t CMake does not interpret it as a list of
- # elements and insert ';' separators which would result in 3.;2.;0 nonsense.
- set(EIGEN_VERSION "${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION}")
- endif (NOT EXISTS ${EIGEN_VERSION_FILE})
-endif (EIGEN_INCLUDE_DIR)
-
-# Set standard CMake FindPackage variables if found.
-if (EIGEN_FOUND)
- set(EIGEN_INCLUDE_DIRS ${EIGEN_INCLUDE_DIR})
-endif (EIGEN_FOUND)
-
-# Handle REQUIRED / QUIET optional arguments and version.
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(Eigen
- REQUIRED_VARS EIGEN_INCLUDE_DIRS
- VERSION_VAR EIGEN_VERSION)
-
-# Only mark internal variables as advanced if we found Eigen, otherwise
-# leave it visible in the standard GUI for the user to set manually.
-if (EIGEN_FOUND)
- mark_as_advanced(FORCE EIGEN_INCLUDE_DIR
- Eigen3_DIR) # Autogenerated by find_package(Eigen3)
-endif (EIGEN_FOUND)
diff --git a/cmake/FindGflags.cmake b/cmake/FindGflags.cmake
deleted file mode 100644
index 32c04ea..0000000
--- a/cmake/FindGflags.cmake
+++ /dev/null
@@ -1,591 +0,0 @@
-# Ceres Solver - A fast non-linear least squares minimizer
-# Copyright 2015 Google Inc. All rights reserved.
-# http://ceres-solver.org/
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * Neither the name of Google Inc. nor the names of its contributors may be
-# used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-# Author: alexs.mac@gmail.com (Alex Stewart)
-#
-
-# FindGflags.cmake - Find Google gflags logging library.
-#
-# This module will attempt to find gflags, either via an exported CMake
-# configuration (generated by gflags >= 2.1 which are built with CMake), or
-# by performing a standard search for all gflags components. The order of
-# precedence for these two methods of finding gflags is controlled by:
-# GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION.
-#
-# This module defines the following variables:
-#
-# GFLAGS_FOUND: TRUE iff gflags is found.
-# GFLAGS_INCLUDE_DIRS: Include directories for gflags.
-# GFLAGS_LIBRARIES: Libraries required to link gflags.
-# GFLAGS_NAMESPACE: The namespace in which gflags is defined. In versions of
-# gflags < 2.1, this was google, for versions >= 2.1 it is
-# by default gflags, although can be configured when building
-# gflags to be something else (i.e. google for legacy
-# compatibility).
-# FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION: True iff the version of gflags
-# found was built & installed /
-# exported as a CMake package.
-#
-# The following variables control the behaviour of this module when an exported
-# gflags CMake configuration is not found.
-#
-# GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION: TRUE/FALSE, iff TRUE then
-# then prefer using an exported CMake configuration
-# generated by gflags >= 2.1 over searching for the
-# gflags components manually. Otherwise (FALSE)
-# ignore any exported gflags CMake configurations and
-# always perform a manual search for the components.
-# Default: TRUE iff user does not define this variable
-# before we are called, and does NOT specify either
-# GFLAGS_INCLUDE_DIR_HINTS or GFLAGS_LIBRARY_DIR_HINTS
-# otherwise FALSE.
-# GFLAGS_INCLUDE_DIR_HINTS: List of additional directories in which to
-# search for gflags includes, e.g: /timbuktu/include.
-# GFLAGS_LIBRARY_DIR_HINTS: List of additional directories in which to
-# search for gflags libraries, e.g: /timbuktu/lib.
-#
-# The following variables are also defined by this module, but in line with
-# CMake recommended FindPackage() module style should NOT be referenced directly
-# by callers (use the plural variables detailed above instead). These variables
-# do however affect the behaviour of the module via FIND_[PATH/LIBRARY]() which
-# are NOT re-called (i.e. search for library is not repeated) if these variables
-# are set with valid values _in the CMake cache_. This means that if these
-# variables are set directly in the cache, either by the user in the CMake GUI,
-# or by the user passing -DVAR=VALUE directives to CMake when called (which
-# explicitly defines a cache variable), then they will be used verbatim,
-# bypassing the HINTS variables and other hard-coded search locations.
-#
-# GFLAGS_INCLUDE_DIR: Include directory for gflags, not including the
-# include directory of any dependencies.
-# GFLAGS_LIBRARY: gflags library, not including the libraries of any
-# dependencies.
-
-# Reset CALLERS_CMAKE_FIND_LIBRARY_PREFIXES to its value when FindGflags was
-# invoked, necessary for MSVC.
-macro(GFLAGS_RESET_FIND_LIBRARY_PREFIX)
- if (MSVC AND CALLERS_CMAKE_FIND_LIBRARY_PREFIXES)
- set(CMAKE_FIND_LIBRARY_PREFIXES "${CALLERS_CMAKE_FIND_LIBRARY_PREFIXES}")
- endif()
-endmacro(GFLAGS_RESET_FIND_LIBRARY_PREFIX)
-
-# Called if we failed to find gflags 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(GFLAGS_REPORT_NOT_FOUND REASON_MSG)
- unset(GFLAGS_FOUND)
- unset(GFLAGS_INCLUDE_DIRS)
- unset(GFLAGS_LIBRARIES)
- # Do not use unset, as we want to keep GFLAGS_NAMESPACE in the cache,
- # but simply clear its value.
- set(GFLAGS_NAMESPACE "" CACHE STRING
- "gflags namespace (google or gflags)" FORCE)
-
- # Make results of search visible in the CMake GUI if gflags has not
- # been found so that user does not have to toggle to advanced view.
- mark_as_advanced(CLEAR GFLAGS_INCLUDE_DIR
- GFLAGS_LIBRARY
- GFLAGS_NAMESPACE)
-
- gflags_reset_find_library_prefix()
-
- # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage()
- # use the camelcase library name, not uppercase.
- if (Gflags_FIND_QUIETLY)
- message(STATUS "Failed to find gflags - " ${REASON_MSG} ${ARGN})
- elseif (Gflags_FIND_REQUIRED)
- message(FATAL_ERROR "Failed to find gflags - " ${REASON_MSG} ${ARGN})
- else()
- # Neither QUIETLY nor REQUIRED, use no priority which emits a message
- # but continues configuration and allows generation.
- message("-- Failed to find gflags - " ${REASON_MSG} ${ARGN})
- endif ()
- return()
-endmacro(GFLAGS_REPORT_NOT_FOUND)
-
-# Verify that all variable names passed as arguments are defined (can be empty
-# but must be defined) or raise a fatal error.
-macro(GFLAGS_CHECK_VARS_DEFINED)
- foreach(CHECK_VAR ${ARGN})
- if (NOT DEFINED ${CHECK_VAR})
- message(FATAL_ERROR "Ceres Bug: ${CHECK_VAR} is not defined.")
- endif()
- endforeach()
-endmacro(GFLAGS_CHECK_VARS_DEFINED)
-
-# Use check_cxx_source_compiles() to compile trivial test programs to determine
-# the gflags namespace. This works on all OSs except Windows. If using Visual
-# Studio, it fails because msbuild forces check_cxx_source_compiles() to use
-# CMAKE_BUILD_TYPE=Debug for the test project, which usually breaks detection
-# because MSVC requires that the test project use the same build type as gflags,
-# which would normally be built in Release.
-#
-# Defines: GFLAGS_NAMESPACE in the caller's scope with the detected namespace,
-# which is blank (empty string, will test FALSE is CMake conditionals)
-# if detection failed.
-function(GFLAGS_CHECK_GFLAGS_NAMESPACE_USING_TRY_COMPILE)
- # Verify that all required variables are defined.
- gflags_check_vars_defined(
- GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)
- # Ensure that GFLAGS_NAMESPACE is always unset on completion unless
- # we explicitly set if after having the correct namespace.
- set(GFLAGS_NAMESPACE "" PARENT_SCOPE)
-
- include(CheckCXXSourceCompiles)
- # Setup include path & link library for gflags for CHECK_CXX_SOURCE_COMPILES.
- set(CMAKE_REQUIRED_INCLUDES ${GFLAGS_INCLUDE_DIR})
- set(CMAKE_REQUIRED_LIBRARIES ${GFLAGS_LIBRARY} ${GFLAGS_LINK_LIBRARIES})
- # First try the (older) google namespace. Note that the output variable
- # MUST be unique to the build type as otherwise the test is not repeated as
- # it is assumed to have already been performed.
- check_cxx_source_compiles(
- "#include <gflags/gflags.h>
- int main(int argc, char * argv[]) {
- google::ParseCommandLineFlags(&argc, &argv, true);
- return 0;
- }"
- GFLAGS_IN_GOOGLE_NAMESPACE)
- if (GFLAGS_IN_GOOGLE_NAMESPACE)
- set(GFLAGS_NAMESPACE google PARENT_SCOPE)
- return()
- endif()
-
- # Try (newer) gflags namespace instead. Note that the output variable
- # MUST be unique to the build type as otherwise the test is not repeated as
- # it is assumed to have already been performed.
- set(CMAKE_REQUIRED_INCLUDES ${GFLAGS_INCLUDE_DIR})
- set(CMAKE_REQUIRED_LIBRARIES ${GFLAGS_LIBRARY} ${GFLAGS_LINK_LIBRARIES})
- check_cxx_source_compiles(
- "#include <gflags/gflags.h>
- int main(int argc, char * argv[]) {
- gflags::ParseCommandLineFlags(&argc, &argv, true);
- return 0;
- }"
- GFLAGS_IN_GFLAGS_NAMESPACE)
- if (GFLAGS_IN_GFLAGS_NAMESPACE)
- set(GFLAGS_NAMESPACE gflags PARENT_SCOPE)
- return()
- endif (GFLAGS_IN_GFLAGS_NAMESPACE)
-endfunction(GFLAGS_CHECK_GFLAGS_NAMESPACE_USING_TRY_COMPILE)
-
-# Use regex on the gflags headers to attempt to determine the gflags namespace.
-# Checks both gflags.h (contained namespace on versions < 2.1.2) and
-# gflags_declare.h, which contains the namespace on versions >= 2.1.2.
-# In general, this method should only be used when
-# GFLAGS_CHECK_GFLAGS_NAMESPACE_USING_TRY_COMPILE() cannot be used, or has
-# failed.
-#
-# Defines: GFLAGS_NAMESPACE in the caller's scope with the detected namespace,
-# which is blank (empty string, will test FALSE is CMake conditionals)
-# if detection failed.
-function(GFLAGS_CHECK_GFLAGS_NAMESPACE_USING_REGEX)
- # Verify that all required variables are defined.
- gflags_check_vars_defined(GFLAGS_INCLUDE_DIR)
- # Ensure that GFLAGS_NAMESPACE is always undefined on completion unless
- # we explicitly set if after having the correct namespace.
- set(GFLAGS_NAMESPACE "" PARENT_SCOPE)
-
- # Scan gflags.h to identify what namespace gflags was built with. On
- # versions of gflags < 2.1.2, gflags.h was configured with the namespace
- # directly, on >= 2.1.2, gflags.h uses the GFLAGS_NAMESPACE #define which
- # is defined in gflags_declare.h, we try each location in turn.
- set(GFLAGS_HEADER_FILE ${GFLAGS_INCLUDE_DIR}/gflags/gflags.h)
- if (NOT EXISTS ${GFLAGS_HEADER_FILE})
- gflags_report_not_found(
- "Could not find file: ${GFLAGS_HEADER_FILE} "
- "containing namespace information in gflags install located at: "
- "${GFLAGS_INCLUDE_DIR}.")
- endif()
- file(READ ${GFLAGS_HEADER_FILE} GFLAGS_HEADER_FILE_CONTENTS)
-
- string(REGEX MATCH "namespace [A-Za-z]+"
- GFLAGS_NAMESPACE "${GFLAGS_HEADER_FILE_CONTENTS}")
- string(REGEX REPLACE "namespace ([A-Za-z]+)" "\\1"
- GFLAGS_NAMESPACE "${GFLAGS_NAMESPACE}")
-
- if (NOT GFLAGS_NAMESPACE)
- gflags_report_not_found(
- "Failed to extract gflags namespace from header file: "
- "${GFLAGS_HEADER_FILE}.")
- endif (NOT GFLAGS_NAMESPACE)
-
- if (GFLAGS_NAMESPACE STREQUAL "google" OR
- GFLAGS_NAMESPACE STREQUAL "gflags")
- # Found valid gflags namespace from gflags.h.
- set(GFLAGS_NAMESPACE "${GFLAGS_NAMESPACE}" PARENT_SCOPE)
- return()
- endif()
-
- # Failed to find gflags namespace from gflags.h, gflags is likely a new
- # version, check gflags_declare.h, which in newer versions (>= 2.1.2) contains
- # the GFLAGS_NAMESPACE #define, which is then referenced in gflags.h.
- set(GFLAGS_DECLARE_FILE ${GFLAGS_INCLUDE_DIR}/gflags/gflags_declare.h)
- if (NOT EXISTS ${GFLAGS_DECLARE_FILE})
- gflags_report_not_found(
- "Could not find file: ${GFLAGS_DECLARE_FILE} "
- "containing namespace information in gflags install located at: "
- "${GFLAGS_INCLUDE_DIR}.")
- endif()
- file(READ ${GFLAGS_DECLARE_FILE} GFLAGS_DECLARE_FILE_CONTENTS)
-
- string(REGEX MATCH "#define GFLAGS_NAMESPACE [A-Za-z]+"
- GFLAGS_NAMESPACE "${GFLAGS_DECLARE_FILE_CONTENTS}")
- string(REGEX REPLACE "#define GFLAGS_NAMESPACE ([A-Za-z]+)" "\\1"
- GFLAGS_NAMESPACE "${GFLAGS_NAMESPACE}")
-
- if (NOT GFLAGS_NAMESPACE)
- gflags_report_not_found(
- "Failed to extract gflags namespace from declare file: "
- "${GFLAGS_DECLARE_FILE}.")
- endif (NOT GFLAGS_NAMESPACE)
-
- if (GFLAGS_NAMESPACE STREQUAL "google" OR
- GFLAGS_NAMESPACE STREQUAL "gflags")
- # Found valid gflags namespace from gflags.h.
- set(GFLAGS_NAMESPACE "${GFLAGS_NAMESPACE}" PARENT_SCOPE)
- return()
- endif()
-endfunction(GFLAGS_CHECK_GFLAGS_NAMESPACE_USING_REGEX)
-
-# Protect against any alternative find_package scripts for this library having
-# been called previously (in a client project) which set GFLAGS_FOUND, but not
-# the other variables we require / set here which could cause the search logic
-# here to fail.
-unset(GFLAGS_FOUND)
-
-# -----------------------------------------------------------------
-# By default, if the user has expressed no preference for using an exported
-# gflags CMake configuration over performing a search for the installed
-# components, and has not specified any hints for the search locations, then
-# prefer a gflags exported configuration if available.
-if (NOT DEFINED GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION
- AND NOT GFLAGS_INCLUDE_DIR_HINTS
- AND NOT GFLAGS_LIBRARY_DIR_HINTS)
- message(STATUS "No preference for use of exported gflags CMake configuration "
- "set, and no hints for include/library directories provided. "
- "Defaulting to preferring an installed/exported gflags CMake configuration "
- "if available.")
- set(GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION TRUE)
-endif()
-
-if (GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION)
- # Try to find an exported CMake configuration for gflags, as generated by
- # gflags versions >= 2.1.
- #
- # We search twice, s/t we can invert the ordering of precedence used by
- # find_package() for exported package build directories, and installed
- # packages (found via CMAKE_SYSTEM_PREFIX_PATH), listed as items 6) and 7)
- # respectively in [1].
- #
- # By default, exported build directories are (in theory) detected first, and
- # this is usually the case on Windows. However, on OS X & Linux, the install
- # path (/usr/local) is typically present in the PATH environment variable
- # which is checked in item 4) in [1] (i.e. before both of the above, unless
- # NO_SYSTEM_ENVIRONMENT_PATH is passed). As such on those OSs installed
- # packages are usually detected in preference to exported package build
- # directories.
- #
- # To ensure a more consistent response across all OSs, and as users usually
- # want to prefer an installed version of a package over a locally built one
- # where both exist (esp. as the exported build directory might be removed
- # after installation), we first search with NO_CMAKE_PACKAGE_REGISTRY which
- # means any build directories exported by the user are ignored, and thus
- # installed directories are preferred. If this fails to find the package
- # we then research again, but without NO_CMAKE_PACKAGE_REGISTRY, so any
- # exported build directories will now be detected.
- #
- # To prevent confusion on Windows, we also pass NO_CMAKE_BUILDS_PATH (which
- # is item 5) in [1]), to not preferentially use projects that were built
- # recently with the CMake GUI to ensure that we always prefer an installed
- # version if available.
- #
- # [1] http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:find_package
- find_package(gflags QUIET
- NO_MODULE
- NO_CMAKE_PACKAGE_REGISTRY
- NO_CMAKE_BUILDS_PATH)
- if (gflags_FOUND)
- message(STATUS "Found installed version of gflags: ${gflags_DIR}")
- else(gflags_FOUND)
- # Failed to find an installed version of gflags, repeat search allowing
- # exported build directories.
- message(STATUS "Failed to find installed gflags CMake configuration, "
- "searching for gflags build directories exported with CMake.")
- # Again pass NO_CMAKE_BUILDS_PATH, as we know that gflags is exported and
- # do not want to treat projects built with the CMake GUI preferentially.
- find_package(gflags QUIET
- NO_MODULE
- NO_CMAKE_BUILDS_PATH)
- if (gflags_FOUND)
- message(STATUS "Found exported gflags build directory: ${gflags_DIR}")
- endif(gflags_FOUND)
- endif(gflags_FOUND)
-
- set(FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION ${gflags_FOUND})
-
- # gflags v2.1 - 2.1.2 shipped with a bug in their gflags-config.cmake [1]
- # whereby gflags_LIBRARIES = "gflags", but there was no imported target
- # called "gflags", they were called: gflags[_nothreads]-[static/shared].
- # As this causes linker errors when gflags is not installed in a location
- # on the current library paths, detect if this problem is present and
- # fix it.
- #
- # [1] https://github.com/gflags/gflags/issues/110
- if (gflags_FOUND)
- # NOTE: This is not written as additional conditions in the outer
- # if (gflags_FOUND) as the NOT TARGET "${gflags_LIBRARIES}"
- # condition causes problems if gflags is not found.
- if (${gflags_VERSION} VERSION_LESS 2.1.3 AND
- NOT TARGET "${gflags_LIBRARIES}")
- message(STATUS "Detected broken gflags install in: ${gflags_DIR}, "
- "version: ${gflags_VERSION} <= 2.1.2 which defines gflags_LIBRARIES = "
- "${gflags_LIBRARIES} which is not an imported CMake target, see: "
- "https://github.com/gflags/gflags/issues/110. Attempting to fix by "
- "detecting correct gflags target.")
- # Ordering here expresses preference for detection, specifically we do not
- # want to use the _nothreads variants if the full library is available.
- list(APPEND CHECK_GFLAGS_IMPORTED_TARGET_NAMES
- gflags-shared gflags-static
- gflags_nothreads-shared gflags_nothreads-static)
- foreach(CHECK_GFLAGS_TARGET ${CHECK_GFLAGS_IMPORTED_TARGET_NAMES})
- if (TARGET ${CHECK_GFLAGS_TARGET})
- message(STATUS "Found valid gflags target: ${CHECK_GFLAGS_TARGET}, "
- "updating gflags_LIBRARIES.")
- set(gflags_LIBRARIES ${CHECK_GFLAGS_TARGET})
- break()
- endif()
- endforeach()
- if (NOT TARGET ${gflags_LIBRARIES})
- message(STATUS "Failed to fix detected broken gflags install in: "
- "${gflags_DIR}, version: ${gflags_VERSION} <= 2.1.2, none of the "
- "imported targets for gflags: ${CHECK_GFLAGS_IMPORTED_TARGET_NAMES} "
- "are defined. Will continue with a manual search for gflags "
- "components. We recommend you build/install a version of gflags > "
- "2.1.2 (or master).")
- set(FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION FALSE)
- endif()
- endif()
- endif()
-
- if (FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION)
- message(STATUS "Detected gflags version: ${gflags_VERSION}")
- set(GFLAGS_FOUND ${gflags_FOUND})
- set(GFLAGS_INCLUDE_DIR ${gflags_INCLUDE_DIR})
- set(GFLAGS_LIBRARY ${gflags_LIBRARIES})
-
- # gflags does not export the namespace in their CMake configuration, so
- # use our function to determine what it should be, as it can be either
- # gflags or google dependent upon version & configuration.
- #
- # NOTE: We use the regex method to determine the namespace here, as
- # check_cxx_source_compiles() will not use imported targets, which
- # is what gflags will be in this case.
- gflags_check_gflags_namespace_using_regex()
-
- if (NOT GFLAGS_NAMESPACE)
- gflags_report_not_found(
- "Failed to determine gflags namespace using regex for gflags "
- "version: ${gflags_VERSION} exported here: ${gflags_DIR} using CMake.")
- endif (NOT GFLAGS_NAMESPACE)
- else (FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION)
- message(STATUS "Failed to find an installed/exported CMake configuration "
- "for gflags, will perform search for installed gflags components.")
- endif (FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION)
-endif(GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION)
-
-if (NOT GFLAGS_FOUND)
- # Either failed to find an exported gflags CMake configuration, or user
- # told us not to use one. Perform a manual search for all gflags components.
-
- # Handle possible presence of lib prefix for libraries on MSVC, see
- # also GFLAGS_RESET_FIND_LIBRARY_PREFIX().
- if (MSVC)
- # Preserve the caller's original values for CMAKE_FIND_LIBRARY_PREFIXES
- # s/t we can set it back before returning.
- set(CALLERS_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
- # The empty string in this list is important, it represents the case when
- # the libraries have no prefix (shared libraries / DLLs).
- set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "" "${CMAKE_FIND_LIBRARY_PREFIXES}")
- endif (MSVC)
-
- # Search user-installed locations first, so that we prefer user installs
- # to system installs where both exist.
- list(APPEND GFLAGS_CHECK_INCLUDE_DIRS
- /usr/local/include
- /usr/local/homebrew/include # Mac OS X
- /opt/local/var/macports/software # Mac OS X.
- /opt/local/include
- /usr/include)
- list(APPEND GFLAGS_CHECK_PATH_SUFFIXES
- gflags/include # Windows (for C:/Program Files prefix).
- gflags/Include ) # Windows (for C:/Program Files prefix).
-
- list(APPEND GFLAGS_CHECK_LIBRARY_DIRS
- /usr/local/lib
- /usr/local/homebrew/lib # Mac OS X.
- /opt/local/lib
- /usr/lib)
- list(APPEND GFLAGS_CHECK_LIBRARY_SUFFIXES
- gflags/lib # Windows (for C:/Program Files prefix).
- gflags/Lib ) # Windows (for C:/Program Files prefix).
-
- # Search supplied hint directories first if supplied.
- find_path(GFLAGS_INCLUDE_DIR
- NAMES gflags/gflags.h
- HINTS ${GFLAGS_INCLUDE_DIR_HINTS}
- PATHS ${GFLAGS_CHECK_INCLUDE_DIRS}
- PATH_SUFFIXES ${GFLAGS_CHECK_PATH_SUFFIXES})
- if (NOT GFLAGS_INCLUDE_DIR OR
- NOT EXISTS ${GFLAGS_INCLUDE_DIR})
- gflags_report_not_found(
- "Could not find gflags include directory, set GFLAGS_INCLUDE_DIR "
- "to directory containing gflags/gflags.h")
- endif (NOT GFLAGS_INCLUDE_DIR OR
- NOT EXISTS ${GFLAGS_INCLUDE_DIR})
-
- find_library(GFLAGS_LIBRARY NAMES gflags
- HINTS ${GFLAGS_LIBRARY_DIR_HINTS}
- PATHS ${GFLAGS_CHECK_LIBRARY_DIRS}
- PATH_SUFFIXES ${GFLAGS_CHECK_LIBRARY_SUFFIXES})
- if (NOT GFLAGS_LIBRARY OR
- NOT EXISTS ${GFLAGS_LIBRARY})
- gflags_report_not_found(
- "Could not find gflags library, set GFLAGS_LIBRARY "
- "to full path to libgflags.")
- endif (NOT GFLAGS_LIBRARY OR
- NOT EXISTS ${GFLAGS_LIBRARY})
-
- # gflags typically requires a threading library (which is OS dependent), note
- # that this defines the CMAKE_THREAD_LIBS_INIT variable. If we are able to
- # detect threads, we assume that gflags requires it.
- find_package(Threads QUIET)
- set(GFLAGS_LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
- # On Windows (including MinGW), the Shlwapi library is used by gflags if
- # available.
- if (WIN32)
- include(CheckIncludeFileCXX)
- check_include_file_cxx("shlwapi.h" HAVE_SHLWAPI)
- if (HAVE_SHLWAPI)
- list(APPEND GFLAGS_LINK_LIBRARIES shlwapi.lib)
- endif(HAVE_SHLWAPI)
- endif (WIN32)
-
- # Mark internally as found, then verify. GFLAGS_REPORT_NOT_FOUND() unsets
- # if called.
- set(GFLAGS_FOUND TRUE)
-
- # Identify what namespace gflags was built with.
- if (GFLAGS_INCLUDE_DIR AND NOT GFLAGS_NAMESPACE)
- # To handle Windows peculiarities / CMake bugs on MSVC we try two approaches
- # to detect the gflags namespace:
- #
- # 1) Try to use check_cxx_source_compiles() to compile a trivial program
- # with the two choices for the gflags namespace.
- #
- # 2) [In the event 1) fails] Use regex on the gflags headers to try to
- # determine the gflags namespace. Whilst this is less robust than 1),
- # it does avoid any interaction with msbuild.
- gflags_check_gflags_namespace_using_try_compile()
-
- if (NOT GFLAGS_NAMESPACE)
- # Failed to determine gflags namespace using check_cxx_source_compiles()
- # method, try and obtain it using regex on the gflags headers instead.
- message(STATUS "Failed to find gflags namespace using using "
- "check_cxx_source_compiles(), trying namespace regex instead, "
- "this is expected on Windows.")
- gflags_check_gflags_namespace_using_regex()
-
- if (NOT GFLAGS_NAMESPACE)
- gflags_report_not_found(
- "Failed to determine gflags namespace either by "
- "check_cxx_source_compiles(), or namespace regex.")
- endif (NOT GFLAGS_NAMESPACE)
- endif (NOT GFLAGS_NAMESPACE)
- endif (GFLAGS_INCLUDE_DIR AND NOT GFLAGS_NAMESPACE)
-
- # Make the GFLAGS_NAMESPACE a cache variable s/t the user can view it, and could
- # overwrite it in the CMake GUI.
- set(GFLAGS_NAMESPACE "${GFLAGS_NAMESPACE}" CACHE STRING
- "gflags namespace (google or gflags)" FORCE)
-
- # gflags does not seem to provide any record of the version in its
- # source tree, thus cannot extract version.
-
- # Catch case when caller has set GFLAGS_NAMESPACE in the cache / GUI
- # with an invalid value.
- if (GFLAGS_NAMESPACE AND
- NOT GFLAGS_NAMESPACE STREQUAL "google" AND
- NOT GFLAGS_NAMESPACE STREQUAL "gflags")
- gflags_report_not_found(
- "Caller defined GFLAGS_NAMESPACE:"
- " ${GFLAGS_NAMESPACE} is not valid, not google or gflags.")
- endif ()
- # Catch case when caller has set GFLAGS_INCLUDE_DIR in the cache / GUI and
- # thus FIND_[PATH/LIBRARY] are not called, but specified locations are
- # invalid, otherwise we would report the library as found.
- if (GFLAGS_INCLUDE_DIR AND
- NOT EXISTS ${GFLAGS_INCLUDE_DIR}/gflags/gflags.h)
- gflags_report_not_found(
- "Caller defined GFLAGS_INCLUDE_DIR:"
- " ${GFLAGS_INCLUDE_DIR} does not contain gflags/gflags.h header.")
- endif (GFLAGS_INCLUDE_DIR AND
- NOT EXISTS ${GFLAGS_INCLUDE_DIR}/gflags/gflags.h)
- # TODO: This regex for gflags library is pretty primitive, we use lowercase
- # for comparison to handle Windows using CamelCase library names, could
- # this check be better?
- string(TOLOWER "${GFLAGS_LIBRARY}" LOWERCASE_GFLAGS_LIBRARY)
- if (GFLAGS_LIBRARY AND
- NOT "${LOWERCASE_GFLAGS_LIBRARY}" MATCHES ".*gflags[^/]*")
- gflags_report_not_found(
- "Caller defined GFLAGS_LIBRARY: "
- "${GFLAGS_LIBRARY} does not match gflags.")
- endif (GFLAGS_LIBRARY AND
- NOT "${LOWERCASE_GFLAGS_LIBRARY}" MATCHES ".*gflags[^/]*")
-
- gflags_reset_find_library_prefix()
-
-endif(NOT GFLAGS_FOUND)
-
-# Set standard CMake FindPackage variables if found.
-if (GFLAGS_FOUND)
- set(GFLAGS_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR})
- set(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY} ${GFLAGS_LINK_LIBRARIES})
-endif (GFLAGS_FOUND)
-
-# Handle REQUIRED / QUIET optional arguments.
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(Gflags DEFAULT_MSG
- GFLAGS_INCLUDE_DIRS GFLAGS_LIBRARIES GFLAGS_NAMESPACE)
-
-# Only mark internal variables as advanced if we found gflags, otherwise
-# leave them visible in the standard GUI for the user to set manually.
-if (GFLAGS_FOUND)
- mark_as_advanced(FORCE GFLAGS_INCLUDE_DIR
- GFLAGS_LIBRARY
- GFLAGS_NAMESPACE
- gflags_DIR) # Autogenerated by find_package(gflags)
-endif (GFLAGS_FOUND)
diff --git a/cmake/FindGlog.cmake b/cmake/FindGlog.cmake
index 979dced..1a7b6c0 100644
--- a/cmake/FindGlog.cmake
+++ b/cmake/FindGlog.cmake
@@ -109,6 +109,16 @@
return()
endmacro(GLOG_REPORT_NOT_FOUND)
+# glog_message([mode] "message text")
+#
+# Wraps the standard cmake 'message' command, but suppresses output
+# if the QUIET flag was passed to the find_package(Glog ...) call.
+function(GLOG_MESSAGE)
+ if (NOT Glog_FIND_QUIETLY)
+ message(${ARGN})
+ endif()
+endfunction()
+
# Protect against any alternative find_package scripts for this library having
# been called previously (in a client project) which set GLOG_FOUND, but not
# the other variables we require / set here which could cause the search logic
@@ -123,13 +133,34 @@
if (NOT DEFINED GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION
AND NOT GLOG_INCLUDE_DIR_HINTS
AND NOT GLOG_LIBRARY_DIR_HINTS)
- message(STATUS "No preference for use of exported glog CMake configuration "
- "set, and no hints for include/library directories provided. "
+ glog_message(STATUS "No preference for use of exported glog CMake "
+ "configuration set, and no hints for include/library directories provided. "
"Defaulting to preferring an installed/exported glog CMake configuration "
"if available.")
set(GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION TRUE)
endif()
+# On macOS, add the Homebrew prefix (with appropriate suffixes) to the
+# respective HINTS directories (after any user-specified locations). This
+# handles Homebrew installations into non-standard locations (not /usr/local).
+# We do not use CMAKE_PREFIX_PATH for this as given the search ordering of
+# find_xxx(), doing so would override any user-specified HINTS locations with
+# the Homebrew version if it exists.
+if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ find_program(HOMEBREW_EXECUTABLE brew)
+ mark_as_advanced(FORCE HOMEBREW_EXECUTABLE)
+ if (HOMEBREW_EXECUTABLE)
+ # Detected a Homebrew install, query for its install prefix.
+ execute_process(COMMAND ${HOMEBREW_EXECUTABLE} --prefix
+ OUTPUT_VARIABLE HOMEBREW_INSTALL_PREFIX
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ glog_message(STATUS "Detected Homebrew with install prefix: "
+ "${HOMEBREW_INSTALL_PREFIX}, adding to CMake search paths.")
+ list(APPEND GLOG_INCLUDE_DIR_HINTS "${HOMEBREW_INSTALL_PREFIX}/include")
+ list(APPEND GLOG_LIBRARY_DIR_HINTS "${HOMEBREW_INSTALL_PREFIX}/lib")
+ endif()
+endif()
+
if (GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION)
# Try to find an exported CMake configuration for glog, as generated by
# glog versions > 0.3.4
@@ -176,15 +207,16 @@
# [1] http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:find_package
find_package(glog QUIET
NAMES google-glog glog
+ HINTS ${glog_DIR} ${HOMEBREW_INSTALL_PREFIX}
NO_MODULE
NO_CMAKE_PACKAGE_REGISTRY
NO_CMAKE_BUILDS_PATH)
if (glog_FOUND)
- message(STATUS "Found installed version of glog: ${glog_DIR}")
+ glog_message(STATUS "Found installed version of glog: ${glog_DIR}")
else()
# Failed to find an installed version of glog, repeat search allowing
# exported build directories.
- message(STATUS "Failed to find installed glog CMake configuration, "
+ glog_message(STATUS "Failed to find installed glog CMake configuration, "
"searching for glog build directories exported with CMake.")
# Again pass NO_CMAKE_BUILDS_PATH, as we know that glog is exported and
# do not want to treat projects built with the CMake GUI preferentially.
@@ -193,21 +225,22 @@
NO_MODULE
NO_CMAKE_BUILDS_PATH)
if (glog_FOUND)
- message(STATUS "Found exported glog build directory: ${glog_DIR}")
+ glog_message(STATUS "Found exported glog build directory: ${glog_DIR}")
endif(glog_FOUND)
endif(glog_FOUND)
set(FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION ${glog_FOUND})
if (FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION)
- message(STATUS "Detected glog version: ${glog_VERSION}")
+ glog_message(STATUS "Detected glog version: ${glog_VERSION}")
set(GLOG_FOUND ${glog_FOUND})
# glog wraps the include directories into the exported glog::glog target.
set(GLOG_INCLUDE_DIR "")
set(GLOG_LIBRARY glog::glog)
else (FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION)
- message(STATUS "Failed to find an installed/exported CMake configuration "
- "for glog, will perform search for installed glog components.")
+ glog_message(STATUS "Failed to find an installed/exported CMake "
+ "configuration for glog, will perform search for installed glog "
+ "components.")
endif (FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION)
endif(GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION)
diff --git a/cmake/FindSuiteSparse.cmake b/cmake/FindSuiteSparse.cmake
index e4de8b0..aad8904 100644
--- a/cmake/FindSuiteSparse.cmake
+++ b/cmake/FindSuiteSparse.cmake
@@ -165,6 +165,27 @@
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "" "${CMAKE_FIND_LIBRARY_PREFIXES}")
endif (MSVC)
+# On macOS, add the Homebrew prefix (with appropriate suffixes) to the
+# respective HINTS directories (after any user-specified locations). This
+# handles Homebrew installations into non-standard locations (not /usr/local).
+# We do not use CMAKE_PREFIX_PATH for this as given the search ordering of
+# find_xxx(), doing so would override any user-specified HINTS locations with
+# the Homebrew version if it exists.
+if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ find_program(HOMEBREW_EXECUTABLE brew)
+ mark_as_advanced(FORCE HOMEBREW_EXECUTABLE)
+ if (HOMEBREW_EXECUTABLE)
+ # Detected a Homebrew install, query for its install prefix.
+ execute_process(COMMAND ${HOMEBREW_EXECUTABLE} --prefix
+ OUTPUT_VARIABLE HOMEBREW_INSTALL_PREFIX
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ message(STATUS "Detected Homebrew with install prefix: "
+ "${HOMEBREW_INSTALL_PREFIX}, adding to CMake search paths.")
+ list(APPEND SUITESPARSE_INCLUDE_DIR_HINTS "${HOMEBREW_INSTALL_PREFIX}/include")
+ list(APPEND SUITESPARSE_LIBRARY_DIR_HINTS "${HOMEBREW_INSTALL_PREFIX}/lib")
+ endif()
+endif()
+
# Specify search directories for include files and libraries (this is the union
# of the search directories for all OSs). Search user-specified hint
# directories first if supplied, and search user-installed locations first
@@ -288,8 +309,9 @@
find_package(TBB QUIET)
if (TBB_FOUND)
message(STATUS "Found Intel Thread Building Blocks (TBB) library "
- "(${TBB_VERSION}) assuming SuiteSparseQR was compiled "
- "with TBB.")
+ "(${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} / ${TBB_INTERFACE_VERSION}) "
+ "include location: ${TBB_INCLUDE_DIRS}. Assuming SuiteSparseQR was "
+ "compiled with TBB.")
# Add the TBB libraries to the SuiteSparseQR libraries (the only
# libraries to optionally depend on TBB).
list(APPEND SUITESPARSEQR_LIBRARY ${TBB_LIBRARIES})
diff --git a/cmake/FindTBB.cmake b/cmake/FindTBB.cmake
index d3e2852..5ae7b61 100644
--- a/cmake/FindTBB.cmake
+++ b/cmake/FindTBB.cmake
@@ -1,245 +1,455 @@
-# The MIT License (MIT)
+# - Find ThreadingBuildingBlocks include dirs and libraries
+# Use this module by invoking find_package with the form:
+# find_package(TBB
+# [REQUIRED] # Fail with error if TBB is not found
+# ) #
+# Once done, this will define
#
-# Copyright (c) 2015 Justus Calvin
+# TBB_FOUND - system has TBB
+# TBB_INCLUDE_DIRS - the TBB include directories
+# TBB_LIBRARIES - TBB libraries to be lined, doesn't include malloc or
+# malloc proxy
+# TBB::tbb - imported target for the TBB library
#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
+# TBB_VERSION_MAJOR - Major Product Version Number
+# TBB_VERSION_MINOR - Minor Product Version Number
+# TBB_INTERFACE_VERSION - Engineering Focused Version Number
+# TBB_COMPATIBLE_INTERFACE_VERSION - The oldest major interface version
+# still supported. This uses the engineering
+# focused interface version numbers.
#
-# The above copyright notice and this permission notice shall be included in all
-# copies or substantial portions of the Software.
+# TBB_MALLOC_FOUND - system has TBB malloc library
+# TBB_MALLOC_INCLUDE_DIRS - the TBB malloc include directories
+# TBB_MALLOC_LIBRARIES - The TBB malloc libraries to be lined
+# TBB::malloc - imported target for the TBB malloc library
#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
+# TBB_MALLOC_PROXY_FOUND - system has TBB malloc proxy library
+# TBB_MALLOC_PROXY_INCLUDE_DIRS = the TBB malloc proxy include directories
+# TBB_MALLOC_PROXY_LIBRARIES - The TBB malloc proxy libraries to be lined
+# TBB::malloc_proxy - imported target for the TBB malloc proxy library
+#
+#
+# This module reads hints about search locations from variables:
+# ENV TBB_ARCH_PLATFORM - for eg. set it to "mic" for Xeon Phi builds
+# ENV TBB_ROOT or just TBB_ROOT - root directory of tbb installation
+# ENV TBB_BUILD_PREFIX - specifies the build prefix for user built tbb
+# libraries. Should be specified with ENV TBB_ROOT
+# and optionally...
+# ENV TBB_BUILD_DIR - if build directory is different than ${TBB_ROOT}/build
+#
+#
+# Modified by Robert Maynard from the original OGRE source
+#
+#-------------------------------------------------------------------
+# This file is part of the CMake build system for OGRE
+# (Object-oriented Graphics Rendering Engine)
+# For the latest info, see http://www.ogre3d.org/
+#
+# The contents of this file are placed in the public domain. Feel
+# free to make use of it in any way you like.
+#-------------------------------------------------------------------
+#
+# =========================================================================
+# Taken from Copyright.txt in the root of the VTK source tree as per
+# instructions to substitute the full license in place of the summary
+# reference when distributing outside of VTK
+# =========================================================================
+#
+# Program: Visualization Toolkit
+# Module: Copyright.txt
+#
+# Copyright (c) 1993-2015 Ken Martin, Will Schroeder, Bill Lorensen
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
+# of any contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# =========================================================================*/
+#=============================================================================
+# FindTBB helper functions and macros
#
-# FindTBB
-# -------
-#
-# Find TBB include directories and libraries.
-#
-# Usage:
-#
-# find_package(TBB [major[.minor]] [EXACT]
-# [QUIET] [REQUIRED]
-# [[COMPONENTS] [components...]]
-# [OPTIONAL_COMPONENTS components...])
-#
-# where the allowed components are tbbmalloc and tbb_preview. Users may modify
-# the behavior of this module with the following variables:
-#
-# * TBB_ROOT_DIR - The base directory the of TBB installation.
-# * TBB_INCLUDE_DIR - The directory that contains the TBB headers files.
-# * TBB_LIBRARY - The directory that contains the TBB library files.
-# * TBB_<library>_LIBRARY - The path of the TBB the corresponding TBB library.
-# These libraries, if specified, override the
-# corresponding library search results, where <library>
-# may be tbb, tbb_debug, tbbmalloc, tbbmalloc_debug,
-# tbb_preview, or tbb_preview_debug.
-# * TBB_USE_DEBUG_BUILD - The debug version of tbb libraries, if present, will
-# be used instead of the release version.
-#
-# Users may modify the behavior of this module with the following environment
-# variables:
-#
-# * TBB_INSTALL_DIR
-# * TBBROOT
-# * LIBRARY_PATH
-#
-# This module will set the following variables:
-#
-# * TBB_FOUND - Set to false, or undefined, if we haven’t found, or
-# don’t want to use TBB.
-# * TBB_<component>_FOUND - If False, optional <component> part of TBB sytem is
-# not available.
-# * TBB_VERSION - The full version string
-# * TBB_VERSION_MAJOR - The major version
-# * TBB_VERSION_MINOR - The minor version
-# * TBB_INTERFACE_VERSION - The interface version number defined in
-# tbb/tbb_stddef.h.
-# * TBB_<library>_LIBRARY_RELEASE - The path of the TBB release version of
-# <library>, where <library> may be tbb, tbb_debug,
-# tbbmalloc, tbbmalloc_debug, tbb_preview, or
-# tbb_preview_debug.
-# * TBB_<library>_LIBRARY_DEGUG - The path of the TBB release version of
-# <library>, where <library> may be tbb, tbb_debug,
-# tbbmalloc, tbbmalloc_debug, tbb_preview, or
-# tbb_preview_debug.
-#
-# The following varibles should be used to build and link with TBB:
-#
-# * TBB_INCLUDE_DIRS - The include directory for TBB.
-# * TBB_LIBRARIES - The libraries to link against to use TBB.
-# * TBB_DEFINITIONS - Definitions to use when compiling code that uses TBB.
-include(FindPackageHandleStandardArgs)
-
-if(NOT TBB_FOUND)
-
- ##################################
- # Check the build type
- ##################################
-
- if(NOT DEFINED TBB_USE_DEBUG_BUILD)
- if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug|RelWithDebInfo|RELWITHDEBINFO|relwithdebinfo)")
- set(TBB_USE_DEBUG_BUILD TRUE)
- else()
- set(TBB_USE_DEBUG_BUILD FALSE)
- endif()
+#====================================================
+# Fix the library path in case it is a linker script
+#====================================================
+function(tbb_extract_real_library library real_library)
+ if(NOT UNIX OR NOT EXISTS ${library})
+ set(${real_library} "${library}" PARENT_SCOPE)
+ return()
endif()
- ##################################
- # Set the TBB search directories
- ##################################
-
- # Define search paths based on user input and environment variables
- set(TBB_SEARCH_DIR ${TBB_ROOT_DIR} $ENV{TBB_INSTALL_DIR} $ENV{TBBROOT})
-
- # Define the search directories based on the current platform
- if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
- set(TBB_DEFAULT_SEARCH_DIR "C:/Program Files/Intel/TBB"
- "C:/Program Files (x86)/Intel/TBB")
-
- # Set the target architecture
- if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- set(TBB_ARCHITECTURE "intel64")
- else()
- set(TBB_ARCHITECTURE "ia32")
- endif()
-
- # Set the TBB search library path search suffix based on the version of VC
- if(WINDOWS_STORE)
- set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11_ui")
- elseif(MSVC14)
- set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc14")
- elseif(MSVC12)
- set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc12")
- elseif(MSVC11)
- set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11")
- elseif(MSVC10)
- set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc10")
- endif()
-
- # Add the library path search suffix for the VC independent version of TBB
- list(APPEND TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc_mt")
-
- elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
- # OS X
- set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb")
-
- # TODO: Check to see which C++ library is being used by the compiler.
- if(NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 13.0)
- # The default C++ library on OS X 10.9 and later is libc++
- set(TBB_LIB_PATH_SUFFIX "lib/libc++")
- else()
- set(TBB_LIB_PATH_SUFFIX "lib")
- endif()
- elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
- # Linux
- set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb")
-
- # TODO: Check compiler version to see the suffix should be <arch>/gcc4.1 or
- # <arch>/gcc4.1. For now, assume that the compiler is more recent than
- # gcc 4.4.x or later.
- if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
- set(TBB_LIB_PATH_SUFFIX "lib/intel64/gcc4.4")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
- set(TBB_LIB_PATH_SUFFIX "lib/ia32/gcc4.4")
- endif()
+ #Read in the first 4 bytes and see if they are the ELF magic number
+ set(_elf_magic "7f454c46")
+ file(READ ${library} _hex_data OFFSET 0 LIMIT 4 HEX)
+ if(_hex_data STREQUAL _elf_magic)
+ #we have opened a elf binary so this is what
+ #we should link to
+ set(${real_library} "${library}" PARENT_SCOPE)
+ return()
endif()
- ##################################
- # Find the TBB include dir
- ##################################
+ file(READ ${library} _data OFFSET 0 LIMIT 1024)
+ if("${_data}" MATCHES "INPUT \\(([^(]+)\\)")
+ #extract out the .so name from REGEX MATCH command
+ set(_proper_so_name "${CMAKE_MATCH_1}")
- find_path(TBB_INCLUDE_DIRS tbb/tbb.h
- HINTS ${TBB_INCLUDE_DIR} ${TBB_SEARCH_DIR}
- PATHS ${TBB_DEFAULT_SEARCH_DIR}
- PATH_SUFFIXES include)
+ #construct path to the real .so which is presumed to be in the same directory
+ #as the input file
+ get_filename_component(_so_dir "${library}" DIRECTORY)
+ set(${real_library} "${_so_dir}/${_proper_so_name}" PARENT_SCOPE)
+ else()
+ #unable to determine what this library is so just hope everything works
+ #and pass it unmodified.
+ set(${real_library} "${library}" PARENT_SCOPE)
+ endif()
+endfunction()
- ##################################
- # Find TBB components
- ##################################
+#===============================================
+# Do the final processing for the package find.
+#===============================================
+macro(findpkg_finish PREFIX TARGET_NAME)
+ if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
+ set(${PREFIX}_FOUND TRUE)
+ set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
+ set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
+ else ()
+ if (${PREFIX}_FIND_REQUIRED AND NOT ${PREFIX}_FIND_QUIETLY)
+ message(FATAL_ERROR "Required library ${PREFIX} not found.")
+ endif ()
+ endif ()
- # Find each component
- foreach(_comp tbb_preview tbbmalloc tbb)
- # Search for the libraries
- find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp}
- HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
- PATHS ${TBB_DEFAULT_SEARCH_DIR}
- PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX})
+ if (NOT TARGET "TBB::${TARGET_NAME}")
+ if (${PREFIX}_LIBRARY_RELEASE)
+ tbb_extract_real_library(${${PREFIX}_LIBRARY_RELEASE} real_release)
+ endif ()
+ if (${PREFIX}_LIBRARY_DEBUG)
+ tbb_extract_real_library(${${PREFIX}_LIBRARY_DEBUG} real_debug)
+ endif ()
+ add_library(TBB::${TARGET_NAME} UNKNOWN IMPORTED)
+ set_target_properties(TBB::${TARGET_NAME} PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${${PREFIX}_INCLUDE_DIR}")
+ if (${PREFIX}_LIBRARY_DEBUG AND ${PREFIX}_LIBRARY_RELEASE)
+ set_target_properties(TBB::${TARGET_NAME} PROPERTIES
+ IMPORTED_LOCATION "${real_release}"
+ IMPORTED_LOCATION_DEBUG "${real_debug}"
+ IMPORTED_LOCATION_RELEASE "${real_release}")
+ elseif (${PREFIX}_LIBRARY_RELEASE)
+ set_target_properties(TBB::${TARGET_NAME} PROPERTIES
+ IMPORTED_LOCATION "${real_release}")
+ elseif (${PREFIX}_LIBRARY_DEBUG)
+ set_target_properties(TBB::${TARGET_NAME} PROPERTIES
+ IMPORTED_LOCATION "${real_debug}")
+ endif ()
+ endif ()
- find_library(TBB_${_comp}_LIBRARY_DEBUG ${_comp}_debug
- HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
- PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
- PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX})
+ #mark the following variables as internal variables
+ mark_as_advanced(${PREFIX}_INCLUDE_DIR
+ ${PREFIX}_LIBRARY
+ ${PREFIX}_LIBRARY_DEBUG
+ ${PREFIX}_LIBRARY_RELEASE)
+endmacro()
-
- # Set the library to be used for the component
- if(NOT TBB_${_comp}_LIBRARY)
- if(TBB_USE_DEBUG_BUILD AND TBB_${_comp}_LIBRARY_DEBUG)
- set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_DEBUG}")
- elseif(TBB_${_comp}_LIBRARY_RELEASE)
- set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_RELEASE}")
- elseif(TBB_${_comp}_LIBRARY_DEBUG)
- set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_DEBUG}")
- endif()
- endif()
-
- # Set the TBB library list and component found variables
- if(TBB_${_comp}_LIBRARY)
- list(APPEND TBB_LIBRARIES "${TBB_${_comp}_LIBRARY}")
- set(TBB_${_comp}_FOUND TRUE)
- else()
- set(TBB_${_comp}_FOUND FALSE)
- endif()
-
- mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE)
- mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG)
- mark_as_advanced(TBB_${_comp}_LIBRARY)
-
+#===============================================
+# Generate debug names from given release names
+#===============================================
+macro(get_debug_names PREFIX)
+ foreach(i ${${PREFIX}})
+ set(${PREFIX}_DEBUG ${${PREFIX}_DEBUG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i})
endforeach()
+endmacro()
- ##################################
- # Set compile flags
- ##################################
+#===============================================
+# See if we have env vars to help us find tbb
+#===============================================
+macro(getenv_path VAR)
+ set(ENV_${VAR} $ENV{${VAR}})
+ # replace won't work if var is blank
+ if (ENV_${VAR})
+ string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} )
+ endif ()
+endmacro()
- if(TBB_tbb_LIBRARY MATCHES "debug")
- set(TBB_DEFINITIONS "-DTBB_USE_DEBUG=1")
+#===============================================
+# Couple a set of release AND debug libraries
+#===============================================
+macro(make_library_set PREFIX)
+ if (${PREFIX}_RELEASE AND ${PREFIX}_DEBUG)
+ set(${PREFIX} optimized ${${PREFIX}_RELEASE} debug ${${PREFIX}_DEBUG})
+ elseif (${PREFIX}_RELEASE)
+ set(${PREFIX} ${${PREFIX}_RELEASE})
+ elseif (${PREFIX}_DEBUG)
+ set(${PREFIX} ${${PREFIX}_DEBUG})
+ endif ()
+endmacro()
+
+#===============================================
+# Ensure that the release & debug libraries found are from the same installation.
+#===============================================
+macro(find_tbb_library_verifying_release_debug_locations PREFIX)
+ find_library(${PREFIX}_RELEASE
+ NAMES ${${PREFIX}_NAMES}
+ HINTS ${TBB_LIB_SEARCH_PATH})
+ if (${PREFIX}_RELEASE)
+ # To avoid finding a mismatched set of release & debug libraries from
+ # different installations if the first found does not have debug libraries
+ # by forcing the search for debug to only occur within the detected release
+ # library directory (if found). Although this would break detection if the
+ # release & debug libraries were shipped in different directories, this is
+ # not the case in the official TBB releases for any platform.
+ get_filename_component(
+ FOUND_RELEASE_LIB_DIR "${${PREFIX}_RELEASE}" DIRECTORY)
+ find_library(${PREFIX}_DEBUG
+ NAMES ${${PREFIX}_NAMES_DEBUG}
+ HINTS ${FOUND_RELEASE_LIB_DIR}
+ NO_DEFAULT_PATH)
+ else()
+ find_library(${PREFIX}_DEBUG
+ NAMES ${${PREFIX}_NAMES_DEBUG}
+ HINTS ${TBB_LIB_SEARCH_PATH})
endif()
+endmacro()
- ##################################
- # Set version strings
- ##################################
+#=============================================================================
+# Now to actually find TBB
+#
- if(TBB_INCLUDE_DIRS)
- file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file)
- string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
- TBB_VERSION_MAJOR "${_tbb_version_file}")
- string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
- TBB_VERSION_MINOR "${_tbb_version_file}")
- string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1"
- TBB_INTERFACE_VERSION "${_tbb_version_file}")
- set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}")
+# Get path, convert backslashes as ${ENV_${var}}
+getenv_path(TBB_ROOT)
+
+# initialize search paths
+set(TBB_PREFIX_PATH ${TBB_ROOT} ${ENV_TBB_ROOT})
+set(TBB_INC_SEARCH_PATH "")
+set(TBB_LIB_SEARCH_PATH "")
+
+
+# If user built from sources
+set(TBB_BUILD_PREFIX $ENV{TBB_BUILD_PREFIX})
+if (TBB_BUILD_PREFIX AND ENV_TBB_ROOT)
+ getenv_path(TBB_BUILD_DIR)
+ if (NOT ENV_TBB_BUILD_DIR)
+ set(ENV_TBB_BUILD_DIR ${ENV_TBB_ROOT}/build)
+ endif ()
+
+ # include directory under ${ENV_TBB_ROOT}/include
+ list(APPEND TBB_LIB_SEARCH_PATH
+ ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_release
+ ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_debug)
+endif ()
+
+
+# For Windows, let's assume that the user might be using the precompiled
+# TBB packages from the main website. These use a rather awkward directory
+# structure (at least for automatically finding the right files) depending
+# on platform and compiler, but we'll do our best to accommodate it.
+# Not adding the same effort for the precompiled linux builds, though. Those
+# have different versions for CC compiler versions and linux kernels which
+# will never adequately match the user's setup, so there is no feasible way
+# to detect the "best" version to use. The user will have to manually
+# select the right files. (Chances are the distributions are shipping their
+# custom version of tbb, anyway, so the problem is probably nonexistent.)
+if (WIN32 AND MSVC)
+ set(COMPILER_PREFIX "vc7.1")
+ if (MSVC_VERSION EQUAL 1400)
+ set(COMPILER_PREFIX "vc8")
+ elseif(MSVC_VERSION EQUAL 1500)
+ set(COMPILER_PREFIX "vc9")
+ elseif(MSVC_VERSION EQUAL 1600)
+ set(COMPILER_PREFIX "vc10")
+ elseif(MSVC_VERSION EQUAL 1700)
+ set(COMPILER_PREFIX "vc11")
+ elseif(MSVC_VERSION EQUAL 1800)
+ set(COMPILER_PREFIX "vc12")
+ elseif(MSVC_VERSION GREATER_EQUAL 1900)
+ set(COMPILER_PREFIX "vc14")
+ endif ()
+
+ # for each prefix path, add ia32/64\${COMPILER_PREFIX}\lib to the lib search path
+ foreach (dir IN LISTS TBB_PREFIX_PATH)
+ if (CMAKE_CL_64)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia64/${COMPILER_PREFIX}/lib)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia64/${COMPILER_PREFIX})
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${COMPILER_PREFIX}/lib)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${COMPILER_PREFIX})
+ else ()
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${COMPILER_PREFIX}/lib)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${COMPILER_PREFIX})
+ endif ()
+ endforeach ()
+endif ()
+
+# For OS X binary distribution, choose libc++ based libraries for Mavericks (10.9)
+# and above and AppleClang
+if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND
+ NOT CMAKE_SYSTEM_VERSION VERSION_LESS 13.0)
+ set (USE_LIBCXX OFF)
+ cmake_policy(GET CMP0025 POLICY_VAR)
+
+ if (POLICY_VAR STREQUAL "NEW")
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
+ set (USE_LIBCXX ON)
+ endif ()
+ else ()
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ set (USE_LIBCXX ON)
+ endif ()
+ endif ()
+
+ if (USE_LIBCXX)
+ foreach (dir IN LISTS TBB_PREFIX_PATH)
+ list (APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/libc++ ${dir}/libc++/lib)
+ endforeach ()
+ endif ()
+endif ()
+
+# check compiler ABI
+if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ set(COMPILER_PREFIX)
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
+ list(APPEND COMPILER_PREFIX "gcc4.8")
endif()
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+ list(APPEND COMPILER_PREFIX "gcc4.7")
+ endif()
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
+ list(APPEND COMPILER_PREFIX "gcc4.4")
+ endif()
+ list(APPEND COMPILER_PREFIX "gcc4.1")
+elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ set(COMPILER_PREFIX)
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) # Complete guess
+ list(APPEND COMPILER_PREFIX "gcc4.8")
+ endif()
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
+ list(APPEND COMPILER_PREFIX "gcc4.7")
+ endif()
+ list(APPEND COMPILER_PREFIX "gcc4.4")
+else() # Assume compatibility with 4.4 for other compilers
+ list(APPEND COMPILER_PREFIX "gcc4.4")
+endif ()
- find_package_handle_standard_args(TBB
- REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES
- HANDLE_COMPONENTS
- VERSION_VAR TBB_VERSION)
+# if platform architecture is explicitly specified
+set(TBB_ARCH_PLATFORM $ENV{TBB_ARCH_PLATFORM})
+if (TBB_ARCH_PLATFORM)
+ foreach (dir IN LISTS TBB_PREFIX_PATH)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/${TBB_ARCH_PLATFORM}/lib)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/${TBB_ARCH_PLATFORM})
+ endforeach ()
+endif ()
- mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES)
+foreach (dir IN LISTS TBB_PREFIX_PATH)
+ foreach (prefix IN LISTS COMPILER_PREFIX)
+ if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${prefix})
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/lib)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${prefix}/lib)
+ else ()
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${prefix})
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/lib)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${prefix}/lib)
+ endif ()
+ endforeach()
+endforeach ()
- unset(TBB_ARCHITECTURE)
- unset(TBB_LIB_PATH_SUFFIX)
- unset(TBB_DEFAULT_SEARCH_DIR)
+# add general search paths
+foreach (dir IN LISTS TBB_PREFIX_PATH)
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib ${dir}/Lib ${dir}/lib/tbb
+ ${dir}/Libs)
+ list(APPEND TBB_INC_SEARCH_PATH ${dir}/include ${dir}/Include
+ ${dir}/include/tbb)
+endforeach ()
+
+set(TBB_LIBRARY_NAMES tbb)
+get_debug_names(TBB_LIBRARY_NAMES)
+
+find_path(TBB_INCLUDE_DIR
+ NAMES tbb/tbb.h
+ HINTS ${TBB_INC_SEARCH_PATH})
+find_tbb_library_verifying_release_debug_locations(TBB_LIBRARY)
+make_library_set(TBB_LIBRARY)
+
+findpkg_finish(TBB tbb)
+
+#if we haven't found TBB no point on going any further
+if (NOT TBB_FOUND)
+ return()
+endif ()
+
+#=============================================================================
+# Look for TBB's malloc package
+set(TBB_MALLOC_LIBRARY_NAMES tbbmalloc)
+get_debug_names(TBB_MALLOC_LIBRARY_NAMES)
+
+find_path(TBB_MALLOC_INCLUDE_DIR
+ NAMES tbb/tbb.h
+ HINTS ${TBB_INC_SEARCH_PATH})
+find_tbb_library_verifying_release_debug_locations(TBB_MALLOC_LIBRARY)
+make_library_set(TBB_MALLOC_LIBRARY)
+
+findpkg_finish(TBB_MALLOC tbbmalloc)
+
+#=============================================================================
+# Look for TBB's malloc proxy package
+set(TBB_MALLOC_PROXY_LIBRARY_NAMES tbbmalloc_proxy)
+get_debug_names(TBB_MALLOC_PROXY_LIBRARY_NAMES)
+
+find_path(TBB_MALLOC_PROXY_INCLUDE_DIR
+ NAMES tbb/tbbmalloc_proxy.h
+ HINTS ${TBB_INC_SEARCH_PATH})
+find_tbb_library_verifying_release_debug_locations(TBB_MALLOC_PROXY_LIBRARY)
+make_library_set(TBB_MALLOC_PROXY_LIBRARY)
+
+findpkg_finish(TBB_MALLOC_PROXY tbbmalloc_proxy)
+
+
+#=============================================================================
+#parse all the version numbers from tbb
+if(NOT TBB_VERSION)
+
+ #only read the start of the file
+ file(STRINGS
+ "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h"
+ TBB_VERSION_CONTENTS
+ REGEX "VERSION")
+
+ string(REGEX REPLACE
+ ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
+ TBB_VERSION_MAJOR "${TBB_VERSION_CONTENTS}")
+
+ string(REGEX REPLACE
+ ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
+ TBB_VERSION_MINOR "${TBB_VERSION_CONTENTS}")
+
+ string(REGEX REPLACE
+ ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1"
+ TBB_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}")
+
+ string(REGEX REPLACE
+ ".*#define TBB_COMPATIBLE_INTERFACE_VERSION ([0-9]+).*" "\\1"
+ TBB_COMPATIBLE_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}")
endif()
diff --git a/cmake/config.h.in b/cmake/config.h.in
index 1caacfe..4a516f6 100644
--- a/cmake/config.h.in
+++ b/cmake/config.h.in
@@ -73,10 +73,10 @@
// If defined, Ceres was compiled without multithreading support.
@CERES_NO_THREADS@
-// If defined Ceres was compiled with OpenMP multithreading support.
+// If defined Ceres was compiled with OpenMP multithreading.
@CERES_USE_OPENMP@
-// If defined Ceres was compiled with C++11 thread support.
-@CERES_USE_CXX11_THREADS@
+// If defined Ceres was compiled with modern C++ multithreading.
+@CERES_USE_CXX_THREADS@
// If defined, Ceres was built as a shared library.
@CERES_USING_SHARED_LIBRARY@
diff --git a/cmake/iOS.cmake b/cmake/iOS.cmake
index bb42802..4029f96 100644
--- a/cmake/iOS.cmake
+++ b/cmake/iOS.cmake
@@ -297,7 +297,7 @@
# Set the find root to the iOS developer roots and to user defined paths.
set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_OSX_SYSROOT}
- ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root" FORCE)
+ ${CMAKE_PREFIX_PATH} CACHE STRING "iOS find search path root" FORCE)
# Default to searching for frameworks first.
set(CMAKE_FIND_FRAMEWORK FIRST)