source: pacpussensors/trunk/Vislab/lib3dv/eigen/CMakeLists.txt@ 141

Last change on this file since 141 was 136, checked in by ldecherf, 8 years ago

Doc

File size: 16.0 KB
Line 
1project(Eigen)
2cmake_minimum_required(VERSION 2.8.5)
3
4# guard against in-source builds
5
6if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
7 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. ")
8endif()
9
10# guard against bad build-type strings
11
12if (NOT CMAKE_BUILD_TYPE)
13 set(CMAKE_BUILD_TYPE "Release")
14endif()
15
16string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
17if( NOT cmake_build_type_tolower STREQUAL "debug"
18 AND NOT cmake_build_type_tolower STREQUAL "release"
19 AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo")
20 message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).")
21endif()
22
23
24#############################################################################
25# retrieve version infomation #
26#############################################################################
27
28# automatically parse the version number
29file(READ "${PROJECT_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header)
30string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}")
31set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}")
32string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}")
33set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}")
34string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}")
35set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}")
36set(EIGEN_VERSION_NUMBER ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})
37
38# if the mercurial program is absent, this will leave the EIGEN_HG_CHANGESET string empty,
39# but won't stop CMake.
40execute_process(COMMAND hg tip -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_HGTIP_OUTPUT)
41execute_process(COMMAND hg branch -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_BRANCH_OUTPUT)
42
43# if this is the default (aka development) branch, extract the mercurial changeset number from the hg tip output...
44if(EIGEN_BRANCH_OUTPUT MATCHES "default")
45string(REGEX MATCH "^changeset: *[0-9]*:([0-9;a-f]+).*" EIGEN_HG_CHANGESET_MATCH "${EIGEN_HGTIP_OUTPUT}")
46set(EIGEN_HG_CHANGESET "${CMAKE_MATCH_1}")
47endif(EIGEN_BRANCH_OUTPUT MATCHES "default")
48#...and show it next to the version number
49if(EIGEN_HG_CHANGESET)
50 set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (mercurial changeset ${EIGEN_HG_CHANGESET})")
51else(EIGEN_HG_CHANGESET)
52 set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}")
53endif(EIGEN_HG_CHANGESET)
54
55
56include(CheckCXXCompilerFlag)
57include(GNUInstallDirs)
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
108set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320")
109
110macro(ei_add_cxx_compiler_flag FLAG)
111 string(REGEX REPLACE "-" "" SFLAG ${FLAG})
112 check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG})
113 if(COMPILER_SUPPORT_${SFLAG})
114 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
115 endif()
116endmacro(ei_add_cxx_compiler_flag)
117
118if(NOT MSVC)
119 # We assume that other compilers are partly compatible with GNUCC
120
121 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
122 set(CMAKE_CXX_FLAGS_DEBUG "-g3")
123 set(CMAKE_CXX_FLAGS_RELEASE "-g0 -O2")
124
125 # clang outputs some warnings for unknwon flags that are not caught by check_cxx_compiler_flag
126 # adding -Werror turns such warnings into errors
127 check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)
128 if(COMPILER_SUPPORT_WERROR)
129 set(CMAKE_REQUIRED_FLAGS "-Werror")
130 endif()
131
132 ei_add_cxx_compiler_flag("-pedantic")
133 ei_add_cxx_compiler_flag("-Wall")
134 ei_add_cxx_compiler_flag("-Wextra")
135 #ei_add_cxx_compiler_flag("-Weverything") # clang
136
137 ei_add_cxx_compiler_flag("-Wundef")
138 ei_add_cxx_compiler_flag("-Wcast-align")
139 ei_add_cxx_compiler_flag("-Wchar-subscripts")
140 ei_add_cxx_compiler_flag("-Wnon-virtual-dtor")
141 ei_add_cxx_compiler_flag("-Wunused-local-typedefs")
142 ei_add_cxx_compiler_flag("-Wpointer-arith")
143 ei_add_cxx_compiler_flag("-Wwrite-strings")
144 ei_add_cxx_compiler_flag("-Wformat-security")
145
146 ei_add_cxx_compiler_flag("-Wno-psabi")
147 ei_add_cxx_compiler_flag("-Wno-variadic-macros")
148 ei_add_cxx_compiler_flag("-Wno-long-long")
149
150 ei_add_cxx_compiler_flag("-fno-check-new")
151 ei_add_cxx_compiler_flag("-fno-common")
152 ei_add_cxx_compiler_flag("-fstrict-aliasing")
153 ei_add_cxx_compiler_flag("-wd981") # disable ICC's "operands are evaluated in unspecified order" remark
154 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
155
156 # The -ansi flag must be added last, otherwise it is also used as a linker flag by check_cxx_compiler_flag making it fails
157 # Moreover we should not set both -strict-ansi and -ansi
158 check_cxx_compiler_flag("-strict-ansi" COMPILER_SUPPORT_STRICTANSI)
159 ei_add_cxx_compiler_flag("-Qunused-arguments") # disable clang warning: argument unused during compilation: '-ansi'
160
161 if(COMPILER_SUPPORT_STRICTANSI)
162 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -strict-ansi")
163 else()
164 ei_add_cxx_compiler_flag("-ansi")
165 endif()
166
167 set(CMAKE_REQUIRED_FLAGS "")
168
169 option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
170 if(EIGEN_TEST_SSE2)
171 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
172 message(STATUS "Enabling SSE2 in tests/examples")
173 endif()
174
175 option(EIGEN_TEST_SSE3 "Enable/Disable SSE3 in tests/examples" OFF)
176 if(EIGEN_TEST_SSE3)
177 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
178 message(STATUS "Enabling SSE3 in tests/examples")
179 endif()
180
181 option(EIGEN_TEST_SSSE3 "Enable/Disable SSSE3 in tests/examples" OFF)
182 if(EIGEN_TEST_SSSE3)
183 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3")
184 message(STATUS "Enabling SSSE3 in tests/examples")
185 endif()
186
187 option(EIGEN_TEST_SSE4_1 "Enable/Disable SSE4.1 in tests/examples" OFF)
188 if(EIGEN_TEST_SSE4_1)
189 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
190 message(STATUS "Enabling SSE4.1 in tests/examples")
191 endif()
192
193 option(EIGEN_TEST_SSE4_2 "Enable/Disable SSE4.2 in tests/examples" OFF)
194 if(EIGEN_TEST_SSE4_2)
195 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
196 message(STATUS "Enabling SSE4.2 in tests/examples")
197 endif()
198
199 option(EIGEN_TEST_ALTIVEC "Enable/Disable AltiVec in tests/examples" OFF)
200 if(EIGEN_TEST_ALTIVEC)
201 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec -mabi=altivec")
202 message(STATUS "Enabling AltiVec in tests/examples")
203 endif()
204
205 option(EIGEN_TEST_NEON "Enable/Disable Neon in tests/examples" OFF)
206 if(EIGEN_TEST_NEON)
207 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -mcpu=cortex-a8")
208 message(STATUS "Enabling NEON in tests/examples")
209 endif()
210
211 check_cxx_compiler_flag("-fopenmp" COMPILER_SUPPORT_OPENMP)
212 if(COMPILER_SUPPORT_OPENMP)
213 option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
214 if(EIGEN_TEST_OPENMP)
215 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
216 message(STATUS "Enabling OpenMP in tests/examples")
217 endif()
218 endif()
219
220else(NOT MSVC)
221
222 # C4127 - conditional expression is constant
223 # C4714 - marked as __forceinline not inlined (I failed to deactivate it selectively)
224 # We can disable this warning in the unit tests since it is clear that it occurs
225 # because we are oftentimes returning objects that have a destructor or may
226 # throw exceptions - in particular in the unit tests we are throwing extra many
227 # exceptions to cover indexing errors.
228 # C4505 - unreferenced local function has been removed (impossible to deactive selectively)
229 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /wd4127 /wd4505 /wd4714")
230
231 # replace all /Wx by /W4
232 string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
233
234 check_cxx_compiler_flag("/openmp" COMPILER_SUPPORT_OPENMP)
235 if(COMPILER_SUPPORT_OPENMP)
236 option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
237 if(EIGEN_TEST_OPENMP)
238 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
239 message(STATUS "Enabling OpenMP in tests/examples")
240 endif()
241 endif()
242
243 option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
244 if(EIGEN_TEST_SSE2)
245 if(NOT CMAKE_CL_64)
246 # arch is not supported on 64 bit systems, SSE is enabled automatically.
247 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
248 endif(NOT CMAKE_CL_64)
249 message(STATUS "Enabling SSE2 in tests/examples")
250 endif(EIGEN_TEST_SSE2)
251endif(NOT MSVC)
252
253option(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION "Disable explicit vectorization in tests/examples" OFF)
254option(EIGEN_TEST_X87 "Force using X87 instructions. Implies no vectorization." OFF)
255option(EIGEN_TEST_32BIT "Force generating 32bit code." OFF)
256
257if(EIGEN_TEST_X87)
258 set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION ON)
259 if(CMAKE_COMPILER_IS_GNUCXX)
260 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=387")
261 message(STATUS "Forcing use of x87 instructions in tests/examples")
262 else()
263 message(STATUS "EIGEN_TEST_X87 ignored on your compiler")
264 endif()
265endif()
266
267if(EIGEN_TEST_32BIT)
268 if(CMAKE_COMPILER_IS_GNUCXX)
269 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
270 message(STATUS "Forcing generation of 32-bit code in tests/examples")
271 else()
272 message(STATUS "EIGEN_TEST_32BIT ignored on your compiler")
273 endif()
274endif()
275
276if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
277 add_definitions(-DEIGEN_DONT_VECTORIZE=1)
278 message(STATUS "Disabling vectorization in tests/examples")
279endif()
280
281option(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT "Disable explicit alignment (hence vectorization) in tests/examples" OFF)
282if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT)
283 add_definitions(-DEIGEN_DONT_ALIGN=1)
284 message(STATUS "Disabling alignment in tests/examples")
285endif()
286
287option(EIGEN_TEST_C++0x "Enables all C++0x features." OFF)
288
289include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
290
291# Backward compatibility support for EIGEN_INCLUDE_INSTALL_DIR
292if(EIGEN_INCLUDE_INSTALL_DIR AND NOT INCLUDE_INSTALL_DIR)
293 set(INCLUDE_INSTALL_DIR ${EIGEN_INCLUDE_INSTALL_DIR}
294 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where Eigen header files are installed")
295else()
296 set(INCLUDE_INSTALL_DIR
297 "${CMAKE_INSTALL_INCLUDEDIR}/eigen3"
298 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where Eigen header files are installed"
299 )
300endif()
301
302set(CMAKEPACKAGE_INSTALL_DIR
303 "${CMAKE_INSTALL_LIBDIR}/cmake/eigen3"
304 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where Eigen3Config.cmake is installed"
305 )
306set(PKGCONFIG_INSTALL_DIR
307 "${CMAKE_INSTALL_DATADIR}/pkgconfig"
308 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where eigen3.pc is installed"
309 )
310
311# similar to set_target_properties but append the property instead of overwriting it
312macro(ei_add_target_property target prop value)
313
314 get_target_property(previous ${target} ${prop})
315 # if the property wasn't previously set, ${previous} is now "previous-NOTFOUND" which cmake allows catching with plain if()
316 if(NOT previous)
317 set(previous "")
318 endif(NOT previous)
319 set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}")
320endmacro(ei_add_target_property)
321
322install(FILES
323 signature_of_eigen3_matrix_library
324 DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel
325 )
326
327if(EIGEN_BUILD_PKGCONFIG)
328 configure_file(eigen3.pc.in eigen3.pc @ONLY)
329 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eigen3.pc
330 DESTINATION ${PKGCONFIG_INSTALL_DIR}
331 )
332endif(EIGEN_BUILD_PKGCONFIG)
333
334add_subdirectory(Eigen)
335
336add_subdirectory(doc EXCLUDE_FROM_ALL)
337
338include(EigenConfigureTesting)
339
340# fixme, not sure this line is still needed:
341enable_testing() # must be called from the root CMakeLists, see man page
342
343
344if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
345 add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest
346else()
347 add_subdirectory(test EXCLUDE_FROM_ALL)
348endif()
349
350if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
351 add_subdirectory(blas)
352 add_subdirectory(lapack)
353else()
354 add_subdirectory(blas EXCLUDE_FROM_ALL)
355 add_subdirectory(lapack EXCLUDE_FROM_ALL)
356endif()
357
358add_subdirectory(unsupported)
359
360add_subdirectory(demos EXCLUDE_FROM_ALL)
361
362# must be after test and unsupported, for configuring buildtests.in
363add_subdirectory(scripts EXCLUDE_FROM_ALL)
364
365# TODO: consider also replacing EIGEN_BUILD_BTL by a custom target "make btl"?
366if(EIGEN_BUILD_BTL)
367 add_subdirectory(bench/btl EXCLUDE_FROM_ALL)
368endif(EIGEN_BUILD_BTL)
369
370if(NOT WIN32)
371 add_subdirectory(bench/spbench EXCLUDE_FROM_ALL)
372endif(NOT WIN32)
373
374configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY)
375
376ei_testing_print_summary()
377
378message(STATUS "")
379message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
380message(STATUS "")
381
382option(EIGEN_FAILTEST "Enable failtests." OFF)
383if(EIGEN_FAILTEST)
384 add_subdirectory(failtest)
385endif()
386
387string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
388if(cmake_generator_tolower MATCHES "makefile")
389 message(STATUS "Some things you can do now:")
390 message(STATUS "--------------+--------------------------------------------------------------")
391 message(STATUS "Command | Description")
392 message(STATUS "--------------+--------------------------------------------------------------")
393 message(STATUS "make install | Install Eigen. Headers will be installed to:")
394 message(STATUS " | <CMAKE_INSTALL_PREFIX>/<INCLUDE_INSTALL_DIR>")
395 message(STATUS " | Using the following values:")
396 message(STATUS " | CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
397 message(STATUS " | INCLUDE_INSTALL_DIR: ${INCLUDE_INSTALL_DIR}")
398 message(STATUS " | Change the install location of Eigen headers using:")
399 message(STATUS " | cmake . -DCMAKE_INSTALL_PREFIX=yourprefix")
400 message(STATUS " | Or:")
401 message(STATUS " | cmake . -DINCLUDE_INSTALL_DIR=yourdir")
402 message(STATUS "make doc | Generate the API documentation, requires Doxygen & LaTeX")
403 message(STATUS "make check | Build and run the unit-tests. Read this page:")
404 message(STATUS " | http://eigen.tuxfamily.org/index.php?title=Tests")
405 message(STATUS "make blas | Build BLAS library (not the same thing as Eigen)")
406 message(STATUS "--------------+--------------------------------------------------------------")
407else()
408 message(STATUS "To build/run the unit tests, read this page:")
409 message(STATUS " http://eigen.tuxfamily.org/index.php?title=Tests")
410endif()
411
412message(STATUS "")
Note: See TracBrowser for help on using the repository browser.