From d487a42b311c5d0c7544031e3071a388c488c429 Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Tue, 16 Jan 2024 10:10:48 +0100 Subject: [PATCH] [cmake] Set CMAKE_CXX_STANDARD explicitly in RootUseFile.cmake Closes #6384, --------- Co-authored-by: Jonas Rembser --- CMakeLists.txt | 26 ++++++++++++++++---------- cmake/modules/CheckCompiler.cmake | 11 ----------- cmake/modules/RootConfiguration.cmake | 5 ++++- cmake/modules/RootMacros.cmake | 4 ---- cmake/scripts/RootUseFile.cmake.in | 1 + config/root-config.in | 6 +++++- 6 files changed, 26 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f09f0c84bb199..078998c130686 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -757,18 +757,24 @@ endif() cmake_host_system_information(RESULT PROCESSOR QUERY PROCESSOR_DESCRIPTION) message(STATUS "ROOT Configuration \n -System ${CMAKE_SYSTEM} -Processor ${PROCESSOR} (${CMAKE_SYSTEM_PROCESSOR}) -Build type ${CMAKE_BUILD_TYPE} -Install path ${CMAKE_INSTALL_PREFIX} -Compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} +System: ${CMAKE_SYSTEM} +ROOT Platform: ${ROOT_PLATFORM} +ROOT Architecture: ${ROOT_ARCHITECTURE} +Processor: ${PROCESSOR} (${CMAKE_SYSTEM_PROCESSOR}) +Build type: ${CMAKE_BUILD_TYPE} +Install path: ${CMAKE_INSTALL_PREFIX} +Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} +C++ standard: ${CMAKE_CXX_STANDARD} Compiler flags: -C ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_BUILD_TYPE_UPPER}} -C++ ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_BUILD_TYPE_UPPER}} + - C: ${CMAKE_C_FLAGS} + - C (built type specific): ${CMAKE_C_FLAGS_${_BUILD_TYPE_UPPER}} + - C++: ${CMAKE_CXX_FLAGS} + - C++ (built type specific): ${CMAKE_CXX_FLAGS_${_BUILD_TYPE_UPPER}} Linker flags: -Executable ${CMAKE_EXE_LINKER_FLAGS} -Module ${CMAKE_MODULE_LINKER_FLAGS} -Shared ${CMAKE_SHARED_LINKER_FLAGS}\n") + - Executable: ${CMAKE_EXE_LINKER_FLAGS} + - Module: ${CMAKE_MODULE_LINKER_FLAGS} + - Shared: ${CMAKE_SHARED_LINKER_FLAGS}\n") + ROOT_SHOW_ENABLED_OPTIONS() diff --git a/cmake/modules/CheckCompiler.cmake b/cmake/modules/CheckCompiler.cmake index 4321d93b596f2..3ef2668eaabda 100644 --- a/cmake/modules/CheckCompiler.cmake +++ b/cmake/modules/CheckCompiler.cmake @@ -176,9 +176,6 @@ if(NOT CMAKE_CXX_STANDARD MATCHES "17|20") message(FATAL_ERROR "Unsupported C++ standard: ${CMAKE_CXX_STANDARD}. Supported standards are: 17, 20.") endif() -# needed by roottest, to be removed once roottest is fixed -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}") - #---Check for libcxx option------------------------------------------------------------ if(libcxx) CHECK_CXX_COMPILER_FLAG("-stdlib=libc++" HAS_LIBCXX11) @@ -249,11 +246,3 @@ check_cxx_source_compiles( #endif int main() {} " GLIBCXX_USE_CXX11_ABI) - -#---Print the final compiler flags-------------------------------------------------------------------- -message(STATUS "ROOT Platform: ${ROOT_PLATFORM}") -message(STATUS "ROOT Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") -message(STATUS "ROOT Processor: ${CMAKE_SYSTEM_PROCESSOR}") -message(STATUS "ROOT Architecture: ${ROOT_ARCHITECTURE}") -message(STATUS "Build Type: '${CMAKE_BUILD_TYPE}' (flags = '${CMAKE_CXX_FLAGS_${_BUILD_TYPE_UPPER}}')") -message(STATUS "Compiler Flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_BUILD_TYPE_UPPER}}") diff --git a/cmake/modules/RootConfiguration.cmake b/cmake/modules/RootConfiguration.cmake index 8898749244ea2..e0037b5a3d1d5 100644 --- a/cmake/modules/RootConfiguration.cmake +++ b/cmake/modules/RootConfiguration.cmake @@ -613,6 +613,7 @@ string(REGEX REPLACE "(^|[ ]*)-W[^ ]*" "" __fflags "${CMAKE_Fortran_FLAGS}") string(REGEX MATCHALL "(-Wp,)?-(D|U)[^ ]*" __defs "${CMAKE_CXX_FLAGS}") set(ROOT_COMPILER_FLAG_HINTS "# set(ROOT_DEFINITIONS \"${__defs}\") +set(ROOT_CXX_STANDARD ${CMAKE_CXX_STANDARD}) set(ROOT_CXX_FLAGS \"${__cxxflags}\") set(ROOT_C_FLAGS \"${__cflags}\") set(ROOT_fortran_FLAGS \"${__fflags}\") @@ -723,9 +724,11 @@ if(WIN32) # We cannot use the compiledata.sh script for windows configure_file(${CMAKE_SOURCE_DIR}/cmake/scripts/compiledata.win32.in ${CMAKE_BINARY_DIR}/ginclude/compiledata.h NEWLINE_STYLE UNIX) else() + # Needed by ACLIC, while in ROOT we are using everywhere C++ standard via CMake features that are requested to build target + set(CMAKE_CXX_ACLIC_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}") execute_process(COMMAND ${CMAKE_SOURCE_DIR}/build/unix/compiledata.sh ${CMAKE_BINARY_DIR}/ginclude/compiledata.h "${CMAKE_CXX_COMPILER}" - "${CMAKE_CXX_FLAGS_RELEASE}" "${CMAKE_CXX_FLAGS_DEBUG}" "${CMAKE_CXX_FLAGS}" + "${CMAKE_CXX_FLAGS_RELEASE}" "${CMAKE_CXX_FLAGS_DEBUG}" "${CMAKE_CXX_ACLIC_FLAGS}" "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}" "${CMAKE_EXE_LINKER_FLAGS}" "so" "${libdir}" "-lCore" "-lRint" "${incdir}" "" "" "${ROOT_ARCHITECTURE}" "${ROOTBUILD}") endif() diff --git a/cmake/modules/RootMacros.cmake b/cmake/modules/RootMacros.cmake index 70af7c204a723..debf338955395 100644 --- a/cmake/modules/RootMacros.cmake +++ b/cmake/modules/RootMacros.cmake @@ -915,10 +915,6 @@ function(ROOT_LINKER_LIBRARY library) target_link_libraries(${library} PUBLIC ${ARG_LIBRARIES} ${ARG_DEPENDENCIES}) endif() - if(DEFINED CMAKE_CXX_STANDARD) - target_compile_features(${library} INTERFACE cxx_std_${CMAKE_CXX_STANDARD}) - endif() - if(PROJECT_NAME STREQUAL "ROOT") if(NOT TARGET ROOT::${library}) add_library(ROOT::${library} ALIAS ${library}) diff --git a/cmake/scripts/RootUseFile.cmake.in b/cmake/scripts/RootUseFile.cmake.in index 7c4dc42ba0cf8..178d896493661 100644 --- a/cmake/scripts/RootUseFile.cmake.in +++ b/cmake/scripts/RootUseFile.cmake.in @@ -12,3 +12,4 @@ add_definitions(${ROOT_DEFINITIONS}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ROOT_CXX_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ROOT_C_FLAGS}") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${ROOT_fortran_FLAGS}") +set(CMAKE_CXX_STANDARD ${ROOT_CXX_STANDARD}) diff --git a/config/root-config.in b/config/root-config.in index 57b61ff89cad3..6d46bc72997f6 100755 --- a/config/root-config.in +++ b/config/root-config.in @@ -448,7 +448,7 @@ Usage: root-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version]\ [--noauxcflags] [--noauxlibs] [--noldflags] [--has-] [--arch]\ [--platform] [--config] [--features] [--ncpu] [--git-revision]\ [--python-version] [--python2-version] [--python3-version]\ - [--cc] [--cxx] [--f77] [--ld ] [--help]" + [--cxxstandard] [--cc] [--cxx] [--f77] [--ld ] [--help]" if test $# -eq 0; then echo "${usage}" 1>&2 @@ -573,6 +573,9 @@ while test $# -gt 0; do --python3-version) out="$out @python3vers@" ;; + --cxxstandard) + out="$out @CMAKE_CXX_STANDARD@" + ;; --cflags) ### Output the compiler flags if test "${incdir}" != "/usr/include"; then @@ -849,6 +852,7 @@ while test $# -gt 0; do echo " --python-version Print the Python version used by ROOT" echo " --python2-version Print the Python2 version used by PyROOT" echo " --python3-version Print the Python3 version used by PyROOT" + echo " --cxxstandard Print the C++ standard used to compile ROOT" echo " --ncpu Print number of available (hyperthreaded) cores" echo " --cc Print alternative C compiler specified when ROOT was built" echo " --cxx Print alternative C++ compiler specified when ROOT was built"