1- #
2- # Copyright 2020 Adobe. All rights reserved.
3- # This file is licensed to you under the Apache License, Version 2.0 (the "License");
4- # you may not use this file except in compliance with the License. You may obtain a copy
5- # of the License at http://www.apache.org/licenses/LICENSE-2.0
6- #
7- # Unless required by applicable law or agreed to in writing, software distributed under
8- # the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9- # OF ANY KIND, either express or implied. See the License for the specific language
10- # governing permissions and limitations under the License.
11- #
1+ # Eigen (https://gitlab.com/libeigen/eigen)
2+ # License: MPL 2.0
123if (TARGET Eigen3::Eigen)
134 return ()
145endif ()
156
167option (EIGEN_WITH_MKL "Use Eigen with MKL" OFF )
8+ option (EIGEN_DONT_VECTORIZE "Disable Eigen vectorization" OFF )
9+ option (EIGEN_MPL2_ONLY "Enable Eigen MPL2 license only" OFF )
1710
18- if (EIGEN_ROOT)
19- message (STATUS "Third-party: creating target 'Eigen3::Eigen' for external path: ${EIGEN_ROOT} " )
20- set (EIGEN_INCLUDE_DIRS ${EIGEN_ROOT} )
21- else ()
22- message (STATUS "Third-party: creating target 'Eigen3::Eigen'" )
11+ message (STATUS "Third-party: creating target 'Eigen3::Eigen'" )
2312
24- include (FetchContent)
25- FetchContent_Declare(
26- eigen
27- GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
28- GIT_TAG tags/3.4.0
29- GIT_SHALLOW TRUE
30- )
31- FetchContent_GetProperties(eigen)
32- if (NOT eigen_POPULATED)
33- FetchContent_Populate(eigen)
34- endif ()
35- set (EIGEN_INCLUDE_DIRS ${eigen_SOURCE_DIR} )
36-
37- install (DIRECTORY ${EIGEN_INCLUDE_DIRS} /Eigen
38- DESTINATION include
39- )
40- endif ()
13+ include (CPM)
14+ CPMAddPackage(
15+ NAME eigen
16+ GITLAB_REPOSITORY libeigen/eigen
17+ GIT_TAG 3.4.0
18+ DOWNLOAD_ONLY YES
19+ )
4120
4221add_library (Eigen3_Eigen INTERFACE )
4322add_library (Eigen3::Eigen ALIAS Eigen3_Eigen)
4423
4524include (GNUInstallDirs)
4625target_include_directories (Eigen3_Eigen SYSTEM INTERFACE
47- $<BUILD_INTERFACE:${EIGEN_INCLUDE_DIRS } >
26+ $<BUILD_INTERFACE:${eigen_SOURCE_DIR } >
4827 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
4928)
50- # target_compile_definitions(Eigen3_Eigen INTERFACE EIGEN_MPL2_ONLY)
29+
30+ if (EIGEN_MPL2_ONLY)
31+ target_compile_definitions (Eigen3_Eigen INTERFACE EIGEN_MPL2_ONLY)
32+ endif ()
33+
34+ if (EIGEN_DONT_VECTORIZE)
35+ target_compile_definitions (Eigen3_Eigen INTERFACE EIGEN_DONT_VECTORIZE)
36+ endif ()
5137
5238if (EIGEN_WITH_MKL)
5339 # TODO: Checks that, on 64bits systems, `mkl::mkl` is using the LP64 interface
@@ -58,6 +44,27 @@ if(EIGEN_WITH_MKL)
5844 EIGEN_USE_MKL_ALL
5945 EIGEN_USE_LAPACKE_STRICT
6046 )
47+ elseif (APPLE )
48+ find_package (BLAS REQUIRED)
49+ find_library (LAPACKE lapacke PATHS
50+ "/opt/local/lib/lapack"
51+ "/opt/homebrew/opt/lapack/lib"
52+ )
53+ if (NOT LAPACKE)
54+ # BLAS should be available on macOS, but LAPACKE might not be
55+ message (WARNING "LAPACKE library not found (required for EIGEN_USE_LAPACKE on macOS)! "
56+ "Perhaps you need to install it (e.g., brew install lapack). "
57+ "Eigen will be built without LAPACKE support." )
58+ else ()
59+ message (STATUS "Found BLAS and LAPACKE. Enabling Eigen LAPACKE support." )
60+ target_link_libraries (Eigen3_Eigen INTERFACE
61+ ${BLAS_LIBRARIES} ${LAPACKE}
62+ )
63+ target_compile_definitions (Eigen3_Eigen INTERFACE
64+ EIGEN_USE_BLAS
65+ EIGEN_USE_LAPACKE_STRICT
66+ )
67+ endif ()
6168endif ()
6269
6370# On Windows, enable natvis files to improve debugging experience
@@ -68,6 +75,6 @@ endif()
6875# Install rules
6976set (CMAKE_INSTALL_DEFAULT_COMPONENT_NAME eigen)
7077set_target_properties (Eigen3_Eigen PROPERTIES EXPORT_NAME Eigen)
71- install (DIRECTORY ${EIGEN_INCLUDE_DIRS } DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
78+ install (DIRECTORY ${eigen_SOURCE_DIR } DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
7279install (TARGETS Eigen3_Eigen EXPORT Eigen_Targets)
73- install (EXPORT Eigen_Targets DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/eigen NAMESPACE Eigen3::)
80+ install (EXPORT Eigen_Targets DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/eigen NAMESPACE Eigen3::)
0 commit comments