Skip to content

Commit

Permalink
ADDED: a function to prevent code repetition (#205)
Browse files Browse the repository at this point in the history
* 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 <ignaciovizzo@gmail.com>
  • Loading branch information
NehilDanis and nachovizzo authored Aug 18, 2023
1 parent 06f7243 commit f078513
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
47 changes: 15 additions & 32 deletions cpp/kiss_icp/3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion cpp/kiss_icp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f078513

Please sign in to comment.