Commit 9b3d60d0 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Build system: always chose the C++ version ROOT is built against

parent 8c46b2b9
Loading
Loading
Loading
Loading
+36 −31
Original line number Diff line number Diff line
@@ -178,6 +178,34 @@ ENDIF()
# We need PkgConfig for some dependencies:
FIND_PACKAGE(PkgConfig REQUIRED)


#################################
# Figure out ROOT's C++ version #
#################################

FIND_PACKAGE(ROOT REQUIRED COMPONENTS Geom Core GenVector Hist RIO NO_MODULE)
IF(NOT ROOT_FOUND)
    MESSAGE(FATAL_ERROR "Could not find ROOT, make sure to source the ROOT environment\n"
                        "$ source YOUR_ROOT_DIR/bin/thisroot.sh")
ENDIF()

# Check which C++ version ROOT was built against
IF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+2[0a].*")
    SET(ROOT_CXX_STD 20)
ELSEIF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+1[7z].*")
    SET(ROOT_CXX_STD 17)
ELSEIF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+.*")
    MESSAGE(FATAL_ERROR "ROOT was built with an unsupported C++ version, at least C++17 is required: ${ROOT_CXX_FLAGS}")
ELSE()
    MESSAGE(FATAL_ERROR "Could not deduce ROOT's C++ version from build flags: ${ROOT_CXX_FLAGS}")
ENDIF()

# Check ROOT version
IF(NOT ${ROOT_VERSION} VERSION_GREATER "6.0")
    MESSAGE(FATAL_ERROR "ROOT versions below 6.0 are not supported")
ENDIF()


###################################
# Define build flags for allpix   #
###################################
@@ -226,14 +254,18 @@ IF(CCACHE_FOUND)
        CACHE PATH "CCache program" FORCE)
ENDIF()

# Require C++17
# Require C++17 or C++20
CHECK_CXX_COMPILER_FLAG(-std=c++17 SUPPORT_STD_CXX17)
CHECK_CXX_COMPILER_FLAG(-std=c++20 SUPPORT_STD_CXX20)
IF(NOT SUPPORT_STD_CXX17)
    MESSAGE(FATAL_ERROR "Compiler does not support required standard C++17")
IF(ROOT_CXX_STD EQUAL 20 AND NOT SUPPORT_STD_CXX20)
    MESSAGE(FATAL_ERROR "Compiler does not support standard required by ROOT: C++20")
ELSEIF(ROOT_CXX_STD EQUAL 17 AND NOT SUPPORT_STD_CXX17)
    MESSAGE(FATAL_ERROR "Compiler does not support standard required by ROOT: C++17")
ENDIF()

SET(CMAKE_CXX_STANDARD 17)
# Build with C++20 or C++17
SET(CMAKE_CXX_STANDARD "${ROOT_CXX_STD}")
MESSAGE(STATUS "Building against C++ version ${CMAKE_CXX_STANDARD}")
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)

@@ -293,33 +325,6 @@ SET(ALLPIX_BUILD_GEANT4_INTERFACE
    "OFF"
    CACHE BOOL "Build Geant4 interface library" FORCE)

# ROOT is required for vector and persistency etc
FIND_PACKAGE(ROOT REQUIRED COMPONENTS Geom Core GenVector Hist RIO NO_MODULE)
IF(NOT ROOT_FOUND)
    MESSAGE(FATAL_ERROR "Could not find ROOT, make sure to source the ROOT environment\n"
                        "$ source YOUR_ROOT_DIR/bin/thisroot.sh")
ENDIF()

# Downgrade to C++14 if ROOT is not build with C++17 support
IF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+2[0a].*")
    IF(NOT SUPPORT_STD_CXX20)
        MESSAGE(FATAL_ERROR "ROOT was built with C++20 support but current compiler doesn't support it")
    ENDIF()
ELSEIF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+1[7z].*")
    IF(NOT SUPPORT_STD_CXX17)
        MESSAGE(FATAL_ERROR "ROOT was built with C++17 support but current compiler doesn't support it")
    ENDIF()
ELSEIF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+.*")
    MESSAGE(FATAL_ERROR "ROOT was built with an unsupported C++ version, C++17 is required: ${ROOT_CXX_FLAGS}")
ELSE()
    MESSAGE(FATAL_ERROR "Could not deduce ROOT's C++ version from build flags: ${ROOT_CXX_FLAGS}")
ENDIF()

# Check ROOT version
IF(NOT ${ROOT_VERSION} VERSION_GREATER "6.0")
    MESSAGE(FATAL_ERROR "ROOT versions below 6.0 are not supported")
ENDIF()

# Prepare ROOT Targets if necessary:
ALLPIX_SETUP_ROOT_TARGETS()