Skip to content

Commit

Permalink
Feature/eigen free (#64)
Browse files Browse the repository at this point in the history
* Change the place of option

* Make the dependency of Eigen free

* (minor) remove "" for consistency
  • Loading branch information
LimHyungTae authored Dec 6, 2024
1 parent 9c97f17 commit ec260c2
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 5 deletions.
25 changes: 23 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.11)
project(patchworkpp VERSION 1.0.1)

option(USE_SYSTEM_EIGEN3 "Use system pre-installed Eigen" OFF)
option(INCLUDE_CPP_EXAMPLES "Include C++ example codes, which require Open3D for visualization" OFF)

set(CMAKE_CXX_STANDARD 20)
set(PYTHON_EXECUTABLE python3)
set(CMAKE_BUILD_TYPE Release)
Expand All @@ -10,14 +13,32 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${Open3D_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Open3D_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Open3D_EXE_LINKER_FLAGS}")

if(CMAKE_VERSION VERSION_LESS "3.15")
if(CMAKE_VERSION VERSION_LESS 3.15)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/ListPrepend.cmake")
list_prepend(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
else()
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
endif()

option(INCLUDE_CPP_EXAMPLES "Include C++ example codes, which require Open3D for visualization" OFF)
if(CMAKE_VERSION VERSION_GREATER 3.24)
cmake_policy(SET CMP0135 OLD)
endif()

# Originally, below code was from `find_dependencies.cmake`
# The below code is to make dependency of Eigen free
function(find_external_dependency 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()

find_external_dependency("Eigen3" "Eigen3::Eigen" "${CMAKE_CURRENT_LIST_DIR}/cmake/eigen.cmake")

# Parameters in `patchworkpp` subdirectory.
# Thus, link should be `patchworkpp::ground_seg_cores`
Expand Down
18 changes: 18 additions & 0 deletions cpp/cmake/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Eigen is primarily MPL2 licensed. See COPYING.MPL2 and these links:
http://www.mozilla.org/MPL/2.0/
http://www.mozilla.org/MPL/2.0/FAQ.html

Some files contain third-party code under BSD or LGPL licenses, whence the other
COPYING.* files here.

All the LGPL code is either LGPL 2.1-only, or LGPL 2.1-or-later.
For this reason, the COPYING.LGPL file contains the LGPL 2.1 text.

If you want to guarantee that the Eigen code that you are #including is licensed
under the MPL2 and possibly more permissive licenses (like BSD), #define this
preprocessor symbol:
EIGEN_MPL2_ONLY
For example, with most compilers, you could add this to your project CXXFLAGS:
-DEIGEN_MPL2_ONLY
This will cause a compilation error to be generated if you #include any code that is
LGPL licensed.
47 changes: 47 additions & 0 deletions cpp/cmake/eigen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# MIT License
#
# Copyright (c) 2022 Ignacio Vizzo, Tiziano Guadagnino, Benedikt Mersch, Cyrill
# Stachniss.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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.

set(EIGEN_BUILD_DOC OFF CACHE BOOL "Don't build Eigen docs")
set(EIGEN_BUILD_TESTING OFF CACHE BOOL "Don't build Eigen tests")
set(EIGEN_BUILD_PKGCONFIG OFF CACHE BOOL "Don't build Eigen pkg-config")
set(EIGEN_BUILD_BLAS OFF CACHE BOOL "Don't build blas module")
set(EIGEN_BUILD_LAPACK OFF CACHE BOOL "Don't build lapack module")

include(FetchContent)
FetchContent_Declare(eigen URL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_LIST_DIR}/eigen.patch UPDATE_DISCONNECTED 1)
FetchContent_GetProperties(eigen)
if(NOT eigen_POPULATED)
FetchContent_Populate(eigen)
if(${CMAKE_VERSION} GREATER_EQUAL 3.25)
add_subdirectory(${eigen_SOURCE_DIR} ${eigen_BINARY_DIR} SYSTEM EXCLUDE_FROM_ALL)
else()
# Emulate the SYSTEM flag introduced in CMake 3.25. Withouth this flag the compiler will
# consider this 3rdparty headers as source code and fail due the -Werror flag.
add_subdirectory(${eigen_SOURCE_DIR} ${eigen_BINARY_DIR} EXCLUDE_FROM_ALL)
get_target_property(eigen_include_dirs eigen INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties(eigen PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${eigen_include_dirs}")
endif()
endif()


74 changes: 74 additions & 0 deletions cpp/cmake/eigen.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
commit cf82186416d04ea5df2a397d8fe09dc78d40ca65
Author: Antonio Sánchez <cantonios@google.com>
Date: Sat Mar 5 05:49:45 2022 +0000

Adds new CMake Options for controlling build components.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index de1c23e91..0af36a53a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -477,6 +477,9 @@ if(EIGEN_BUILD_TESTING)
add_subdirectory(failtest)
endif()

+include(CMakeDetermineFortranCompiler)
+option(EIGEN_BUILD_BLAS "Toggles the building of the Eigen Blas library" ${CMAKE_Fortran_COMPILER})
+option(EIGEN_BUILD_LAPACK "Toggles the building of the included Eigen LAPACK library" ${CMAKE_Fortran_COMPILER})
if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
add_subdirectory(blas)
add_subdirectory(lapack)
@@ -611,6 +614,8 @@ set_target_properties (eigen PROPERTIES EXPORT_NAME Eigen)

install (TARGETS eigen EXPORT Eigen3Targets)

+option(EIGEN_BUILD_CMAKE_PACKAGE "Enables the creation of EigenConfig.cmake and related files" ON)
+if(EIGEN_BUILD_CMAKE_PACKAGE)
configure_package_config_file (
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
@@ -655,6 +660,7 @@ install (FILES ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
# Add uninstall target
add_custom_target ( uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/EigenUninstall.cmake)
+endif()

if (EIGEN_SPLIT_TESTSUITE)
ei_split_testsuite("${EIGEN_SPLIT_TESTSUITE}")
diff --git a/blas/CMakeLists.txt b/blas/CMakeLists.txt
index 8d3cb86dc..c530957fb 100644
--- a/blas/CMakeLists.txt
+++ b/blas/CMakeLists.txt
@@ -1,6 +1,7 @@

project(EigenBlas CXX)

+if(EIGEN_BUILD_BLAS)
include(CheckLanguage)
check_language(Fortran)
if(CMAKE_Fortran_COMPILER)
@@ -59,4 +60,4 @@ if(EIGEN_BUILD_TESTING)
endif()

endif()
-
+endif()
diff --git a/lapack/CMakeLists.txt b/lapack/CMakeLists.txt
index c8ca64001..8d6d75401 100644
--- a/lapack/CMakeLists.txt
+++ b/lapack/CMakeLists.txt
@@ -1,5 +1,7 @@
project(EigenLapack CXX)

+if(EIGEN_BUILD_LAPACK AND EIGEN_BUILD_BLAS)
+
include(CheckLanguage)
check_language(Fortran)
if(CMAKE_Fortran_COMPILER)
@@ -457,3 +459,6 @@ if(EXISTS ${eigen_full_path_to_testing_lapack})

endif()

+elseif(EIGEN_BUILD_LAPACK AND NOT EIGEN_BUILD_BLAS)
+ message(FATAL_ERROR "EIGEN_BUILD_LAPACK requires EIGEN_BUILD_BLAS")
+endif() #EIGEN_BUILD_LAPACK
3 changes: 0 additions & 3 deletions cpp/patchworkpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ project(patchworkpp_src)
include(GNUInstallDirs)

message("Parent project name: " ${PARENT_PROJECT_NAME})

find_package(Eigen3 REQUIRED QUIET)

add_library(${TARGET_NAME} STATIC src/patchworkpp.cpp)
set_target_properties(${TARGET_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)

Expand Down

0 comments on commit ec260c2

Please sign in to comment.