Commit Graph

105 Commits

Author SHA1 Message Date
Kuang Fangjun 0d3a84fce5 Fix typos in doc and errors in the demo code.
Change-Id: I237402958ed8747ae438643132fcab90113ac27d
2018-09-22 12:01:20 +08:00
Alex Stewart 402a2e4b6d Import Threads::Threads CMake target in CeresConfig.cmake
- Required now that Threads is a public dependency for Ceres and so
  Threads::Threads will appear in the dependency list for the Ceres
  target and so must be defined when Ceres itself is imported.

Change-Id: Ia5f8ea16e8f24cf0158f40e1fc8d3962106459a6
2018-08-23 09:22:22 +01:00
Alex Stewart 16f9b34c3b Remove Intel TBB threading support.
- In light of the C++11 threads threading option this is no longer
  necessary for cross-platform threading support and did not offer a
  noticeable performance gain over either the C++11 threads
  implementation or OpenMP.

Change-Id: Icb588d520888c19a1775171795b55bcaffb3d256
2018-07-03 18:05:36 +00:00
Alex Stewart 2166bad133 Replace include_directories() with target_include_directories().
- Now that we require CMake >= 3.x, we can roll the definition of the
  include directories for clients linking against Ceres into the
  exported Ceres CMake target via target_include_directories().
- This removes the requirement for CERES_INCLUDE_DIRS.

Change-Id: Ibe3bbf796339871d66138fc9520053d1766f09a8
2018-07-02 12:15:13 +01:00
Alex Stewart 8f41ca6abc Add Apple's Accelerate framework as a sparse linear algebra library.
- Currently DynamicSparseNormalCholeskySolver is unsupported for
  Accelerate.

Change-Id: I03b5a86bb22fef249c4aecd48947a613e8eff7a5
2018-06-29 09:43:03 +01:00
Alex Stewart d656d34809 Refactor Ceres threading option configuration.
- Previously we had separate variables for each of the threading
  backends, each of which were made mutually exclusive via
  cmake_dependent_option().  This has unfortunate side-effects when
  trying to disable options if they are not currently enabled, in which
  case they are not defined.
- As all the threading options are mutually exclusive, this replaces
  all threading option variables with a single variable: CERES_THREADS,
  which is constrained to take the value of only the available threading
  backends.

Change-Id: I0822eefbac9a30772907b7732add365b37cc8ca0
2018-06-20 23:20:57 +00:00
Alex Stewart 799fd50192 Ensure host-built packages are not used when building for iOS.
- Add missing CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = ONLY, mimicking what
  we previously set for INCLUDE/LIBRARY/PROGRAM s/t the standard
  package locations on the host system will not be searched by
  find_package() when cross-compiling for iOS.
- Remove now unnecessary forced disabling of dependency options on iOS
  as they should now never be found (unless they were explicitly built
  for iOS) irrespective of whether the option defaults to ON initially.

Change-Id: I1d2c5da4838d7becb8ebd43f90a88cfc6ded4a1f
2018-06-20 09:43:26 +01:00
Alex Stewart 7582834a7e Do not bypass default CMake compiler checks on iOS.
- This should no longer be required on newer (3.5+) CMake versions and
  breaks the detection of supplementary compiler feature information
  such as the population of CMAKE_CXX_COMPILE_FEATURES which is required
  in order to compile Ceres.

Change-Id: Ibceab545925aa1e829320efa03fb74ef149cbb8b
2018-06-17 16:13:56 +01:00
Alex Stewart af77d3e676 Fix exported gflags include path.
- In practice, this was not causing any errors, as
  GFLAGS_INCLUDE_DIR_HINTS is set from GFLAGS_INCLUDE_DIRS so the two
  would have been equivalent, but we should nonetheless be using the
  one set after the find_package() call.
- Note that this would only have been active for older gflags versions
  that were not built with CMake.

Change-Id: Ie54145f522c974b7685052aafb1d2f6055d22337
2018-04-03 18:07:43 +01:00
Keir Mierle 7c4e8a454e Replace scoped_ptr with C++11's unique_ptr
Change-Id: Ib5a504c491e3a79af52a95accf009df473470c6b
2018-04-02 14:47:47 -07:00
Sameer Agarwal fc9336e12a Deprecate mutex.h
Use C++11's std::mutex and std::lock_guard instead.

Change-Id: If8d513d5d8f2ee2a49c1ebb249ffa93e4a80086b
2018-04-02 06:03:06 -07:00
Sameer Agarwal a1458f3348 More C++11ification.
1. Replace HashMap and HashSet with std::unordered_map and
   std::unordered_set respectively.
2. Extract the pair hasher into a struct pair_hash.
3. Delete collections_port.h
4. Convert explicit iterator based loops to auto based
   loops where sensible.

Change-Id: Ib88bcd13a7463d18435639d3b771abaa52080efb
2018-03-30 12:03:28 -07:00
Sameer Agarwal ffae101c75 Removed CERES_USE_CXX11
Remove the special handling for tr1::shared_ptr.

Change-Id: Ic405dcfe881dd6560d236956f84bfb8911d0bcbb
2018-03-29 15:16:49 -07:00
Alex Stewart 282b8b5f35 Require >= C++11 & CMake >= 3.5 when building Ceres.
- Removes CXX11 option, and all associate paraphernalia.  Ceres now
  requires a compiler with full >= C++11 support.  In MSVC terms this
  means >= 2013 Release 4.
- This deprecates the use of CERES_STD_UNORDERED_MAP and CERES_USE_CXX11
  as they will now always be defined.  They will be removed from the
  source in a future CL.
- For clients with CMake >= 3.8 we propagate via the exported/installed
  Ceres target the CXX version that was specified when Ceres was built.
  For versions < 3.8 (but >= 3.5) we specify the CXX features currently
  used in the Ceres public API.

Change-Id: I535b545b10156e4426659c270a4a0649e071df0e
2018-03-29 09:32:59 +01:00
Alex Stewart a80b8cfeac Fix C++11 detection for VS2010.
- Use cmake_dependent_option() for all threading models and encode their
  respective mutual exclusivity in the dependent-option s/t the job of
  ensuring mutual exclusivity is performed by CMake.
- Use of cmake_dependent_option() has the downside that options are
  removed from the GUI if their requirements for availability are not
  met.  So if CXX11 is OFF, then neither TBB nor CXX11_THREADS will
  even appear as options (they will be undefined, assumed OFF).
- Perform checks for availability of C++11 if CXX11 is enabled prior to
  testing other options to handle dependence of TBB & CXX11_THREADS on
  CXX11 actually being present.
- Add check for availability of C++11-specific math functions used in
  jet.h before reporting C++11 as found.
- Add check for <atomic> before allowing TBB or CXX11_THREADS, as both
  options require it and it may not always be available even if the
  other required C++11 components are.

Change-Id: Ife8cd182aeb1978539ce2c9966910ae59ebd9177
2018-03-19 09:40:48 +00:00
Alex Stewart df2d882540 Remove armv7 from target architectures when building for iOS >= 11.
- iOS 11+ requires a 64-bit architecture, so only arm64 is supported.

Change-Id: Ieb2ead13ba8722c6c0777b78f59f667331ad670c
2018-03-04 12:16:27 +00:00
Mike Vitus 7b2717582a Adds C++11 parallel for implementation.
Implements ParallelFor using the C++11 based ThreadPool.  The C++11
parallel for is 50-70% faster than single threaded, and 20-30% slower
than TBB.

Tested by compiling with OpenMP, TBB, and C++11 Threading support and
ran the unit tests.  Ran bazel as well.

Change-Id: I7fd6c9037ff9f200ce6999b5f39918995bb6b8ea
2018-02-26 16:12:03 -08:00
Alex Stewart c426f464ab Fix TBB detection on Windows.
- Reported as issue #334 by anuppari:
  https://github.com/ceres-solver/ceres-solver/issues/334.

Change-Id: Ie8af4b3ce7ef97e471deb780e2b7d683dcb0d658
2018-02-15 19:14:08 +00:00
Alex Stewart 488d401ac3 Cleanup import of TBB in CMake.
- Update FindSuiteSparse to use FindTBB.cmake to find TBB.
- Fix logic handling of TBB=ON if TBB is not found to continue with
  build after disabling TBB rather than throwing a fatal error.
- Use TBB_LIBRARIES instead of TBB_tbb_LIBRARY as a Ceres dependency,
  the former also includes the TBB malloc library.
- Add warning message about GPL licensing if TBB version < 2017.
- Add ‘TBB’ & ‘Mulithreading’ component options to find_package(Ceres),
  where ‘Mulithreading’ is equivalent to ‘TBB’ || ‘OpenMP’.

Change-Id: Ifc7f1d01b050ba6e2097ad1913b178805df4769a
2017-12-11 10:15:32 +00:00
Yury Prokazov 4ffec20a44 Add TBB threading support.
There are platforms where OpenMP is not available. This
patch adds support for Intel Threading Building Blocks (TBB)
as an alternative threading backend.

Change-Id: I94497d7cba0c3cfaccfc992169236f17fe948ae9
2017-09-25 12:43:14 +02:00
Alex Stewart d8f40912f0 Hide optional SuiteSparse vars in CMake GUI by default.
Change-Id: I7d7a82d1cbb8a6689bb383e4de2b9415ab7a3a81
2017-08-13 19:16:46 +01:00
Alex Stewart ffe7cc3eca Always hide TBB_LIBRARY in CMake GUI by default.
Change-Id: I4e5c0985144b48c977ebab539634f66741922502
2017-08-13 18:59:31 +01:00
Alex Stewart f58eacf082 Fix suppression of C++11 propagation warning.
- Since the update to optionally use target_compile_features(), the
  warning about Ceres propagating C++11 compile flag requirements to
  clients was suppressed dependent upon the compiler option selected by
  CMake to satisfy the C++11 requirements for Ceres (e.g. if using
  -std=gnu++11 instead of -std=c++11).
- Now we display the warning for all CMake versions where any C++11
  related flags can be exported in the Ceres target (CMake >= 2.8.12)
  if Ceres was compiled with the CXX11 option enabled.

Change-Id: I5cb91e773fc7c41996b5eabadcaa295ebd7de4f7
2017-08-09 14:58:34 +01:00
Arkady Shapkin a1ff7f720f Support suitesparse path suffix on Windows for SuiteSparse and CXSparse
Change-Id: Iaf9b75dc1cb7da5d305ee3fac9a8c28b3d0a2346
2017-07-07 08:44:46 +00:00
Taylor Braun-Jones e6c14a4e3c Fix cmake error from CeresConfig.cmake when Ceres not found
Change-Id: I944c950ecfcb23d4c49b2b4f98852a99913f2f8b
2017-07-06 09:31:30 -04:00
Sameer Agarwal 60811dffe1 Fix a bug introduced in fa39fae0b7
The FindSuiteSparse.cmake refactor had a typo where CCOLAMD
and COLAMD were conflated.

Thanks to @jasjuang for reporting this issue and finding the exact
commit where this bug was introduced.

Change-Id: If8ef6624df3b8b2fd7f0861eafc4700173401435
2017-07-02 00:09:21 -07:00
Alex Stewart fa39fae0b7 Pass user-specified search hints as HINTS not PATHS.
- As reported as Issue #285, previously we passed user-specified hint
  locations as PATHS to find_path/library which means that they are
  searched after system locations. Now we pass them as HINTS, which are
  searched before system locations.
- Also clean-up FindSuiteSparse to replace repeated code for finding
  each component with a common macro.

Change-Id: I20a1f905d929a23037b1d0b7fb7ffe817abaa3e3
2017-06-05 08:35:02 +00:00
Alex Stewart ec5bd23237 Prefer Eigen installs over exported build directories.
- Use the same logic as per gflags & glog whereby we perform (up to)
  two find_package() calls such that installed packages are preferred
  to exported build directories across all platforms.

Change-Id: Ifb9a7ba322ee43ed18c5774633e4bb527ce7cd75
2017-06-04 14:09:00 +01:00
Alex Stewart d72e19d985 Use target_compile_features() to specify C++11 requirement if available.
- Use target_compile_features() to specify the C++11 dependency for
  Ceres if the CXX11 option is enabled and the current CMake version
  supports it (>= 3.1).  Otherwise fall back onto our existing
  target_compile_options() solution if available.
- We prefer the use of target_compile_features() if available as it more
  gracefully handles ‘upgrading’ of the C++ standard in client projects
  that depend upon Ceres, e.g. if the client requires C++14.  The
  current solution may fail to produce the expected result in this case
  as raised in
  https://github.com/ceres-solver/ceres-solver/issues/273.

Change-Id: Ib3cff8d4b9fe93fa6d6b376b4dd53923bb1c4ecc
2017-04-30 14:51:03 +00:00
Alex Stewart 74df65b142 Optionally use exported Eigen CMake configuration if available.
- Updates FindEigen.cmake to default to an installed Eigen CMake
  Configuration if available, otherwise falls back to previous behaviour
  of searching for Eigen components.
- This mimics the behaviour of FindGflags.cmake & FindGlog.cmake.

Change-Id: Ifce948d554a0135ce1a0c443267c0230e516f14b
2017-04-19 16:16:27 +01:00
Sameer Agarwal 0b74859788 Fix how NOT binds in the if statement
Change-Id: Ia6a165abc7c898b031d73179eaf318d8d0c229ec
2017-04-11 12:26:02 -07:00
Alex Stewart c123864372 Use Ceres_[SOURCE/BINARY]_DIR not CMAKE_XXX_DIR to support nesting.
- Using Ceres_[SOURCE/BINARY]_DIR (which are defined by CMake when
  project(Ceres) is called, in favour of CMAKE_[SOURCE/BINARY]_DIR
  enables Ceres to be nested within (and built by) a larger CMake
  project (which also contains other projects).
- CMAKE_[SOURCE/BINARY]_DIR always refers to the top-level source
  and binary directories (i.e. the first encountered), as a result if
  Ceres is a nested project within a larger project, these would not
  correctly identify the source/binary directories for Ceres (as they
  would refer to the root project in which Ceres is nested).
- Using Ceres_[SOURCE/BINARY]_DIR should ensure that Ceres always uses
  the correct source/binary directories, irrespective of whether Ceres
  is nested or not.

Change-Id: I62226ea3f6552b1d7e2bdac1aef02f1f489ae55e
2017-04-03 14:47:29 +01:00
Alex Stewart 04291898fd Add default Fedora/Debian locations for CXSparse to search paths.
Change-Id: I7361ae3e821eb1f481b28dc9b94f57cb5eb0093f
2017-03-24 14:01:34 +00:00
Alex Stewart af3b9394ea Fix search path for miniglog headers when Ceres is exported.
- When Ceres is exported (rather than installed), the miniglog headers
  still reside in the internal Ceres source directory, not the public
  headers directory.

Change-Id: Ia54eb7f8bb0cd24c0112a715a739c15247bc9239
2017-03-09 18:19:16 +00:00
Alex Stewart 9321b620ac Fix detection of deprecated Bessel function names on MSVC.
- MSVC deprecated the standard POSIX names for Bessel functions in
  favour of underscore prefixed versions.
- Previously we were checking for the presence of the newer underscore
  functions via a macro, which fails as the functions are not defined
  as macros.
- Now we check via a check_cxx_source_compiles() if the newer underscore
  prefixed versions exist when compiling on MSVC and use a new Ceres
  configuration #define to switch on their presence in jet.h

Change-Id: I430880bde2981d12f4d03dbc94d903b9842e887e
2017-01-27 22:31:53 +00:00
Alex Stewart 7b4ec98ea9 Fix detection of CMake-built glog on Windows.
- glog has a bug in its CMakeLists.txt whereby it uses ‘google-glog’ as
  its project() name in its CMakeLists.txt, but exports itself as ‘glog’
  which results in an install prefix on Windows which contains
  ‘google-glog’ instead of ‘glog’ which breaks find_package(glog).
  This has been raised as a glog issue here:
  https://github.com/google/glog/issues/149.
- We now force find_package(glog) to search glog using both
  ‘google-glog’ (for Windows) & ‘glog’ (for all other OSs).

Change-Id: I6c0edccdec405200eaa0fea1476b574e73bd3f14
2017-01-06 18:27:47 +00:00
Alex Stewart adb5f8e92c Add additional search paths for glog & Eigen on Windows.
- When built with CMake on Windows, the default install prefix
  will be C:/Program Files/<PROJECT_NAME> (instead of /usr/local on
  Linux / OS X.
- Due to an upstream change in Eigen >= 3.3, the project name for Eigen
  changed to Eigen3 from Eigen, thus changing the default install
  location.
- glog, uses the project name “google-glog”, thus when it is build with
  CMake, this becomes it’s default install path instead of just glog
  when built with other tools.
- This patch adds both of these paths to the default search list on
  Windows.

Change-Id: I987b502fed0f6e685c504fd47fd504307aad8bef
2017-01-02 13:44:29 +00:00
Alex Stewart 8a2da98ac2 Clear XXX_FOUND in Find<XXX>.cmake prior to searching.
- This protects against a client project which invokes
  find_package(Ceres) after having called find_package(Foo) with their
  own version of FindFoo.cmake which conflicts with Ceres’ exported
  version and defines FOO_FOUND, but not the other variables Ceres’
  FindFoo.cmake is expecting which can break the detection logic.

Change-Id: I9fe7bfa8a34bb58b09ffe34446da973912cf5587
2016-12-01 18:20:11 +00:00
Alex Stewart 523e397be2 Fix missing gflags imported target definition in CeresConfig.cmake
- If gflags was built & exported with CMake but glog was not, but both
  were found then as we now make gflags a public dependency of Ceres if
  both it and glog are found, the *name* of the exported gflags CMake
  target (gflags-shared or similar) will appear in CERES_LIBRARIES.
- However, as imported targets are not re-exported, this results in a
  linker error when compiling client code, as the name of the exported
  gflags target is not known to CMake, it assumes it is a library name,
  which it is not.
- Confusingly, if glog was built with CMake, this problem would not
  occur, as in that case glog’s CMake target would bring in gflags’.
- Now we explicitly call find_package(Gflags) in CeresConfig.cmake if
  Ceres was built with gflags as a public dependency (via glog).

Change-Id: I5cc9483a1fae50f4e9e3a8fbba491b645fd45db6
2016-11-21 11:56:19 +00:00
Alex Stewart d38e49a6cc Add support for glog exported CMake target.
- The latest version of glog supports building with CMake, in which case
  it exports itself via CMake as a target that contains important meta
  information such as Windows-specific compilation definitions.
- This patch updates FindGlog.cmake such that it can optionally use
  an exported glog target if one exists, if not it will fall back to
  the current approach whereby the glog components are found manually.
  This behaviour (and the implementation) is very similar to that of
  FindGflags.cmake.

Change-Id: Idfb5f49c1b457707029bff52068f58237c0e285d
2016-11-20 19:29:16 +00:00
Alex Stewart c5c6f559ab Fix potential invalid reset of CMAKE_FIND_LIBRARY_PREFIXES on MSVC.
- gflags_report_not_found() calls gflags_reset_find_library_prefix()
  and we only reset CMAKE_FIND_LIBRARY_PREFIXES when performing a manual
  search for gflags, but gflags_report_not_found() is also used
  before the manual search when searching for an exported gflags target.
- As such, it was possible that we could have cleared
  CMAKE_FIND_LIBRARY_PREFIXES rather than reset it if
  gflags_report_not_found() was invoked during the exported target
  search.
- This patch prevents this possibility by verifying that the cached
  version of CMAKE_FIND_LIBRARY_PREFIXES exists before updating it.

Change-Id: I07528ae5f197a366c7da342196b3e977f9a1fc93
2016-11-13 11:42:44 +00:00
Alex Stewart 9843f32803 Report Ceres compile options as components in find_package().
- Users can now specify particular components from Ceres, such as
  SuiteSparse support) that must be present in a detected version of
  Ceres in order for it to be reported as found by find_package().
- This allows users to specify for example that they require a version
  of Ceres with SuiteSparse support at configure time, rather than
  finding out only at run time that Ceres was not compiled with the
  options they require.
- The list of available components are built directly from the Ceres
  compile options.
- The meta-module SparseLinearAlgebraLibrary is present if at least
  one sparse linear algebra backend is available.

Change-Id: I65f1ddfd7697e6dd25bb4ac7e54f5097d3ca6266
2016-04-10 17:27:26 +00:00
Alex Stewart 562a72ea2b Fix missing early return() in xxx_not_found() dependency macros.
- This could result in potentially confusing output if dependencies
  were found with the QUIET option: "XXX not found due to ...", followed
  by "found <part of> XXX".
- If find_package() was called with REQUIRED, then a FATAL_ERROR was
  triggered in the xxx_not_found() macros, resulting in early
  termination.

Change-Id: Ibf59afd10067b9debd1a5e15f735a41b61bed52e
2016-02-06 15:58:10 +00:00
Alex Stewart b5f5100f57 Make CMake read Ceres version directly from include/ceres/version.h.
- Previously we had the Ceres version defined in two places, one in
  include/ceres/version.h, and one in the main CMakeLists.
- Now the main CMakeLists reads the Ceres version directly from
  version.h, as does the make_release script, so that we have a single
  place (version.h) in which the current Ceres version is defined.

Change-Id: Ie80aa7d38f5b576d3ed4d6109dd699f565c91027
2015-12-01 20:50:53 +00:00
Eduard Feicho 7efc92d413 Add IOS_DEPLOYMENT_TARGET variable to iOS.cmake
- Gives an option to specify a lower deployment target version than the
  current SDK for backward compatibility.

Change-Id: Ieb84ba7f42cdf925510f84b8e0cd01b5e9fc051b
2015-10-27 22:22:55 +00:00
Alex Stewart 89c40005bf Only use LTO when compiling Ceres itself, not tests or examples.
- If Ceres is built as a shared library, and LTO is enabled for Ceres
  and the tests, then type_info::operator==() incorrectly returns false
  in gtests' CheckedDowncastToActualType() in the following tests:
-- levenberg_marquardt_strategy_test.
-- gradient_checking_cost_function_test.
  on at least Xcode 6 & 7 as reported here:
  https://github.com/google/googletest/issues/595.
- This does not appear to be a gtest issue, but is perhaps an LLVM bug
  or an RTTI shared library issue.  Either way, disabling the use of
  LTO when compiling the test application resolves the issue.
- Allow LTO to be enabled for GCC, if it is supported.
- Add CMake function to allow easy appending to target properties s/t
  Ceres library-specific compile flags can be iteratively constructed.

Change-Id: I923e6aae4f7cefa098cf32b2f8fc19389e7918c9
2015-09-28 15:08:39 +01:00
Alex Stewart 90e32a8dc4 Use old minimum iOS version flags on Xcode < 7.0.
- The newer style, which are more specific and match the SDK names
  are not available on Xcode < 7.0.

Change-Id: I2f07a0365183d2781157cdb05fd49b30ae001ac5
2015-09-21 21:08:25 +01:00
Alex Stewart c4c7947211 Clean up iOS.cmake to use xcrun/xcodebuild & libtool.
- Substantial cleanup of iOS.cmake to use xcrun & xcodebuild to
  determine the SDK & tool paths.
- Use libtool -static to link libraries instead of ar + ranlib, which
  is not compatible with Xcode 7+, this change should be backwards
  compatible to at least Xcode 6.
- Force locations of unordered_map & shared_ptr on iOS to work around
  check_cxx_source_compiles() running in a forked CMake instance without
  access to the variables (IOS_PLATFORM) defined by the user.
- Minor CMake style updates.

Change-Id: I5f83a60607db34d461ebe85f9dce861f53d98277
2015-09-20 20:12:04 +01:00
Alex Stewart 1936d47e21 Revert increased inline threshold (iff Clang) to exported Ceres target.
- Increasing the inline threshold results in very variable performance
  improvements, and could potentially confuse users if they are trying
  to set the inline threshold themselves.
- As such, we no longer export our inline threshold configuration for
  Clang, but instead document how to change it in the FAQs.

Change-Id: I88e2e0001e4586ba2718535845ed1e4b1a5b72bc
2015-09-08 23:27:42 +01:00
Alex Stewart 0e8264cc47 Add increased inline threshold (iff Clang) to exported Ceres target.
- When compiled with Clang, Ceres and all of the examples are compiled
  with an increased inlining-threshold, as the default value can result
  in poor Eigen performance.
- Previously, client code using Ceres would typically not use an
  increased inlining-threshold (unless the user has specifically added
  it themselves).  However, increasing the inlining threshold can result
  in significant performance improvements in auto-diffed CostFunctions.
- This patch adds the inlining-threshold flags to the interface flags
  for the Ceres CMake target s/t any client code using Ceres (via
  CMake), and compiled with Clang, will now be compiled with the same
  increased inlining threshold as used by Ceres itself.

Change-Id: I31e8f1abfda140d22e85bb48aa57f028a68a415e
2015-09-02 19:37:01 +01:00