Newer
Older
###########################################################################
# top-level CMakeLists.txt for building BornAgain
############################################################################
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
set(CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/cmake
${CMAKE_SOURCE_DIR}/cmake/find
${CMAKE_SOURCE_DIR}/cmake/pack)
set(CONFIGURABLES_DIR ${CMAKE_SOURCE_DIR}/cmake/configurables)
include(commons/PreventInSourceBuilds)
DESCRIPTION "BornAgain: simulate and fit scattering at grazing incidence."
HOMEPAGE_URL https://www.bornagainproject.org
) # LANGUAGES CXX)
# TODO modernize FindCerf to get rid of AssertLibraryFunction to restore restriction to CXX
set(CMAKE_C_STANDARD 11)
Matthias Puchner
committed
## Show info about generator type; set CMAKE_BUILD_TYPE if not given
if(CMAKE_CONFIGURATION_TYPES)
message(STATUS "Generator type: Multi-configuration generator")
else()
message(STATUS "Generator type: Single-configuration generator")
endif()
message(" CMAKE_CONFIGURATION_TYPES: ${CMAKE_CONFIGURATION_TYPES}")
# The following is not correct/does not have any effect for multi-configuration generators.
Matthias Puchner
committed
# But when correcting this, be aware that CMAKE_BUILD_TYPE is used in more scripts!
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
message(" CMAKE_BUILD_TYPE type not given - forced to 'Release'")
else()
string(TOUPPER "${CMAKE_BUILD_TYPE}" _upper_build_type)
set(BUILD_${_upper_build_type} 1)
Matthias Puchner
committed
endif()
message(" CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
configure_file("${PROJECT_SOURCE_DIR}/cmake/configurables/config_build.h.in"
"${PROJECT_BINARY_DIR}/inc/config_build.h"
@ONLY)
# GoogleTest: `gtest_discover_tests` discovers tests by asking the _compiled test executable_
# to enumerate its tests. `PRE_TEST` delays test discovery until just prior to test execution;
# this avoids calling the executables during the build phase.
set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE PRE_TEST)

Wuttke, Joachim
committed
include(CTest) # equivalent to "enable_testing() ???
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -LE Fullcheck)
# => 'make check' is an alias for 'ctest'
add_custom_target(fullcheck COMMAND ${CMAKE_CTEST_COMMAND})
# => 'make check' is an alias for 'ctest'
# options that are on by default (switch off for accelerated builds of limited scope)
option(BORNAGAIN_PYTHON "Build with python support" ON)
option(BORNAGAIN_GUI "Build a graphical user interface" ON)
option(BORNAGAIN_TIFF_SUPPORT "Tiff files read/write support" ON)
# options that are off by default (switch on for additional functionality)
option(BORNAGAIN_MPI "Build with MPI support" OFF)
option(CONFIGURE_BINDINGS "Generate python bindings during build (requires swig)" OFF)
option(CONFIGURE_PYTHON_DOCS "Generate python documentation from the doxygen comments" OFF)
option(CONFIGURE_MANPAGE "Build Unix man page" OFF)
option(CONFIGURE_DOXY "Configure Doxygen files" OFF)
option(ALLCONFIG "Regenerate Py docs, Py wrappers, man page, Doxyfiles" OFF)
option(BORNAGAIN_APPLE_BUNDLE "Create a Mac OS X bundle" OFF)
option(ZERO_TOLERANCE "Terminate compilation on warnings" OFF)
option(BORNAGAIN_COVERAGE "Build with test coverage information" OFF)
option(BORNAGAIN_DEBUG_OPTIMIZATION "Build with debug optimization (gcc only)" OFF)
option(BORNAGAIN_TIDY "Invokes clang-tidy" OFF)
option(ALGORITHM_DIAGNOSTIC "Let some algorithms set diagnostic variables" OFF)
Ganeva, Marina
committed
# note on two non-options:
# macro SWIG is defined when code is processed by the tool Swig.
# macros SWIG and USER_API are set by Doc/Doxygen/user/Doxyfile.in
if(BORNAGAIN_TIDY AND BORNAGAIN_PYTHON)
message(FATAL_ERROR "BORNAGAIN_TIDY is incompatible with BORNAGAIN_PYTHON")
endif()
if(BORNAGAIN_GUI AND NOT BORNAGAIN_PYTHON AND NOT BORNAGAIN_TIDY)
message(FATAL_ERROR "BORNAGAIN_GUI without BORNAGAIN_PYTHON is currently unsupported"
" (except with BORNAGAIN_TIDY)")
endif()
if(ALLCONFIG)
set(CONFIGURE_MANPAGE ON)
set(CONFIGURE_PYTHON_DOCS ON)
set(CONFIGURE_BINDINGS ON)
set(CONFIGURE_DOXY ON)

Wuttke, Joachim
committed
endif()
## Various CMake settings (include order is of critical importance)
# function definitions
include(commons/GetFilenameComponent) # fct get_filename_component (overwrites CMake's built-in)
include(BornAgain/PythonDocs) # fct GeneratePythonDocs
include(BornAgain/SwigLib) # fct SwigLib
include(BornAgain/MakeLib) # fct MakeLib
include(BornAgain/Directories)
if(UNIX)
if(CMAKE_SYSTEM_NAME MATCHES Linux)
include(BornAgain/Linux)
elseif(APPLE)
include(BornAgain/MacOS)
else()
message(FATAL_ERROR "Operating system ${CMAKE_SYSTEM_NAME} not supported")
endif()
elseif(WIN32)
include(BornAgain/Windows)
else()
message(FATAL_ERROR "Operating system ${CMAKE_SYSTEM_NAME} is neither UNIX nor WIN32")
endif()
include(BornAgain/Compiler)
if(ZERO_TOLERANCE)
string(APPEND CMAKE_CXX_FLAGS " -Werror -Wfatal-errors")
if(ALGORITHM_DIAGNOSTIC)
string(APPEND CMAKE_CXX_FLAGS " -DALGORITHM_DIAGNOSTIC=ON")
endif()
include(BornAgain/Dependences)
string(APPEND CMAKE_CXX_FLAGS " -DHAVE_QT=ON")
if(BORNAGAIN_PYTHON)
include(BornAgain/PythonAPI)
endif()
# debug optimization
if(BORNAGAIN_DEBUG_OPTIMIZATION)
include(commons/DebugOptimization)
add_subdirectory(Fit/3rdparty)
add_subdirectory(Fit)
add_subdirectory(Fit/Test/Unit)
add_subdirectory(Fit/Test/Functional)
## recurse into the given subdirectories
set(CoreComponents "Base;Param;Sample;Resample;Device;Core")
set(AllComponents "${CoreComponents};GUI")
# code analysis
include(BornAgain/LineLength)
include(commons/CoverageFunction)
include(BornAgain/Coverage)
add_subdirectory(3rdparty/common)
add_subdirectory(3rdparty/Core)
add_subdirectory(3rdparty/GUI/qcustomplot)
# from here on our own code, occasionally scrutinized by clang-tidy
set(CMAKE_CXX_CLANG_TIDY "clang-tidy") # has effect only if compiler is clang; uses .clang-tidy
# core components
foreach(lib ${CoreComponents})
add_subdirectory(${lib})
endforeach()
if(BORNAGAIN_PYTHON)
add_dependencies(BornAgainFit swig_runtime)
endif()
add_subdirectory(Tests/Unit/Param)
add_subdirectory(Tests/Unit/Sample)
add_subdirectory(Tests/Unit/Device)
add_subdirectory(Tests/Unit/Resample)
add_subdirectory(Tests/Unit/Core)
add_subdirectory(Tests/Unit/Numeric)
if(BORNAGAIN_GUI)
add_subdirectory(Tests/Functional)
# documentation
if(BORNAGAIN_USERMANUAL)
add_subdirectory(Doc/UserManual)
endif()
if(CONFIGURE_MANPAGE)
add_subdirectory(Doc/man)
endif()
if(CONFIGURE_DOXY)
add_subdirectory(Doc/Doxygen)
endif()
# make package targets
message(STATUS "CMake done")