Skip to content

Commit

Permalink
Merge branch 'relocateable_config' into hunter-1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
riegl-gc committed Aug 29, 2017
2 parents 046d10e + 544fc28 commit 08d6283
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 44 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.")
Expand Down
47 changes: 16 additions & 31 deletions cmake/CeresConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -248,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})

Expand All @@ -278,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()
Expand Down Expand Up @@ -338,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})

Expand Down
21 changes: 12 additions & 9 deletions internal/ceres/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -247,7 +250,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
Expand All @@ -263,9 +266,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
$<BUILD_INTERFACE:${GLOG_INCLUDE_DIRS}>)
Expand Down Expand Up @@ -305,16 +308,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
Expand Down Expand Up @@ -390,7 +393,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 ()

Expand Down

0 comments on commit 08d6283

Please sign in to comment.