From 85184cb9bf8cc094996b0c45d9826d2d48fa9522 Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Thu, 22 Jan 2026 15:42:09 +0100 Subject: [PATCH 1/3] [cmake][win] Fix compilation errors with /std:c++20 --- cmake/modules/RootMacros.cmake | 9 +++++++++ config/RConfigure.in | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmake/modules/RootMacros.cmake b/cmake/modules/RootMacros.cmake index c9f86da6fe9c7..52ca6dcb8d8e9 100644 --- a/cmake/modules/RootMacros.cmake +++ b/cmake/modules/RootMacros.cmake @@ -1425,6 +1425,9 @@ function(ROOT_EXECUTABLE executable) endif() add_executable(${executable} ${_all} ${exe_srcs}) target_link_libraries(${executable} PRIVATE ${ARG_LIBRARIES}) + if(MSVC) + target_compile_options(${executable} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) + endif() if(WIN32 AND ${executable} MATCHES \\.exe) set_target_properties(${executable} PROPERTIES SUFFIX "") @@ -2785,6 +2788,9 @@ macro(ROOTTEST_GENERATE_EXECUTABLE executable) add_executable(${executable} EXCLUDE_FROM_ALL ${ARG_UNPARSED_ARGUMENTS}) set_target_properties(${executable} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_property(TARGET ${executable} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) # will never be installed anyway + if(MSVC) + target_compile_options(${executable} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) + endif() set_property(TARGET ${executable} APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}) @@ -3420,6 +3426,9 @@ function(ROOTTEST_ADD_UNITTEST_DIR) add_executable(${binary} ${unittests_SRC}) target_link_libraries(${binary} PRIVATE GTest::gtest GTest::gtest_main ${libraries}) set_property(TARGET ${binary} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) # will never be installed anyway + if(MSVC) + target_compile_options(${binary} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) + endif() if(MSVC AND DEFINED ROOT_SOURCE_DIR) if(TARGET ROOTStaticSanitizerConfig) diff --git a/config/RConfigure.in b/config/RConfigure.in index 6642e67fff376..a0e683ede7a8a 100644 --- a/config/RConfigure.in +++ b/config/RConfigure.in @@ -24,7 +24,7 @@ #define ROOT__cplusplus @__cplusplus@ #if defined(__cplusplus) && (__cplusplus != ROOT__cplusplus) # if defined(_MSC_VER) -# pragma message("The C++ standard in this build does not match ROOT configuration (@__cplusplus@); this might cause unexpected issues. And please make sure you are using the -Zc:__cplusplus compilation flag") +# pragma message(__FILE__ ": Warning: The C++ standard in this build does not match ROOT configuration (@__cplusplus@); this might cause unexpected issues. And please make sure you are using the -Zc:__cplusplus compilation flag") # else # warning "The C++ standard in this build does not match ROOT configuration (@__cplusplus@); this might cause unexpected issues" # endif From 6a350c82fe693e6b7219b78be358414bd97509fc Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Thu, 22 Jan 2026 17:49:53 +0100 Subject: [PATCH 2/3] [cmake][win] Fix several tests with /std:c++20 --- cmake/modules/RootMacros.cmake | 9 +++++++++ roottest/cling/dict/ROOT-8096/CMakeLists.txt | 3 +++ 2 files changed, 12 insertions(+) diff --git a/cmake/modules/RootMacros.cmake b/cmake/modules/RootMacros.cmake index 52ca6dcb8d8e9..ddcab216650e1 100644 --- a/cmake/modules/RootMacros.cmake +++ b/cmake/modules/RootMacros.cmake @@ -941,6 +941,9 @@ function(ROOT_LINKER_LIBRARY library) endif() endif() set_target_properties(${library} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + if(MSVC) + target_compile_options(${library} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) + endif() if(DEFINED CMAKE_CXX_STANDARD) target_compile_features(${library} INTERFACE cxx_std_${CMAKE_CXX_STANDARD}) @@ -2608,6 +2611,9 @@ macro(ROOTTEST_GENERATE_DICTIONARY dictname) add_library(${targetname_libgen} EXCLUDE_FROM_ALL SHARED ${dictname}.cxx) set_property(TARGET ${targetname_libgen} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) # will never be installed anyway + if(MSVC) + target_compile_options(${targetname_libgen} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) + endif() if(ARG_SOURCES) target_sources(${targetname_libgen} PUBLIC ${ARG_SOURCES}) @@ -2713,6 +2719,9 @@ macro(ROOTTEST_GENERATE_REFLEX_DICTIONARY dictionary) set_property(TARGET ${targetname_libgen} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) # will never be installed anyway set_target_properties(${targetname_libgen} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) ROOT_SET_OUTPUT_DIRECTORIES(${targetname_libgen}) + if(MSVC) + target_compile_options(${targetname_libgen} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) + endif() if(ARG_LIBNAME) set_target_properties(${targetname_libgen} PROPERTIES PREFIX "") diff --git a/roottest/cling/dict/ROOT-8096/CMakeLists.txt b/roottest/cling/dict/ROOT-8096/CMakeLists.txt index 07c916ce01b19..d664eb45a07d7 100644 --- a/roottest/cling/dict/ROOT-8096/CMakeLists.txt +++ b/roottest/cling/dict/ROOT-8096/CMakeLists.txt @@ -7,6 +7,9 @@ set_source_files_properties(dict.cxx PROPERTIES GENERATED TRUE) add_library(ROOT-8096 EXCLUDE_FROM_ALL SHARED dict.cxx) set_target_properties(ROOT-8096 PROPERTIES ${ROOT_LIBRARY_PROPERTIES} ) +if(MSVC) + target_compile_options(ROOT-8096 PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) +endif() target_link_libraries(ROOT-8096 ${ARG_LIBRARIES} ${ROOT_LIBRARIES}) set_property(TARGET ROOT-8096 APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}) From 0f873ad12480273014d668306619301bb0f8290a Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Fri, 23 Jan 2026 12:45:14 +0100 Subject: [PATCH 3/3] [cmake][win] Remove custom `CMAKE_CXX_FLAGS` Removes the `CMAKE_CXX_FLAGS` that was intended for standalone roottest --- cmake/modules/RootMacros.cmake | 18 ------------------ roottest/CMakeLists.txt | 2 -- roottest/cling/dict/ROOT-8096/CMakeLists.txt | 3 --- 3 files changed, 23 deletions(-) diff --git a/cmake/modules/RootMacros.cmake b/cmake/modules/RootMacros.cmake index ddcab216650e1..c9f86da6fe9c7 100644 --- a/cmake/modules/RootMacros.cmake +++ b/cmake/modules/RootMacros.cmake @@ -941,9 +941,6 @@ function(ROOT_LINKER_LIBRARY library) endif() endif() set_target_properties(${library} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) - if(MSVC) - target_compile_options(${library} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) - endif() if(DEFINED CMAKE_CXX_STANDARD) target_compile_features(${library} INTERFACE cxx_std_${CMAKE_CXX_STANDARD}) @@ -1428,9 +1425,6 @@ function(ROOT_EXECUTABLE executable) endif() add_executable(${executable} ${_all} ${exe_srcs}) target_link_libraries(${executable} PRIVATE ${ARG_LIBRARIES}) - if(MSVC) - target_compile_options(${executable} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) - endif() if(WIN32 AND ${executable} MATCHES \\.exe) set_target_properties(${executable} PROPERTIES SUFFIX "") @@ -2611,9 +2605,6 @@ macro(ROOTTEST_GENERATE_DICTIONARY dictname) add_library(${targetname_libgen} EXCLUDE_FROM_ALL SHARED ${dictname}.cxx) set_property(TARGET ${targetname_libgen} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) # will never be installed anyway - if(MSVC) - target_compile_options(${targetname_libgen} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) - endif() if(ARG_SOURCES) target_sources(${targetname_libgen} PUBLIC ${ARG_SOURCES}) @@ -2719,9 +2710,6 @@ macro(ROOTTEST_GENERATE_REFLEX_DICTIONARY dictionary) set_property(TARGET ${targetname_libgen} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) # will never be installed anyway set_target_properties(${targetname_libgen} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) ROOT_SET_OUTPUT_DIRECTORIES(${targetname_libgen}) - if(MSVC) - target_compile_options(${targetname_libgen} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) - endif() if(ARG_LIBNAME) set_target_properties(${targetname_libgen} PROPERTIES PREFIX "") @@ -2797,9 +2785,6 @@ macro(ROOTTEST_GENERATE_EXECUTABLE executable) add_executable(${executable} EXCLUDE_FROM_ALL ${ARG_UNPARSED_ARGUMENTS}) set_target_properties(${executable} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_property(TARGET ${executable} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) # will never be installed anyway - if(MSVC) - target_compile_options(${executable} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) - endif() set_property(TARGET ${executable} APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}) @@ -3435,9 +3420,6 @@ function(ROOTTEST_ADD_UNITTEST_DIR) add_executable(${binary} ${unittests_SRC}) target_link_libraries(${binary} PRIVATE GTest::gtest GTest::gtest_main ${libraries}) set_property(TARGET ${binary} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) # will never be installed anyway - if(MSVC) - target_compile_options(${binary} PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) - endif() if(MSVC AND DEFINED ROOT_SOURCE_DIR) if(TARGET ROOTStaticSanitizerConfig) diff --git a/roottest/CMakeLists.txt b/roottest/CMakeLists.txt index b80cc81fd2c31..6353f94955119 100644 --- a/roottest/CMakeLists.txt +++ b/roottest/CMakeLists.txt @@ -3,7 +3,6 @@ if(MSVC) set(CMAKE_SUPPRESS_REGENERATION TRUE) set(libsuffix .dll) set(exesuffix .exe) - set(CMAKE_CXX_FLAGS "/nologo /Zc:__cplusplus /MD /GR /EHsc- /W3 /D_WIN32") set(grep_cmd "findstr") set(build_config "--config $") @@ -22,7 +21,6 @@ if(MSVC) set(WILLFAIL_ON_WIN32 WILLFAIL) endif() - set(CMAKE_CXX_FLAGS ${ROOT_CXX_FLAGS}) # ROOT_BINDIR is set by ROOTConfig.cmake set(ROOT_CONFIG_EXECUTABLE ${ROOT_BINDIR}/root-config.bat) execute_process(COMMAND ${ROOT_CONFIG_EXECUTABLE} "--prefix" OUTPUT_VARIABLE ROOTSYS RESULT_VARIABLE RETVAR OUTPUT_STRIP_TRAILING_WHITESPACE) diff --git a/roottest/cling/dict/ROOT-8096/CMakeLists.txt b/roottest/cling/dict/ROOT-8096/CMakeLists.txt index d664eb45a07d7..07c916ce01b19 100644 --- a/roottest/cling/dict/ROOT-8096/CMakeLists.txt +++ b/roottest/cling/dict/ROOT-8096/CMakeLists.txt @@ -7,9 +7,6 @@ set_source_files_properties(dict.cxx PROPERTIES GENERATED TRUE) add_library(ROOT-8096 EXCLUDE_FROM_ALL SHARED dict.cxx) set_target_properties(ROOT-8096 PROPERTIES ${ROOT_LIBRARY_PROPERTIES} ) -if(MSVC) - target_compile_options(ROOT-8096 PRIVATE -Zc:__cplusplus -std:c++${CMAKE_CXX_STANDARD}) -endif() target_link_libraries(ROOT-8096 ${ARG_LIBRARIES} ${ROOT_LIBRARIES}) set_property(TARGET ROOT-8096 APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR})