You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

420 lines
16 KiB

  1. project(Eigen)
  2. cmake_minimum_required(VERSION 2.8.2)
  3. # guard against in-source builds
  4. if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
  5. 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. ")
  6. endif()
  7. # guard against bad build-type strings
  8. if (NOT CMAKE_BUILD_TYPE)
  9. set(CMAKE_BUILD_TYPE "Release")
  10. endif()
  11. string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
  12. if( NOT cmake_build_type_tolower STREQUAL "debug"
  13. AND NOT cmake_build_type_tolower STREQUAL "release"
  14. AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo")
  15. message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).")
  16. endif()
  17. #############################################################################
  18. # retrieve version infomation #
  19. #############################################################################
  20. # automatically parse the version number
  21. file(READ "${PROJECT_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header)
  22. string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}")
  23. set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}")
  24. string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}")
  25. set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}")
  26. string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}")
  27. set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}")
  28. set(EIGEN_VERSION_NUMBER ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})
  29. # if the mercurial program is absent, this will leave the EIGEN_HG_CHANGESET string empty,
  30. # but won't stop CMake.
  31. execute_process(COMMAND hg tip -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_HGTIP_OUTPUT)
  32. execute_process(COMMAND hg branch -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_BRANCH_OUTPUT)
  33. # if this is the default (aka development) branch, extract the mercurial changeset number from the hg tip output...
  34. if(EIGEN_BRANCH_OUTPUT MATCHES "default")
  35. string(REGEX MATCH "^changeset: *[0-9]*:([0-9;a-f]+).*" EIGEN_HG_CHANGESET_MATCH "${EIGEN_HGTIP_OUTPUT}")
  36. set(EIGEN_HG_CHANGESET "${CMAKE_MATCH_1}")
  37. endif(EIGEN_BRANCH_OUTPUT MATCHES "default")
  38. #...and show it next to the version number
  39. if(EIGEN_HG_CHANGESET)
  40. set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (mercurial changeset ${EIGEN_HG_CHANGESET})")
  41. else(EIGEN_HG_CHANGESET)
  42. set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}")
  43. endif(EIGEN_HG_CHANGESET)
  44. include(CheckCXXCompilerFlag)
  45. set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
  46. #############################################################################
  47. # find how to link to the standard libraries #
  48. #############################################################################
  49. find_package(StandardMathLibrary)
  50. set(EIGEN_TEST_CUSTOM_LINKER_FLAGS "" CACHE STRING "Additional linker flags when linking unit tests.")
  51. set(EIGEN_TEST_CUSTOM_CXX_FLAGS "" CACHE STRING "Additional compiler flags when compiling unit tests.")
  52. set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "")
  53. if(NOT STANDARD_MATH_LIBRARY_FOUND)
  54. message(FATAL_ERROR
  55. "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.")
  56. else()
  57. if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
  58. set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}")
  59. else()
  60. set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}")
  61. endif()
  62. endif()
  63. if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
  64. message(STATUS "Standard libraries to link to explicitly: ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}")
  65. else()
  66. message(STATUS "Standard libraries to link to explicitly: none")
  67. endif()
  68. option(EIGEN_BUILD_BTL "Build benchmark suite" OFF)
  69. if(NOT WIN32)
  70. option(EIGEN_BUILD_PKGCONFIG "Build pkg-config .pc file for Eigen" ON)
  71. endif(NOT WIN32)
  72. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  73. option(EIGEN_SPLIT_LARGE_TESTS "Split large tests into smaller executables" ON)
  74. option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF)
  75. if(EIGEN_DEFAULT_TO_ROW_MAJOR)
  76. add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR")
  77. endif()
  78. set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320")
  79. macro(ei_add_cxx_compiler_flag FLAG)
  80. string(REGEX REPLACE "-" "" SFLAG ${FLAG})
  81. check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG})
  82. if(COMPILER_SUPPORT_${SFLAG})
  83. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
  84. endif()
  85. endmacro(ei_add_cxx_compiler_flag)
  86. if(NOT MSVC)
  87. # We assume that other compilers are partly compatible with GNUCC
  88. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
  89. set(CMAKE_CXX_FLAGS_DEBUG "-g3")
  90. set(CMAKE_CXX_FLAGS_RELEASE "-g0 -O2")
  91. # clang outputs some warnings for unknwon flags that are not caught by check_cxx_compiler_flag
  92. # adding -Werror turns such warnings into errors
  93. check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)
  94. if(COMPILER_SUPPORT_WERROR)
  95. set(CMAKE_REQUIRED_FLAGS "-Werror")
  96. endif()
  97. ei_add_cxx_compiler_flag("-pedantic")
  98. ei_add_cxx_compiler_flag("-Wall")
  99. ei_add_cxx_compiler_flag("-Wextra")
  100. #ei_add_cxx_compiler_flag("-Weverything") # clang
  101. ei_add_cxx_compiler_flag("-Wundef")
  102. ei_add_cxx_compiler_flag("-Wcast-align")
  103. ei_add_cxx_compiler_flag("-Wchar-subscripts")
  104. ei_add_cxx_compiler_flag("-Wnon-virtual-dtor")
  105. ei_add_cxx_compiler_flag("-Wunused-local-typedefs")
  106. ei_add_cxx_compiler_flag("-Wpointer-arith")
  107. ei_add_cxx_compiler_flag("-Wwrite-strings")
  108. ei_add_cxx_compiler_flag("-Wformat-security")
  109. ei_add_cxx_compiler_flag("-Wno-psabi")
  110. ei_add_cxx_compiler_flag("-Wno-variadic-macros")
  111. ei_add_cxx_compiler_flag("-Wno-long-long")
  112. ei_add_cxx_compiler_flag("-fno-check-new")
  113. ei_add_cxx_compiler_flag("-fno-common")
  114. ei_add_cxx_compiler_flag("-fstrict-aliasing")
  115. ei_add_cxx_compiler_flag("-wd981") # disable ICC's "operands are evaluated in unspecified order" remark
  116. ei_add_cxx_compiler_flag("-wd2304") # disbale ICC's "warning #2304: non-explicit constructor with single argument may cause implicit type conversion" produced by -Wnon-virtual-dtor
  117. # The -ansi flag must be added last, otherwise it is also used as a linker flag by check_cxx_compiler_flag making it fails
  118. # Moreover we should not set both -strict-ansi and -ansi
  119. check_cxx_compiler_flag("-strict-ansi" COMPILER_SUPPORT_STRICTANSI)
  120. ei_add_cxx_compiler_flag("-Qunused-arguments") # disable clang warning: argument unused during compilation: '-ansi'
  121. if(COMPILER_SUPPORT_STRICTANSI)
  122. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -strict-ansi")
  123. else()
  124. ei_add_cxx_compiler_flag("-ansi")
  125. endif()
  126. set(CMAKE_REQUIRED_FLAGS "")
  127. option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
  128. if(EIGEN_TEST_SSE2)
  129. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
  130. message(STATUS "Enabling SSE2 in tests/examples")
  131. endif()
  132. option(EIGEN_TEST_SSE3 "Enable/Disable SSE3 in tests/examples" OFF)
  133. if(EIGEN_TEST_SSE3)
  134. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
  135. message(STATUS "Enabling SSE3 in tests/examples")
  136. endif()
  137. option(EIGEN_TEST_SSSE3 "Enable/Disable SSSE3 in tests/examples" OFF)
  138. if(EIGEN_TEST_SSSE3)
  139. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3")
  140. message(STATUS "Enabling SSSE3 in tests/examples")
  141. endif()
  142. option(EIGEN_TEST_SSE4_1 "Enable/Disable SSE4.1 in tests/examples" OFF)
  143. if(EIGEN_TEST_SSE4_1)
  144. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
  145. message(STATUS "Enabling SSE4.1 in tests/examples")
  146. endif()
  147. option(EIGEN_TEST_SSE4_2 "Enable/Disable SSE4.2 in tests/examples" OFF)
  148. if(EIGEN_TEST_SSE4_2)
  149. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
  150. message(STATUS "Enabling SSE4.2 in tests/examples")
  151. endif()
  152. option(EIGEN_TEST_ALTIVEC "Enable/Disable AltiVec in tests/examples" OFF)
  153. if(EIGEN_TEST_ALTIVEC)
  154. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec -mabi=altivec")
  155. message(STATUS "Enabling AltiVec in tests/examples")
  156. endif()
  157. option(EIGEN_TEST_NEON "Enable/Disable Neon in tests/examples" OFF)
  158. if(EIGEN_TEST_NEON)
  159. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -mcpu=cortex-a8")
  160. message(STATUS "Enabling NEON in tests/examples")
  161. endif()
  162. check_cxx_compiler_flag("-fopenmp" COMPILER_SUPPORT_OPENMP)
  163. if(COMPILER_SUPPORT_OPENMP)
  164. option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
  165. if(EIGEN_TEST_OPENMP)
  166. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
  167. message(STATUS "Enabling OpenMP in tests/examples")
  168. endif()
  169. endif()
  170. else(NOT MSVC)
  171. # C4127 - conditional expression is constant
  172. # C4714 - marked as __forceinline not inlined (I failed to deactivate it selectively)
  173. # We can disable this warning in the unit tests since it is clear that it occurs
  174. # because we are oftentimes returning objects that have a destructor or may
  175. # throw exceptions - in particular in the unit tests we are throwing extra many
  176. # exceptions to cover indexing errors.
  177. # C4505 - unreferenced local function has been removed (impossible to deactive selectively)
  178. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /wd4127 /wd4505 /wd4714")
  179. # replace all /Wx by /W4
  180. string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  181. check_cxx_compiler_flag("/openmp" COMPILER_SUPPORT_OPENMP)
  182. if(COMPILER_SUPPORT_OPENMP)
  183. option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
  184. if(EIGEN_TEST_OPENMP)
  185. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
  186. message(STATUS "Enabling OpenMP in tests/examples")
  187. endif()
  188. endif()
  189. option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
  190. if(EIGEN_TEST_SSE2)
  191. if(NOT CMAKE_CL_64)
  192. # arch is not supported on 64 bit systems, SSE is enabled automatically.
  193. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
  194. endif(NOT CMAKE_CL_64)
  195. message(STATUS "Enabling SSE2 in tests/examples")
  196. endif(EIGEN_TEST_SSE2)
  197. endif(NOT MSVC)
  198. option(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION "Disable explicit vectorization in tests/examples" OFF)
  199. option(EIGEN_TEST_X87 "Force using X87 instructions. Implies no vectorization." OFF)
  200. option(EIGEN_TEST_32BIT "Force generating 32bit code." OFF)
  201. if(EIGEN_TEST_X87)
  202. set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION ON)
  203. if(CMAKE_COMPILER_IS_GNUCXX)
  204. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=387")
  205. message(STATUS "Forcing use of x87 instructions in tests/examples")
  206. else()
  207. message(STATUS "EIGEN_TEST_X87 ignored on your compiler")
  208. endif()
  209. endif()
  210. if(EIGEN_TEST_32BIT)
  211. if(CMAKE_COMPILER_IS_GNUCXX)
  212. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  213. message(STATUS "Forcing generation of 32-bit code in tests/examples")
  214. else()
  215. message(STATUS "EIGEN_TEST_32BIT ignored on your compiler")
  216. endif()
  217. endif()
  218. if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
  219. add_definitions(-DEIGEN_DONT_VECTORIZE=1)
  220. message(STATUS "Disabling vectorization in tests/examples")
  221. endif()
  222. option(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT "Disable explicit alignment (hence vectorization) in tests/examples" OFF)
  223. if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT)
  224. add_definitions(-DEIGEN_DONT_ALIGN=1)
  225. message(STATUS "Disabling alignment in tests/examples")
  226. endif()
  227. option(EIGEN_TEST_C++0x "Enables all C++0x features." OFF)
  228. include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
  229. # the user modifiable install path for header files
  230. set(EIGEN_INCLUDE_INSTALL_DIR ${EIGEN_INCLUDE_INSTALL_DIR} CACHE PATH "The directory where we install the header files (optional)")
  231. # set the internal install path for header files which depends on wether the user modifiable
  232. # EIGEN_INCLUDE_INSTALL_DIR has been set by the user or not.
  233. if(EIGEN_INCLUDE_INSTALL_DIR)
  234. set(INCLUDE_INSTALL_DIR
  235. ${EIGEN_INCLUDE_INSTALL_DIR}
  236. CACHE INTERNAL
  237. "The directory where we install the header files (internal)"
  238. )
  239. else()
  240. set(INCLUDE_INSTALL_DIR
  241. "${CMAKE_INSTALL_PREFIX}/include/eigen3"
  242. CACHE INTERNAL
  243. "The directory where we install the header files (internal)"
  244. )
  245. endif()
  246. # similar to set_target_properties but append the property instead of overwriting it
  247. macro(ei_add_target_property target prop value)
  248. get_target_property(previous ${target} ${prop})
  249. # if the property wasn't previously set, ${previous} is now "previous-NOTFOUND" which cmake allows catching with plain if()
  250. if(NOT previous)
  251. set(previous "")
  252. endif(NOT previous)
  253. set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}")
  254. endmacro(ei_add_target_property)
  255. install(FILES
  256. signature_of_eigen3_matrix_library
  257. DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel
  258. )
  259. if(EIGEN_BUILD_PKGCONFIG)
  260. SET(path_separator ":")
  261. STRING(REPLACE ${path_separator} ";" pkg_config_libdir_search "$ENV{PKG_CONFIG_LIBDIR}")
  262. message(STATUS "searching for 'pkgconfig' directory in PKG_CONFIG_LIBDIR ( $ENV{PKG_CONFIG_LIBDIR} ), ${CMAKE_INSTALL_PREFIX}/share, and ${CMAKE_INSTALL_PREFIX}/lib")
  263. FIND_PATH(pkg_config_libdir pkgconfig ${pkg_config_libdir_search} ${CMAKE_INSTALL_PREFIX}/share ${CMAKE_INSTALL_PREFIX}/lib ${pkg_config_libdir_search})
  264. if(pkg_config_libdir)
  265. SET(pkg_config_install_dir ${pkg_config_libdir})
  266. message(STATUS "found ${pkg_config_libdir}/pkgconfig" )
  267. else(pkg_config_libdir)
  268. SET(pkg_config_install_dir ${CMAKE_INSTALL_PREFIX}/share)
  269. message(STATUS "pkgconfig not found; installing in ${pkg_config_install_dir}" )
  270. endif(pkg_config_libdir)
  271. configure_file(eigen3.pc.in eigen3.pc)
  272. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eigen3.pc
  273. DESTINATION ${pkg_config_install_dir}/pkgconfig
  274. )
  275. endif(EIGEN_BUILD_PKGCONFIG)
  276. add_subdirectory(Eigen)
  277. add_subdirectory(doc EXCLUDE_FROM_ALL)
  278. include(EigenConfigureTesting)
  279. # fixme, not sure this line is still needed:
  280. enable_testing() # must be called from the root CMakeLists, see man page
  281. if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
  282. add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest
  283. else()
  284. add_subdirectory(test EXCLUDE_FROM_ALL)
  285. endif()
  286. if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
  287. add_subdirectory(blas)
  288. add_subdirectory(lapack)
  289. else()
  290. add_subdirectory(blas EXCLUDE_FROM_ALL)
  291. add_subdirectory(lapack EXCLUDE_FROM_ALL)
  292. endif()
  293. add_subdirectory(unsupported)
  294. add_subdirectory(demos EXCLUDE_FROM_ALL)
  295. # must be after test and unsupported, for configuring buildtests.in
  296. add_subdirectory(scripts EXCLUDE_FROM_ALL)
  297. # TODO: consider also replacing EIGEN_BUILD_BTL by a custom target "make btl"?
  298. if(EIGEN_BUILD_BTL)
  299. add_subdirectory(bench/btl EXCLUDE_FROM_ALL)
  300. endif(EIGEN_BUILD_BTL)
  301. if(NOT WIN32)
  302. add_subdirectory(bench/spbench EXCLUDE_FROM_ALL)
  303. endif(NOT WIN32)
  304. configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY)
  305. ei_testing_print_summary()
  306. message(STATUS "")
  307. message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
  308. message(STATUS "")
  309. option(EIGEN_FAILTEST "Enable failtests." OFF)
  310. if(EIGEN_FAILTEST)
  311. add_subdirectory(failtest)
  312. endif()
  313. string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
  314. if(cmake_generator_tolower MATCHES "makefile")
  315. message(STATUS "Some things you can do now:")
  316. message(STATUS "--------------+--------------------------------------------------------------")
  317. message(STATUS "Command | Description")
  318. message(STATUS "--------------+--------------------------------------------------------------")
  319. message(STATUS "make install | Install to ${CMAKE_INSTALL_PREFIX}. To change that:")
  320. message(STATUS " | cmake . -DCMAKE_INSTALL_PREFIX=yourpath")
  321. message(STATUS " | Eigen headers will then be installed to:")
  322. message(STATUS " | ${INCLUDE_INSTALL_DIR}")
  323. message(STATUS " | To install Eigen headers to a separate location, do:")
  324. message(STATUS " | cmake . -DEIGEN_INCLUDE_INSTALL_DIR=yourpath")
  325. message(STATUS "make doc | Generate the API documentation, requires Doxygen & LaTeX")
  326. message(STATUS "make check | Build and run the unit-tests. Read this page:")
  327. message(STATUS " | http://eigen.tuxfamily.org/index.php?title=Tests")
  328. message(STATUS "make blas | Build BLAS library (not the same thing as Eigen)")
  329. message(STATUS "--------------+--------------------------------------------------------------")
  330. else()
  331. message(STATUS "To build/run the unit tests, read this page:")
  332. message(STATUS " http://eigen.tuxfamily.org/index.php?title=Tests")
  333. endif()
  334. message(STATUS "")