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.

378 lines
15 KiB

  1. project(Eigen)
  2. cmake_minimum_required(VERSION 2.6.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. add_definitions("-DEIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS")
  79. set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320")
  80. if(CMAKE_COMPILER_IS_GNUCXX)
  81. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -fexceptions -fno-check-new -fno-common -fstrict-aliasing")
  82. set(CMAKE_CXX_FLAGS_DEBUG "-g3")
  83. set(CMAKE_CXX_FLAGS_RELEASE "-g0 -O2")
  84. check_cxx_compiler_flag("-Wno-variadic-macros" COMPILER_SUPPORT_WNOVARIADICMACRO)
  85. if(COMPILER_SUPPORT_WNOVARIADICMACRO)
  86. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-variadic-macros")
  87. endif()
  88. check_cxx_compiler_flag("-Wextra" COMPILER_SUPPORT_WEXTRA)
  89. if(COMPILER_SUPPORT_WEXTRA)
  90. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
  91. endif()
  92. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
  93. option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
  94. if(EIGEN_TEST_SSE2)
  95. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
  96. message(STATUS "Enabling SSE2 in tests/examples")
  97. endif()
  98. option(EIGEN_TEST_SSE3 "Enable/Disable SSE3 in tests/examples" OFF)
  99. if(EIGEN_TEST_SSE3)
  100. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
  101. message(STATUS "Enabling SSE3 in tests/examples")
  102. endif()
  103. option(EIGEN_TEST_SSSE3 "Enable/Disable SSSE3 in tests/examples" OFF)
  104. if(EIGEN_TEST_SSSE3)
  105. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3")
  106. message(STATUS "Enabling SSSE3 in tests/examples")
  107. endif()
  108. option(EIGEN_TEST_SSE4_1 "Enable/Disable SSE4.1 in tests/examples" OFF)
  109. if(EIGEN_TEST_SSE4_1)
  110. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
  111. message(STATUS "Enabling SSE4.1 in tests/examples")
  112. endif()
  113. option(EIGEN_TEST_SSE4_2 "Enable/Disable SSE4.2 in tests/examples" OFF)
  114. if(EIGEN_TEST_SSE4_2)
  115. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
  116. message(STATUS "Enabling SSE4.2 in tests/examples")
  117. endif()
  118. option(EIGEN_TEST_ALTIVEC "Enable/Disable AltiVec in tests/examples" OFF)
  119. if(EIGEN_TEST_ALTIVEC)
  120. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec -mabi=altivec")
  121. message(STATUS "Enabling AltiVec in tests/examples")
  122. endif()
  123. option(EIGEN_TEST_NEON "Enable/Disable Neon in tests/examples" OFF)
  124. if(EIGEN_TEST_NEON)
  125. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -mcpu=cortex-a8")
  126. message(STATUS "Enabling NEON in tests/examples")
  127. endif()
  128. check_cxx_compiler_flag("-fopenmp" COMPILER_SUPPORT_OPENMP)
  129. if(COMPILER_SUPPORT_OPENMP)
  130. option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
  131. if(EIGEN_TEST_OPENMP)
  132. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
  133. message(STATUS "Enabling OpenMP in tests/examples")
  134. endif()
  135. endif()
  136. endif(CMAKE_COMPILER_IS_GNUCXX)
  137. if(MSVC)
  138. # C4127 - conditional expression is constant
  139. # C4714 - marked as __forceinline not inlined (I failed to deactivate it selectively)
  140. # We can disable this warning in the unit tests since it is clear that it occurs
  141. # because we are oftentimes returning objects that have a destructor or may
  142. # throw exceptions - in particular in the unit tests we are throwing extra many
  143. # exceptions to cover indexing errors.
  144. # C4505 - unreferenced local function has been removed (impossible to deactive selectively)
  145. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /wd4127 /wd4505 /wd4714")
  146. # replace all /Wx by /W4
  147. string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  148. check_cxx_compiler_flag("/openmp" COMPILER_SUPPORT_OPENMP)
  149. if(COMPILER_SUPPORT_OPENMP)
  150. option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
  151. if(EIGEN_TEST_OPENMP)
  152. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
  153. message(STATUS "Enabling OpenMP in tests/examples")
  154. endif()
  155. endif()
  156. option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
  157. if(EIGEN_TEST_SSE2)
  158. if(NOT CMAKE_CL_64)
  159. # arch is not supported on 64 bit systems, SSE is enabled automatically.
  160. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
  161. endif(NOT CMAKE_CL_64)
  162. message(STATUS "Enabling SSE2 in tests/examples")
  163. endif(EIGEN_TEST_SSE2)
  164. endif(MSVC)
  165. option(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION "Disable explicit vectorization in tests/examples" OFF)
  166. option(EIGEN_TEST_X87 "Force using X87 instructions. Implies no vectorization." OFF)
  167. option(EIGEN_TEST_32BIT "Force generating 32bit code." OFF)
  168. if(EIGEN_TEST_X87)
  169. set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION ON)
  170. if(CMAKE_COMPILER_IS_GNUCXX)
  171. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=387")
  172. message(STATUS "Forcing use of x87 instructions in tests/examples")
  173. else()
  174. message(STATUS "EIGEN_TEST_X87 ignored on your compiler")
  175. endif()
  176. endif()
  177. if(EIGEN_TEST_32BIT)
  178. if(CMAKE_COMPILER_IS_GNUCXX)
  179. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  180. message(STATUS "Forcing generation of 32-bit code in tests/examples")
  181. else()
  182. message(STATUS "EIGEN_TEST_32BIT ignored on your compiler")
  183. endif()
  184. endif()
  185. if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
  186. add_definitions(-DEIGEN_DONT_VECTORIZE=1)
  187. message(STATUS "Disabling vectorization in tests/examples")
  188. endif()
  189. option(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT "Disable explicit alignment (hence vectorization) in tests/examples" OFF)
  190. if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT)
  191. add_definitions(-DEIGEN_DONT_ALIGN=1)
  192. message(STATUS "Disabling alignment in tests/examples")
  193. endif()
  194. option(EIGEN_TEST_C++0x "Enables all C++0x features." OFF)
  195. include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
  196. # the user modifiable install path for header files
  197. set(EIGEN_INCLUDE_INSTALL_DIR ${EIGEN_INCLUDE_INSTALL_DIR} CACHE PATH "The directory where we install the header files (optional)")
  198. # set the internal install path for header files which depends on wether the user modifiable
  199. # EIGEN_INCLUDE_INSTALL_DIR has been set by the user or not.
  200. if(EIGEN_INCLUDE_INSTALL_DIR)
  201. set(INCLUDE_INSTALL_DIR
  202. ${EIGEN_INCLUDE_INSTALL_DIR}
  203. CACHE INTERNAL
  204. "The directory where we install the header files (internal)"
  205. )
  206. else()
  207. set(INCLUDE_INSTALL_DIR
  208. "${CMAKE_INSTALL_PREFIX}/include/eigen3"
  209. CACHE INTERNAL
  210. "The directory where we install the header files (internal)"
  211. )
  212. endif()
  213. # similar to set_target_properties but append the property instead of overwriting it
  214. macro(ei_add_target_property target prop value)
  215. get_target_property(previous ${target} ${prop})
  216. # if the property wasn't previously set, ${previous} is now "previous-NOTFOUND" which cmake allows catching with plain if()
  217. if(NOT previous)
  218. set(previous "")
  219. endif(NOT previous)
  220. set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}")
  221. endmacro(ei_add_target_property)
  222. install(FILES
  223. signature_of_eigen3_matrix_library
  224. DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel
  225. )
  226. if(EIGEN_BUILD_PKGCONFIG)
  227. SET(path_separator ":")
  228. STRING(REPLACE ${path_separator} ";" pkg_config_libdir_search "$ENV{PKG_CONFIG_LIBDIR}")
  229. message(STATUS "searching for 'pkgconfig' directory in PKG_CONFIG_LIBDIR ( $ENV{PKG_CONFIG_LIBDIR} ), ${CMAKE_INSTALL_PREFIX}/share, and ${CMAKE_INSTALL_PREFIX}/lib")
  230. FIND_PATH(pkg_config_libdir pkgconfig ${pkg_config_libdir_search} ${CMAKE_INSTALL_PREFIX}/share ${CMAKE_INSTALL_PREFIX}/lib ${pkg_config_libdir_search})
  231. if(pkg_config_libdir)
  232. SET(pkg_config_install_dir ${pkg_config_libdir})
  233. message(STATUS "found ${pkg_config_libdir}/pkgconfig" )
  234. else(pkg_config_libdir)
  235. SET(pkg_config_install_dir ${CMAKE_INSTALL_PREFIX}/share)
  236. message(STATUS "pkgconfig not found; installing in ${pkg_config_install_dir}" )
  237. endif(pkg_config_libdir)
  238. configure_file(eigen3.pc.in eigen3.pc)
  239. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eigen3.pc
  240. DESTINATION ${pkg_config_install_dir}/pkgconfig
  241. )
  242. endif(EIGEN_BUILD_PKGCONFIG)
  243. add_subdirectory(Eigen)
  244. add_subdirectory(doc EXCLUDE_FROM_ALL)
  245. include(EigenConfigureTesting)
  246. # fixme, not sure this line is still needed:
  247. enable_testing() # must be called from the root CMakeLists, see man page
  248. if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
  249. add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest
  250. else()
  251. add_subdirectory(test EXCLUDE_FROM_ALL)
  252. endif()
  253. if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
  254. add_subdirectory(blas)
  255. add_subdirectory(lapack)
  256. else()
  257. add_subdirectory(blas EXCLUDE_FROM_ALL)
  258. add_subdirectory(lapack EXCLUDE_FROM_ALL)
  259. endif()
  260. add_subdirectory(unsupported)
  261. add_subdirectory(demos EXCLUDE_FROM_ALL)
  262. # must be after test and unsupported, for configuring buildtests.in
  263. add_subdirectory(scripts EXCLUDE_FROM_ALL)
  264. # TODO: consider also replacing EIGEN_BUILD_BTL by a custom target "make btl"?
  265. if(EIGEN_BUILD_BTL)
  266. add_subdirectory(bench/btl EXCLUDE_FROM_ALL)
  267. endif(EIGEN_BUILD_BTL)
  268. if(NOT WIN32)
  269. add_subdirectory(bench/spbench EXCLUDE_FROM_ALL)
  270. endif(NOT WIN32)
  271. ei_testing_print_summary()
  272. message(STATUS "")
  273. message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
  274. message(STATUS "")
  275. option(EIGEN_FAILTEST "Enable failtests." OFF)
  276. if(EIGEN_FAILTEST)
  277. add_subdirectory(failtest)
  278. endif()
  279. string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
  280. if(cmake_generator_tolower MATCHES "makefile")
  281. message(STATUS "Some things you can do now:")
  282. message(STATUS "--------------+--------------------------------------------------------------")
  283. message(STATUS "Command | Description")
  284. message(STATUS "--------------+--------------------------------------------------------------")
  285. message(STATUS "make install | Install to ${CMAKE_INSTALL_PREFIX}. To change that:")
  286. message(STATUS " | cmake . -DCMAKE_INSTALL_PREFIX=yourpath")
  287. message(STATUS " | Eigen headers will then be installed to:")
  288. message(STATUS " | ${INCLUDE_INSTALL_DIR}")
  289. message(STATUS " | To install Eigen headers to a separate location, do:")
  290. message(STATUS " | cmake . -DEIGEN_INCLUDE_INSTALL_DIR=yourpath")
  291. message(STATUS "make doc | Generate the API documentation, requires Doxygen & LaTeX")
  292. message(STATUS "make check | Build and run the unit-tests. Read this page:")
  293. message(STATUS " | http://eigen.tuxfamily.org/index.php?title=Tests")
  294. message(STATUS "make blas | Build BLAS library (not the same thing as Eigen)")
  295. message(STATUS "--------------+--------------------------------------------------------------")
  296. else()
  297. message(STATUS "To build/run the unit tests, read this page:")
  298. message(STATUS " http://eigen.tuxfamily.org/index.php?title=Tests")
  299. endif()
  300. message(STATUS "")