Skip to content

Commit

Permalink
Merge pull request eudaq#752 from arummler/fix-root-ver
Browse files Browse the repository at this point in the history
Fixing root C++ version detection for new root installs.
  • Loading branch information
simonspa authored Jun 19, 2024
2 parents f9a4e73 + 964a164 commit 6276a36
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions cmake/Platform.cmake
Original file line number Diff line number Diff line change
@@ -1,39 +1,60 @@
set_property(GLOBAL PROPERTY CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Check for standard to use
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-std=c++17 SUPPORT_STD_CXX17)
check_cxx_compiler_flag(-std=c++14 SUPPORT_STD_CXX14)

# Check ROOT
set(CMAKE_PREFIX_PATH $ENV{ROOTSYS})
set(ROOT_DIR $ENV{ROOTSYS}/cmake)
find_package(ROOT QUIET)

if(${ROOT_FOUND})
# Check which C++ version ROOT was built against
if(ROOT_USE_FILE)
include(${ROOT_USE_FILE})
endif()
# Downgrade to C++14 if ROOT is not build with C++17 support
IF(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")
IF(ROOT_CXX_STANDARD MATCHES "20")
IF(NOT "cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
MESSAGE(FATAL_ERROR "ROOT was built with C++20 support but current compiler doesn't support it")
ENDIF()
SET(CMAKE_CXX_STANDARD 20)
ELSEIF(ROOT_CXX_STANDARD MATCHES "17")
IF(NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
MESSAGE(FATAL_ERROR "ROOT was built with C++20 support but current compiler doesn't support it")
ENDIF()
SET(CMAKE_CXX_STANDARD 17)
ELSEIF(NOT ROOT_CXX_STANDARD)
#ROOT_CXX_STANDARD does not exist for ROOT versions earlier than 6.30.07.
MESSAGE(WARNING "Could not find ROOT_CXX_STANDARD environment variable. Attempt to deduce from ROOT_CXX_FLAGS")
IF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+2[0a].*")
IF(NOT "cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
MESSAGE(FATAL_ERROR "ROOT was built with C++20 support but current compiler doesn't support it")
ENDIF()
SET(CMAKE_CXX_STANDARD 20)
ELSEIF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+1[7z].*")
IF(NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
MESSAGE(FATAL_ERROR "ROOT was built with C++20 support but current compiler doesn't support it")
ENDIF()
SET(CMAKE_CXX_STANDARD 17)
ELSEIF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+1[14y].*")
IF(NOT "cxx_std_14" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
MESSAGE(FATAL_ERROR "ROOT was built with C++20 support but current compiler doesn't support it")
ENDIF()
SET(CMAKE_CXX_STANDARD 14)
ELSEIF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+.*")
MESSAGE(FATAL_ERROR "ROOT was built with an unsupported C++ version, at least C++14 is required: ${ROOT_CXX_FLAGS}")
ELSE()
MESSAGE(FATAL_ERROR "Could not deduce ROOT's C++ version from build flags: ${ROOT_CXX_FLAGS}")
ENDIF()
ELSEIF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+1[14y].*")
SET(CMAKE_CXX_STANDARD 14)
ELSEIF(ROOT_CXX_FLAGS MATCHES ".*std=c\\+\\+.*")
MESSAGE(FATAL_ERROR "ROOT was built with an unsupported C++ version: ${ROOT_CXX_FLAGS}")
ELSE()
MESSAGE(FATAL_ERROR "Could not deduce ROOT's C++ version from build flags: ${ROOT_CXX_FLAGS}")
MESSAGE(FATAL_ERROR "ROOT was built with an unsupported C++ version, at least C++14 is required: ${ROOT_CXX_STANDARD}")
ENDIF()
else()
# Try activating the highest compiler standard available
if(SUPPORT_STD_CXX17)
if("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_STANDARD 20)
elseif("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_STANDARD 17)
else()
if(SUPPORT_STD_CXX14)
set(CMAKE_CXX_STANDARD 14)
endif()
else("cxx_std_14" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_STANDARD 14)
endif()
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down

0 comments on commit 6276a36

Please sign in to comment.