ROOT breaks CMake on Monterey


ROOT Version: 6.25/01
Platform: MacOS 12.0.1
Compiler: Not Provided


Dear ROOT people,

I have had to upgrade my system to Monterey due to other issues and my C++ builds have started to fail. I am using the latest version of ROOT (6.25/01) and CMake (3.21.4) provided by homebrew and the latest version of the XCode command line tools (13.1).

Whenever I link with ROOT in a CMake file it gives this error:

error: include location '/usr/local/include/root' is unsafe for cross-compilation [-Werror,-Wpoison-system-directories]

Here the compiler seems to imply that I am cross-compiling my pgram which is not my intention. I am running this on the same machine I am building it.

I think this was root because:

  1. when I attempt to build a pure C++ program without ROOT the message doesn’t appear.

  2. When in the same CMake project I add find_package(ROOT REQUIRED CONFIG), the message does not appear.

  3. When I add the dependency relationship using target_link_libraries(root_test ROOT::Core) the message appears and the build fails.

Even though I am not trying to cross-compile my program, I printed out the CMAKE_CROSSCOMPILING variable to check and it does resolve to FALSE.

because of these reasons I think something in ROOT’s CMake configuration may be passing bad flags to my C++ compiler. Perhaps this is something to do with the recently introduced M1 architecture (but I am still on x86_64).

During this process I have also reisntalled the XCode command line tools and ROOT and the error persists.

I am a new forums user so I cant post links so im afraid these files are going to be printed here rather than attached.

This is the very simple hello world file I used to test this:

#include <iostream>

int main(int argc, char *argv[]){

    (void) argc;
    (void) argv;

    std::cout << "Hello, world." << std::endl;
    return 0;

}

This is the CMake file to build it that tried to link root (without even using it in the code) and produces the error shown above:

# Specify the minimum version of CMake
cmake_minimum_required(VERSION 3.0)

# Project's name
Project(root_test CXX)

# Configuration 
set(CMAKE_CXX_STANDARD 17) # Needed by std::filesystem

# Compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wunused-variable -pedantic -Werror -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic")

message(STATUS ${CMAKE_CROSSCOMPILING})

add_executable(root_test main.cpp)

find_package(ROOT REQUIRED CONFIG)

target_link_libraries(root_test
                        ROOT::Core)

Also, here are the outputs of make VERBOSE=1 (log.txt).

/usr/local/Cellar/cmake/3.21.4/bin/cmake -S/Users/sim/Desktop/root_debug -B/Users/sim/Desktop/root_debug --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.21.4/bin/cmake -E cmake_progress_start /Users/sim/Desktop/root_debug/CMakeFiles /Users/sim/Desktop/root_debug//CMakeFiles/progress.marks
/Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/Makefile2 all
/Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/root_test.dir/build.make CMakeFiles/root_test.dir/depend
cd /Users/sim/Desktop/root_debug && /usr/local/Cellar/cmake/3.21.4/bin/cmake -E cmake_depends "Unix Makefiles" /Users/sim/Desktop/root_debug /Users/sim/Desktop/root_debug /Users/sim/Desktop/root_debug /Users/sim/Desktop/root_debug /Users/sim/Desktop/root_debug/CMakeFiles/root_test.dir/DependInfo.cmake --color=
Dependencies file "CMakeFiles/root_test.dir/main.cpp.o.d" is newer than depends file "/Users/sim/Desktop/root_debug/CMakeFiles/root_test.dir/compiler_depend.internal".
Consolidate compiler generated dependencies of target root_test
/Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/root_test.dir/build.make CMakeFiles/root_test.dir/build
[ 50%] Building CXX object CMakeFiles/root_test.dir/main.cpp.o
/Library/Developer/CommandLineTools/usr/bin/c++  -isystem /usr/local/include/root -Wall -Wextra -Wunused-variable -pedantic -Werror -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.0.sdk -std=gnu++17 -MD -MT CMakeFiles/root_test.dir/main.cpp.o -MF CMakeFiles/root_test.dir/main.cpp.o.d -o CMakeFiles/root_test.dir/main.cpp.o -c /Users/sim/Desktop/root_debug/main.cpp
error: include location '/usr/local/include/root' is unsafe for cross-compilation [-Werror,-Wpoison-system-directories]
1 error generated.
make[2]: *** [CMakeFiles/root_test.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/root_test.dir/all] Error 2
make: *** [all] Error 2

Thanks for any help

Hi @sim,

Perhaps, @Axel can provide some hints here (or at least I will make him aware of this problem).

Cheers,
J.

1 Like

First of all: fantastic post, @sim - it has all the info we need, very impressive!

As this is homebrew (and their ROOT build options and compiler), asking them for advice might also be a good idea. If you decide to do that, could you post the link to the homebrew topic as a reply here?

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