From 3f261125d678a373ba65ccc1a42cdaef50a6c55b Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Tue, 29 Aug 2017 12:45:13 +0200 Subject: [PATCH 1/7] config: remove hardcoded Eigen include hints --- cmake/CeresConfig.cmake.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmake/CeresConfig.cmake.in b/cmake/CeresConfig.cmake.in index ee3b5532d0..f801b6f4b8 100644 --- a/cmake/CeresConfig.cmake.in +++ b/cmake/CeresConfig.cmake.in @@ -203,8 +203,6 @@ set(CERES_VERSION @CERES_VERSION@ ) # Eigen. # Flag set during configuration and build of Ceres. set(CERES_EIGEN_VERSION @EIGEN3_VERSION_STRING@) -# Append the locations of Eigen when Ceres was built to the search path hints. -list(APPEND EIGEN3_INCLUDE_DIR_HINTS @EIGEN3_INCLUDE_DIR@) # 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. From 94c8632ed48cf60d1b32c89d6e8a2232a8b54e7a Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Tue, 29 Aug 2017 12:46:10 +0200 Subject: [PATCH 2/7] config: remove hardcoded glog dir hints, use CONFIG Change-Id: I6bce2f294c6828446f519aa0ac4e4ad55434a04e --- cmake/CeresConfig.cmake.in | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/cmake/CeresConfig.cmake.in b/cmake/CeresConfig.cmake.in index f801b6f4b8..b00745d36e 100644 --- a/cmake/CeresConfig.cmake.in +++ b/cmake/CeresConfig.cmake.in @@ -246,25 +246,13 @@ if (CERES_USES_MINIGLOG) message("-- Found Ceres compiled with miniglog substitute " "for glog, beware this will likely cause problems if glog is later linked.") else (CERES_USES_MINIGLOG) - # 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) - else() - 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}) - endif() - # Search quietly s/t we control the timing of the error message if not found. - find_package(glog QUIET) + find_package(glog CONFIG QUIET) if (glog_FOUND) message(STATUS "Found required Ceres dependency: glog") else (glog_FOUND) ceres_report_not_found("Missing required Ceres " - "dependency: glog. Searched using GLOG_INCLUDE_DIR_HINTS: " - "${GLOG_INCLUDE_DIR_HINTS} and glog_DIR: ${glog_DIR}.") + "dependency: glog.") endif (glog_FOUND) list(APPEND CERES_INCLUDE_DIRS ${GLOG_INCLUDE_DIRS}) From 6785dd84f2f7b5798af28ea1593ed64d10b4197f Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Tue, 29 Aug 2017 13:07:30 +0200 Subject: [PATCH 3/7] config: remove hardcoded gflags hints, use CONFIG --- cmake/CeresConfig.cmake.in | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/cmake/CeresConfig.cmake.in b/cmake/CeresConfig.cmake.in index b00745d36e..8b22273810 100644 --- a/cmake/CeresConfig.cmake.in +++ b/cmake/CeresConfig.cmake.in @@ -264,27 +264,14 @@ else (CERES_USES_MINIGLOG) # re-exported. Without this, the 'gflags-shared' target name which is # present in CERES_LIBRARIES in this case would not be defined, and so # CMake will assume it is a library name (which it is not) and fail to link. - # - # Append the locations of gflags when Ceres was built to the search path - # hints. - 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) + find_package(Gflags CONFIG QUIET) if (GFLAGS_FOUND) 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.") endif() list(APPEND CERES_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR_HINTS}) endif() From b919433c81afe2dc13402fa831b9feea339bd634 Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Tue, 29 Aug 2017 13:25:09 +0200 Subject: [PATCH 4/7] internal: explicitly link libraries PUBLIC/PRIVATE - fixes dev warning messages - link glog PRIVATE - link ceres to tests PUBLIC --- internal/ceres/CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt index aaa028377e..7f9088daeb 100644 --- a/internal/ceres/CMakeLists.txt +++ b/internal/ceres/CMakeLists.txt @@ -247,7 +247,7 @@ else (BUILD_SHARED_LIBS) set(CERES_LIBRARY_DEPENDENCIES ${CERES_LIBRARY_PUBLIC_DEPENDENCIES} ${CERES_LIBRARY_PRIVATE_DEPENDENCIES}) - target_link_libraries(ceres ${CERES_LIBRARY_DEPENDENCIES}) + target_link_libraries(ceres PUBLIC ${CERES_LIBRARY_DEPENDENCIES}) endif (BUILD_SHARED_LIBS) # link Eigen3 if target exists, otherwise use legacy variable @@ -263,9 +263,9 @@ endif() if (NOT MINIGLOG) # link to glog for logging if (TARGET glog::glog) - target_link_libraries(ceres glog::glog) + target_link_libraries(ceres PRIVATE glog::glog) elseif (TARGET glog) - target_link_libraries(ceres glog) + target_link_libraries(ceres PRIVATE glog) else() target_include_directories(ceres PRIVATE $) @@ -305,16 +305,16 @@ if (BUILD_TESTING AND GFLAGS) if (MINIGLOG) # When using miniglog, it is compiled into Ceres, thus Ceres becomes # the library against which other libraries should link for logging. - target_link_libraries(gtest ${GFLAGS_LIBRARIES} ceres) - target_link_libraries(test_util ceres gtest) + target_link_libraries(gtest PUBLIC ${GFLAGS_LIBRARIES} ceres) + target_link_libraries(test_util PUBLIC ceres gtest) else (MINIGLOG) - target_link_libraries(gtest ${GFLAGS_LIBRARIES} ${GLOG_LIBRARIES}) - target_link_libraries(test_util ceres gtest ${GLOG_LIBRARIES}) + target_link_libraries(gtest PUBLIC ${GFLAGS_LIBRARIES} ${GLOG_LIBRARIES}) + target_link_libraries(test_util PUBLIC ceres gtest ${GLOG_LIBRARIES}) endif (MINIGLOG) macro (CERES_TEST NAME) add_executable(${NAME}_test ${NAME}_test.cc) - target_link_libraries(${NAME}_test test_util ceres gtest) + target_link_libraries(${NAME}_test PRIVATE test_util ceres gtest) if (BUILD_SHARED_LIBS) # Define gtest-specific shared library flags for linking. append_target_property(${NAME}_test COMPILE_DEFINITIONS @@ -390,7 +390,7 @@ if (BUILD_TESTING AND GFLAGS) # independent of SuiteSparse. if (SUITESPARSE AND SuiteSparse_FOUND) ceres_test(compressed_col_sparse_matrix_utils) - target_link_libraries(compressed_col_sparse_matrix_utils_test + target_link_libraries(compressed_col_sparse_matrix_utils_test PRIVATE ${SuiteSparse_LIBRARIES}) endif () From 9f5da3dfad2955fab90a1008bb74491c75a2c090 Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Tue, 29 Aug 2017 13:21:05 +0200 Subject: [PATCH 5/7] Require CMake 3.1 to get sane policy defaults - FindThreads produces target Threads::Threads starting with 3.1 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0530562a78..af4cc462ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,8 +29,8 @@ # Authors: keir@google.com (Keir Mierle) # alexs.mac@gmail.com (Alex Stewart) -cmake_minimum_required(VERSION 2.8.0) -cmake_policy(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) +cmake_policy(VERSION 3.1) cmake_policy(SET CMP0003 NEW) cmake_policy(SET CMP0053 NEW) From 5a9d6049eebf881ebf05441946d2c87d476dec25 Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Tue, 29 Aug 2017 14:28:57 +0200 Subject: [PATCH 6/7] if OPENMP add Threads::Threads to libraries --- CMakeLists.txt | 5 +++-- internal/ceres/CMakeLists.txt | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af4cc462ee..8c19e33aad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -431,13 +431,14 @@ if (OPENMP) message("-- Building with OpenMP.") list(APPEND CERES_COMPILE_OPTIONS CERES_USE_OPENMP) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - if (UNIX) + if (UNIX OR MINGW) # At least on Linux, we need pthreads to be enabled for mutex to # compile. This may not work on Windows or Android. + set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) list(APPEND CERES_COMPILE_OPTIONS CERES_HAVE_PTHREAD) list(APPEND CERES_COMPILE_OPTIONS CERES_HAVE_RWLOCK) - endif (UNIX) + endif () else (OPENMP_FOUND) message("-- Failed to find OpenMP, disabling. This is expected on " "Clang < 3.8, and at least Xcode <= 7.") diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt index 7f9088daeb..a232bf4225 100644 --- a/internal/ceres/CMakeLists.txt +++ b/internal/ceres/CMakeLists.txt @@ -171,6 +171,9 @@ if (OPENMP_FOUND) if (CMAKE_COMPILER_IS_GNUCXX) list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES gomp) endif() + if (UNIX OR MINGW) + list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES Threads::Threads) + endif() if (NOT MSVC) list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT}) endif() From 544fc2885a7363420e9f0dc3a542e4bed2e86c37 Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Tue, 29 Aug 2017 14:11:23 +0200 Subject: [PATCH 7/7] config: if OpenMP find Threads on UNIX and MINGW --- cmake/CeresConfig.cmake.in | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmake/CeresConfig.cmake.in b/cmake/CeresConfig.cmake.in index 8b22273810..5b892fa317 100644 --- a/cmake/CeresConfig.cmake.in +++ b/cmake/CeresConfig.cmake.in @@ -311,6 +311,18 @@ if (CERES_USES_SUITESPARSE) # SuiteSparse find_package(SuiteSparse CONFIG REQUIRED) endif() +# OpenMP. +# Flag set during configuration and build of Ceres. +set(CERES_USES_OPENMP @OPENMP@) +if (CERES_USES_OPENMP) + if (UNIX OR MINGW) + # At least on Linux, we need pthreads to be enabled for mutex to + # compile. This may not work on Windows or Android. + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + endif () +endif () + # Set legacy include directories variable for backwards compatibility. set(CERES_INCLUDES ${CERES_INCLUDE_DIRS})