4 #! \brief Top level %CMake file for the C++QED core component.
6 #! The file has the following structure:
8 cmake_minimum_required (VERSION 2.8.9)
12 #! \name Project variables
15 #! \brief Path to additional CMake modules.
16 set(CPPQED_CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules")
17 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CPPQED_CMAKE_MODULE_PATH})
21 include(FeatureSummary)
25 #! <!--#########################################################-->
26 #! ### Version management
27 #! <!--#########################################################-->
29 #! Set the major, minor and patch version of C++QED (c.f. \ref versioning). The major and minor
30 #! versions end up in the library names of all components. In this section,
31 #! also the ABI version of the library is set (c.f. \ref ABI).
35 #! \name Version variables
39 #! MAJOR - the grand version of C++QED, as in v2
40 set(CPPQED_VERSION_MAJOR 2)
41 #! MINOR - the milestone release, as in v2m9
42 set(CPPQED_VERSION_MINOR 10)
43 #! PATCH - should be increased on every snapshot package release, reset on milestone change
44 set(CPPQED_VERSION_PATCH 2)
45 #! Full C++QED version
47 "${CPPQED_VERSION_MAJOR}.${CPPQED_VERSION_MINOR}.${CPPQED_VERSION_PATCH}")
48 #! MAJOR.MINOR, at the moment mainly distinguishes stable (2.10) from development (2.99)
49 set(CPPQED_ID "${CPPQED_VERSION_MAJOR}.${CPPQED_VERSION_MINOR}")
54 #! \name ABI versioning scheme
56 #! Adopt the shared library versioning scheme of libtool
57 #! - CURRENT - the current ABI version
58 #! - AGE - number of versions backwards that CURRENT is compatible with
59 #! - REVISION - patch revision
63 #! Bugfixes and Patches which do not affect ABI:
64 #! * increase REVISION
66 #! Symbols added to library (i.e. binary compatibility NOT broken):
68 #! * remember to call dh_makeshlibs with -V packagename (>=packageversion) when packaging
70 #! Symbols removed or changed (i.e. binary compatibility broken):
71 #! * set CURRENT -> CURRENT + AGE + 1, reset AGE
73 #! On every change of AGE or CURRENT: reset REVISION
75 #! The library version (.so.X.Y.Z) is `{CURRENT-AGE}.{AGE}.{REVISION}`, here named
76 #! `{ABI_MAJOR}.{ABI_MINOR}.{ABI_MICRO}`. This way it is ensured that ABI_MAJOR only changes
77 #! when binary compatibility is broken.
79 #! The SONAME of the library always is: `libC++QED-${MAJOR_VERSION}.${MINOR_VERSION}.so.${ABI_MAJOR}`
80 #! and the packages are named `libC++QED-${MAJOR_VERSION}.${MINOR_VERSION}-${ABI_MAJOR}[-dev]`
83 #! The current ABI version
84 set(CPPQED_ABI_CURRENT 3)
85 #! number of Versions backwards that CURRENT is compatible with
88 set(CPPQED_ABI_REVISION 0)
89 #! Set to ABI_CURRENT - ABI_AGE
91 math(EXPR CPPQED_ABI_MAJOR "${CPPQED_ABI_CURRENT}-${CPPQED_ABI_AGE}")
93 set(CPPQED_ABI_MINOR "${CPPQED_ABI_AGE}")
94 #! Same as ABI_REVISION
95 set(CPPQED_ABI_MICRO "${CPPQED_ABI_REVISION}")
100 set(CPPQED_VERSION ${CPPQED_VERSION} PARENT_SCOPE)
101 set(CPPQED_VERSION_MAJOR ${CPPQED_VERSION_MAJOR} PARENT_SCOPE)
102 set(CPPQED_VERSION_MINOR ${CPPQED_VERSION_MINOR} PARENT_SCOPE)
103 set(CPPQED_VERSION_PATCH ${CPPQED_VERSION_PATCH} PARENT_SCOPE)
104 set(CPPQED_ID ${CPPQED_ID} PARENT_SCOPE)
105 set(CPPQED_ABI_MAJOR ${CPPQED_ABI_MAJOR} PARENT_SCOPE)
108 #! \name Project options
111 #! Override the git sha commit information with this value. Used in automated builds
112 #! where git is not available.
113 set(GIT_SHA_OVERRIDE "" CACHE STRING "Override the git sha version information.")
118 #! <!--#########################################################-->
119 #! ### Installation directories
120 #! <!--#########################################################-->
122 #! This controls into which sub-directories to put %CMake config files
123 #! and include files when installing.
125 #! \name Project variables
128 #! Sub-directory of `CMAKE_INSTALL_LIBDIR` into which %CMake files are installed.
129 set(CPPQED_CMAKE_SUBDIR "cmake/CPPQED-${CPPQED_ID}")
130 #! Sub-directory of `CMAKE_INSTALL_INCLUDEDIR` into which header files are installed.
131 set(CPPQED_INCLUDE_DIR "CPPQED-${CPPQED_ID}")
132 set(CPPQED_INCLUDE_SUBDIR "${CPPQED_INCLUDE_DIR}/core")
133 if(CPPQED_MONOLITHIC)
134 set(CPPQED_INCLUDE_DIR ${CPPQED_INCLUDE_DIR} PARENT_SCOPE)
135 set(CPPQED_INCLUDE_SUBDIR ${CPPQED_INCLUDE_SUBDIR} PARENT_SCOPE)
142 #! <!--#########################################################-->
143 #! ### Compiler detection
144 #! <!--#########################################################-->
146 #! At the moment g++ >= 4.7 and Clang >= 3.1 is needed for C++11 features.
149 set(CLANG_MINIMAL 3.1)
152 if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS ${GCC_MINIMAL})
153 message(FATAL_ERROR "GCC g++ version >= ${GCC_MINIMAL} needed.")
156 if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS ${CLANG_MINIMAL})
157 message(FATAL_ERROR "Clang version >= ${CLANG_MINIMAL} needed.")
161 #! <!--#########################################################-->
162 #! ### Library detection
163 #! <!--#########################################################-->
165 #! In this section we look for required and optional dependencies.
167 #! \name Project variables
170 #! \brief Dependency libraries of C++QED core which should become direct dependencies of clients of core.
172 #! Obviously this has to include all libraries which contain templates.
174 #! \brief Dependency libraries of C++QED core which are invisible to clients of core.
176 #! Only libraries which are linked in to core completely (e.g. GSL) can be added to this set. Template
177 #! libraries have to become direct dependencies of clients using core.
182 find_package(GSL REQUIRED)
183 include_directories(SYSTEM ${GSL_INCLUDE_DIRS})
185 #! \name Project options
188 #! Switch for boost serialization.
189 option(SERIALIZATION "Boost serialization" ON)
191 set(CPPQED_SERIALIZATION_FOUND 1)
193 set(CPPQED_SERIALIZATION_FOUND 0)
196 #! Switch for FLENS support.
197 option(FLENS "FLENS support" ON)
202 if(NOT BUNDLED_BLITZ)
203 find_package(blitz REQUIRED)
204 set(PUBLIC_LIBS ${PUBLIC_LIBS} ${blitz_LIBRARIES})
205 set(CPPQED_THIRDPARTY_INCLUDE_DIRS ${CPPQED_THIRDPARTY_INCLUDE_DIRS} ${blitz_INCLUDE_DIRS})
207 message(STATUS "Using bundled blitz from ${blitz_LIBRARIES}.")
208 set(PRIVATE_LIBS ${PRIVATE_LIBS} ${blitz_LIBRARIES})
209 include_directories(SYSTEM ${blitz_INCLUDE_DIRS})
211 if( blitz_SERIALIZATION_FOUND )
212 message(STATUS "Blitz++ built with serialization support.")
213 else( blitz_SERIALIZATION_FOUND )
214 message(STATUS "Blitz++ built without serialization support. Please configure blitz with --enable-serialization to enable optional binary statevector output.")
215 set(CPPQED_SERIALIZATION_FOUND 0)
216 endif( blitz_SERIALIZATION_FOUND )
218 # Boost (OPTIONAL_COMPONENTS does not work with Boost find_package)
219 find_package(Boost 1.46.0 REQUIRED)
220 find_package(Boost QUIET COMPONENTS serialization)
222 if( Boost_SERIALIZATION_FOUND )
223 message(STATUS "Boost serialization library found.")
224 else( Boost_SERIALIZATION_FOUND )
225 message(STATUS "Boost serialization library not found.")
226 set(CPPQED_SERIALIZATION_FOUND 0)
227 endif( Boost_SERIALIZATION_FOUND )
228 set(CPPQED_THIRDPARTY_INCLUDE_DIRS ${CPPQED_THIRDPARTY_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
232 if(NOT BUNDLED_FLENS)
235 if( flens_FOUND AND FLENS )
236 include_directories(SYSTEM ${flens_INCLUDE_DIRS})
238 include_directories(SYSTEM ${flens_INCLUDE_DIRS})
239 message(STATUS "Using bundled flens from ${flens_LIBRARIES}.")
241 set(CPPQED_THIRDPARTY_INCLUDE_DIRS ${CPPQED_THIRDPARTY_INCLUDE_DIRS} ${flens_INCLUDE_DIRS})
243 set(CPPQED_FLENS_FOUND 1)
244 else( flens_FOUND AND FLENS )
245 message(STATUS "Flens library not found or disabled, optional flens support disabled.")
246 set(DO_NOT_USE_FLENS ON)
247 set(CPPQED_FLENS_FOUND 0)
248 endif( flens_FOUND AND FLENS )
250 # Check if serialization can be enabled, inform user
251 if( CPPQED_SERIALIZATION_FOUND )
252 message(STATUS "Support for binary statevector output enabled.")
253 set(PUBLIC_LIBS ${PUBLIC_LIBS} ${Boost_SERIALIZATION_LIBRARY})
254 else( CPPQED_SERIALIZATION_FOUND )
255 set(DO_NOT_USE_BOOST_SERIALIZATION ON)
256 message(STATUS "Optional support for binary statevector output disabled.")
257 endif( CPPQED_SERIALIZATION_FOUND )
259 set(PRIVATE_LIBS ${PRIVATE_LIBS} ${GSL_LIBRARIES})
262 #! <!--#########################################################-->
263 #! ### Compiler definitions and `config.h`
264 #! <!--#########################################################-->
266 #! In this section a `config.h` file is generated and saved in the build directory.
267 #! This header files contains preprocessor macros indicating whether FLENS and
268 #! boost serialization is available. C++QED source files can then conditionally
269 #! compile code that depends on these features. The `config.h` file only has to
270 #! be included where it is needed, which is an advantage over using `-D` compiler flags
271 #! (less code has to be recompiled).
273 #! Also in this section, the flag `-DBOOST_RESULT_OF_USE_TR1` is set globally if needed.
274 #! Note that compiler warnings are set as part of CPPQED_SETUP(), which is called in the next section.
277 configure_file(${CPPQED_CMAKE_MODULE_PATH}/config.h.in ${PROJECT_NAME}_config.h)
279 if(Boost_MAJOR_VERSION EQUAL "1" AND Boost_MINOR_VERSION GREATER "51")
280 set(CPPQED_DEFINITIONS ${CPPQED_DEFINITIONS} -DBOOST_RESULT_OF_USE_TR1)
281 message(STATUS "added -DBOOST_RESULT_OF_USE_TR1" )
286 #! <!--#########################################################-->
288 #! <!--#########################################################-->
290 #! This does some initial setup (c.f. CPPQED_SETUP() and generate_version_files()) and then builds
291 #! the source files in the various sub-directories. This is done by trivial `CMakeLists.txt` files
292 #! which only contain calls to create_object_target(). This function also handles the include
293 #! dependencies between directories.
295 #! Then the core library is linked and some properties like VERSION and SOVERSION are set.
296 #! All header files are registered for installation with the help of the function gather_includes().
300 generate_version_files()
302 include_directories(${PROJECT_BINARY_DIR}) # for generated config files
304 # build libC++QEDcore.so
305 set(CORE_SOURCE_DIRS utils quantumdata quantumoperator structure quantumtrajectory composites)
306 set(quantumdata_NEEDS utils)
307 set(quantumoperator_NEEDS quantumdata structure utils)
308 set(structure_NEEDS quantumdata utils)
309 set(quantumtrajectory_NEEDS structure quantumdata utils)
310 set(composites_NEEDS structure quantumdata utils)
311 foreach(d ${CORE_SOURCE_DIRS})
312 add_subdirectory(${d})
314 set(CPPQEDLIB C++QED-${CPPQED_ID})
316 gather_includes(CORE_SOURCE_DIRS)
317 set(GENERATED_SOURCE ${CPPQED_CMAKE_MODULE_PATH}/config.h.in
318 ${CPPQED_CMAKE_MODULE_PATH}/version.h.in
319 ${CPPQED_CMAKE_MODULE_PATH}/version.cc.in
321 add_library(${CPPQEDLIB}
322 SHARED ${PROJECT_BINARY_DIR}/${PROJECT_NAME}_version.cc
323 ${OBJ_TARGETS} ${core_PUBLIC_HEADERS} ${GENERATED_SOURCE})
324 target_link_libraries(${CPPQEDLIB} LINK_PUBLIC ${PUBLIC_LIBS} LINK_PRIVATE ${PRIVATE_LIBS})
325 set_target_properties(${CPPQEDLIB} PROPERTIES
326 PUBLIC_HEADER "${core_PUBLIC_HEADERS}"
327 INSTALL_NAME_DIR ${CMAKE_INSTALL_FULL_LIBDIR}
328 VERSION ${CPPQED_ABI_MAJOR}.${CPPQED_ABI_MINOR}.${CPPQED_ABI_MICRO}
329 SOVERSION ${CPPQED_ABI_MAJOR}
333 #! <!--#########################################################-->
335 #! <!--#########################################################-->
337 #! Call to cppqed_documentation().
339 if(CPPQED_MONOLITHIC)
340 cppqed_documentation(core_ "")
344 #! <!--#########################################################-->
346 #! <!--#########################################################-->
348 #! This section has two tasks: prepare the build tree so that it can be found by
349 #! other projects which have C++QED core as a dependency, and to install all required
350 #! files to the system.
352 install(TARGETS ${CPPQEDLIB}
353 EXPORT CPPQEDcoreTargets
354 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
355 PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CPPQED_INCLUDE_SUBDIR}
359 # Add all targets to the build-tree export set
360 export(TARGETS ${CPPQEDLIB}
361 FILE "${PROJECT_BINARY_DIR}/CPPQEDcoreTargets.cmake")
363 #! \name Project options
366 #! Enable or disable %CMake registry (c.f. \ref cmake_find_components).
367 option(REGISTRY "Register build trees in the cmake registry so that other projects can find them." ON)
370 export(PACKAGE CPPQED)
373 # Create the CPPQEDConfig.cmake
374 # ... for the build tree
375 set(CONF_INCLUDE_DIRS "${PROJECT_BINARY_DIR}")
376 foreach(d ${CORE_SOURCE_DIRS})
377 set(CONF_INCLUDE_DIRS ${CONF_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/${d})
379 set(CONF_SPECIAL_LIBRARIES ${blitz_LIBRARIES})
381 set(CPPQED_THIRDPARTY_INCLUDE_DIRS ${CPPQED_THIRDPARTY_INCLUDE_DIRS} ${blitz_INCLUDE_DIRS})
383 if(FLENS AND flens_FOUND)
385 set(CPPQED_THIRDPARTY_INCLUDE_DIRS ${CPPQED_THIRDPARTY_INCLUDE_DIRS} ${flens_INCLUDE_DIRS})
387 set(CONF_SPECIAL_LIBRARIES ${CONF_SPECIAL_LIBRARIES} ${flens_LIBRARIES})
389 set(CONF_CMAKE_DIR ${PROJECT_BINARY_DIR})
390 set(CONF_FLAT_INCLUDE 0)
391 configure_package_config_file(CPPQEDConfig.cmake.in "${PROJECT_BINARY_DIR}/CPPQEDConfig.cmake"
392 INSTALL_DESTINATION "${PROJECT_BINARY_DIR}"
393 PATH_VARS CONF_INCLUDE_DIRS CPPQED_THIRDPARTY_INCLUDE_DIRS CONF_CMAKE_DIR CONF_SPECIAL_LIBRARIES
395 write_basic_package_version_file(${PROJECT_BINARY_DIR}/CPPQEDConfigVersion.cmake
396 VERSION ${CPPQED_VERSION_MAJOR}.${CPPQED_VERSION_MINOR}
397 COMPATIBILITY ExactVersion
399 foreach(c CPPQEDUse.cmake ElementsTemplateConfig.cmake.in
400 GetGitRevisionDescription.cmake GetGitRevisionDescription.cmake.in
401 version.cc.in version.h.in component_versions.cc.in component_versions.h.in)
402 configure_file(cmake/Modules/${c} ${PROJECT_BINARY_DIR}/${c} COPYONLY)
405 # ... and for the installation tree
406 set(CONF_INCLUDE_DIRS ${CMAKE_INSTALL_INCLUDEDIR}/${CPPQED_INCLUDE_SUBDIR})
407 set(CONF_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/${CPPQED_CMAKE_SUBDIR})
408 set(CONF_FLAT_INCLUDE 1)
409 if(BUNDLED_BLITZ OR BUNDLED_FLENS)
410 set(CPPQED_THIRDPARTY_INCLUDE_DIRS ${CPPQED_THIRDPARTY_INCLUDE_DIRS} ${BUNDLED_HEADERS})
413 set(CONF_SPECIAL_LIBRARIES ${BUNDLED_BLITZ_INSTALLED_LIBRARY})
415 set(CONF_SPECIAL_LIBRARIES ${blitz_LIBRARIES})
417 if(FLENS AND flens_FOUND)
419 set(CONF_SPECIAL_LIBRARIES ${CONF_SPECIAL_LIBRARIES} ${BUNDLED_FLENS_INSTALLED_LIBRARY})
421 set(CONF_SPECIAL_LIBRARIES ${CONF_SPECIAL_LIBRARIES} ${flens_LIBRARIES})
424 configure_package_config_file(CPPQEDConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CPPQEDConfig.cmake"
425 INSTALL_DESTINATION "${CONF_CMAKE_DIR}"
426 PATH_VARS CONF_INCLUDE_DIRS CPPQED_THIRDPARTY_INCLUDE_DIRS CONF_CMAKE_DIR CONF_SPECIAL_LIBRARIES
429 # Install the CPPQEDConfig.cmake and CPPQEDConfigVersion.cmake
431 "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CPPQEDConfig.cmake"
432 "${PROJECT_BINARY_DIR}/CPPQEDConfigVersion.cmake"
433 "${PROJECT_BINARY_DIR}/CPPQEDUse.cmake"
434 "${PROJECT_BINARY_DIR}/ElementsTemplateConfig.cmake.in"
435 "${PROJECT_BINARY_DIR}/GetGitRevisionDescription.cmake"
436 "${PROJECT_BINARY_DIR}/GetGitRevisionDescription.cmake.in"
437 "${PROJECT_BINARY_DIR}/version.h.in"
438 "${PROJECT_BINARY_DIR}/version.cc.in"
439 "${PROJECT_BINARY_DIR}/component_versions.h.in"
440 "${PROJECT_BINARY_DIR}/component_versions.cc.in"
441 DESTINATION "${CMAKE_INSTALL_LIBDIR}/${CPPQED_CMAKE_SUBDIR}" COMPONENT dev)
443 # Install the export set for use with the install-tree
444 install(EXPORT CPPQEDcoreTargets DESTINATION
445 "${CMAKE_INSTALL_LIBDIR}/${CPPQED_CMAKE_SUBDIR}" COMPONENT dev)
449 #! <!--#########################################################-->
450 #! ### Compile extras
451 #! <!--#########################################################-->
453 #! Compile the example code documented \ref structurebundleguide "here".
455 add_subdirectory(examples)
458 #! <!--#########################################################-->
459 #! ### Summary of enabled/disabled features
460 #! <!--#########################################################-->
462 #! Display some nice summary of which components have been found and which not.
464 set_package_properties(PkgConfig PROPERTIES URL "http://pkgconfig.freedesktop.org/wiki"
465 DESCRIPTION "Package config system that manages compile/link flags"
467 PURPOSE "Assists cmake in finding libraries.")
468 set_package_properties(blitz PROPERTIES URL "http://sf.net/projects/blitz/"
469 DESCRIPTION "High-performance C++ vector mathematics library"
471 PURPOSE "Multi-Array implementation used in the framework.")
472 set_package_properties(flens PROPERTIES URL "http://flens.sourceforge.net"
473 DESCRIPTION "Flexible Library for Efficient Numerical Solutions."
475 PURPOSE "With FLENS the negativity of the partially transposed density operator can be calculated.")
476 set_package_properties(Boost PROPERTIES URL "http://www.boost.org/"
477 DESCRIPTION "Collection of portable C++ source libraries."
479 PURPOSE "Advanced template metaprogramming and preprocessor algorithms.")
480 set_package_properties(GSL PROPERTIES URL "http://www.gnu.org/software/gsl/"
481 DESCRIPTION "GNU Scientific Library"
483 PURPOSE "Used as implementation of an ODE solver and random number generator.")
484 set_package_properties(Doxygen PROPERTIES URL "http://www.doxygen.org/"
485 DESCRIPTION "Generate documentation from source code"
487 PURPOSE "Generation of API documentation.")
488 add_feature_info("FLENS" CPPQED_FLENS_FOUND "compile framework with FLENS support.")
489 add_feature_info("Serialization" CPPQED_SERIALIZATION_FOUND "needed for binary statevector output." )
490 if(NOT ${CPPQED_MONOLITHIC})
491 feature_summary( WHAT ALL )