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
12
3
if (TARGET Eigen3::Eigen)
13
4
return ()
14
5
endif ()
15
6
16
7
option (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 )
17
10
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'" )
23
12
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
+ )
41
20
42
21
add_library (Eigen3_Eigen INTERFACE )
43
22
add_library (Eigen3::Eigen ALIAS Eigen3_Eigen)
44
23
45
24
include (GNUInstallDirs)
46
25
target_include_directories (Eigen3_Eigen SYSTEM INTERFACE
47
- $<BUILD_INTERFACE:${EIGEN_INCLUDE_DIRS } >
26
+ $<BUILD_INTERFACE:${eigen_SOURCE_DIR } >
48
27
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
49
28
)
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 ()
51
37
52
38
if (EIGEN_WITH_MKL)
53
39
# TODO: Checks that, on 64bits systems, `mkl::mkl` is using the LP64 interface
@@ -58,6 +44,27 @@ if(EIGEN_WITH_MKL)
58
44
EIGEN_USE_MKL_ALL
59
45
EIGEN_USE_LAPACKE_STRICT
60
46
)
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 ()
61
68
endif ()
62
69
63
70
# On Windows, enable natvis files to improve debugging experience
@@ -68,6 +75,6 @@ endif()
68
75
# Install rules
69
76
set (CMAKE_INSTALL_DEFAULT_COMPONENT_NAME eigen)
70
77
set_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} )
72
79
install (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