blob: 2bfb6d560b63f1c0d27b2bf2d3125d7b73435f03 [file] [log] [blame]
Austin Schuh189376f2018-12-20 22:11:15 +11001project(Eigen3)
Brian Silverman72890c22015-09-19 14:37:37 -04002
Austin Schuh189376f2018-12-20 22:11:15 +11003cmake_minimum_required(VERSION 2.8.5)
Brian Silverman72890c22015-09-19 14:37:37 -04004
5# guard against in-source builds
6
7if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
8 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. ")
9endif()
10
Austin Schuh189376f2018-12-20 22:11:15 +110011# Alias Eigen_*_DIR to Eigen3_*_DIR:
12
13set(Eigen_SOURCE_DIR ${Eigen3_SOURCE_DIR})
14set(Eigen_BINARY_DIR ${Eigen3_BINARY_DIR})
15
Brian Silverman72890c22015-09-19 14:37:37 -040016# guard against bad build-type strings
17
18if (NOT CMAKE_BUILD_TYPE)
19 set(CMAKE_BUILD_TYPE "Release")
20endif()
21
22string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
23if( NOT cmake_build_type_tolower STREQUAL "debug"
24 AND NOT cmake_build_type_tolower STREQUAL "release"
25 AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo")
26 message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).")
27endif()
28
29
30#############################################################################
31# retrieve version infomation #
32#############################################################################
33
34# automatically parse the version number
35file(READ "${PROJECT_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header)
36string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}")
37set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}")
38string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}")
39set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}")
40string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}")
41set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}")
42set(EIGEN_VERSION_NUMBER ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})
43
Austin Schuh189376f2018-12-20 22:11:15 +110044# if we are not in a mercurial clone
45if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.hg)
46 # if the mercurial program is absent or this will leave the EIGEN_HG_CHANGESET string empty,
47 # but won't stop CMake.
48 execute_process(COMMAND hg tip -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_HGTIP_OUTPUT)
49 execute_process(COMMAND hg branch -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_BRANCH_OUTPUT)
50endif()
Brian Silverman72890c22015-09-19 14:37:37 -040051
52# if this is the default (aka development) branch, extract the mercurial changeset number from the hg tip output...
53if(EIGEN_BRANCH_OUTPUT MATCHES "default")
54string(REGEX MATCH "^changeset: *[0-9]*:([0-9;a-f]+).*" EIGEN_HG_CHANGESET_MATCH "${EIGEN_HGTIP_OUTPUT}")
55set(EIGEN_HG_CHANGESET "${CMAKE_MATCH_1}")
56endif(EIGEN_BRANCH_OUTPUT MATCHES "default")
57#...and show it next to the version number
58if(EIGEN_HG_CHANGESET)
59 set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (mercurial changeset ${EIGEN_HG_CHANGESET})")
60else(EIGEN_HG_CHANGESET)
61 set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}")
62endif(EIGEN_HG_CHANGESET)
63
64
65include(CheckCXXCompilerFlag)
Austin Schuh189376f2018-12-20 22:11:15 +110066include(GNUInstallDirs)
Brian Silverman72890c22015-09-19 14:37:37 -040067
68set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
69
Austin Schuh189376f2018-12-20 22:11:15 +110070
71option(EIGEN_TEST_CXX11 "Enable testing with C++11 and C++11 features (e.g. Tensor module)." OFF)
72
73
74macro(ei_add_cxx_compiler_flag FLAG)
75 string(REGEX REPLACE "-" "" SFLAG1 ${FLAG})
76 string(REGEX REPLACE "\\+" "p" SFLAG ${SFLAG1})
77 check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG})
78 if(COMPILER_SUPPORT_${SFLAG})
79 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
80 endif()
81endmacro(ei_add_cxx_compiler_flag)
82
83check_cxx_compiler_flag("-std=c++11" EIGEN_COMPILER_SUPPORT_CPP11)
84
85if(EIGEN_TEST_CXX11)
86 set(CMAKE_CXX_STANDARD 11)
87 set(CMAKE_CXX_EXTENSIONS OFF)
88 if(EIGEN_COMPILER_SUPPORT_CPP11)
89 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
90 endif()
91else()
92 #set(CMAKE_CXX_STANDARD 03)
93 #set(CMAKE_CXX_EXTENSIONS OFF)
94 ei_add_cxx_compiler_flag("-std=c++03")
95endif()
96
Brian Silverman72890c22015-09-19 14:37:37 -040097#############################################################################
98# find how to link to the standard libraries #
99#############################################################################
100
101find_package(StandardMathLibrary)
102
103
104set(EIGEN_TEST_CUSTOM_LINKER_FLAGS "" CACHE STRING "Additional linker flags when linking unit tests.")
105set(EIGEN_TEST_CUSTOM_CXX_FLAGS "" CACHE STRING "Additional compiler flags when compiling unit tests.")
106
107set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "")
108
109if(NOT STANDARD_MATH_LIBRARY_FOUND)
110
111 message(FATAL_ERROR
112 "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.")
113
114else()
115
116 if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
117 set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}")
118 else()
119 set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}")
120 endif()
121
122endif()
123
124if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
125 message(STATUS "Standard libraries to link to explicitly: ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}")
126else()
127 message(STATUS "Standard libraries to link to explicitly: none")
128endif()
129
130option(EIGEN_BUILD_BTL "Build benchmark suite" OFF)
Austin Schuh189376f2018-12-20 22:11:15 +1100131
132# Disable pkgconfig only for native Windows builds
133if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
Brian Silverman72890c22015-09-19 14:37:37 -0400134 option(EIGEN_BUILD_PKGCONFIG "Build pkg-config .pc file for Eigen" ON)
Austin Schuh189376f2018-12-20 22:11:15 +1100135endif()
Brian Silverman72890c22015-09-19 14:37:37 -0400136
137set(CMAKE_INCLUDE_CURRENT_DIR ON)
138
139option(EIGEN_SPLIT_LARGE_TESTS "Split large tests into smaller executables" ON)
140
141option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF)
142if(EIGEN_DEFAULT_TO_ROW_MAJOR)
143 add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR")
144endif()
145
146set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320")
147
Brian Silverman72890c22015-09-19 14:37:37 -0400148if(NOT MSVC)
149 # We assume that other compilers are partly compatible with GNUCC
Austin Schuh189376f2018-12-20 22:11:15 +1100150
151 # clang outputs some warnings for unknown flags that are not caught by check_cxx_compiler_flag
Brian Silverman72890c22015-09-19 14:37:37 -0400152 # adding -Werror turns such warnings into errors
153 check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)
154 if(COMPILER_SUPPORT_WERROR)
155 set(CMAKE_REQUIRED_FLAGS "-Werror")
156 endif()
Brian Silverman72890c22015-09-19 14:37:37 -0400157 ei_add_cxx_compiler_flag("-pedantic")
158 ei_add_cxx_compiler_flag("-Wall")
159 ei_add_cxx_compiler_flag("-Wextra")
160 #ei_add_cxx_compiler_flag("-Weverything") # clang
161
162 ei_add_cxx_compiler_flag("-Wundef")
163 ei_add_cxx_compiler_flag("-Wcast-align")
164 ei_add_cxx_compiler_flag("-Wchar-subscripts")
165 ei_add_cxx_compiler_flag("-Wnon-virtual-dtor")
166 ei_add_cxx_compiler_flag("-Wunused-local-typedefs")
167 ei_add_cxx_compiler_flag("-Wpointer-arith")
168 ei_add_cxx_compiler_flag("-Wwrite-strings")
169 ei_add_cxx_compiler_flag("-Wformat-security")
Austin Schuh189376f2018-12-20 22:11:15 +1100170 ei_add_cxx_compiler_flag("-Wshorten-64-to-32")
171 ei_add_cxx_compiler_flag("-Wlogical-op")
172 ei_add_cxx_compiler_flag("-Wenum-conversion")
173 ei_add_cxx_compiler_flag("-Wc++11-extensions")
174 ei_add_cxx_compiler_flag("-Wdouble-promotion")
175# ei_add_cxx_compiler_flag("-Wconversion")
176
177 # -Wshadow is insanely too strict with gcc, hopefully it will become usable with gcc 6
178 # if(NOT CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.0.0"))
179 if(NOT CMAKE_COMPILER_IS_GNUCXX)
180 ei_add_cxx_compiler_flag("-Wshadow")
181 endif()
Brian Silverman72890c22015-09-19 14:37:37 -0400182
183 ei_add_cxx_compiler_flag("-Wno-psabi")
184 ei_add_cxx_compiler_flag("-Wno-variadic-macros")
185 ei_add_cxx_compiler_flag("-Wno-long-long")
186
187 ei_add_cxx_compiler_flag("-fno-check-new")
188 ei_add_cxx_compiler_flag("-fno-common")
189 ei_add_cxx_compiler_flag("-fstrict-aliasing")
190 ei_add_cxx_compiler_flag("-wd981") # disable ICC's "operands are evaluated in unspecified order" remark
Austin Schuh189376f2018-12-20 22:11:15 +1100191 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
192
Brian Silverman72890c22015-09-19 14:37:37 -0400193
194 # The -ansi flag must be added last, otherwise it is also used as a linker flag by check_cxx_compiler_flag making it fails
195 # Moreover we should not set both -strict-ansi and -ansi
196 check_cxx_compiler_flag("-strict-ansi" COMPILER_SUPPORT_STRICTANSI)
197 ei_add_cxx_compiler_flag("-Qunused-arguments") # disable clang warning: argument unused during compilation: '-ansi'
198
199 if(COMPILER_SUPPORT_STRICTANSI)
200 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -strict-ansi")
201 else()
202 ei_add_cxx_compiler_flag("-ansi")
203 endif()
Austin Schuh189376f2018-12-20 22:11:15 +1100204
205 if(ANDROID_NDK)
206 ei_add_cxx_compiler_flag("-pie")
207 ei_add_cxx_compiler_flag("-fPIE")
208 endif()
Brian Silverman72890c22015-09-19 14:37:37 -0400209
210 set(CMAKE_REQUIRED_FLAGS "")
211
212 option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
213 if(EIGEN_TEST_SSE2)
214 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
215 message(STATUS "Enabling SSE2 in tests/examples")
216 endif()
217
218 option(EIGEN_TEST_SSE3 "Enable/Disable SSE3 in tests/examples" OFF)
219 if(EIGEN_TEST_SSE3)
220 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
221 message(STATUS "Enabling SSE3 in tests/examples")
222 endif()
223
224 option(EIGEN_TEST_SSSE3 "Enable/Disable SSSE3 in tests/examples" OFF)
225 if(EIGEN_TEST_SSSE3)
226 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3")
227 message(STATUS "Enabling SSSE3 in tests/examples")
228 endif()
229
230 option(EIGEN_TEST_SSE4_1 "Enable/Disable SSE4.1 in tests/examples" OFF)
231 if(EIGEN_TEST_SSE4_1)
232 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
233 message(STATUS "Enabling SSE4.1 in tests/examples")
234 endif()
235
236 option(EIGEN_TEST_SSE4_2 "Enable/Disable SSE4.2 in tests/examples" OFF)
237 if(EIGEN_TEST_SSE4_2)
238 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
239 message(STATUS "Enabling SSE4.2 in tests/examples")
240 endif()
241
Austin Schuh189376f2018-12-20 22:11:15 +1100242 option(EIGEN_TEST_AVX "Enable/Disable AVX in tests/examples" OFF)
243 if(EIGEN_TEST_AVX)
244 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
245 message(STATUS "Enabling AVX in tests/examples")
246 endif()
247
248 option(EIGEN_TEST_FMA "Enable/Disable FMA in tests/examples" OFF)
249 if(EIGEN_TEST_FMA AND NOT EIGEN_TEST_NEON)
250 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma")
251 message(STATUS "Enabling FMA in tests/examples")
252 endif()
253
254 option(EIGEN_TEST_AVX512 "Enable/Disable AVX512 in tests/examples" OFF)
255 if(EIGEN_TEST_AVX512)
256 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -fabi-version=6 -DEIGEN_ENABLE_AVX512")
257 message(STATUS "Enabling AVX512 in tests/examples")
258 endif()
259
260 option(EIGEN_TEST_F16C "Enable/Disable F16C in tests/examples" OFF)
261 if(EIGEN_TEST_F16C)
262 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c")
263 message(STATUS "Enabling F16C in tests/examples")
264 endif()
265
Brian Silverman72890c22015-09-19 14:37:37 -0400266 option(EIGEN_TEST_ALTIVEC "Enable/Disable AltiVec in tests/examples" OFF)
267 if(EIGEN_TEST_ALTIVEC)
268 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec -mabi=altivec")
269 message(STATUS "Enabling AltiVec in tests/examples")
270 endif()
271
Austin Schuh189376f2018-12-20 22:11:15 +1100272 option(EIGEN_TEST_VSX "Enable/Disable VSX in tests/examples" OFF)
273 if(EIGEN_TEST_VSX)
274 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -mvsx")
275 message(STATUS "Enabling VSX in tests/examples")
276 endif()
277
Brian Silverman72890c22015-09-19 14:37:37 -0400278 option(EIGEN_TEST_NEON "Enable/Disable Neon in tests/examples" OFF)
279 if(EIGEN_TEST_NEON)
Austin Schuh189376f2018-12-20 22:11:15 +1100280 if(EIGEN_TEST_FMA)
281 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon-vfpv4")
282 else()
283 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
284 endif()
285 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard")
Brian Silverman72890c22015-09-19 14:37:37 -0400286 message(STATUS "Enabling NEON in tests/examples")
287 endif()
288
Austin Schuh189376f2018-12-20 22:11:15 +1100289 option(EIGEN_TEST_NEON64 "Enable/Disable Neon in tests/examples" OFF)
290 if(EIGEN_TEST_NEON64)
291 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
292 message(STATUS "Enabling NEON in tests/examples")
293 endif()
294
295 option(EIGEN_TEST_ZVECTOR "Enable/Disable S390X(zEC13) ZVECTOR in tests/examples" OFF)
296 if(EIGEN_TEST_ZVECTOR)
297 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z13 -mzvector")
298 message(STATUS "Enabling S390X(zEC13) ZVECTOR in tests/examples")
299 endif()
300
Brian Silverman72890c22015-09-19 14:37:37 -0400301 check_cxx_compiler_flag("-fopenmp" COMPILER_SUPPORT_OPENMP)
302 if(COMPILER_SUPPORT_OPENMP)
303 option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
304 if(EIGEN_TEST_OPENMP)
305 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
306 message(STATUS "Enabling OpenMP in tests/examples")
307 endif()
308 endif()
309
310else(NOT MSVC)
311
312 # C4127 - conditional expression is constant
313 # C4714 - marked as __forceinline not inlined (I failed to deactivate it selectively)
314 # We can disable this warning in the unit tests since it is clear that it occurs
315 # because we are oftentimes returning objects that have a destructor or may
316 # throw exceptions - in particular in the unit tests we are throwing extra many
317 # exceptions to cover indexing errors.
318 # C4505 - unreferenced local function has been removed (impossible to deactive selectively)
319 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /wd4127 /wd4505 /wd4714")
320
321 # replace all /Wx by /W4
322 string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
323
324 check_cxx_compiler_flag("/openmp" 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} /openmp")
329 message(STATUS "Enabling OpenMP in tests/examples")
330 endif()
331 endif()
332
333 option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
334 if(EIGEN_TEST_SSE2)
335 if(NOT CMAKE_CL_64)
336 # arch is not supported on 64 bit systems, SSE is enabled automatically.
337 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
338 endif(NOT CMAKE_CL_64)
339 message(STATUS "Enabling SSE2 in tests/examples")
340 endif(EIGEN_TEST_SSE2)
341endif(NOT MSVC)
342
343option(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION "Disable explicit vectorization in tests/examples" OFF)
344option(EIGEN_TEST_X87 "Force using X87 instructions. Implies no vectorization." OFF)
345option(EIGEN_TEST_32BIT "Force generating 32bit code." OFF)
346
347if(EIGEN_TEST_X87)
348 set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION ON)
349 if(CMAKE_COMPILER_IS_GNUCXX)
350 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=387")
351 message(STATUS "Forcing use of x87 instructions in tests/examples")
352 else()
353 message(STATUS "EIGEN_TEST_X87 ignored on your compiler")
354 endif()
355endif()
356
357if(EIGEN_TEST_32BIT)
358 if(CMAKE_COMPILER_IS_GNUCXX)
359 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
360 message(STATUS "Forcing generation of 32-bit code in tests/examples")
361 else()
362 message(STATUS "EIGEN_TEST_32BIT ignored on your compiler")
363 endif()
364endif()
365
366if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
367 add_definitions(-DEIGEN_DONT_VECTORIZE=1)
368 message(STATUS "Disabling vectorization in tests/examples")
369endif()
370
371option(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT "Disable explicit alignment (hence vectorization) in tests/examples" OFF)
372if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT)
373 add_definitions(-DEIGEN_DONT_ALIGN=1)
374 message(STATUS "Disabling alignment in tests/examples")
375endif()
376
Austin Schuh189376f2018-12-20 22:11:15 +1100377option(EIGEN_TEST_NO_EXCEPTIONS "Disables C++ exceptions" OFF)
378if(EIGEN_TEST_NO_EXCEPTIONS)
379 ei_add_cxx_compiler_flag("-fno-exceptions")
380 message(STATUS "Disabling exceptions in tests/examples")
381endif()
382
383set(EIGEN_CUDA_COMPUTE_ARCH 30 CACHE STRING "The CUDA compute architecture level to target when compiling CUDA code")
Brian Silverman72890c22015-09-19 14:37:37 -0400384
385include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
386
Austin Schuh189376f2018-12-20 22:11:15 +1100387# Backward compatibility support for EIGEN_INCLUDE_INSTALL_DIR
Brian Silverman72890c22015-09-19 14:37:37 -0400388if(EIGEN_INCLUDE_INSTALL_DIR)
Austin Schuh189376f2018-12-20 22:11:15 +1100389 message(WARNING "EIGEN_INCLUDE_INSTALL_DIR is deprecated. Use INCLUDE_INSTALL_DIR instead.")
390endif()
391
392if(EIGEN_INCLUDE_INSTALL_DIR AND NOT INCLUDE_INSTALL_DIR)
393 set(INCLUDE_INSTALL_DIR ${EIGEN_INCLUDE_INSTALL_DIR}
394 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where Eigen header files are installed")
Brian Silverman72890c22015-09-19 14:37:37 -0400395else()
396 set(INCLUDE_INSTALL_DIR
Austin Schuh189376f2018-12-20 22:11:15 +1100397 "${CMAKE_INSTALL_INCLUDEDIR}/eigen3"
398 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where Eigen header files are installed"
399 )
Brian Silverman72890c22015-09-19 14:37:37 -0400400endif()
Austin Schuh189376f2018-12-20 22:11:15 +1100401set(CMAKEPACKAGE_INSTALL_DIR
402 "${CMAKE_INSTALL_DATADIR}/eigen3/cmake"
403 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where Eigen3Config.cmake is installed"
404 )
405set(PKGCONFIG_INSTALL_DIR
406 "${CMAKE_INSTALL_DATADIR}/pkgconfig"
407 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where eigen3.pc is installed"
408 )
409
Brian Silverman72890c22015-09-19 14:37:37 -0400410
411# similar to set_target_properties but append the property instead of overwriting it
412macro(ei_add_target_property target prop value)
413
414 get_target_property(previous ${target} ${prop})
415 # if the property wasn't previously set, ${previous} is now "previous-NOTFOUND" which cmake allows catching with plain if()
416 if(NOT previous)
417 set(previous "")
418 endif(NOT previous)
419 set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}")
420endmacro(ei_add_target_property)
421
422install(FILES
423 signature_of_eigen3_matrix_library
424 DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel
425 )
426
427if(EIGEN_BUILD_PKGCONFIG)
Austin Schuh189376f2018-12-20 22:11:15 +1100428 configure_file(eigen3.pc.in eigen3.pc @ONLY)
Brian Silverman72890c22015-09-19 14:37:37 -0400429 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eigen3.pc
Austin Schuh189376f2018-12-20 22:11:15 +1100430 DESTINATION ${PKGCONFIG_INSTALL_DIR}
Brian Silverman72890c22015-09-19 14:37:37 -0400431 )
Austin Schuh189376f2018-12-20 22:11:15 +1100432endif()
Brian Silverman72890c22015-09-19 14:37:37 -0400433
434add_subdirectory(Eigen)
435
436add_subdirectory(doc EXCLUDE_FROM_ALL)
437
Austin Schuh189376f2018-12-20 22:11:15 +1100438option(BUILD_TESTING "Enable creation of Eigen tests." ON)
439if(BUILD_TESTING)
440 include(EigenConfigureTesting)
Brian Silverman72890c22015-09-19 14:37:37 -0400441
Austin Schuh189376f2018-12-20 22:11:15 +1100442 if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
443 add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest
444 else()
445 add_subdirectory(test EXCLUDE_FROM_ALL)
446 endif()
Brian Silverman72890c22015-09-19 14:37:37 -0400447endif()
448
449if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
450 add_subdirectory(blas)
451 add_subdirectory(lapack)
452else()
453 add_subdirectory(blas EXCLUDE_FROM_ALL)
454 add_subdirectory(lapack EXCLUDE_FROM_ALL)
455endif()
456
Austin Schuh189376f2018-12-20 22:11:15 +1100457# add SYCL
458option(EIGEN_TEST_SYCL "Add Sycl support." OFF)
459if(EIGEN_TEST_SYCL)
460 set (CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "cmake/Modules/" "${CMAKE_MODULE_PATH}")
461 include(FindComputeCpp)
462endif()
463
Brian Silverman72890c22015-09-19 14:37:37 -0400464add_subdirectory(unsupported)
465
466add_subdirectory(demos EXCLUDE_FROM_ALL)
467
468# must be after test and unsupported, for configuring buildtests.in
469add_subdirectory(scripts EXCLUDE_FROM_ALL)
470
471# TODO: consider also replacing EIGEN_BUILD_BTL by a custom target "make btl"?
472if(EIGEN_BUILD_BTL)
473 add_subdirectory(bench/btl EXCLUDE_FROM_ALL)
474endif(EIGEN_BUILD_BTL)
475
476if(NOT WIN32)
477 add_subdirectory(bench/spbench EXCLUDE_FROM_ALL)
478endif(NOT WIN32)
479
480configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY)
481
Austin Schuh189376f2018-12-20 22:11:15 +1100482if(BUILD_TESTING)
483 ei_testing_print_summary()
484endif()
Brian Silverman72890c22015-09-19 14:37:37 -0400485
486message(STATUS "")
487message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
488message(STATUS "")
489
490option(EIGEN_FAILTEST "Enable failtests." OFF)
491if(EIGEN_FAILTEST)
492 add_subdirectory(failtest)
493endif()
494
495string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
496if(cmake_generator_tolower MATCHES "makefile")
497 message(STATUS "Some things you can do now:")
498 message(STATUS "--------------+--------------------------------------------------------------")
499 message(STATUS "Command | Description")
500 message(STATUS "--------------+--------------------------------------------------------------")
Austin Schuh189376f2018-12-20 22:11:15 +1100501 message(STATUS "make install | Install Eigen. Headers will be installed to:")
502 message(STATUS " | <CMAKE_INSTALL_PREFIX>/<INCLUDE_INSTALL_DIR>")
503 message(STATUS " | Using the following values:")
504 message(STATUS " | CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
505 message(STATUS " | INCLUDE_INSTALL_DIR: ${INCLUDE_INSTALL_DIR}")
506 message(STATUS " | Change the install location of Eigen headers using:")
507 message(STATUS " | cmake . -DCMAKE_INSTALL_PREFIX=yourprefix")
508 message(STATUS " | Or:")
509 message(STATUS " | cmake . -DINCLUDE_INSTALL_DIR=yourdir")
Brian Silverman72890c22015-09-19 14:37:37 -0400510 message(STATUS "make doc | Generate the API documentation, requires Doxygen & LaTeX")
511 message(STATUS "make check | Build and run the unit-tests. Read this page:")
512 message(STATUS " | http://eigen.tuxfamily.org/index.php?title=Tests")
513 message(STATUS "make blas | Build BLAS library (not the same thing as Eigen)")
Austin Schuh189376f2018-12-20 22:11:15 +1100514 message(STATUS "make uninstall| Removes files installed by make install")
Brian Silverman72890c22015-09-19 14:37:37 -0400515 message(STATUS "--------------+--------------------------------------------------------------")
516else()
517 message(STATUS "To build/run the unit tests, read this page:")
518 message(STATUS " http://eigen.tuxfamily.org/index.php?title=Tests")
519endif()
520
521message(STATUS "")
Austin Schuh189376f2018-12-20 22:11:15 +1100522
523
524set ( EIGEN_VERSION_STRING ${EIGEN_VERSION_NUMBER} )
525set ( EIGEN_VERSION_MAJOR ${EIGEN_WORLD_VERSION} )
526set ( EIGEN_VERSION_MINOR ${EIGEN_MAJOR_VERSION} )
527set ( EIGEN_VERSION_PATCH ${EIGEN_MINOR_VERSION} )
528set ( EIGEN_DEFINITIONS "")
529set ( EIGEN_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}" )
530set ( EIGEN_ROOT_DIR ${CMAKE_INSTALL_PREFIX} )
531
532# Interface libraries require at least CMake 3.0
533if (NOT CMAKE_VERSION VERSION_LESS 3.0)
534 include (CMakePackageConfigHelpers)
535
536 # Imported target support
537 add_library (eigen INTERFACE)
538
539 target_compile_definitions (eigen INTERFACE ${EIGEN_DEFINITIONS})
540 target_include_directories (eigen INTERFACE
541 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
542 $<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
543 )
544
545 # Export as title case Eigen
546 set_target_properties (eigen PROPERTIES EXPORT_NAME Eigen)
547
548 install (TARGETS eigen EXPORT Eigen3Targets)
549
550 configure_package_config_file (
551 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3Config.cmake.in
552 ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
553 PATH_VARS EIGEN_INCLUDE_DIR EIGEN_ROOT_DIR
554 INSTALL_DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}
555 NO_CHECK_REQUIRED_COMPONENTS_MACRO # Eigen does not provide components
556 )
557 # Remove CMAKE_SIZEOF_VOID_P from Eigen3ConfigVersion.cmake since Eigen does
558 # not depend on architecture specific settings or libraries. More
559 # specifically, an Eigen3Config.cmake generated from a 64 bit target can be
560 # used for 32 bit targets as well (and vice versa).
561 set (_Eigen3_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
562 unset (CMAKE_SIZEOF_VOID_P)
563 write_basic_package_version_file (Eigen3ConfigVersion.cmake
564 VERSION ${EIGEN_VERSION_NUMBER}
565 COMPATIBILITY SameMajorVersion)
566 set (CMAKE_SIZEOF_VOID_P ${_Eigen3_CMAKE_SIZEOF_VOID_P})
567
568 # The Eigen target will be located in the Eigen3 namespace. Other CMake
569 # targets can refer to it using Eigen3::Eigen.
570 export (TARGETS eigen NAMESPACE Eigen3:: FILE Eigen3Targets.cmake)
571 # Export Eigen3 package to CMake registry such that it can be easily found by
572 # CMake even if it has not been installed to a standard directory.
573 export (PACKAGE Eigen3)
574
575 install (EXPORT Eigen3Targets NAMESPACE Eigen3:: DESTINATION ${CMAKEPACKAGE_INSTALL_DIR})
576
577else (NOT CMAKE_VERSION VERSION_LESS 3.0)
578 # Fallback to legacy Eigen3Config.cmake without the imported target
579
580 # If CMakePackageConfigHelpers module is available (CMake >= 2.8.8)
581 # create a relocatable Config file, otherwise leave the hardcoded paths
582 include(CMakePackageConfigHelpers OPTIONAL RESULT_VARIABLE CPCH_PATH)
583
584 if(CPCH_PATH)
585 configure_package_config_file (
586 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3ConfigLegacy.cmake.in
587 ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
588 PATH_VARS EIGEN_INCLUDE_DIR EIGEN_ROOT_DIR
589 INSTALL_DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}
590 NO_CHECK_REQUIRED_COMPONENTS_MACRO # Eigen does not provide components
591 )
592 else()
593 # The PACKAGE_* variables are defined by the configure_package_config_file
594 # but without it we define them manually to the hardcoded paths
595 set(PACKAGE_INIT "")
596 set(PACKAGE_EIGEN_INCLUDE_DIR ${EIGEN_INCLUDE_DIR})
597 set(PACKAGE_EIGEN_ROOT_DIR ${EIGEN_ROOT_DIR})
598 configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3ConfigLegacy.cmake.in
599 ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
600 @ONLY ESCAPE_QUOTES )
601 endif()
602
603 write_basic_package_version_file( Eigen3ConfigVersion.cmake
604 VERSION ${EIGEN_VERSION_NUMBER}
605 COMPATIBILITY SameMajorVersion )
606
607endif (NOT CMAKE_VERSION VERSION_LESS 3.0)
608
609install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseEigen3.cmake
610 ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
611 ${CMAKE_CURRENT_BINARY_DIR}/Eigen3ConfigVersion.cmake
612 DESTINATION ${CMAKEPACKAGE_INSTALL_DIR} )
613
614# Add uninstall target
615add_custom_target ( uninstall
616 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/EigenUninstall.cmake)