Skip to content

Commit 1ef751a

Browse files
committed
Modernize dependency handling
1 parent d4f5d28 commit 1ef751a

4 files changed

Lines changed: 60 additions & 26 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# configure project
2424
##################################
2525

26-
cmake_minimum_required(VERSION 3.8)
26+
cmake_minimum_required(VERSION 3.20)
2727

2828
project(libRSF VERSION "2.0.0" LANGUAGES CXX)
2929

@@ -43,10 +43,10 @@ option(LIBRSF_BUILD_TEST "If enabled, the tests get build." OFF)
4343
##################################
4444

4545
# path for custom find scripts
46-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
46+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
4747

4848
# path for locally installed dependencies
49-
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_SOURCE_DIR}/externals/install)
49+
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/externals/install)
5050

5151
# Eigen for vectorized calculations
5252
find_package(Eigen3 3.3.5 REQUIRED NO_MODULE)

cmake/FindGeographicLib.cmake

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,61 @@ find_library (GeographicLib_LIBRARIES
1010
NAMES GeographicLib Geographic
1111
PATHS "${CMAKE_INSTALL_PREFIX}/../GeographicLib/lib")
1212

13+
find_path (GeographicLib_INCLUDE_DIRS
14+
NAMES GeographicLib/Config.h
15+
PATHS
16+
"${CMAKE_INSTALL_PREFIX}/../GeographicLib/include"
17+
"${CMAKE_INSTALL_PREFIX}/include")
18+
19+
unset (GeographicLib_LIBRARY_DIRS)
1320
if (GeographicLib_LIBRARIES)
1421
get_filename_component (GeographicLib_LIBRARY_DIRS
1522
"${GeographicLib_LIBRARIES}" PATH)
16-
get_filename_component (_ROOT_DIR "${GeographicLib_LIBRARY_DIRS}" PATH)
17-
set (GeographicLib_INCLUDE_DIRS "${_ROOT_DIR}/include")
18-
set (GeographicLib_BINARY_DIRS "${_ROOT_DIR}/bin")
19-
if (NOT EXISTS "${GeographicLib_INCLUDE_DIRS}/GeographicLib/Config.h")
20-
# On Debian systems the library is in e.g.,
21-
# /usr/lib/x86_64-linux-gnu/libGeographic.so
22-
# so try stripping another element off _ROOT_DIR
23-
get_filename_component (_ROOT_DIR "${_ROOT_DIR}" PATH)
24-
set (GeographicLib_INCLUDE_DIRS "${_ROOT_DIR}/include")
25-
set (GeographicLib_BINARY_DIRS "${_ROOT_DIR}/bin")
26-
if (NOT EXISTS "${GeographicLib_INCLUDE_DIRS}/GeographicLib/Config.h")
27-
unset (GeographicLib_INCLUDE_DIRS)
28-
unset (GeographicLib_LIBRARIES)
29-
unset (GeographicLib_LIBRARY_DIRS)
30-
unset (GeographicLib_BINARY_DIRS)
31-
endif ()
23+
endif ()
24+
25+
unset (GeographicLib_BINARY_DIRS)
26+
if (GeographicLib_INCLUDE_DIRS)
27+
get_filename_component (_GeographicLib_PREFIX "${GeographicLib_INCLUDE_DIRS}" PATH)
28+
if (EXISTS "${_GeographicLib_PREFIX}/bin")
29+
set (GeographicLib_BINARY_DIRS "${_GeographicLib_PREFIX}/bin")
3230
endif ()
33-
unset (_ROOT_DIR)
31+
unset (_GeographicLib_PREFIX)
32+
endif ()
33+
34+
if (NOT GeographicLib_BINARY_DIRS)
35+
find_program (_GeographicLib_TOOL
36+
NAMES GeodSolve GeoConvert)
37+
if (_GeographicLib_TOOL)
38+
get_filename_component (GeographicLib_BINARY_DIRS "${_GeographicLib_TOOL}" PATH)
39+
endif ()
40+
unset (_GeographicLib_TOOL CACHE)
41+
unset (_GeographicLib_TOOL)
3442
endif ()
3543

3644
include (FindPackageHandleStandardArgs)
3745
find_package_handle_standard_args (GeographicLib DEFAULT_MSG
3846
GeographicLib_LIBRARY_DIRS GeographicLib_LIBRARIES
3947
GeographicLib_INCLUDE_DIRS)
48+
49+
if(GeographicLib_FOUND)
50+
set(GEOGRAPHICLIB_FOUND TRUE)
51+
endif()
52+
53+
if(GeographicLib_FOUND AND NOT TARGET GeographicLib::GeographicLib)
54+
# Determine the library type from the file extension so that target
55+
# introspection (get_target_property TYPE) returns the correct value.
56+
if(GeographicLib_LIBRARIES MATCHES "\\.a$")
57+
set(_geographiclib_lib_type STATIC)
58+
else()
59+
set(_geographiclib_lib_type SHARED)
60+
endif()
61+
add_library(GeographicLib::GeographicLib ${_geographiclib_lib_type} IMPORTED)
62+
set_target_properties(GeographicLib::GeographicLib PROPERTIES
63+
IMPORTED_LOCATION "${GeographicLib_LIBRARIES}"
64+
INTERFACE_INCLUDE_DIRECTORIES "${GeographicLib_INCLUDE_DIRS}"
65+
)
66+
unset(_geographiclib_lib_type)
67+
endif()
68+
4069
mark_as_advanced (GeographicLib_LIBRARY_DIRS GeographicLib_LIBRARIES
4170
GeographicLib_INCLUDE_DIRS)

cmake/libRSFConfig.cmake.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ include(CMakeFindDependencyMacro)
2323

2424
list(APPEND CMAKE_MODULE_PATH ${libRSF_CMAKE_DIR})
2525

26-
find_package(Ceres 2.0 REQUIRED)
27-
find_package(Eigen3 3.3.5 REQUIRED)
28-
find_package(yaml-cpp REQUIRED)
29-
find_package(GeographicLib REQUIRED)
26+
find_dependency(Ceres 2.0 REQUIRED)
27+
find_dependency(Eigen3 3.3.5 REQUIRED NO_MODULE)
28+
find_dependency(yaml-cpp REQUIRED)
29+
find_dependency(GeographicLib REQUIRED)
3030

3131
list(REMOVE_AT CMAKE_MODULE_PATH -1)
3232

src/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,14 @@ add_library(libRSF STATIC ${SOURCEFILES} ${HEADERFILES})
9191
# require at least C++ 17
9292
target_compile_features(libRSF PUBLIC cxx_std_17)
9393

94+
set(LIBRSF_YAML_TARGET yaml-cpp::yaml-cpp)
95+
if(NOT TARGET yaml-cpp::yaml-cpp)
96+
set(LIBRSF_YAML_TARGET yaml-cpp)
97+
endif()
98+
9499
# to allow shared libraries to link against static libRSF
95100
set_target_properties(libRSF PROPERTIES POSITION_INDEPENDENT_CODE ON
96-
CMAKE_CXX_EXTENSIONS OFF)
101+
CXX_EXTENSIONS OFF)
97102

98103
# set include dir of library depending on current tree (build/install)
99104
target_include_directories(libRSF
@@ -105,7 +110,7 @@ target_include_directories(libRSF
105110
)
106111

107112
# set target (libRSF) dependencies
108-
target_link_libraries(libRSF PUBLIC Threads::Threads Eigen3::Eigen Ceres::ceres yaml-cpp ${GeographicLib_LIBRARIES})
113+
target_link_libraries(libRSF PUBLIC Threads::Threads Eigen3::Eigen Ceres::ceres ${LIBRSF_YAML_TARGET} GeographicLib::GeographicLib)
109114

110115
# enable all warnings for libRSF (this is just enabled from time to time to check the code quality)
111116
#target_compile_options(libRSF PUBLIC -Wextra -Wpedantic -Wall -fmax-errors=100 -Wno-unused-parameter)

0 commit comments

Comments
 (0)