Skip to content

Commit

Permalink
Eigen: switch to imported modules and NO_MODULE (#5613)
Browse files Browse the repository at this point in the history
* Eigen: switch to imported modules and NO_MODULE

Use Eigens native cmake support to replace the custom FindEigen.cmake

* Use target Eigen3::Eigen

* Remove usage of Eigen3_INCLUDE_DIR

* Print Eigens target properties

* Temp: Hard code property list

* Link Eigen to cuda_io

* Revert "Temp: Hard code property list"

This reverts commit 10ded79.

* Revert "Print Eigens target properties"

This reverts commit 93a7b93.

* Link common to cuda_io

* Link common to cuda_features

* Link common to cuda_segmentation

* Link common to gpu_containers

* Fix target name in PCLConfig.cmake.in

* Make all in one installer independent of Eigen3 internals

* Fix cmake errors

* Append existing target_link_libraries
  • Loading branch information
ptrckschcknbch committed Jul 13, 2023
1 parent 79e6ccd commit c6fb0d7
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 64 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,8 @@ endif()
# Threads (required)
find_package(Threads REQUIRED)

# Eigen (required)
find_package(Eigen 3.3 REQUIRED)
include_directories(SYSTEM ${EIGEN_INCLUDE_DIRS})
# Eigen3 (required)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)

# FLANN (required)
find_package(FLANN 1.9.1 REQUIRED)
Expand Down
13 changes: 5 additions & 8 deletions PCLConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,11 @@ macro(find_boost)
endif()
endmacro()

#remove this as soon as eigen is shipped with FindEigen.cmake
macro(find_eigen)
macro(find_eigen3)
if(PCL_ALL_IN_ONE_INSTALLER)
set(EIGEN_ROOT "${PCL_ROOT}/3rdParty/Eigen")
elseif(NOT EIGEN_ROOT)
get_filename_component(EIGEN_ROOT "@EIGEN_INCLUDE_DIRS@" ABSOLUTE)
set(Eigen3_DIR "${PCL_ROOT}/3rdParty/Eigen3/share/eigen3/cmake/")
endif()
find_package(Eigen 3.3)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
endmacro()

#remove this as soon as qhull is shipped with FindQhull.cmake
Expand Down Expand Up @@ -271,8 +268,8 @@ endmacro()
function(find_external_library _component _lib _is_optional)
if("${_lib}" STREQUAL "boost")
find_boost()
elseif("${_lib}" STREQUAL "eigen")
find_eigen()
elseif("${_lib}" STREQUAL "eigen3")
find_eigen3()
elseif("${_lib}" STREQUAL "flann")
find_flann()
elseif("${_lib}" STREQUAL "qhull")
Expand Down
41 changes: 0 additions & 41 deletions cmake/Modules/FindEigen.cmake

This file was deleted.

54 changes: 52 additions & 2 deletions cmake/pcl_all_in_one_installer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ endif()
# get root directory of each dependency libraries to be copied to PCL/3rdParty
get_filename_component(BOOST_ROOT "${Boost_INCLUDE_DIR}" PATH) # ../Boost/include/boost-x_x/ -> ../Boost/include/
get_filename_component(BOOST_ROOT "${BOOST_ROOT}" PATH) # ../Boost/include/ -> ../Boost/
get_filename_component(EIGEN_ROOT "${EIGEN_INCLUDE_DIRS}" PATH) # ../Eigen3/include/ -> ../Eigen3/
get_filename_component(QHULL_ROOT "${Qhull_DIR}" PATH) # ../qhull/lib/cmake/Qhull/ -> ../qhull/lib/cmake
get_filename_component(QHULL_ROOT "${QHULL_ROOT}" PATH) # ../qhull/lib/cmake/ -> ../qhull/lib/
get_filename_component(QHULL_ROOT "${QHULL_ROOT}" PATH) # ../qhull/lib/ -> ../qhull/
Expand All @@ -19,7 +18,7 @@ get_filename_component(VTK_ROOT "${VTK_ROOT}" PATH) # ../VTK/lib/cma
get_filename_component(VTK_ROOT "${VTK_ROOT}" PATH) # ../VTK/lib/ -> ../VTK/

set(PCL_3RDPARTY_COMPONENTS)
foreach(dep Eigen Boost Qhull FLANN VTK)
foreach(dep Boost Qhull FLANN VTK)
string(TOUPPER ${dep} DEP)
install(
DIRECTORY "${${DEP}_ROOT}/"
Expand All @@ -30,6 +29,57 @@ foreach(dep Eigen Boost Qhull FLANN VTK)
list(APPEND PCL_3RDPARTY_COMPONENTS ${dep})
endforeach()

# Try to set EIGEN3_INCLUDE_DIR in case it is
# no longer exported by Eigen3 itself.
if (NOT EXISTS ${EIGEN3_INCLUDE_DIR})
if (EXISTS ${EIGEN3_INCLUDE_DIRS})
set(EIGEN3_INCLUDE_DIR ${EIGEN3_INCLUDE_DIRS})
else()
set(EIGEN3_INCLUDE_DIR "${Eigen3_DIR}/../../../include/eigen3/")
endif()
endif()
if(NOT EXISTS ${EIGEN3_INCLUDE_DIR})
message(FATAL_ERROR "EIGEN3_INCLUDE_DIR is not existing: ${EIGEN3_INCLUDE_DIR}")
endif()

# Try to find EIGEN3_COMMON_ROOT_PATH, which is meant to hold
# the first common root folder of Eigen3_DIR and EIGEN3_INCLUDE_DIR.
# E.g. Eigen3_DIR = /usr/local/share/eigen3/cmake/
# EIGEN3_INCLUDE_DIR = /usr/local/include/eigen3/
# => EIGEN3_COMMON_ROOT_PATH = /usr/local/
file(TO_CMAKE_PATH ${Eigen3_DIR} Eigen3_DIR)
file(TO_CMAKE_PATH ${EIGEN3_INCLUDE_DIR} EIGEN3_INCLUDE_DIR)
set(EIGEN3_INCLUDE_PATH_LOOP ${EIGEN3_INCLUDE_DIR})
set(PREVIOUS_EIGEN3_INCLUDE_PATH_LOOP "INVALID")
while (NOT ${PREVIOUS_EIGEN3_INCLUDE_PATH_LOOP} STREQUAL ${EIGEN3_INCLUDE_PATH_LOOP})
if (${Eigen3_DIR} MATCHES ${EIGEN3_INCLUDE_PATH_LOOP})
set(EIGEN3_COMMON_ROOT_PATH ${EIGEN3_INCLUDE_PATH_LOOP})
break()
endif()
set(PREVIOUS_EIGEN3_INCLUDE_PATH_LOOP ${EIGEN3_INCLUDE_PATH_LOOP})
get_filename_component(EIGEN3_INCLUDE_PATH_LOOP ${EIGEN3_INCLUDE_PATH_LOOP} DIRECTORY)
endwhile()
if(NOT EXISTS ${EIGEN3_COMMON_ROOT_PATH})
message(FATAL_ERROR "Could not copy Eigen3.")
endif()

# Install Eigen3 to 3rdParty directory
string(LENGTH ${EIGEN3_COMMON_ROOT_PATH} LENGTH_OF_EIGEN3_COMMON_ROOT_PATH)
string(SUBSTRING ${Eigen3_DIR} ${LENGTH_OF_EIGEN3_COMMON_ROOT_PATH} -1 DESTINATION_EIGEN3_DIR)
string(SUBSTRING ${EIGEN3_INCLUDE_DIR} ${LENGTH_OF_EIGEN3_COMMON_ROOT_PATH} -1 DESTINATION_EIGEN3_INCLUDE_DIR)
set(dep_Eigen3 Eigen3)
install(
DIRECTORY "${Eigen3_DIR}/"
DESTINATION 3rdParty/${dep_Eigen3}${DESTINATION_EIGEN3_DIR}
COMPONENT ${dep_Eigen3}
)
install(
DIRECTORY "${EIGEN3_INCLUDE_DIR}/"
DESTINATION 3rdParty/${dep_Eigen3}${DESTINATION_EIGEN3_INCLUDE_DIR}
COMPONENT ${dep_Eigen3}
)
list(APPEND PCL_3RDPARTY_COMPONENTS ${dep_Eigen3})

if(WITH_RSSDK2)
get_filename_component(RSSDK2_ROOT "${RSSDK2_INCLUDE_DIRS}" PATH)
install(
Expand Down
4 changes: 2 additions & 2 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(SUBSYS_DEPS)

set(build TRUE)
PCL_SUBSYS_OPTION(build "${SUBSYS_NAME}" "${SUBSYS_DESC}" ON)
PCL_SUBSYS_DEPEND(build NAME ${SUBSYS_NAME} DEPS ${SUBSYS_DEPS} EXT_DEPS eigen boost)
PCL_SUBSYS_DEPEND(build NAME ${SUBSYS_NAME} DEPS ${SUBSYS_DEPS} EXT_DEPS eigen3 boost)

PCL_ADD_DOC("${SUBSYS_NAME}")

Expand Down Expand Up @@ -179,7 +179,7 @@ target_include_directories(${LIB_NAME} PUBLIC
$<INSTALL_INTERFACE:include>
)

target_link_libraries(${LIB_NAME} Boost::boost)
target_link_libraries(${LIB_NAME} Boost::boost Eigen3::Eigen)

if(MSVC AND NOT (MSVC_VERSION LESS 1915))
# MSVC resolved a byte alignment issue in compiler version 15.9
Expand Down
1 change: 1 addition & 0 deletions cuda/features/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(incs
set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs})
target_link_libraries(${LIB_NAME} pcl_common)

set(EXT_DEPS "")
#set(EXT_DEPS CUDA)
Expand Down
1 change: 1 addition & 0 deletions cuda/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(incs
set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs})
target_link_libraries(${LIB_NAME} pcl_common)

PCL_MAKE_PKGCONFIG(${LIB_NAME} COMPONENT ${SUBSYS_NAME} DESC ${SUBSYS_DESC} PCL_DEPS ${SUBSYS_DEPS} EXT_DEPS ${SUBSYS_EXT_DEPS})

Expand Down
1 change: 1 addition & 0 deletions cuda/segmentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(srcs
set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs})
target_link_libraries(${LIB_NAME} pcl_common)

set(EXT_DEPS "")
#set(EXT_DEPS CUDA)
Expand Down
12 changes: 5 additions & 7 deletions doc/tutorials/content/building_pcl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ The available ROOTs you can set are as follow:
* **CMINPACK_ROOT**: for cminpack with value `C:/Program Files/CMINPACK 1.1.13` for instance
* **QHULL_ROOT**: for qhull with value `C:/Program Files/qhull 6.2.0.1373` for instance
* **FLANN_ROOT**: for flann with value `C:/Program Files/flann 1.6.8` for instance
* **EIGEN_ROOT**: for eigen with value `C:/Program Files/Eigen 3.0.0` for instance

To ensure that all the dependencies were correctly found, beside the
message you get from CMake, you can check or edit each dependency specific
Expand Down Expand Up @@ -253,9 +252,8 @@ then a sample value is given for reference.

* Eigen

+------------------+---------------------------------+---------------------------+
| cache variable | meaning | sample value |
+==================+=================================+===========================+
| EIGEN_INCLUDE_DIR| path to eigen headers directory | /usr/local/include/eigen3 |
+------------------+---------------------------------+---------------------------+

+--------------------+---------------------------------+-------------------------------+
| cache variable | meaning | sample value |
+====================+=================================+===============================+
| Eigen3_DIR | path to eigen cmake directory | /usr/local/share/eigen3/cmake |
+--------------------+---------------------------------+-------------------------------+
1 change: 1 addition & 0 deletions gpu/containers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ get_filename_component(UTILS_INC "${CMAKE_CURRENT_SOURCE_DIR}/../utils/include"
set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include" ${UTILS_INC})
PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs})
target_link_libraries(${LIB_NAME} pcl_common)

#Ensures that CUDA is added and the project can compile as it uses cuda calls.
set_source_files_properties(src/device_memory.cpp PROPERTIES LANGUAGE CUDA)
Expand Down
2 changes: 1 addition & 1 deletion io/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(SUBSYS_NAME io)
set(SUBSYS_DESC "Point cloud IO library")
set(SUBSYS_DEPS common octree)
set(SUBSYS_EXT_DEPS boost eigen)
set(SUBSYS_EXT_DEPS boost eigen3)

set(build TRUE)
PCL_SUBSYS_OPTION(build "${SUBSYS_NAME}" "${SUBSYS_DESC}" ON)
Expand Down

0 comments on commit c6fb0d7

Please sign in to comment.