diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8014932..502b142 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,6 +12,8 @@ include(cmake/version.cmake)
project(${META_PROJECT_NAME} VERSION ${META_VERSION} LANGUAGES C CXX)
+option(BUILD_ONLY_BASE "Only build base library" OFF)
+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(_DEFAULT_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install)
set(CMAKE_INSTALL_PREFIX ${_DEFAULT_INSTALL_PREFIX}
@@ -97,7 +99,7 @@ cmake_policy(SET CMP0077 NEW) # ENABLE CMP0077: option() honors normal variables
#
# c++11
#
-set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake
index c6bfefc..a2b08fd 100644
--- a/cmake/dependencies.cmake
+++ b/cmake/dependencies.cmake
@@ -1,32 +1,43 @@
-#
-# find external project and embbed to main project
-#
+# Public Target for target_link_libraries
+set(XRPRIMER_PUBLIC_TARGET)
if(NOT IOS)
find_package(Eigen3 REQUIRED CONFIG)
- find_package(Ceres REQUIRED CONFIG)
+ list(APPEND XRPRIMER_PUBLIC_TARGET Eigen3::Eigen)
- if(NOT TARGET Ceres::ceres)
- add_library(Ceres::ceres INTERFACE IMPORTED)
- set_target_properties(
- Ceres::ceres PROPERTIES INTERFACE_LINK_LIBRARIES ceres
- )
- endif()
-
- find_package(OpenCV REQUIRED CONFIG)
+ find_package(jsoncpp REQUIRED CONFIG)
+ list(APPEND XRPRIMER_PUBLIC_TARGET jsoncpp_static)
- if(OpenCV_FOUND)
- add_library(OpenCV::OpenCV INTERFACE IMPORTED GLOBAL)
- target_include_directories(
- OpenCV::OpenCV INTERFACE ${OpenCV_INCLUDE_DIRS}
- )
- target_link_libraries(OpenCV::OpenCV INTERFACE ${OpenCV_LIBS})
- endif()
+ find_package(spdlog REQUIRED CONFIG)
+ list(APPEND XRPRIMER_PUBLIC_TARGET spdlog::spdlog_header_only)
find_package(pybind11 REQUIRED CONFIG)
- find_package(jsoncpp REQUIRED CONFIG)
- find_package(spdlog REQUIRED CONFIG)
- find_package(PnpSolver REQUIRED CONFIG)
+
+ if(NOT BUILD_ONLY_BASE)
+ find_package(Ceres REQUIRED CONFIG)
+
+ if(NOT TARGET Ceres::ceres)
+ add_library(Ceres::ceres INTERFACE IMPORTED)
+ set_target_properties(
+ Ceres::ceres PROPERTIES INTERFACE_LINK_LIBRARIES ceres
+ )
+ endif()
+
+ list(APPEND XRPRIMER_PUBLIC_TARGET Ceres::ceres)
+
+ find_package(OpenCV REQUIRED CONFIG)
+
+ if(OpenCV_FOUND)
+ add_library(OpenCV::OpenCV INTERFACE IMPORTED GLOBAL)
+ target_include_directories(
+ OpenCV::OpenCV INTERFACE ${OpenCV_INCLUDE_DIRS}
+ )
+ target_link_libraries(OpenCV::OpenCV INTERFACE ${OpenCV_LIBS})
+ endif()
+
+ find_package(PnpSolver REQUIRED CONFIG)
+ list(APPEND XRPRIMER_PUBLIC_TARGET PnpSolver::PnpSolver)
+ endif()
else()
# 指定opencv_framework_path
if(EXISTS ${xrprimer_framework_path})
@@ -35,6 +46,7 @@ else()
OpenCV::OpenCV INTERFACE -F${xrprimer_framework_path}
)
target_link_options(OpenCV::OpenCV INTERFACE -framework opencv2)
+ list(APPEND XRPRIMER_PUBLIC_TARGET OpenCV::OpenCV)
else()
message(
FATAL_ERROR
diff --git a/cmake/external/pybind11.cmake b/cmake/external/pybind11.cmake
index f3dff7c..a33555a 100644
--- a/cmake/external/pybind11.cmake
+++ b/cmake/external/pybind11.cmake
@@ -1,15 +1,13 @@
if(NOT IOS)
include(ExternalProject)
-
externalproject_add(
ext_pybind11
PREFIX pybind11
- URL https://github.com/pybind/pybind11/archive/refs/tags/v2.6.2.tar.gz
- URL_HASH
- SHA256=8ff2fff22df038f5cd02cea8af56622bc67f5b64534f1b83b9f133b8366acff2
+ URL https://github.com/pybind/pybind11/archive/refs/tags/v2.10.4.tar.gz
+ DOWNLOAD_EXTRACT_TIMESTAMP TRUE
CMAKE_ARGS ${ExternalProject_CMAKE_ARGS_hidden}
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}/pybind11
- -DBUILD_TESTING=OFF
+ -DBUILD_TESTING=OFF -DPYBIND11_USE_STATIC_PYTHON=ON
)
else()
message(STATUS "[XRPrimer] Disable pybind11 on IOS")
diff --git a/cmake/setup_deps.cmake b/cmake/setup_deps.cmake
index b763490..7e058e7 100644
--- a/cmake/setup_deps.cmake
+++ b/cmake/setup_deps.cmake
@@ -3,14 +3,21 @@
#
if(3RT_FROM_LOCAL)
+ if(POLICY CMP0135)
+ cmake_policy(SET CMP0135 NEW)
+ endif()
+
include(${CMAKE_SOURCE_DIR}/cmake/external/common.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/external/eigen.cmake)
- include(${CMAKE_SOURCE_DIR}/cmake/external/ceres.cmake)
- include(${CMAKE_SOURCE_DIR}/cmake/external/opencv.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/external/pybind11.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/external/spdlog.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/external/jsoncpp.cmake)
- include(${CMAKE_SOURCE_DIR}/cmake/external/pnpsolver.cmake)
+
+ if(NOT BUILD_ONLY_BASE)
+ include(${CMAKE_SOURCE_DIR}/cmake/external/ceres.cmake)
+ include(${CMAKE_SOURCE_DIR}/cmake/external/opencv.cmake)
+ include(${CMAKE_SOURCE_DIR}/cmake/external/pnpsolver.cmake)
+ endif()
endif()
if(3RT_FROM_CONAN)
diff --git a/cpp/pybind/CMakeLists.txt b/cpp/pybind/CMakeLists.txt
index e727547..e5d70b8 100644
--- a/cpp/pybind/CMakeLists.txt
+++ b/cpp/pybind/CMakeLists.txt
@@ -1,5 +1,7 @@
find_package(Python3 COMPONENTS Interpreter Development)
+find_package(pybind11 REQUIRED CONFIG)
+
if(Python3_FOUND)
set(PYTHON_EXECUTABLE
${Python3_EXECUTABLE}
@@ -15,16 +17,26 @@ endif()
set(PYTHON_VERSION "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}")
-pybind11_add_module(
- xrprimer_cpp xrprimer_pybind.cpp data_structure/camera.cpp
- data_structure/pose.cpp calibration/calibrator_api.cpp ops/pnpsolver.cpp
- common/version.cpp
+pybind11_add_module(xrprimer_cpp)
+target_sources(
+ xrprimer_cpp PRIVATE xrprimer_pybind.cpp data_structure/camera.cpp
+ data_structure/pose.cpp common/version.cpp
)
-target_link_libraries(
- xrprimer_cpp PUBLIC XRPrimer::xrprimer opencv_imgcodecs opencv_calib3d
- opencv_core
-)
+set(EXTERNAL_MODULES XRPrimer::xrprimer)
+
+if(NOT BUILD_ONLY_BASE)
+ set(EXTERNAL_MODULES ${EXTERNAL_MODULES} opencv_imgcodecs opencv_calib3d
+ opencv_core
+ )
+else()
+ target_compile_definitions(xrprimer_cpp PRIVATE XRPRIMER_BUILD_BASE)
+endif()
+
+add_subdirectory(calibration)
+add_subdirectory(ops)
+
+target_link_libraries(xrprimer_cpp PUBLIC ${EXTERNAL_MODULES})
target_include_directories(
xrprimer_cpp PUBLIC $
$
diff --git a/cpp/pybind/calibration/CMakeLists.txt b/cpp/pybind/calibration/CMakeLists.txt
new file mode 100644
index 0000000..958fd87
--- /dev/null
+++ b/cpp/pybind/calibration/CMakeLists.txt
@@ -0,0 +1 @@
+target_sources(xrprimer_cpp PRIVATE calibrator_api.cpp)
diff --git a/cpp/pybind/calibration/calibrator_api.cpp b/cpp/pybind/calibration/calibrator_api.cpp
index 6049fc5..2f5efff 100644
--- a/cpp/pybind/calibration/calibrator_api.cpp
+++ b/cpp/pybind/calibration/calibrator_api.cpp
@@ -1,7 +1,12 @@
-#include
#include
+#ifdef XRPRIMER_BUILD_BASE
+void xrprimer_pybind_calibrator(py::module &m) {}
+#else
+
+#include
+
void pybind_camera_calibrator(py::module &m) {
m.def("CalibrateMultiPinholeCamera", &CalibrateMultiPinholeCamera);
}
@@ -10,3 +15,4 @@ void xrprimer_pybind_calibrator(py::module &m) {
py::module m_submodule = m.def_submodule("calibrator");
pybind_camera_calibrator(m_submodule);
}
+#endif
diff --git a/cpp/pybind/ops/CMakeLists.txt b/cpp/pybind/ops/CMakeLists.txt
new file mode 100644
index 0000000..823ba84
--- /dev/null
+++ b/cpp/pybind/ops/CMakeLists.txt
@@ -0,0 +1 @@
+target_sources(xrprimer_cpp PRIVATE pnpsolver.cpp)
diff --git a/cpp/pybind/ops/pnpsolver.cpp b/cpp/pybind/ops/pnpsolver.cpp
index 8bd22e1..16df797 100644
--- a/cpp/pybind/ops/pnpsolver.cpp
+++ b/cpp/pybind/ops/pnpsolver.cpp
@@ -1,6 +1,12 @@
-#include
+
#include
+#ifdef XRPRIMER_BUILD_BASE
+void xrprimer_pybind_pnpsolver(py::module &m) {}
+#else
+
+#include
+
py::dict prior_guided_pnp(
const Eigen::Ref>
points2D,
@@ -71,3 +77,4 @@ void xrprimer_pybind_pnpsolver(py::module &m) {
py::module m_submodule = m.def_submodule("ops");
pybind_pnpsolver(m_submodule);
}
+#endif
diff --git a/cpp/pybind/xrprimer_pybind.cpp b/cpp/pybind/xrprimer_pybind.cpp
index daac458..535ef52 100644
--- a/cpp/pybind/xrprimer_pybind.cpp
+++ b/cpp/pybind/xrprimer_pybind.cpp
@@ -190,8 +190,8 @@ PYBIND11_MODULE(xrprimer_cpp, m) {
pybind_eigen_classes(m);
xrprimer_pybind_camera(m);
- xrprimer_pybind_calibrator(m);
xrprimer_pybind_version(m);
xrprimer_pybind_pose(m);
+ xrprimer_pybind_calibrator(m);
xrprimer_pybind_pnpsolver(m);
}
diff --git a/cpp/xrprimer/CMakeLists.txt b/cpp/xrprimer/CMakeLists.txt
index 07c8b3a..c978baf 100644
--- a/cpp/xrprimer/CMakeLists.txt
+++ b/cpp/xrprimer/CMakeLists.txt
@@ -1,60 +1,42 @@
-set(Headers
- common/version.h
- calibration/calibrator.h
- calibration/calibrator_api.h
- data_structure/math_util.h
- data_structure/camera/camera.h
- data_structure/camera/pinhole_camera.h
- data_structure/camera/omni_camera.h
- data_structure/camera/fisheye_camera.h
- data_structure/image.h
- data_structure/pose.h
- utils/logging.h
-)
-source_group("Headers" FILES ${Headers})
-
-set(Sources
- common/version.cpp
- calibration/calibrator.cpp
- calibration/calibrator_api.cpp
- data_structure/camera/camera.cpp
- data_structure/camera/pinhole_camera.cpp
- data_structure/camera/omni_camera.cpp
- data_structure/camera/fisheye_camera.cpp
- data_structure/image.cpp
- data_structure/pose.cpp
- utils/logging.cpp
-)
+if(NOT BUILD_ONLY_BASE)
+ add_subdirectory(calibration)
+endif()
-source_group("Sources" FILES ${Sources})
+add_library(xrprimer)
+add_library(XRPrimer::xrprimer ALIAS xrprimer)
-set(target xrprimer)
-
-add_library(${target} ${Headers} ${Sources})
-add_library(XRPrimer::${target} ALIAS ${target})
+target_sources(
+ xrprimer
+ PRIVATE common/version.cpp
+ data_structure/image.cpp
+ data_structure/pose.cpp
+ data_structure/camera/camera.cpp
+ data_structure/camera/fisheye_camera.cpp
+ data_structure/camera/omni_camera.cpp
+ data_structure/camera/pinhole_camera.cpp
+)
-target_compile_options(${target} PRIVATE -fPIC)
+target_compile_options(xrprimer PRIVATE -fPIC)
include(GenerateExportHeader)
generate_export_header(
- ${target} EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/xrprimer_export.h
+ xrprimer EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/xrprimer_export.h
)
target_include_directories(
- ${target}
+ xrprimer
PUBLIC $
$
$
)
target_link_libraries(
- ${target}
- PUBLIC $<$>:PnpSolver::pnpsolver> OpenCV::OpenCV
- Eigen3::Eigen Ceres::ceres jsoncpp_static spdlog::spdlog_header_only
+ xrprimer PUBLIC $<$:calibrator_obj>
+ ${XRPRIMER_PUBLIC_TARGET}
)
-install(TARGETS ${target} DESTINATION lib EXPORT ${target}-targets)
-install(EXPORT ${target}-targets DESTINATION lib/cmake/xrprimer
+install(TARGETS xrprimer DESTINATION lib EXPORT xrprimer-targets)
+install(EXPORT xrprimer-targets DESTINATION lib/cmake/xrprimer
NAMESPACE XRPrimer::
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING
diff --git a/cpp/xrprimer/calibration/CMakelists.txt b/cpp/xrprimer/calibration/CMakelists.txt
new file mode 100644
index 0000000..89b9c37
--- /dev/null
+++ b/cpp/xrprimer/calibration/CMakelists.txt
@@ -0,0 +1,3 @@
+add_library(calibrator_obj OBJECT)
+target_sources(calibrator_obj PUBLIC calibrator.cpp calibrator_api.cpp)
+target_include_directories(calibrator_obj PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
diff --git a/docs/en/installation/cpp.md b/docs/en/installation/cpp.md
index b5cf6d1..6e8b0f9 100644
--- a/docs/en/installation/cpp.md
+++ b/docs/en/installation/cpp.md
@@ -69,6 +69,7 @@ It is currently tested on Linux and iOS. Ideally it can be also compiled on macO
```bash
#1. First run, get external dependencies, will install external deps to 3rdparty
cmake -S. -Bbuild_deps <-D3RT_FROM_LOCAL=ON/-D3RT_FROM_CONAN=ON>
+cmake -S. -Bbuild_deps -D3RT_FROM_LOCAL=ON
cmake --build build_deps
#2. build xrprimer