CMakeLists.txt 24 KB

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