Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make kiss_icp c++ package installable via cmake #408

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions cpp/include_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.18.0)
project(kiss_icp_include_example)

find_package(kiss_icp REQUIRED CONFIG)

add_executable(example src/example.cpp)
target_link_libraries(example PRIVATE kiss_icp::kiss_icp_pipeline)
#for other components (not used in example.cpp):
#target_link_libraries(example PRIVATE kiss_icp::kiss_icp_core)
#target_link_libraries(example PRIVATE kiss_icp::kiss_icp_metrics)
9 changes: 9 additions & 0 deletions cpp/include_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Example on how to include the KissICP library in other C++ projects with CMake

See `CMakeLists.txt` for details on how to find the library and link the targets, and `src/example.cpp` on how to include the corresponding files.

## Building your project
```bash
cmake -Bbuild
cmake --build build -j$(nproc --all)
```
14 changes: 14 additions & 0 deletions cpp/include_example/src/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <kiss_icp/pipeline/KissICP.hpp>

int main() {
struct kiss_icp::pipeline::KISSConfig config;
config.deskew = true;
config.initial_threshold = 2.0;
config.min_range = 8.0;
config.max_range = 100.0;
config.max_points_per_voxel = 20;
config.min_motion_th = 0.1;
config.voxel_size = 1.0;
kiss_icp::pipeline::KissICP icp_pipeline{config};
// TODO: use pipeline here
}
83 changes: 79 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,82 @@ 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
# clone & install from https://github.com/Tessil/robin-map.git into misc_ws, and run `cmake -Bbuild && cmake --build build && sudo cmake --install build`)
find_package(tsl-robin-map REQUIRED)

else()
find_package(Eigen3 QUIET)
find_package(Sophus QUIET)
find_package(TBB QUIET)
find_package(tsl-robin-map QUIET)
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(INSTALL_KISS_ICP_CPP AND NOT (TARGET Eigen3::Eigen AND TARGET Sophus::Sophus AND TARGET tsl::robin_map AND TARGET
TBB::tbb))
message(
WARNING
"
Exporting fetched dependencies is currently broken.
I have no idea how to do it automatically ¯\\_(ツ)_/¯
If you want to make the kiss_icp c++ library available system-wide,
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.
")
set(INSTALL_KISS_ICP_CPP OFF)
else()
if(INSTALL_KISS_ICP_CPP)
message("All system dependencies found! Installing kiss_icp as a c++ library is possible.")
endif()
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)
30 changes: 25 additions & 5 deletions cpp/kiss_icp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
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" ON)
option(INSTALL_KISS_ICP_CPP "Install kiss_icp c++ library, requires all dependencies to be installed system-wide" ON)

# ccache setup
if(USE_CCACHE)
Expand All @@ -45,9 +50,24 @@ 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)

if(INSTALL_KISS_ICP_CPP)
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")

add_subdirectory(core)
add_subdirectory(metrics)
add_subdirectory(pipeline)
# 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")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/kiss_icpConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/kiss_icpConfigVersion.cmake" DESTINATION "share/cmake/kiss_icp")
endif()
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)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <sophus/se3.hpp>
#include <vector>

#include "VoxelHashMap.hpp"
#include "kiss_icp/core/VoxelHashMap.hpp"

namespace kiss_icp {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <sophus/se3.hpp>
#include <vector>

#include "VoxelUtils.hpp"
#include "kiss_icp/core/VoxelUtils.hpp"

namespace kiss_icp {
struct VoxelHashMap {
Expand Down
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,10 @@
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>
$<INSTALL_INTERFACE:include>)
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 @@ -20,7 +20,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "Deskew.hpp"
#include "kiss_icp/core/Deskew.hpp"

#include <tbb/parallel_for.h>

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "Preprocessing.hpp"
#include "kiss_icp/core/Preprocessing.hpp"

#include <tsl/robin_map.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "Registration.hpp"
#include "kiss_icp/core/Registration.hpp"

#include <tbb/blocked_range.h>
#include <tbb/global_control.h>
Expand All @@ -35,8 +35,8 @@
#include <sophus/so3.hpp>
#include <tuple>

#include "VoxelHashMap.hpp"
#include "VoxelUtils.hpp"
#include "kiss_icp/core/VoxelHashMap.hpp"
#include "kiss_icp/core/VoxelUtils.hpp"

namespace Eigen {
using Matrix6d = Eigen::Matrix<double, 6, 6>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "Threshold.hpp"
#include "kiss_icp/core/Threshold.hpp"

#include <Eigen/Geometry>
#include <cmath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "VoxelHashMap.hpp"
#include "kiss_icp/core/VoxelHashMap.hpp"

#include <Eigen/Core>
#include <algorithm>
#include <sophus/se3.hpp>
#include <vector>

#include "VoxelUtils.hpp"
#include "kiss_icp/core/VoxelUtils.hpp"

namespace {
using kiss_icp::Voxel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "VoxelUtils.hpp"
#include "kiss_icp/core/VoxelUtils.hpp"

#include <tsl/robin_map.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
# 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>
$<INSTALL_INTERFACE:include>)
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)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "Metrics.hpp"
#include "kiss_icp/metrics/Metrics.hpp"

#include <Eigen/Core>
#include <Eigen/Geometry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@

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>
$<INSTALL_INTERFACE:include>)
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
Loading