Skip to content

Commit

Permalink
make cpp installable
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Uecker committed Nov 18, 2024
1 parent 0395784 commit a31be32
Show file tree
Hide file tree
Showing 25 changed files with 159 additions and 15 deletions.
73 changes: 69 additions & 4 deletions cpp/kiss_icp/3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,72 @@ function(find_external_dependency PACKAGE_NAME TARGET_NAME INCLUDED_CMAKE_PATH)
endif()
endfunction()

find_external_dependency("Eigen3" "Eigen3::Eigen" "${CMAKE_CURRENT_LIST_DIR}/eigen/eigen.cmake")
find_external_dependency("Sophus" "Sophus::Sophus" "${CMAKE_CURRENT_LIST_DIR}/sophus/sophus.cmake")
find_external_dependency("TBB" "TBB::tbb" "${CMAKE_CURRENT_LIST_DIR}/tbb/tbb.cmake")
find_external_dependency("tsl-robin-map" "tsl::robin_map" "${CMAKE_CURRENT_LIST_DIR}/tsl_robin/tsl_robin.cmake")
if(NOT DOWNLOAD_MISSING_DEPS)
find_package(Eigen3 REQUIRED) # sudo apt install libeigen3-dev
find_package(Sophus REQUIRED) # sudo apt install ros-noetic-sophus
find_package(TBB REQUIRED) # sudo apt install libtbb-dev
find_package(tsl-robin-map REQUIRED) # clone & install from https://github.com/Tessil/robin-map.git into misc_ws, and run `cmake -Bbuild && cmake --build build && sudo cmake --install build`)

else()
find_package(Eigen3)
find_package(Sophus)
find_package(TBB)
find_package(tsl-robin-map)
endif()

if(TARGET Eigen3::Eigen)
message("Found package Eigen3 locally")
endif()
if(TARGET Sophus::Sophus)
message("Found package Sophus locally")
endif()
if(TARGET TBB::tbb)
message("Found package TBB locally")
endif()
if(TARGET tsl::robin_map)
message("Found package tsl-robin-map locally")
endif()

if(NOT (TARGET Eigen3::Eigen AND TARGET Sophus::Sophus AND TARGET tsl::robin_map AND TARGET TBB::tbb))
message(FATAL_ERROR "
Exporting fetched dependencies is currently broken
I have no idea how to do it automatically ¯\\_(ツ)_/¯
please set DOWNLOAD_MISSING_DEPS to OFF in the main CMakeLists.txt and install the dependencies yourself.
The find_dependencies file lists the corresponding installation instructions.
")
endif()

if(DOWNLOAD_MISSING_DEPS)
if(NOT TARGET Eigen3::Eigen)
message("Trying to download external dependency Eigen3...")
find_external_dependency("Eigen3" "Eigen3::Eigen" "${CMAKE_CURRENT_LIST_DIR}/eigen/eigen.cmake")
message("done.")
if(NOT TARGET Eigen3::Eigen)
message(FATAL_ERROR "loading Eigen3::Eigen failed.")
endif()
endif()
if(NOT TARGET Sophus::Sophus)
message("Trying to download external dependency Sophus...")
find_external_dependency("Sophus" "Sophus::Sophus" "${CMAKE_CURRENT_LIST_DIR}/sophus/sophus.cmake")
message("done.")
if(NOT TARGET Sophus::Sophus)
message(FATAL_ERROR "loading Sophus::Sophus failed.")
endif()
endif()
if(NOT TARGET TBB::tbb)
message("Trying to download external dependency TBB...")
find_external_dependency("TBB" "TBB::tbb" "${CMAKE_CURRENT_LIST_DIR}/tbb/tbb.cmake")
message("done.")
if(NOT TARGET TBB::tbb)
message(FATAL_ERROR "loading TBB:tbb failed.")
endif()
endif()
if(NOT TARGET tsl::robin_map)
message("Trying to download external dependency tsl-robin-map...")
find_external_dependency("tsl-robin-map" "tsl::robin_map" "${CMAKE_CURRENT_LIST_DIR}/tsl_robin/tsl_robin.cmake")
message("done.")
if(NOT TARGET tsl::robin_map)
message(FATAL_ERROR "loading tsl::robin_map failed.")
endif()
endif()
endif()
4 changes: 2 additions & 2 deletions cpp/kiss_icp/3rdparty/tsl_robin/tsl_robin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
include(FetchContent)
FetchContent_Declare(tessil SYSTEM URL https://github.com/Tessil/robin-map/archive/refs/tags/v1.2.1.tar.gz)
FetchContent_MakeAvailable(tessil)
FetchContent_Declare(tsl-robin-map SYSTEM URL https://github.com/Tessil/robin-map/archive/refs/tags/v1.2.1.tar.gz)
FetchContent_MakeAvailable(tsl-robin-map)
40 changes: 35 additions & 5 deletions cpp/kiss_icp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
cmake_minimum_required(VERSION 3.16...3.26)
project(kiss_icp_cpp VERSION 1.1.0 LANGUAGES CXX)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

# Setup build options
option(USE_CCACHE "Build using Ccache if found on the path" ON)
option(USE_SYSTEM_EIGEN3 "Use system pre-installed Eigen" ON)
option(USE_SYSTEM_SOPHUS "Use system pre-installed Sophus" ON)
option(USE_SYSTEM_TSL-ROBIN-MAP "Use system pre-installed tsl_robin" ON)
option(USE_SYSTEM_TBB "Use system pre-installed oneAPI/tbb" ON)
option(DOWNLOAD_MISSING_DEPS "try and download missing depedencies from repos" OFF)

# ccache setup
if(USE_CCACHE)
Expand All @@ -45,9 +49,35 @@ set(CMAKE_BUILD_TYPE Release)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

include(3rdparty/find_dependencies.cmake)
include(cmake/CompilerOptions.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/3rdparty/find_dependencies.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/CompilerOptions.cmake)

add_subdirectory(src)

install(EXPORT kiss_icpTargets
FILE kiss_icpTargets.cmake
NAMESPACE kiss_icp::
DESTINATION "share/cmake/kiss_icp")


configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/kiss_icpConfig.cmake"
INSTALL_DESTINATION "share/cmake/kiss_icp"
)

# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/kiss_icpConfigVersion.cmake"
VERSION "${version}"
COMPATIBILITY SameMinorVersion
)


install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include/kiss_icp"
DESTINATION "include")

add_subdirectory(core)
add_subdirectory(metrics)
add_subdirectory(pipeline)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/kiss_icpConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/kiss_icpConfigVersion.cmake"
DESTINATION "share/cmake/kiss_icp"
)
11 changes: 10 additions & 1 deletion cpp/kiss_icp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

## How to build

```sh
```bash
cmake -Bbuild
cmake --build build -j$(nproc --all)
```

## How to install:

```bash
# install system-wide
cmake --install build
# or install to a custom location (e.g. "/usr/local")
cmake --install build --prefix "<your_custom_install_prefix>"
```

## Dependencies

The cmake build system should handle all dependencies for you. In case you have some particular
Expand Down
11 changes: 11 additions & 0 deletions cpp/kiss_icp/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(Eigen3 REQUIRED)
find_dependency(Sophus REQUIRED)
find_dependency(TBB REQUIRED)
find_dependency(tsl-robin-map REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/kiss_icpTargets.cmake")

check_required_components(kiss_icp)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions cpp/kiss_icp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_subdirectory(core)
add_subdirectory(metrics)
add_subdirectory(pipeline)
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@
add_library(kiss_icp_core STATIC)
target_sources(kiss_icp_core PRIVATE Registration.cpp Deskew.cpp VoxelHashMap.cpp VoxelUtils.cpp Preprocessing.cpp
Threshold.cpp)
target_link_libraries(kiss_icp_core PUBLIC Eigen3::Eigen tsl::robin_map TBB::tbb Sophus::Sophus)
target_include_directories(kiss_icp_core PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/kiss_icp/core>
$<INSTALL_INTERFACE:include/kiss_icp/core>
)
target_link_libraries(kiss_icp_core PUBLIC Eigen3::Eigen tsl::robin_map Sophus::Sophus)
target_link_libraries(kiss_icp_core PRIVATE TBB::tbb)
set_global_target_properties(kiss_icp_core)

install(TARGETS kiss_icp_core
DESTINATION lib/kiss_icp/core
EXPORT kiss_icpTargets)
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace {
/// TODO(Nacho) Explain what is the very important meaning of this param
constexpr double mid_pose_timestamp{0.5};
constexpr double mid_pose_timestamp{0.5}; // 0.5 for middle of scan
} // namespace

namespace kiss_icp {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@
# SOFTWARE.
add_library(kiss_icp_metrics STATIC)
target_sources(kiss_icp_metrics PRIVATE Metrics.cpp)
target_include_directories(kiss_icp_metrics PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/kiss_icp/metrics>
$<INSTALL_INTERFACE:include/kiss_icp/metrics>
)
target_link_libraries(kiss_icp_metrics PUBLIC Eigen3::Eigen)
set_global_target_properties(kiss_icp_metrics)

install(TARGETS kiss_icp_metrics
DESTINATION lib/kiss_icp/metrics
EXPORT kiss_icpTargets)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@

add_library(kiss_icp_pipeline STATIC)
target_sources(kiss_icp_pipeline PRIVATE KissICP.cpp)
target_include_directories(kiss_icp_pipeline PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/kiss_icp/pipeline>
$<INSTALL_INTERFACE:include/kiss_icp/pipeline>
)
target_link_libraries(kiss_icp_pipeline PUBLIC kiss_icp_core)
set_global_target_properties(kiss_icp_pipeline)

install(TARGETS kiss_icp_pipeline
DESTINATION lib/kiss_icp/pipeline
EXPORT kiss_icpTargets
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "KissICP.hpp"
#include "kiss_icp/pipeline/KissICP.hpp"

#include <Eigen/Core>
#include <vector>
Expand Down

0 comments on commit a31be32

Please sign in to comment.