mirror of https://github.com/koide3/small_gicp.git
Improve the project's CMake and Python structure to aid packaging (#6)
* Adjust CMake to use more standard dependency names * Don't force shared libraries * Improve CMake installation logic * Replace setup.py with pyproject.toml * Add small_gicp-config.cmake.in to set dependencies correctly
This commit is contained in:
parent
ae2f3cb2d1
commit
c1b08efedb
208
CMakeLists.txt
208
CMakeLists.txt
|
|
@ -1,24 +1,23 @@
|
||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
project(small_gicp)
|
project(small_gicp VERSION 0.0.1 LANGUAGES CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
|
||||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Eigen is the sole mandatory dependency
|
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
|
||||||
find_package(Eigen3 REQUIRED)
|
option(CMAKE_POSITION_INDEPENDENT_CODE "Generate position-independent code" ON)
|
||||||
find_package(OpenMP)
|
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
|
||||||
|
|
||||||
option(BUILD_HELPER "Build helper library" ON)
|
option(BUILD_HELPER "Build helper library" ON)
|
||||||
option(BUILD_TESTS "Build tests" OFF)
|
option(BUILD_TESTS "Build tests" OFF)
|
||||||
option(BUILD_EXAMPLES "Build examples" OFF)
|
option(BUILD_EXAMPLES "Build examples" OFF)
|
||||||
option(BUILD_BENCHMARKS "Build benchmarks" OFF)
|
option(BUILD_BENCHMARKS "Build benchmarks" OFF)
|
||||||
|
set(BUILD_WITH_OPENMP CACHE STRING "Build with OpenMP" "auto")
|
||||||
option(BUILD_WITH_TBB "Build with TBB" ON)
|
option(BUILD_WITH_TBB "Build with TBB" ON)
|
||||||
option(BUILD_WITH_PCL "Build with PCL (required for benchmark and test only)" OFF)
|
option(BUILD_WITH_PCL "Build with PCL (required for benchmark and test only)" OFF)
|
||||||
option(BUILD_WITH_FAST_GICP "Build with fast_gicp (required for benchmark and test only)" OFF)
|
option(BUILD_WITH_FAST_GICP "Build with fast_gicp (required for benchmark and test only)" OFF)
|
||||||
|
|
@ -27,10 +26,18 @@ option(BUILD_WITH_MARCH_NATIVE "Build with -march=native" OFF)
|
||||||
option(ENABLE_COVERAGE "Enable coverage" OFF)
|
option(ENABLE_COVERAGE "Enable coverage" OFF)
|
||||||
option(BUILD_PYTHON_BINDINGS "Build python bindings" OFF)
|
option(BUILD_PYTHON_BINDINGS "Build python bindings" OFF)
|
||||||
|
|
||||||
|
# Eigen is the sole mandatory dependency
|
||||||
|
find_package(Eigen3 REQUIRED CONFIG)
|
||||||
|
|
||||||
|
if(BUILD_WITH_OPENMP STREQUAL "auto")
|
||||||
|
find_package(OpenMP)
|
||||||
|
set(BUILD_WITH_OPENMP ${OpenMP_FOUND})
|
||||||
|
elseif(BUILD_WITH_OPENMP)
|
||||||
|
find_package(OpenMP REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(BUILD_WITH_MARCH_NATIVE)
|
if(BUILD_WITH_MARCH_NATIVE)
|
||||||
add_compile_options(-march=native)
|
add_compile_options(-march=native)
|
||||||
set(CMAKE_C_FLAGS "-march=native ${CMAKE_C_FLAGS}")
|
|
||||||
set(CMAKE_CXX_FLAGS "-march=native ${CMAKE_CXX_FLAGS}")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
##############
|
##############
|
||||||
|
|
@ -50,46 +57,36 @@ if(ENABLE_COVERAGE)
|
||||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#############
|
|
||||||
## Install ##
|
|
||||||
#############
|
|
||||||
install(DIRECTORY include/ DESTINATION include)
|
|
||||||
|
|
||||||
###########
|
###########
|
||||||
## Build ##
|
## Build ##
|
||||||
###########
|
###########
|
||||||
|
|
||||||
|
include_directories(include)
|
||||||
|
|
||||||
# Helper library
|
# Helper library
|
||||||
if(BUILD_HELPER)
|
if(BUILD_HELPER)
|
||||||
add_library(small_gicp_helper SHARED
|
add_library(small_gicp
|
||||||
src/small_gicp/registration/registration.cpp
|
src/small_gicp/registration/registration.cpp
|
||||||
src/small_gicp/registration/registration_helper.cpp
|
src/small_gicp/registration/registration_helper.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(small_gicp_helper PUBLIC
|
target_include_directories(small_gicp PUBLIC
|
||||||
include
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
${EIGEN3_INCLUDE_DIR}
|
$<INSTALL_INTERFACE:include>
|
||||||
)
|
)
|
||||||
target_link_libraries(small_gicp_helper
|
target_link_libraries(small_gicp PUBLIC
|
||||||
OpenMP::OpenMP_CXX
|
Eigen3::Eigen
|
||||||
|
$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_CXX>
|
||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS small_gicp_helper DESTINATION lib)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(Python COMPONENTS Interpreter Development)
|
|
||||||
find_package(pybind11 CONFIG)
|
|
||||||
|
|
||||||
# Python bindings
|
# Python bindings
|
||||||
if(BUILD_PYTHON_BINDINGS)
|
if(BUILD_PYTHON_BINDINGS)
|
||||||
pybind11_add_module(small_gicp src/python/python.cpp)
|
find_package(Python COMPONENTS Interpreter Development REQUIRED)
|
||||||
target_include_directories(small_gicp PUBLIC
|
find_package(pybind11 CONFIG REQUIRED)
|
||||||
include
|
|
||||||
${EIGEN3_INCLUDE_DIR}
|
pybind11_add_module(small_gicp_python src/python/python.cpp)
|
||||||
)
|
set_target_properties(small_gicp_python PROPERTIES OUTPUT_NAME small_gicp)
|
||||||
target_link_libraries(small_gicp PRIVATE
|
target_link_libraries(small_gicp_python PRIVATE small_gicp)
|
||||||
small_gicp_helper
|
|
||||||
OpenMP::OpenMP_CXX
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
###############
|
###############
|
||||||
|
|
@ -104,6 +101,13 @@ if(BUILD_BENCHMARKS)
|
||||||
if (BUILD_WITH_PCL)
|
if (BUILD_WITH_PCL)
|
||||||
find_package(PCL REQUIRED)
|
find_package(PCL REQUIRED)
|
||||||
add_compile_definitions(BUILD_WITH_PCL)
|
add_compile_definitions(BUILD_WITH_PCL)
|
||||||
|
if (NOT TARGET PCL::PCL)
|
||||||
|
add_library(PCL::PCL INTERFACE IMPORTED)
|
||||||
|
set_target_properties(PCL::PCL PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${PCL_INCLUDE_DIRS}"
|
||||||
|
INTERFACE_LINK_LIBRARIES "${PCL_LIBRARIES}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if (BUILD_WITH_IRIDESCENCE)
|
if (BUILD_WITH_IRIDESCENCE)
|
||||||
find_package(Iridescence REQUIRED)
|
find_package(Iridescence REQUIRED)
|
||||||
|
|
@ -132,34 +136,28 @@ if(BUILD_BENCHMARKS)
|
||||||
src/benchmark/odometry_benchmark.cpp
|
src/benchmark/odometry_benchmark.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(odometry_benchmark PUBLIC
|
target_include_directories(odometry_benchmark PUBLIC
|
||||||
include
|
|
||||||
${PCL_INCLUDE_DIRS}
|
|
||||||
${TBB_INCLUDE_DIRS}
|
|
||||||
${EIGEN3_INCLUDE_DIR}
|
|
||||||
${Iridescence_INCLUDE_DIRS}
|
|
||||||
${FAST_GICP_INCLUDE_DIR}
|
${FAST_GICP_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
target_link_libraries(odometry_benchmark
|
target_link_libraries(odometry_benchmark PRIVATE
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
OpenMP::OpenMP_CXX
|
Eigen3::Eigen
|
||||||
${PCL_LIBRARIES}
|
$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_CXX>
|
||||||
${TBB_LIBRARIES}
|
Iridescence::Iridescence
|
||||||
${Iridescence_LIBRARIES}
|
TBB::tbb
|
||||||
|
TBB::tbbmalloc
|
||||||
|
PCL::PCL
|
||||||
)
|
)
|
||||||
|
|
||||||
# KdTree construction benchmark
|
# KdTree construction benchmark
|
||||||
add_executable(kdtree_benchmark
|
add_executable(kdtree_benchmark
|
||||||
src/benchmark/kdtree_benchmark.cpp
|
src/benchmark/kdtree_benchmark.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(kdtree_benchmark PUBLIC
|
target_link_libraries(kdtree_benchmark PRIVATE
|
||||||
include
|
|
||||||
${TBB_INCLUDE_DIRS}
|
|
||||||
${EIGEN3_INCLUDE_DIR}
|
|
||||||
)
|
|
||||||
target_link_libraries(kdtree_benchmark
|
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
OpenMP::OpenMP_CXX
|
Eigen3::Eigen
|
||||||
${TBB_LIBRARIES}
|
$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_CXX>
|
||||||
|
TBB::tbb
|
||||||
|
TBB::tbbmalloc
|
||||||
)
|
)
|
||||||
|
|
||||||
if(BUILD_WITH_PCL)
|
if(BUILD_WITH_PCL)
|
||||||
|
|
@ -167,17 +165,13 @@ if(BUILD_BENCHMARKS)
|
||||||
add_executable(downsampling_benchmark
|
add_executable(downsampling_benchmark
|
||||||
src/benchmark/downsampling_benchmark.cpp
|
src/benchmark/downsampling_benchmark.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(downsampling_benchmark PUBLIC
|
target_link_libraries(downsampling_benchmark PRIVATE
|
||||||
include
|
|
||||||
${PCL_INCLUDE_DIRS}
|
|
||||||
${TBB_INCLUDE_DIRS}
|
|
||||||
${EIGEN3_INCLUDE_DIR}
|
|
||||||
)
|
|
||||||
target_link_libraries(downsampling_benchmark
|
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
OpenMP::OpenMP_CXX
|
Eigen3::Eigen
|
||||||
${PCL_LIBRARIES}
|
$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_CXX>
|
||||||
${TBB_LIBRARIES}
|
TBB::tbb
|
||||||
|
TBB::tbbmalloc
|
||||||
|
PCL::PCL
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -194,18 +188,12 @@ if(BUILD_EXAMPLES)
|
||||||
foreach(EXAMPLE_SOURCE ${EXAMPLE_SOURCES})
|
foreach(EXAMPLE_SOURCE ${EXAMPLE_SOURCES})
|
||||||
get_filename_component(EXAMPLE_NAME ${EXAMPLE_SOURCE} NAME_WE)
|
get_filename_component(EXAMPLE_NAME ${EXAMPLE_SOURCE} NAME_WE)
|
||||||
add_executable(${EXAMPLE_NAME} ${EXAMPLE_SOURCE})
|
add_executable(${EXAMPLE_NAME} ${EXAMPLE_SOURCE})
|
||||||
target_include_directories(${EXAMPLE_NAME} PUBLIC
|
target_link_libraries(${EXAMPLE_NAME} PRIVATE
|
||||||
include
|
small_gicp
|
||||||
${PCL_INCLUDE_DIRS}
|
|
||||||
${TBB_INCLUDE_DIRS}
|
|
||||||
${EIGEN3_INCLUDE_DIR}
|
|
||||||
)
|
|
||||||
target_link_libraries(${EXAMPLE_NAME}
|
|
||||||
small_gicp_helper
|
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
OpenMP::OpenMP_CXX
|
TBB::tbb
|
||||||
${PCL_LIBRARIES}
|
TBB::tbbmalloc
|
||||||
${TBB_LIBRARIES}
|
PCL::PCL
|
||||||
)
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -225,21 +213,73 @@ if(BUILD_TESTS)
|
||||||
foreach(TEST_SOURCE ${TEST_SOURCES})
|
foreach(TEST_SOURCE ${TEST_SOURCES})
|
||||||
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
|
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
|
||||||
add_executable(${TEST_NAME} ${TEST_SOURCE})
|
add_executable(${TEST_NAME} ${TEST_SOURCE})
|
||||||
target_include_directories(${TEST_NAME} PUBLIC
|
target_link_libraries(${TEST_NAME} PRIVATE
|
||||||
include
|
small_gicp
|
||||||
${PCL_INCLUDE_DIRS}
|
|
||||||
${TBB_INCLUDE_DIRS}
|
|
||||||
${EIGEN3_INCLUDE_DIR}
|
|
||||||
)
|
|
||||||
target_link_libraries(${TEST_NAME}
|
|
||||||
small_gicp_helper
|
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
OpenMP::OpenMP_CXX
|
|
||||||
GTest::gtest_main
|
GTest::gtest_main
|
||||||
${PCL_LIBRARIES}
|
TBB::tbb
|
||||||
${TBB_LIBRARIES}
|
TBB::tbbmalloc
|
||||||
|
PCL::PCL
|
||||||
)
|
)
|
||||||
|
|
||||||
gtest_discover_tests(${TEST_NAME} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
gtest_discover_tests(${TEST_NAME} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
#############
|
||||||
|
## Install ##
|
||||||
|
#############
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
|
|
||||||
|
if(BUILD_HELPER)
|
||||||
|
install(TARGETS small_gicp
|
||||||
|
EXPORT small_gicp-targets
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
)
|
||||||
|
set(CMAKE_CONFIG_INSTALL_DIR
|
||||||
|
"${CMAKE_INSTALL_LIBDIR}/cmake/small_gicp"
|
||||||
|
CACHE PATH "Install directory for CMake config files"
|
||||||
|
)
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
install(EXPORT small_gicp-targets
|
||||||
|
FILE small_gicp-targets.cmake
|
||||||
|
NAMESPACE small_gicp::
|
||||||
|
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
|
||||||
|
)
|
||||||
|
configure_package_config_file(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/small_gicp-config.cmake.in"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/small_gicp-config.cmake"
|
||||||
|
INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
|
||||||
|
)
|
||||||
|
write_basic_package_version_file(
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/small_gicp-config-version.cmake"
|
||||||
|
VERSION ${VERSION}
|
||||||
|
COMPATIBILITY SameMajorVersion
|
||||||
|
)
|
||||||
|
install(FILES
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/small_gicp-config.cmake"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/small_gicp-config-version.cmake"
|
||||||
|
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
|
||||||
|
)
|
||||||
|
install(FILES
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindTBB.cmake"
|
||||||
|
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(BUILD_PYTHON_BINDINGS)
|
||||||
|
if(DEFINED SKBUILD_PROJECT_NAME)
|
||||||
|
set(PYTHON_INSTALL_DIR .)
|
||||||
|
elseif(NOT DEFINED PYTHON_INSTALL_DIR)
|
||||||
|
set(PYTHON_INSTALL_DIR lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages)
|
||||||
|
endif()
|
||||||
|
install(TARGETS small_gicp_python small_gicp
|
||||||
|
LIBRARY DESTINATION ${PYTHON_INSTALL_DIR}
|
||||||
|
COMPONENT python
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,20 @@ find_library(GTSAM_UNSTABLE_LIB NAMES gtsam_unstable
|
||||||
HINTS /usr/local/lib /usr/lib
|
HINTS /usr/local/lib /usr/lib
|
||||||
DOC "GTSAM_UNSTABLE libraries")
|
DOC "GTSAM_UNSTABLE libraries")
|
||||||
|
|
||||||
find_library(TBB_LIB NAMES tbb
|
find_dependency(TBB REQUIRED)
|
||||||
HINTS /usr/local/lib /usr/lib
|
|
||||||
DOC "TBB libraries")
|
|
||||||
|
|
||||||
find_library(TBB_MALLOC_LIB NAMES tbbmalloc
|
add_library(gtsam INTERFACE IMPORTED GLOBAL)
|
||||||
HINTS /usr/local/lib /usr/lib
|
set_target_properties(gtsam PROPERTIES
|
||||||
DOC "TBB malloc libraries")
|
INTERFACE_INCLUDE_DIRECTORIES "${GTSAM_INCLUDE_DIRS}"
|
||||||
|
INTERFACE_LINK_LIBRARIES "${GTSAM_LIB} TBB::tbb TBB::tbbmalloc")
|
||||||
|
|
||||||
if(GTSAM_LIB AND GTSAM_UNSTABLE_LIB AND TBB_LIB)
|
add_library(gtsam_unstable INTERFACE IMPORTED GLOBAL)
|
||||||
set(GTSAM_LIBRARIES ${GTSAM_LIB} ${GTSAM_UNSTABLE_LIB} ${TBB_LIB} ${TBB_MALLOC_LIB})
|
set_target_properties(gtsam_unstable PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${GTSAM_INCLUDE_DIRS}"
|
||||||
|
INTERFACE_LINK_LIBRARIES "${GTSAM_UNSTABLE_LIB} gtsam")
|
||||||
|
|
||||||
|
if(GTSAM_LIB AND GTSAM_UNSTABLE_LIB AND TARGET TBB::tbb AND TARGET TBB::tbbmalloc)
|
||||||
|
set(GTSAM_LIBRARIES gtsam gtsam_unstable)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
|
||||||
|
|
@ -12,5 +12,10 @@ find_library(Iridescence_LIBRARY NAMES iridescence
|
||||||
|
|
||||||
set(Iridescence_LIBRARIES ${Iridescence_LIBRARY} ${gl_imgui_LIBRARY})
|
set(Iridescence_LIBRARIES ${Iridescence_LIBRARY} ${gl_imgui_LIBRARY})
|
||||||
|
|
||||||
|
add_library(Iridescence::Iridescence INTERFACE IMPORTED GLOBAL)
|
||||||
|
set_target_properties(Iridescence::Iridescence PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${Iridescence_INCLUDE_DIRS}"
|
||||||
|
INTERFACE_LINK_LIBRARIES "${Iridescence_LIBRARIES}")
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(Iridescence DEFAULT_MSG Iridescence_INCLUDE_DIRS Iridescence_LIBRARIES)
|
find_package_handle_standard_args(Iridescence DEFAULT_MSG Iridescence_INCLUDE_DIRS Iridescence_LIBRARIES)
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,22 @@ find_library(TBB_LIB NAMES tbb
|
||||||
HINTS /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu
|
HINTS /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu
|
||||||
DOC "TBB libraries")
|
DOC "TBB libraries")
|
||||||
|
|
||||||
# if(GTSAM_LIB AND GTSAM_UNSTABLE_LIB AND TBB_LIB)
|
find_library(TBB_MALLOC_LIB NAMES tbbmalloc
|
||||||
if(TBB_LIB)
|
HINTS /usr/local/lib /usr/lib
|
||||||
set(TBB_LIBRARIES ${TBB_LIB})
|
DOC "TBB malloc libraries")
|
||||||
|
|
||||||
|
add_library(TBB::tbb INTERFACE IMPORTED GLOBAL)
|
||||||
|
set_target_properties(TBB::tbb PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${TBB_INCLUDE_DIRS}"
|
||||||
|
INTERFACE_LINK_LIBRARIES "${TBB_LIBRARIES}")
|
||||||
|
|
||||||
|
add_library(TBB::tbbmalloc INTERFACE IMPORTED GLOBAL)
|
||||||
|
set_target_properties(TBB::tbbmalloc PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${TBB_INCLUDE_DIRS}"
|
||||||
|
INTERFACE_LINK_LIBRARIES "${TBB_LIBRARIES}")
|
||||||
|
|
||||||
|
if(TBB_LIB AND TBB_MALLOC_LIB)
|
||||||
|
set(TBB_LIBRARIES TBB::tbb TBB::tbbmalloc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
# Config file for the small_gicp package
|
||||||
|
#
|
||||||
|
# Usage from an external project:
|
||||||
|
#
|
||||||
|
# find_package(small_gicp REQUIRED)
|
||||||
|
# target_link_libraries(MY_TARGET_NAME small_gicp::small_gicp)
|
||||||
|
#
|
||||||
|
# Optionally, for TBB support in *_tbb.hpp headers also add:
|
||||||
|
#
|
||||||
|
# find_package(TBB REQUIRED)
|
||||||
|
# target_link_libraries(MY_TARGET_NAME TBB::tbb TBB::tbbmalloc)
|
||||||
|
#
|
||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include_guard()
|
||||||
|
|
||||||
|
set(BUILD_WITH_OPENMP @BUILD_WITH_OPENMP@)
|
||||||
|
|
||||||
|
include(CMakeFindDependencyMacro)
|
||||||
|
find_dependency(Eigen3 REQUIRED)
|
||||||
|
if (BUILD_WITH_OPENMP)
|
||||||
|
find_dependency(OpenMP REQUIRED COMPONENTS CXX)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# For FindTBB.cmake
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/small_gicp-targets.cmake")
|
||||||
|
|
@ -1,3 +1,37 @@
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["setuptools>=42", "wheel", "pybind11>2.10.0"]
|
requires = ["scikit-build-core >=0.4.3", "pybind11 >2.10.0"]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "scikit_build_core.build"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "small_gicp"
|
||||||
|
version = "0.0.1"
|
||||||
|
authors = [{name = "Kenji Koide", email = "k.koide@aist.go.jp"}]
|
||||||
|
description = "Efficient and parallelized algorithms for fine point cloud registration"
|
||||||
|
readme = "README.md"
|
||||||
|
license = {text = "MIT"}
|
||||||
|
requires-python = ">=3.7"
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Homepage = "https://github.com/koide3/small_gicp"
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
test = ["pytest>=6.0"]
|
||||||
|
|
||||||
|
[tool.setuptools]
|
||||||
|
zip_safe = false
|
||||||
|
|
||||||
|
[tool.scikit-build]
|
||||||
|
wheel.license-files = ["LICENSE"]
|
||||||
|
install.components = ["python"]
|
||||||
|
build-dir = "build/{wheel_tag}"
|
||||||
|
wheel.py-api = "cp312" # Build stable ABI wheels for CPython 3.12+
|
||||||
|
|
||||||
|
[tool.scikit-build.cmake.define]
|
||||||
|
BUILD_PYTHON_BINDINGS = true
|
||||||
|
BUILD_SHARED_LIBS = false
|
||||||
|
|
||||||
|
[tool.cibuildwheel]
|
||||||
|
build = "*"
|
||||||
|
skip = "pp*" # Don't build for PyPy
|
||||||
|
test-command = "pytest {project}/src --color=yes -v"
|
||||||
|
build-verbosity = 1
|
||||||
|
|
|
||||||
137
setup.py
137
setup.py
|
|
@ -1,137 +0,0 @@
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from setuptools import Extension, setup
|
|
||||||
from setuptools.command.build_ext import build_ext
|
|
||||||
|
|
||||||
# Convert distutils Windows platform specifiers to CMake -A arguments
|
|
||||||
PLAT_TO_CMAKE = {
|
|
||||||
"win32": "Win32",
|
|
||||||
"win-amd64": "x64",
|
|
||||||
"win-arm32": "ARM",
|
|
||||||
"win-arm64": "ARM64",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# A CMakeExtension needs a sourcedir instead of a file list.
|
|
||||||
# The name must be the _single_ output extension from the CMake build.
|
|
||||||
# If you need multiple extensions, see scikit-build.
|
|
||||||
class CMakeExtension(Extension):
|
|
||||||
def __init__(self, name: str, sourcedir: str = "") -> None:
|
|
||||||
super().__init__(name, sources=[])
|
|
||||||
self.sourcedir = os.fspath(Path(sourcedir).resolve())
|
|
||||||
|
|
||||||
|
|
||||||
class CMakeBuild(build_ext):
|
|
||||||
def build_extension(self, ext: CMakeExtension) -> None:
|
|
||||||
# Must be in this form due to bug in .resolve() only fixed in Python 3.10+
|
|
||||||
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
|
|
||||||
extdir = ext_fullpath.parent.resolve()
|
|
||||||
|
|
||||||
# Using this requires trailing slash for auto-detection & inclusion of
|
|
||||||
# auxiliary "native" libs
|
|
||||||
|
|
||||||
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
|
|
||||||
cfg = "Debug" if debug else "Release"
|
|
||||||
|
|
||||||
# CMake lets you override the generator - we need to check this.
|
|
||||||
# Can be set with Conda-Build, for example.
|
|
||||||
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
|
|
||||||
|
|
||||||
# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
|
|
||||||
# EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
|
|
||||||
# from Python.
|
|
||||||
cmake_args = [
|
|
||||||
f"-DBUILD_PYTHON_BINDINGS=ON",
|
|
||||||
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
|
|
||||||
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
|
|
||||||
]
|
|
||||||
build_args = []
|
|
||||||
# Adding CMake arguments set as environment variable
|
|
||||||
# (needed e.g. to build for ARM OSx on conda-forge)
|
|
||||||
if "CMAKE_ARGS" in os.environ:
|
|
||||||
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]
|
|
||||||
|
|
||||||
if self.compiler.compiler_type != "msvc":
|
|
||||||
# Using Ninja-build since it a) is available as a wheel and b)
|
|
||||||
# multithreads automatically. MSVC would require all variables be
|
|
||||||
# exported for Ninja to pick it up, which is a little tricky to do.
|
|
||||||
# Users can override the generator with CMAKE_GENERATOR in CMake
|
|
||||||
# 3.15+.
|
|
||||||
if not cmake_generator or cmake_generator == "Ninja":
|
|
||||||
try:
|
|
||||||
import ninja
|
|
||||||
|
|
||||||
ninja_executable_path = Path(ninja.BIN_DIR) / "ninja"
|
|
||||||
cmake_args += [
|
|
||||||
"-GNinja",
|
|
||||||
f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}",
|
|
||||||
]
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
else:
|
|
||||||
# Single config generators are handled "normally"
|
|
||||||
single_config = any(x in cmake_generator for x in {"NMake", "Ninja"})
|
|
||||||
|
|
||||||
# CMake allows an arch-in-generator style for backward compatibility
|
|
||||||
contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})
|
|
||||||
|
|
||||||
# Specify the arch if using MSVC generator, but only if it doesn't
|
|
||||||
# contain a backward-compatibility arch spec already in the
|
|
||||||
# generator name.
|
|
||||||
if not single_config and not contains_arch:
|
|
||||||
cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]
|
|
||||||
|
|
||||||
# Multi-config generators have a different way to specify configs
|
|
||||||
if not single_config:
|
|
||||||
cmake_args += [
|
|
||||||
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"
|
|
||||||
]
|
|
||||||
build_args += ["--config", cfg]
|
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
|
||||||
# Cross-compile support for macOS - respect ARCHFLAGS if set
|
|
||||||
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
|
|
||||||
if archs:
|
|
||||||
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
|
|
||||||
|
|
||||||
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
|
|
||||||
# across all generators.
|
|
||||||
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
|
|
||||||
# self.parallel is a Python 3 only way to set parallel jobs by hand
|
|
||||||
# using -j in the build_ext call, not supported by pip or PyPA-build.
|
|
||||||
if hasattr(self, "parallel") and self.parallel:
|
|
||||||
# CMake 3.12+ only.
|
|
||||||
build_args += [f"-j{self.parallel}"]
|
|
||||||
|
|
||||||
build_temp = Path(self.build_temp) / ext.name
|
|
||||||
if not build_temp.exists():
|
|
||||||
build_temp.mkdir(parents=True)
|
|
||||||
|
|
||||||
subprocess.run(
|
|
||||||
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True
|
|
||||||
)
|
|
||||||
subprocess.run(
|
|
||||||
["cmake", "--build", ".", *build_args], cwd=build_temp, check=True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# The information here can also be placed in setup.cfg - better separation of
|
|
||||||
# logic and declaration, and simpler if you include description/version in a file.
|
|
||||||
setup(
|
|
||||||
name="small_gicp",
|
|
||||||
version="0.0.1",
|
|
||||||
author="Kenji Koide",
|
|
||||||
author_email="k.koide@aist.go.jp",
|
|
||||||
description="Efficient and parallelized algorithms for fine point cloud registration",
|
|
||||||
long_description="",
|
|
||||||
ext_modules=[CMakeExtension("small_gicp")],
|
|
||||||
cmdclass={"build_ext": CMakeBuild},
|
|
||||||
zip_safe=False,
|
|
||||||
extras_require={"test": ["pytest>=6.0"]},
|
|
||||||
python_requires=">=3.7",
|
|
||||||
)
|
|
||||||
Loading…
Reference in New Issue