Skip to content

Commit

Permalink
build: CMake check if Root is compiled with C++17 (#737)
Browse files Browse the repository at this point in the history
This PR introduces a cmake check at configure time, which checks if the Root version works (i.e., if it is compiled with C++17). If not, it causes a compile error related to std::string_view and a kind of root-backport of it. This happens e.g., with the distributed Root version of CentOS 8.
  • Loading branch information
benjaminhuth committed Mar 2, 2021
1 parent ba29171 commit f264087
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ set_option_if(
set_option_if(ACTS_BUILD_PLUGIN_LEGACY ACTS_BUILD_EVERYTHING)
set_option_if(ACTS_BUILD_PLUGIN_AUTODIFF ACTS_BUILD_EVERYTHING)

# feature tests
include(CheckCXXSourceCompiles)

# function that tests if the root installation is compatible (i.e., compiled with C++17)
function(check_root_compatibility)
get_target_property(ROOT_INCLUDE_DIR ROOT::Core INTERFACE_INCLUDE_DIRECTORIES)
set(CMAKE_REQUIRED_FLAGS -std=c++17)
set(CMAKE_REQUIRED_INCLUDES ${ROOT_INCLUDE_DIR})
check_cxx_source_compiles("#include <string>\n#include <TString.h>\nint main(){}" ROOT_COMPATIBILITY_CHECK)
if(NOT ROOT_COMPATIBILITY_CHECK)
message(FATAL_ERROR "Root installation is misconfigured. Ensure that your Root installation was compiled with C++17.")
endif()
endfunction()

# additional configuration and tools
include(GNUInstallDirs) # GNU-like installation paths, e.g. lib/, include/, ...
include(ActsCompilerOptions) # default compile options
Expand Down Expand Up @@ -181,13 +195,15 @@ if(ACTS_BUILD_PLUGIN_SYCL)
endif()
if(ACTS_BUILD_PLUGIN_TGEO)
find_package(ROOT ${_acts_root_version} REQUIRED CONFIG COMPONENTS Geom)
check_root_compatibility()
endif()
# examples dependencies
if(ACTS_BUILD_EXAMPLES)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# for simplicity always request all potentially required components.
find_package(ROOT ${_acts_root_version} REQUIRED CONFIG COMPONENTS Core Geom GenVector Hist Tree TreePlayer)
check_root_compatibility()
# newer DD4hep version require TBB and search interally for TBB in
# config-only mode. to avoid missmatches we explicitely search using
# config-only mode first to be sure that we find the same version.
Expand Down

0 comments on commit f264087

Please sign in to comment.