Fix TBB detection on Windows. - Reported as issue #334 by anuppari: https://github.com/ceres-solver/ceres-solver/issues/334. Change-Id: Ie8af4b3ce7ef97e471deb780e2b7d683dcb0d658
diff --git a/CMakeLists.txt b/CMakeLists.txt index f12d5ed..7df2219 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -111,23 +111,16 @@ # Enable the use of Eigen as a sparse linear algebra library for # solving the nonlinear least squares problems. option(EIGENSPARSE "Enable Eigen as a sparse linear algebra library." ON) -if (NOT MSVC) - # Ceres does not use C++11 internally, however it does use shared_ptr - # (required) and unordered_map (if available), both of which were present in - # previous iterations of what became C++11. GCC & Clang can have both TR1 & - # C++11 versions of both shared_ptr & unordered_map and by default on Linux, - # we will detect the TR1 versions if they exist, as they do NOT require - # -std=c++11 to be passed when compiling Ceres, and any client code that uses - # Ceres. This will result in conflicts if the client code uses C++11. - # Enabling this option forces the use of the C++11 versions (& -std=c++11) if - # available. - # - # This option is not available on Windows when using MSVC, as there, any new - # (C++11 etc) features available are on by default and there is no analogue to - # -std=c++11. It will however be available for MinGW & CygWin, which can - # support -std=c++11. - option(CXX11 "Enable use of C++11 headers if available (requires client code use C++11)." OFF) -endif(NOT MSVC) +# Ceres does not use C++11 internally, however it does use shared_ptr +# (required) and unordered_map (if available), both of which were present in +# previous iterations of what became C++11. GCC & Clang can have both TR1 & +# C++11 versions of both shared_ptr & unordered_map and by default on Linux, +# we will detect the TR1 versions if they exist, as they do NOT require +# -std=c++11 to be passed when compiling Ceres, and any client code that uses +# Ceres. This will result in conflicts if the client code uses C++11. +# Enabling this option forces the use of the C++11 versions (& -std=c++11) if +# available. +option(CXX11 "Enable use of C++11 headers if available (requires client code use C++11)." OFF) option(EXPORT_BUILD_DIR "Export build directory using CMake (enables external use without install)." OFF) option(BUILD_TESTING "Enable tests" ON) @@ -136,6 +129,13 @@ cmake_dependent_option(BUILD_BENCHMARKS "Build Ceres benchmarking suite" ON "CXX11" OFF) option(BUILD_SHARED_LIBS "Build Ceres as a shared library." OFF) if (MSVC) + # CXX11 is always enabled on Windows when using MSVC, as there, any new + # (C++11 etc) features available are on by default and there is no analogue to + # -std=c++11. It is however optional for MinGW & CygWin, which can support + # -std=c++11. + update_cache_variable(CXX11 ON) + mark_as_advanced(FORCE CXX11) + option(MSVC_USE_STATIC_CRT "MS Visual Studio: Use static C-Run Time Library in place of shared." OFF) @@ -529,6 +529,7 @@ message("-- Failed to find Google benchmark library, disabling build of benchmarks.") update_cache_variable(BUILD_BENCHMARKS OFF) endif() + mark_as_advanced(benchmark_DIR) endif() include_directories(
diff --git a/cmake/FindTBB.cmake b/cmake/FindTBB.cmake index 8d57c80..d3e2852 100644 --- a/cmake/FindTBB.cmake +++ b/cmake/FindTBB.cmake
@@ -89,7 +89,7 @@ ################################## if(NOT DEFINED TBB_USE_DEBUG_BUILD) - if(CMAKE_BUILD_TYPE MATCHES "[Debug|DEBUG|debug|RelWithDebInfo|RELWITHDEBINFO|relwithdebinfo]") + if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug|RelWithDebInfo|RELWITHDEBINFO|relwithdebinfo)") set(TBB_USE_DEBUG_BUILD TRUE) else() set(TBB_USE_DEBUG_BUILD FALSE) @@ -175,12 +175,12 @@ find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp} HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} PATHS ${TBB_DEFAULT_SEARCH_DIR} - PATH_SUFFIXES "${TBB_LIB_PATH_SUFFIX}") + PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX}) 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}") + PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX}) # Set the library to be used for the component