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