From f078513c92933d24b309e2853148b0ac06bbd414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nehil=20Dan=C4=B1=C5=9F?= Date: Fri, 18 Aug 2023 08:07:32 +0200 Subject: [PATCH] ADDED: a function to prevent code repetition (#205) * ADDED: a function to prevent code repetition * BUGFIX: applied cmake format * Shrink cmake script and capitalize everything * merge into one file for better visibility * fix usage * Fix --------- Co-authored-by: Ignacio Vizzo --- cpp/kiss_icp/3rdparty/find_dependencies.cmake | 47 ++++++------------- cpp/kiss_icp/CMakeLists.txt | 2 +- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/cpp/kiss_icp/3rdparty/find_dependencies.cmake b/cpp/kiss_icp/3rdparty/find_dependencies.cmake index f4dffe0a..b9feb895 100644 --- a/cpp/kiss_icp/3rdparty/find_dependencies.cmake +++ b/cpp/kiss_icp/3rdparty/find_dependencies.cmake @@ -20,41 +20,24 @@ # 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. - # Silence timestamp warning if(CMAKE_VERSION VERSION_GREATER 3.24) cmake_policy(SET CMP0135 OLD) endif() -if(USE_SYSTEM_EIGEN3) - find_package(Eigen3 QUIET NO_MODULE) -endif() -if(NOT USE_SYSTEM_EIGEN3 OR NOT TARGET Eigen3::Eigen) - set(USE_SYSTEM_EIGEN3 OFF) - include(${CMAKE_CURRENT_LIST_DIR}/eigen/eigen.cmake) -endif() - -if(USE_SYSTEM_SOPHUS) - find_package(Sophus QUIET NO_MODULE) -endif() -if(NOT USE_SYSTEM_SOPHUS OR NOT TARGET Sophus::Sophus) - set(USE_SYSTEM_SOPHUS OFF) - include(${CMAKE_CURRENT_LIST_DIR}/sophus/sophus.cmake) -endif() +function(find_external_dependecy PACKAGE_NAME TARGET_NAME INCLUDED_CMAKE_PATH) + string(TOUPPER ${PACKAGE_NAME} PACKAGE_NAME_UP) + set(USE_FROM_SYSTEM_OPTION "USE_SYSTEM_${PACKAGE_NAME_UP}") + if(${${USE_FROM_SYSTEM_OPTION}}) + find_package(${PACKAGE_NAME} QUIET NO_MODULE) + endif() + if(NOT ${${USE_FROM_SYSTEM_OPTION}} OR NOT TARGET ${TARGET_NAME}) + set(${USE_FROM_SYSTEM_OPTION} OFF PARENT_SCOPE) + include(${INCLUDED_CMAKE_PATH}) + endif() +endfunction() -# tbb needs to be statically linked, so, also do it always :) -if(USE_SYSTEM_TBB) - find_package(TBB QUIET NO_MODULE) -endif() -if(NOT USE_SYSTEM_TBB OR NOT TARGET TBB::tbb) - set(USE_SYSTEM_TBB OFF) - include(${CMAKE_CURRENT_LIST_DIR}/tbb/tbb.cmake) -endif() - -if(USE_SYSTEM_TSLMAP) - find_package(tsl-robin-map QUIET NO_MODULE) -endif() -if(NOT USE_SYSTEM_TSLMAP OR NOT TARGET tsl::robin_map) - set(USE_SYSTEM_TSLMAP OFF) - include(${CMAKE_CURRENT_LIST_DIR}/tsl_robin/tsl_robin.cmake) -endif() +find_external_dependecy("Eigen3" "Eigen3::Eigen" "${CMAKE_CURRENT_LIST_DIR}/eigen/eigen.cmake") +find_external_dependecy("Sophus" "Sophus::Sophus" "${CMAKE_CURRENT_LIST_DIR}/sophus/sophus.cmake") +find_external_dependecy("TBB" "TBB::tbb" "${CMAKE_CURRENT_LIST_DIR}/tbb/tbb.cmake") +find_external_dependecy("tsl-robin-map" "tsl::robin_map" "${CMAKE_CURRENT_LIST_DIR}/tsl_robin/tsl_robin.cmake") diff --git a/cpp/kiss_icp/CMakeLists.txt b/cpp/kiss_icp/CMakeLists.txt index d13144c2..b4eac189 100644 --- a/cpp/kiss_icp/CMakeLists.txt +++ b/cpp/kiss_icp/CMakeLists.txt @@ -27,7 +27,7 @@ project(kiss_icp_cpp VERSION 0.2.10 LANGUAGES CXX) 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_TSLMAP "Use system pre-installed tsl_robin" 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) # ccache setup