xref: /aosp_15_r20/external/eigen/CMakeLists.txt (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1# cmake_minimum_require must be the first command of the file
2cmake_minimum_required(VERSION 3.5.0)
3
4project(Eigen3)
5
6# guard against in-source builds
7
8if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
9  message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. ")
10endif()
11
12
13# Alias Eigen_*_DIR to Eigen3_*_DIR:
14
15set(Eigen_SOURCE_DIR ${Eigen3_SOURCE_DIR})
16set(Eigen_BINARY_DIR ${Eigen3_BINARY_DIR})
17
18# guard against bad build-type strings
19
20if (NOT CMAKE_BUILD_TYPE)
21  set(CMAKE_BUILD_TYPE "Release")
22endif()
23
24
25#############################################################################
26# retrieve version information                                               #
27#############################################################################
28
29# automatically parse the version number
30file(READ "${PROJECT_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header)
31string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}")
32set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}")
33string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}")
34set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}")
35string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}")
36set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}")
37set(EIGEN_VERSION_NUMBER ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})
38
39# if we are not in a git clone
40if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)
41  # if the git program is absent or this will leave the EIGEN_GIT_REVNUM string empty,
42  # but won't stop CMake.
43  execute_process(COMMAND git ls-remote --refs -q ${CMAKE_SOURCE_DIR} HEAD OUTPUT_VARIABLE EIGEN_GIT_OUTPUT)
44endif()
45
46# extract the git rev number from the git output...
47if(EIGEN_GIT_OUTPUT)
48string(REGEX MATCH "^([0-9;a-f]+).*" EIGEN_GIT_CHANGESET_MATCH "${EIGEN_GIT_OUTPUT}")
49set(EIGEN_GIT_REVNUM "${CMAKE_MATCH_1}")
50endif()
51#...and show it next to the version number
52if(EIGEN_GIT_REVNUM)
53  set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (git rev ${EIGEN_GIT_REVNUM})")
54else()
55  set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}")
56endif()
57
58include(CheckCXXCompilerFlag)
59include(GNUInstallDirs)
60include(CMakeDependentOption)
61
62set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
63
64
65option(EIGEN_TEST_CXX11 "Enable testing with C++11 and C++11 features (e.g. Tensor module)." OFF)
66
67
68macro(ei_add_cxx_compiler_flag FLAG)
69  string(REGEX REPLACE "-" "" SFLAG1 ${FLAG})
70  string(REGEX REPLACE "\\+" "p" SFLAG ${SFLAG1})
71  check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG})
72  if(COMPILER_SUPPORT_${SFLAG})
73    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
74  endif()
75endmacro()
76
77check_cxx_compiler_flag("-std=c++11" EIGEN_COMPILER_SUPPORT_CPP11)
78
79if(EIGEN_TEST_CXX11)
80  set(CMAKE_CXX_STANDARD 11)
81  set(CMAKE_CXX_EXTENSIONS OFF)
82  if(EIGEN_COMPILER_SUPPORT_CPP11)
83    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
84  endif()
85else()
86  #set(CMAKE_CXX_STANDARD 03)
87  #set(CMAKE_CXX_EXTENSIONS OFF)
88  ei_add_cxx_compiler_flag("-std=c++03")
89endif()
90
91# Determine if we should build shared libraries on this platform.
92get_cmake_property(EIGEN_BUILD_SHARED_LIBS TARGET_SUPPORTS_SHARED_LIBS)
93
94#############################################################################
95# find how to link to the standard libraries                                #
96#############################################################################
97
98find_package(StandardMathLibrary)
99
100
101set(EIGEN_TEST_CUSTOM_LINKER_FLAGS  "" CACHE STRING "Additional linker flags when linking unit tests.")
102set(EIGEN_TEST_CUSTOM_CXX_FLAGS     "" CACHE STRING "Additional compiler flags when compiling unit tests.")
103
104set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "")
105
106if(NOT STANDARD_MATH_LIBRARY_FOUND)
107
108  message(FATAL_ERROR
109    "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.")
110
111else()
112
113  if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
114    set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}")
115  else()
116    set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}")
117  endif()
118
119endif()
120
121if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
122  message(STATUS "Standard libraries to link to explicitly: ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}")
123else()
124  message(STATUS "Standard libraries to link to explicitly: none")
125endif()
126
127option(EIGEN_BUILD_BTL "Build benchmark suite" OFF)
128
129# Disable pkgconfig only for native Windows builds
130if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
131  option(EIGEN_BUILD_PKGCONFIG "Build pkg-config .pc file for Eigen" ON)
132endif()
133
134set(CMAKE_INCLUDE_CURRENT_DIR OFF)
135
136option(EIGEN_SPLIT_LARGE_TESTS "Split large tests into smaller executables" ON)
137
138option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF)
139if(EIGEN_DEFAULT_TO_ROW_MAJOR)
140  add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR")
141endif()
142
143set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320")
144
145if(NOT MSVC)
146  # We assume that other compilers are partly compatible with GNUCC
147
148  # clang outputs some warnings for unknown flags that are not caught by check_cxx_compiler_flag
149  # adding -Werror turns such warnings into errors
150  check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)
151  if(COMPILER_SUPPORT_WERROR)
152    set(CMAKE_REQUIRED_FLAGS "-Werror")
153  endif()
154  ei_add_cxx_compiler_flag("-pedantic")
155  ei_add_cxx_compiler_flag("-Wall")
156  ei_add_cxx_compiler_flag("-Wextra")
157  #ei_add_cxx_compiler_flag("-Weverything")              # clang
158
159  ei_add_cxx_compiler_flag("-Wundef")
160  ei_add_cxx_compiler_flag("-Wcast-align")
161  ei_add_cxx_compiler_flag("-Wchar-subscripts")
162  ei_add_cxx_compiler_flag("-Wnon-virtual-dtor")
163  ei_add_cxx_compiler_flag("-Wunused-local-typedefs")
164  ei_add_cxx_compiler_flag("-Wpointer-arith")
165  ei_add_cxx_compiler_flag("-Wwrite-strings")
166  ei_add_cxx_compiler_flag("-Wformat-security")
167  ei_add_cxx_compiler_flag("-Wshorten-64-to-32")
168  ei_add_cxx_compiler_flag("-Wlogical-op")
169  ei_add_cxx_compiler_flag("-Wenum-conversion")
170  ei_add_cxx_compiler_flag("-Wc++11-extensions")
171  ei_add_cxx_compiler_flag("-Wdouble-promotion")
172#  ei_add_cxx_compiler_flag("-Wconversion")
173
174  ei_add_cxx_compiler_flag("-Wshadow")
175
176  ei_add_cxx_compiler_flag("-Wno-psabi")
177  ei_add_cxx_compiler_flag("-Wno-variadic-macros")
178  ei_add_cxx_compiler_flag("-Wno-long-long")
179
180  ei_add_cxx_compiler_flag("-fno-check-new")
181  ei_add_cxx_compiler_flag("-fno-common")
182  ei_add_cxx_compiler_flag("-fstrict-aliasing")
183  ei_add_cxx_compiler_flag("-wd981")                    # disable ICC's "operands are evaluated in unspecified order" remark
184  ei_add_cxx_compiler_flag("-wd2304")                   # disable ICC's "warning #2304: non-explicit constructor with single argument may cause implicit type conversion" produced by -Wnon-virtual-dtor
185
186
187  # The -ansi flag must be added last, otherwise it is also used as a linker flag by check_cxx_compiler_flag making it fails
188  # Moreover we should not set both -strict-ansi and -ansi
189  check_cxx_compiler_flag("-strict-ansi" COMPILER_SUPPORT_STRICTANSI)
190  ei_add_cxx_compiler_flag("-Qunused-arguments")        # disable clang warning: argument unused during compilation: '-ansi'
191
192  if(COMPILER_SUPPORT_STRICTANSI)
193    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -strict-ansi")
194  else()
195    ei_add_cxx_compiler_flag("-ansi")
196  endif()
197
198  if(ANDROID_NDK)
199    ei_add_cxx_compiler_flag("-pie")
200    ei_add_cxx_compiler_flag("-fPIE")
201  endif()
202
203  set(CMAKE_REQUIRED_FLAGS "")
204
205  option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
206  if(EIGEN_TEST_SSE2)
207    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
208    message(STATUS "Enabling SSE2 in tests/examples")
209  endif()
210
211  option(EIGEN_TEST_SSE3 "Enable/Disable SSE3 in tests/examples" OFF)
212  if(EIGEN_TEST_SSE3)
213    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
214    message(STATUS "Enabling SSE3 in tests/examples")
215  endif()
216
217  option(EIGEN_TEST_SSSE3 "Enable/Disable SSSE3 in tests/examples" OFF)
218  if(EIGEN_TEST_SSSE3)
219    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3")
220    message(STATUS "Enabling SSSE3 in tests/examples")
221  endif()
222
223  option(EIGEN_TEST_SSE4_1 "Enable/Disable SSE4.1 in tests/examples" OFF)
224  if(EIGEN_TEST_SSE4_1)
225    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
226    message(STATUS "Enabling SSE4.1 in tests/examples")
227  endif()
228
229  option(EIGEN_TEST_SSE4_2 "Enable/Disable SSE4.2 in tests/examples" OFF)
230  if(EIGEN_TEST_SSE4_2)
231    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
232    message(STATUS "Enabling SSE4.2 in tests/examples")
233  endif()
234
235  option(EIGEN_TEST_AVX "Enable/Disable AVX in tests/examples" OFF)
236  if(EIGEN_TEST_AVX)
237    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
238    message(STATUS "Enabling AVX in tests/examples")
239  endif()
240
241  option(EIGEN_TEST_FMA "Enable/Disable FMA in tests/examples" OFF)
242  if(EIGEN_TEST_FMA AND NOT EIGEN_TEST_NEON)
243    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma")
244    message(STATUS "Enabling FMA in tests/examples")
245  endif()
246
247  option(EIGEN_TEST_AVX2 "Enable/Disable AVX2 in tests/examples" OFF)
248  if(EIGEN_TEST_AVX2)
249    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2 -mfma")
250    message(STATUS "Enabling AVX2 in tests/examples")
251  endif()
252
253  option(EIGEN_TEST_AVX512 "Enable/Disable AVX512 in tests/examples" OFF)
254  if(EIGEN_TEST_AVX512)
255    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -mfma")
256    if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
257      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fabi-version=6")
258    endif()
259    message(STATUS "Enabling AVX512 in tests/examples")
260  endif()
261
262  option(EIGEN_TEST_AVX512DQ "Enable/Disable AVX512DQ in tests/examples" OFF)
263  if(EIGEN_TEST_AVX512DQ)
264    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512dq")
265    if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
266      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fabi-version=6")
267    endif()
268    message(STATUS "Enabling AVX512DQ in tests/examples")
269  endif()
270
271  option(EIGEN_TEST_F16C "Enable/Disable F16C in tests/examples" OFF)
272  if(EIGEN_TEST_F16C)
273    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c")
274    message(STATUS "Enabling F16C in tests/examples")
275  endif()
276
277  option(EIGEN_TEST_ALTIVEC "Enable/Disable AltiVec in tests/examples" OFF)
278  if(EIGEN_TEST_ALTIVEC)
279    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec -mabi=altivec")
280    message(STATUS "Enabling AltiVec in tests/examples")
281  endif()
282
283  option(EIGEN_TEST_VSX "Enable/Disable VSX in tests/examples" OFF)
284  if(EIGEN_TEST_VSX)
285    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -mvsx")
286    message(STATUS "Enabling VSX in tests/examples")
287  endif()
288
289  option(EIGEN_TEST_MSA "Enable/Disable MSA in tests/examples" OFF)
290  if(EIGEN_TEST_MSA)
291    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmsa")
292    message(STATUS "Enabling MSA in tests/examples")
293  endif()
294
295  option(EIGEN_TEST_NEON "Enable/Disable Neon in tests/examples" OFF)
296  if(EIGEN_TEST_NEON)
297    if(EIGEN_TEST_FMA)
298      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon-vfpv4")
299    else()
300      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
301    endif()
302    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard")
303    message(STATUS "Enabling NEON in tests/examples")
304  endif()
305
306  option(EIGEN_TEST_NEON64 "Enable/Disable Neon in tests/examples" OFF)
307  if(EIGEN_TEST_NEON64)
308    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
309    message(STATUS "Enabling NEON in tests/examples")
310  endif()
311
312  option(EIGEN_TEST_Z13 "Enable/Disable S390X(zEC13) ZVECTOR in tests/examples" OFF)
313  if(EIGEN_TEST_Z13)
314    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z13 -mzvector")
315    message(STATUS "Enabling S390X(zEC13) ZVECTOR in tests/examples")
316  endif()
317
318  option(EIGEN_TEST_Z14 "Enable/Disable S390X(zEC14) ZVECTOR in tests/examples" OFF)
319  if(EIGEN_TEST_Z14)
320    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z14 -mzvector")
321    message(STATUS "Enabling S390X(zEC13) ZVECTOR in tests/examples")
322  endif()
323
324  check_cxx_compiler_flag("-fopenmp" COMPILER_SUPPORT_OPENMP)
325  if(COMPILER_SUPPORT_OPENMP)
326    option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
327    if(EIGEN_TEST_OPENMP)
328      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
329      message(STATUS "Enabling OpenMP in tests/examples")
330    endif()
331  endif()
332
333else()
334
335  # C4127 - conditional expression is constant
336  # C4714 - marked as __forceinline not inlined (I failed to deactivate it selectively)
337  #         We can disable this warning in the unit tests since it is clear that it occurs
338  #         because we are oftentimes returning objects that have a destructor or may
339  #         throw exceptions - in particular in the unit tests we are throwing extra many
340  #         exceptions to cover indexing errors.
341  # C4505 - unreferenced local function has been removed (impossible to deactivate selectively)
342  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /wd4127 /wd4505 /wd4714")
343
344  # replace all /Wx by /W4
345  string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
346
347  check_cxx_compiler_flag("/openmp" COMPILER_SUPPORT_OPENMP)
348  if(COMPILER_SUPPORT_OPENMP)
349    option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
350    if(EIGEN_TEST_OPENMP)
351      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
352      message(STATUS "Enabling OpenMP in tests/examples")
353    endif()
354  endif()
355
356  option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
357  if(EIGEN_TEST_SSE2)
358    if(NOT CMAKE_CL_64)
359      # arch is not supported on 64 bit systems, SSE is enabled automatically.
360      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
361    endif()
362    message(STATUS "Enabling SSE2 in tests/examples")
363  endif()
364
365  option(EIGEN_TEST_AVX "Enable/Disable AVX in tests/examples" OFF)
366  if(EIGEN_TEST_AVX)
367    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX")
368    message(STATUS "Enabling AVX in tests/examples")
369  endif()
370
371  option(EIGEN_TEST_FMA "Enable/Disable FMA/AVX2 in tests/examples" OFF)
372  if(EIGEN_TEST_FMA AND NOT EIGEN_TEST_NEON)
373    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
374    message(STATUS "Enabling FMA/AVX2 in tests/examples")
375  endif()
376
377endif()
378
379option(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION "Disable explicit vectorization in tests/examples" OFF)
380option(EIGEN_TEST_X87 "Force using X87 instructions. Implies no vectorization." OFF)
381option(EIGEN_TEST_32BIT "Force generating 32bit code." OFF)
382
383if(EIGEN_TEST_X87)
384  set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION ON)
385  if(CMAKE_COMPILER_IS_GNUCXX)
386    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=387")
387    message(STATUS "Forcing use of x87 instructions in tests/examples")
388  else()
389    message(STATUS "EIGEN_TEST_X87 ignored on your compiler")
390  endif()
391endif()
392
393if(EIGEN_TEST_32BIT)
394  if(CMAKE_COMPILER_IS_GNUCXX)
395    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
396    message(STATUS "Forcing generation of 32-bit code in tests/examples")
397  else()
398    message(STATUS "EIGEN_TEST_32BIT ignored on your compiler")
399  endif()
400endif()
401
402if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
403  add_definitions(-DEIGEN_DONT_VECTORIZE=1)
404  message(STATUS "Disabling vectorization in tests/examples")
405endif()
406
407option(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT "Disable explicit alignment (hence vectorization) in tests/examples" OFF)
408if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT)
409  add_definitions(-DEIGEN_DONT_ALIGN=1)
410  message(STATUS "Disabling alignment in tests/examples")
411endif()
412
413option(EIGEN_TEST_NO_EXCEPTIONS "Disables C++ exceptions" OFF)
414if(EIGEN_TEST_NO_EXCEPTIONS)
415  ei_add_cxx_compiler_flag("-fno-exceptions")
416  message(STATUS "Disabling exceptions in tests/examples")
417endif()
418
419set(EIGEN_CUDA_COMPUTE_ARCH 30 CACHE STRING "The CUDA compute architecture level to target when compiling CUDA code")
420
421include_directories(${CMAKE_CURRENT_SOURCE_DIR})
422
423# Backward compatibility support for EIGEN_INCLUDE_INSTALL_DIR
424if(EIGEN_INCLUDE_INSTALL_DIR)
425  message(WARNING "EIGEN_INCLUDE_INSTALL_DIR is deprecated. Use INCLUDE_INSTALL_DIR instead.")
426endif()
427
428if(EIGEN_INCLUDE_INSTALL_DIR AND NOT INCLUDE_INSTALL_DIR)
429  set(INCLUDE_INSTALL_DIR ${EIGEN_INCLUDE_INSTALL_DIR}
430      CACHE PATH "The directory relative to CMAKE_INSTALL_PREFIX where Eigen header files are installed")
431else()
432  set(INCLUDE_INSTALL_DIR
433      "${CMAKE_INSTALL_INCLUDEDIR}/eigen3"
434      CACHE PATH "The directory relative to CMAKE_INSTALL_PREFIX where Eigen header files are installed"
435      )
436endif()
437set(CMAKEPACKAGE_INSTALL_DIR
438    "${CMAKE_INSTALL_DATADIR}/eigen3/cmake"
439    CACHE PATH "The directory relative to CMAKE_INSTALL_PREFIX where Eigen3Config.cmake is installed"
440    )
441set(PKGCONFIG_INSTALL_DIR
442    "${CMAKE_INSTALL_DATADIR}/pkgconfig"
443    CACHE PATH "The directory relative to CMAKE_INSTALL_PREFIX where eigen3.pc is installed"
444    )
445
446foreach(var INCLUDE_INSTALL_DIR CMAKEPACKAGE_INSTALL_DIR PKGCONFIG_INSTALL_DIR)
447  # If an absolute path is specified, make it relative to "{CMAKE_INSTALL_PREFIX}".
448  if(IS_ABSOLUTE "${${var}}")
449    file(RELATIVE_PATH "${var}" "${CMAKE_INSTALL_PREFIX}" "${${var}}")
450  endif()
451endforeach()
452
453# similar to set_target_properties but append the property instead of overwriting it
454macro(ei_add_target_property target prop value)
455
456  get_target_property(previous ${target} ${prop})
457  # if the property wasn't previously set, ${previous} is now "previous-NOTFOUND" which cmake allows catching with plain if()
458  if(NOT previous)
459    set(previous "")
460  endif()
461  set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}")
462endmacro()
463
464install(FILES
465  signature_of_eigen3_matrix_library
466  DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel
467  )
468
469if(EIGEN_BUILD_PKGCONFIG)
470    configure_file(eigen3.pc.in eigen3.pc @ONLY)
471    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eigen3.pc
472        DESTINATION ${PKGCONFIG_INSTALL_DIR}
473        )
474endif()
475
476install(DIRECTORY Eigen DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel)
477
478
479option(EIGEN_BUILD_DOC "Enable creation of Eigen documentation" ON)
480if(EIGEN_BUILD_DOC)
481  add_subdirectory(doc EXCLUDE_FROM_ALL)
482endif()
483
484
485option(BUILD_TESTING "Enable creation of Eigen tests." ON)
486if(BUILD_TESTING)
487  include(EigenConfigureTesting)
488
489  if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
490    add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest
491  else()
492    add_subdirectory(test EXCLUDE_FROM_ALL)
493  endif()
494
495  add_subdirectory(failtest)
496endif()
497
498if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
499  add_subdirectory(blas)
500  add_subdirectory(lapack)
501else()
502  add_subdirectory(blas EXCLUDE_FROM_ALL)
503  add_subdirectory(lapack EXCLUDE_FROM_ALL)
504endif()
505
506# add SYCL
507option(EIGEN_TEST_SYCL "Add Sycl support." OFF)
508option(EIGEN_SYCL_TRISYCL "Use the triSYCL Sycl implementation (ComputeCPP by default)." OFF)
509if(EIGEN_TEST_SYCL)
510  set (CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "cmake/Modules/" "${CMAKE_MODULE_PATH}")
511  find_package(Threads REQUIRED)
512  if(EIGEN_SYCL_TRISYCL)
513    message(STATUS "Using triSYCL")
514    include(FindTriSYCL)
515  else()
516    message(STATUS "Using ComputeCPP SYCL")
517    include(FindComputeCpp)
518    set(COMPUTECPP_DRIVER_DEFAULT_VALUE OFF)
519    if (NOT MSVC)
520      set(COMPUTECPP_DRIVER_DEFAULT_VALUE ON)
521    endif()
522    option(COMPUTECPP_USE_COMPILER_DRIVER
523      "Use ComputeCpp driver instead of a 2 steps compilation"
524      ${COMPUTECPP_DRIVER_DEFAULT_VALUE}
525    )
526  endif(EIGEN_SYCL_TRISYCL)
527  option(EIGEN_DONT_VECTORIZE_SYCL "Don't use vectorisation in the SYCL tests." OFF)
528  if(EIGEN_DONT_VECTORIZE_SYCL)
529    message(STATUS "Disabling SYCL vectorization in tests/examples")
530    # When disabling SYCL vectorization, also disable Eigen default vectorization
531    add_definitions(-DEIGEN_DONT_VECTORIZE=1)
532    add_definitions(-DEIGEN_DONT_VECTORIZE_SYCL=1)
533  endif()
534endif()
535
536add_subdirectory(unsupported)
537
538add_subdirectory(demos EXCLUDE_FROM_ALL)
539
540# must be after test and unsupported, for configuring buildtests.in
541add_subdirectory(scripts EXCLUDE_FROM_ALL)
542
543# TODO: consider also replacing EIGEN_BUILD_BTL by a custom target "make btl"?
544if(EIGEN_BUILD_BTL)
545  add_subdirectory(bench/btl EXCLUDE_FROM_ALL)
546endif()
547
548if(NOT WIN32)
549  add_subdirectory(bench/spbench EXCLUDE_FROM_ALL)
550endif()
551
552configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY)
553
554if(BUILD_TESTING)
555  ei_testing_print_summary()
556endif()
557
558message(STATUS "")
559message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
560message(STATUS "")
561
562string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
563if(cmake_generator_tolower MATCHES "makefile")
564  message(STATUS "Available targets (use: make TARGET):")
565else()
566  message(STATUS "Available targets (use: cmake --build . --target TARGET):")
567endif()
568message(STATUS "---------+--------------------------------------------------------------")
569message(STATUS "Target   |   Description")
570message(STATUS "---------+--------------------------------------------------------------")
571message(STATUS "install  | Install Eigen. Headers will be installed to:")
572message(STATUS "         |     <CMAKE_INSTALL_PREFIX>/<INCLUDE_INSTALL_DIR>")
573message(STATUS "         |   Using the following values:")
574message(STATUS "         |     CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
575message(STATUS "         |     INCLUDE_INSTALL_DIR:  ${INCLUDE_INSTALL_DIR}")
576message(STATUS "         |   Change the install location of Eigen headers using:")
577message(STATUS "         |     cmake . -DCMAKE_INSTALL_PREFIX=yourprefix")
578message(STATUS "         |   Or:")
579message(STATUS "         |     cmake . -DINCLUDE_INSTALL_DIR=yourdir")
580message(STATUS "doc      | Generate the API documentation, requires Doxygen & LaTeX")
581if(BUILD_TESTING)
582  message(STATUS "check    | Build and run the unit-tests. Read this page:")
583  message(STATUS "         |   http://eigen.tuxfamily.org/index.php?title=Tests")
584endif()
585message(STATUS "blas     | Build BLAS library (not the same thing as Eigen)")
586message(STATUS "uninstall| Remove files installed by the install target")
587message(STATUS "---------+--------------------------------------------------------------")
588message(STATUS "")
589
590
591set ( EIGEN_VERSION_STRING ${EIGEN_VERSION_NUMBER} )
592set ( EIGEN_VERSION_MAJOR  ${EIGEN_WORLD_VERSION} )
593set ( EIGEN_VERSION_MINOR  ${EIGEN_MAJOR_VERSION} )
594set ( EIGEN_VERSION_PATCH  ${EIGEN_MINOR_VERSION} )
595set ( EIGEN_DEFINITIONS "")
596set ( EIGEN_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}" )
597set ( EIGEN_ROOT_DIR ${CMAKE_INSTALL_PREFIX} )
598
599include (CMakePackageConfigHelpers)
600
601# Imported target support
602add_library (eigen INTERFACE)
603add_library (Eigen3::Eigen ALIAS eigen)
604target_compile_definitions (eigen INTERFACE ${EIGEN_DEFINITIONS})
605target_include_directories (eigen INTERFACE
606  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
607  $<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
608)
609
610# Export as title case Eigen
611set_target_properties (eigen PROPERTIES EXPORT_NAME Eigen)
612
613install (TARGETS eigen EXPORT Eigen3Targets)
614
615configure_package_config_file (
616  ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3Config.cmake.in
617  ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
618  PATH_VARS EIGEN_INCLUDE_DIR EIGEN_ROOT_DIR
619  INSTALL_DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}
620  NO_CHECK_REQUIRED_COMPONENTS_MACRO # Eigen does not provide components
621)
622# Remove CMAKE_SIZEOF_VOID_P from Eigen3ConfigVersion.cmake since Eigen does
623# not depend on architecture specific settings or libraries. More
624# specifically, an Eigen3Config.cmake generated from a 64 bit target can be
625# used for 32 bit targets as well (and vice versa).
626set (_Eigen3_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
627unset (CMAKE_SIZEOF_VOID_P)
628write_basic_package_version_file (Eigen3ConfigVersion.cmake
629                                  VERSION ${EIGEN_VERSION_NUMBER}
630                                  COMPATIBILITY SameMajorVersion)
631set (CMAKE_SIZEOF_VOID_P ${_Eigen3_CMAKE_SIZEOF_VOID_P})
632
633# The Eigen target will be located in the Eigen3 namespace. Other CMake
634# targets can refer to it using Eigen3::Eigen.
635export (TARGETS eigen NAMESPACE Eigen3:: FILE Eigen3Targets.cmake)
636# Export Eigen3 package to CMake registry such that it can be easily found by
637# CMake even if it has not been installed to a standard directory.
638export (PACKAGE Eigen3)
639
640install (EXPORT Eigen3Targets NAMESPACE Eigen3:: DESTINATION ${CMAKEPACKAGE_INSTALL_DIR})
641
642install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseEigen3.cmake
643                ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
644                ${CMAKE_CURRENT_BINARY_DIR}/Eigen3ConfigVersion.cmake
645          DESTINATION ${CMAKEPACKAGE_INSTALL_DIR} )
646
647# Add uninstall target
648add_custom_target ( uninstall
649    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/EigenUninstall.cmake)
650
651if (EIGEN_SPLIT_TESTSUITE)
652  ei_split_testsuite("${EIGEN_SPLIT_TESTSUITE}")
653endif()
654