Link ROOT to a library using the ROOT CXX compilation flags?

Hello,

I am compiling a library using ROOT as a dependancy. My problem is that some users are using a C++11 version of ROOT, and some other a C++14 version of ROOT. if they are using a C++14 ROOT version, when compiling my library, they obtain the error:

**/Users/dudouet/Softs/ROOT/install/v6-26-02/include/ROOT/RConfig.hxx:50:5:** **error:** **"Pass -std=c++14 as compiler argument."**

It works then if I add in my CMakeList the line :

set(CMAKE_CXX_STANDARD 14)

But then it does not work anymore for the users using a C++11 version of ROOT. My question is : Is there a way, in my library’s CMakeList, to automatically define the CXX version that has been used for ROOT compilation ?

Thanks in advance

Jérémie


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


in your CMakeLists.txt

find_package(ROOT REQUIRED)
set(CMAKE_CXX_FLAGS "${ROOT_CXX_FLAGS}")

@bellenot You may want to “inherit” the “CMAKE_CXX_STANDARD” from ROOT but NOT “pollute” “CMAKE_CXX_FLAGS” (when building another package / library).

@Wile_E_Coyote I agree, but we need to make deep changes in the ROOT CMake infrastructure for that

Actually I found a solution doing something like this:

    find_package(ROOT REQUIRED)
    include(${ROOT_USE_FILE})
    if(ROOT_FOUND AND NOT ROOT_CXX_FLAGS STREQUAL "")
        string(FIND ${ROOT_CXX_FLAGS} "-std=c++11" _check_c11)
        string(FIND ${ROOT_CXX_FLAGS} "-std=c++14" _check_c14)
        string(FIND ${ROOT_CXX_FLAGS} "-std=c++17" _check_c17)
        string(FIND ${ROOT_CXX_FLAGS} "-std=c++20" _check_c20)
        if(NOT ${_check_c11} EQUAL -1)
            set(CMAKE_CXX_STANDARD 11)
        elseif(NOT ${_check_c14} EQUAL -1)
            set(CMAKE_CXX_STANDARD 14)
        elseif(NOT ${_check_c17} EQUAL -1)
            set(CMAKE_CXX_STANDARD 17)
        elseif(NOT ${_check_c20} EQUAL -1)
            set(CMAKE_CXX_STANDARD 20)
        endif()
        message("FOUND ROOT with flags ${ROOT_CXX_FLAGS} stream take standard ${CMAKE_CXX_STANDARD}")
    endif()

    if(NOT CMAKE_CXX_STANDARD)
        set(CMAKE_CXX_STANDARD 11)
    endif()

Don’t know if this is the most efficient way to do but it works.

Jérémie

Doing only this is not working for me, I need to redefine CMAKE_CXX_STANDARD to make it work

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.