1- set (THIRDPARTY_LIBS "" )
2- set (THIRDPARTY_INCLUDE_DIRS "" )
31
42include (FetchContent)
53
6- set (BUILD_TESTING_OLD ${BUILD_TESTING} ) # Save your setting
7- set (BUILD_TESTING OFF CACHE BOOL "" FORCE) # Disbale third party tests
4+ set (BUILD_TESTING_OLD ${BUILD_TESTING} ) # Save setting
5+ set (BUILD_TESTING OFF CACHE BOOL "" FORCE) # Disable third party tests
86
97# For now, Eigen is mandatory
108find_package (Eigen3 QUIET )
11-
9+ set (EIGEN_BUILD_TESTING OFF )
10+ set (EIGEN_BUILD_DOC OFF )
11+ set (EIGEN_BUILD_PKGCONFIG OFF )
1212if (EIGEN3_FOUND)
1313 message ("Eigen3 found at ${EIGEN3_INCLUDE_DIR} " )
1414else ()
@@ -22,48 +22,47 @@ else()
2222 )
2323 block (SCOPE_FOR VARIABLES ) # requires cmake 3.25+
2424 set (BUILD_TESTING OFF )
25- set (EIGEN_BUILD_TESTS OFF )
26- set (EIGEN_BUILD_DOC OFF )
27- set (EIGEN_BUILD_DEMOS OFF )
28- set (EIGEN_BUILD_PKGCONFIG OFF )
2925 set (EIGEN_TEST_CXX11 OFF )
26+ set (EIGEN_HAS_CXX11_MATH ON )
3027 FetchContent_MakeAvailable(Eigen)
3128 endblock ()
3229 set (EIGEN3_INCLUDE_DIR "${eigen3_SOURCE_DIR} " CACHE PATH "Eigen3 include directory" FORCE)
30+ set (EIGEN3_FOUND TRUE CACHE BOOL "Eigen3 found" FORCE)
31+ endif ()
32+
33+ # Eigen is mandatory
34+ if (NOT TARGET Eigen3::Eigen)
35+ message (FATAL_ERROR "Eigen3 not found" )
3336endif ()
34- add_definitions (-DHAS_EIGEN)
35- set (THIRDPARTY_LIBS ${THIRDPARTY_LIBS} Eigen3::Eigen)
3637
38+
39+ # FMT
3740if (TINYOPT_USE_FMT)
3841 find_package (fmt REQUIRED)
3942 message ("fmt found at ${FMT_INCLUDE_DIR} " )
40- set (THIRDPARTY_LIBS ${THIRDPARTY_LIBS} fmt::fmt)
41- add_definitions (-DHAS_FMT)
4243endif ()
4344
4445
4546if (TINYOPT_BUILD_CERES)
4647 find_package (Ceres QUIET )
48+ set (MINIGLOG ON )
4749 if (NOT Ceres_FOUND)
4850 message ("Ceres not found, fetching..." )
4951 FetchContent_Declare(Ceres
5052 GIT_REPOSITORY https://github.com/ceres-solver/ceres-solver
5153 GIT_TAG 2.2.0
5254 GIT_SHALLOW TRUE
5355 GIT_PROGRESS TRUE )
54- block (SCOPE_FOR VARIABLES ) # requires cmake 3.25+
55- set (BUILD_TESTING OFF )
56- set (BUILD_EXAMPLES OFF )
57- set (BUILD_BENCHMARKS OFF )
58- set (MINIGLOG ON )
59- FetchContent_MakeAvailable(Ceres)
60- endblock ()
61- set (CERES_LIBRARIES Ceres::ceres)
56+ set (BUILD_TESTING OFF )
57+ set (BUILD_EXAMPLES OFF )
58+ set (BUILD_BENCHMARKS OFF )
59+ set (MINIGLOG ON )
60+ FetchContent_MakeAvailable(Ceres)
6261 target_compile_options (ceres PUBLIC "-Wno-reorder" "-Wno-maybe-uninitialized" )
6362 endif ()
64- set (THIRDPARTY_INCLUDE_DIRS ${THIRDPARTY_INCLUDE_DIRS} ${CERES_INCLUDE_DIRS} )
65- set (THIRDPARTY_LIBS ${THIRDPARTY_LIBS} ${CERES_LIBRARIES} )
66- add_definitions (-DHAS_CERES )
63+ if ( NOT TARGET Ceres::ceres )
64+ message (FATAL_ERROR "Ceres target not found" )
65+ endif ( )
6766endif ()
6867
6968
@@ -85,16 +84,19 @@ if (TINYOPT_BUILD_SOPHUS_TEST)
8584 FetchContent_MakeAvailable(Sophus)
8685 endblock ()
8786 endif ()
88- add_definitions (-DHAS_SOPHUS)
89- #include_directories(${Sophus_SOURCE_DIR}/sophus)
90- #add_definitions(-DSOPHUS_USE_BASIC_LOGGING=1)
91- set (THIRDPARTY_LIBS ${THIRDPARTY_LIBS} Sophus::Sophus)
92- set (THIRDPARTY_INCLUDE_DIRS ${THIRDPARTY_INCLUDE_DIRS} ${SOPHUS_INCLUDE_DIR} )
87+ message ("Sophus ${Sophus_FOUND} : found at ${Sophus_INCLUDE_DIR} " )
88+
89+ if (TARGET Sophus::Sophus)
90+ elseif (Sophus_FOUND)
91+ else ()
92+ message (FATAL_ERROR "Sophus target not found" )
93+ endif ()
9394endif ()
9495
9596
9697if (TINYOPT_BUILD_LIEPLUSPLUS_TEST)
9798 find_package (LiePlusPlus QUIET )
99+ set (LIEPLUSPLUS_TESTS OFF )
98100 if (NOT LiePlusPlus_FOUND)
99101 message ("Lie++ not found, fetching..." )
100102 FetchContent_Declare(
@@ -108,40 +110,29 @@ if (TINYOPT_BUILD_LIEPLUSPLUS_TEST)
108110 set (LIEPLUSPLUS_TESTS OFF )
109111 FetchContent_MakeAvailable(LiePlusPlus)
110112 endblock ()
113+ FetchContent_MakeAvailable(LiePlusPlus)
111114 endif ()
112- add_definitions (-DHAS_LIEPLUSPLUS)
113- #include_directories(${LiePlusPlus_SOURCE_DIR}/include)
114- set (THIRDPARTY_LIBS ${THIRDPARTY_LIBS} LiePlusPlus)
115- set (THIRDPARTY_INCLUDE_DIRS ${THIRDPARTY_INCLUDE_DIRS} ${SOPHUS_INCLUDE_DIR} )
115+ message ("LiePlusPlus ${LiePlusPlus_FOUND} : found at ${LiePlusPlus_INCLUDE_DIR} target ${LiePlusPlus_TARGET} " )
116+
117+ # Conditionally link to LiePlusPlus
118+ if (NOT LiePlusPlus_INCLUDE_DIR)
119+ message (FATAL_ERROR "LiePlusPlus not found" )
120+ endif ()
116121endif ()
117122
118123
119124if (TINYOPT_BUILD_TESTS OR TINYOPT_BUILD_BENCHMARKS)
120- find_package (Catch2 QUIET )
121- if (NOT Catch2_FOUND)
122- include (FetchContent)
123- message ("Catch2 is missing, fetching..." )
124- FetchContent_Declare(
125- Catch2
126- GIT_REPOSITORY https://github.com/catchorg/Catch2.git
127- GIT_TAG devel
128- GIT_SHALLOW TRUE
129- GIT_PROGRESS TRUE
130- OVERRIDE_FIND_PACKAGE
131- )
132- FetchContent_MakeAvailable(Catch2)
133- if (NOT Catch2_VERSION)
134- get_directory_property (Catch2_VERSION DIRECTORY "${catch2_SOURCE_DIR} " DEFINITION PROJECT_VERSION)
135- endif ()
136- set (Catch2_FOUND TRUE )
137- endif ()
138- message (STATUS "Found Catch2 version: ${Catch2_VERSION} " )
139- set (THIRDPARTY_TEST_LIBS ${THIRDPARTY_LIBS} Catch2::Catch2WithMain)
140- if (${Catch2_VERSION} GREATER_EQUAL 3.0.0)
141- add_definitions (-DCATCH2_VERSION=3)
142- else ()
143- add_definitions (-DCATCH2_VERSION=2)
144- endif ()
145- endif ()
125+ find_package (Catch2 3 REQUIRED)
126+ # Conditionally link to Catch2
127+ if (TARGET Catch2::Catch2WithMain)
128+ if (${Catch2_VERSION} GREATER_EQUAL 3.0.0)
129+ set (CATCH2_MAJOR_VERSION 3)
130+ else ()
131+ set (CATCH2_MAJOR_VERSION 2)
132+ endif ()
133+ else ()
134+ message (FATAL_ERROR "Catch2 target not found" )
135+ endif ()
146136
137+ endif ()
147138set (BUILD_TESTING ${BUILD_TESTING_OLD} CACHE BOOL "" FORCE) # Restore testing config
0 commit comments