View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015591CMakeCMakepublic2015-05-28 10:562016-06-10 14:31
ReporterChris Bieneman 
Assigned ToKitware Robot 
PlatformOSOS Version
Product VersionCMake 3.2.2 
Target VersionFixed in Version 
Summary0015591: CMAKE_OSX_SYSROOT and CMAKE_OSX_ARCHITECTURES variables are actually clang-specific not osx-specific
DescriptionThe CMAKE_OSX_SYSROOT and CMAKE_OSX_ARCHITECTURES flags are currently the best supported way to set the -isysroot and -arch flags used by clang for cross-compiling, but they only function fully if you are on Darwin. Clang supports these flags on all platforms, so they should really be CMAKE_CLANG_SYSROOT and CMAKE_CLANG_ARCHITECTURES.

Having platform-agnostic CMAKE_CLANG_ARCHITECTURES and CMAKE_CLANG_SYSROOT flags would significantly improve cross-compiling support with clang. It would also greatly help the LLVM project in our efforts to replace our autoconf build system with CMake.
TagsNo tags attached.
Attached Files


Brad King (manager)
2015-05-28 11:07

The -arch and -isysroot flags have been on OS X in their GNU compiler port since long before Clang even existed. CMAKE_OSX_SYSROOT and CMAKE_OSX_ARCHITECTURES were created back then.

We now have CMAKE_SYSROOT: [^]


CMAKE_OSX_ARCHITECTURES is for OS X universal binaries where the toolchains and loaders natively support storing multiple architectures in single binary files. Does Clang support this elsewhere? Otherwise the -arch flag can simply be specified explicitly like any other compiler flag.
Chris Bieneman (reporter)
2015-05-28 12:12

The CMAKE_SYSROOT flag controls --sysroot, wheras the CMAKE_OSX_SYSROOT flag controls -isysroot. These two flags behave differently. Clang passes --sysroot through to the linker as the library root, and uses -isysroot as the header root. If you set -isysroot and not --sysroot it implies setting --sysroot to the value of -isysroot.

If it is intended to work universally, it needs to control -isysroot for clang. If it did that then it could replace the CMAKE_OSX_SYSROOT flag entirely.

The history of the CMAKE_OSX flags makes sense. Clang only supports generation of fat binaries on Darwin, so I can see a case for leaving the ARCHITECTURES flag as-is. Eventually clang will likely support fat elf binaries as well, in which case a more-general flag will be warranted.
Brad King (manager)
2015-05-29 09:33

Re 0015591:0038812: Right, I forgot about the difference between --sysroot and -isysroot.

The CMAKE_OSX_SYSROOT was created for -isysroot originally because the option was at one time required on OS X just to compile a simple program as a universal binary. Also it allows us to set the parameter correctly in the Xcode generator without having to parse -isysroot out of user-provided flags.

For other platforms with Clang is there any reason a dedicated option is needed instead of adding -isysroot to the flags normally?
Chris Bieneman (reporter)
2015-05-29 13:35

At this point what I'm really asking for is a cleanup and merge of the CMAKE_OSX_SYSROOT flag and the CMAKE_SYSROOT flag. There are two reasons for that. (1) is consistency, and the other is the entire justification for the CMAKE_SYSROOT flag in the first place.

From a consistency perspective:

I would like to see a single sysroot flag that works across a variety of toolchains so that when generating build files for cross-compiling we don't have to hack around this for every target platform and all supported tools variants.

For example. Today if you are on darwin with clang cross-targeting iOS, Android, or Linux it is trivial, you just set CMAKE_OSX_SYSROOT to point at your SYSROOT, and use a toolchain file to setup linkers and low-level tools and it is actually quite clean.

If you're on Linux the story is quite different if you are using GCC vs Clang. For GCC the CMAKE_SYSROOT flag works, but for clang that flag behaves quite oddly, so you need to hack around and add appropriate isysroot.

If you're on Windows it gets even odder because you might be using GCC, or Clang (native or through cygwin), or MSVC. This all requires special handling. While we can do special handling of this in our project (and we do), it would be nice if some of this logic were built into CMake.

On the other side, when talking about the CMAKE_SYSROOT flag, it is worth noting, from looking at the revision history the CMAKE_SYSROOT flag was added (de4da66) and reverted (0416c94) before being added again (7cd65c9). The reason for the revert was so the flag could be merged with the CMAKE_OSX_SYSROOT flag, a merging that didn't happen.

The most important bit from the commit WRT why CMAKE_SYSROOT is an important concept outside a compiler flag is:

"The contents of this variable is passed to supporting compilers as --sysroot. It is also accounted for when processing implicit link directories reported by the compiler, and when generating RPATH information."
Stephen Kelly (developer)
2015-05-30 15:05

For reference, this relates to llvm bug 21562 [^] [^]

We discussed related issues here: [^] [^]

The most up to date information I have about cross compiling with Clang and CMake is [^]

so it would be useful to update [^]

if there is a further outcome from this.
Stephen Kelly (developer)
2015-05-30 16:08

Further context: [^]

Chris, you can probably use


after the project() command to get the options you want.
Chris Bieneman (reporter)
2015-06-01 12:54


Thank you, I wasn't aware of the CMAKE_${lang_COMPILE_OPTIONS_SYSROOT. I think I can accomplish what I need with that.

Also to provide some extra context, there are instructions for cross-compiling LLVM for iOS with CMake here: [^]

I know Stephen is aware of what we're trying to do, but for anyone else following along, the big complication with our bug ( [^]), is that the compiler-rt project is inherently a cross-compile.

When you build a full clang toolchain you can select a set of target architectures to build support for. After clang is built if you are building compiler-rt (our version of libgcc), you need to use the just-built clang to cross-compile the runtime library for each target architecture.

Today we hack around this and don't actually treat it as a cross-compile. For us to obsolete our autotools build system we need to address a number of limitations in our current CMake system, and my plan for how to do that is to treat compiler-rt builds as a proper cross-compile.
Brad King (manager)
2015-06-01 13:02

Re 0015591:0038869: Thanks for the info. FYI, CMAKE_<LANG>_COMPILE_OPTIONS_SYSROOT is an undocumented internal variable that is supposed to be filled out by the compiler information modules for the current toolchain if it has such a flag. Setting it as Steve mentioned in 0015591:0038827 will override/workaround the builtin default but is not a first-class solution. Further work/discussion/design will be needed to consolidate all these sysroot options.
Kitware Robot (administrator)
2016-06-10 14:29

Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2015-05-28 10:56 Chris Bieneman New Issue
2015-05-28 11:07 Brad King Note Added: 0038809
2015-05-28 12:12 Chris Bieneman Note Added: 0038812
2015-05-29 09:33 Brad King Note Added: 0038818
2015-05-29 13:35 Chris Bieneman Note Added: 0038822
2015-05-30 15:05 Stephen Kelly Note Added: 0038826
2015-05-30 16:08 Stephen Kelly Note Added: 0038827
2015-06-01 12:54 Chris Bieneman Note Added: 0038869
2015-06-01 13:02 Brad King Note Added: 0038870
2016-06-10 14:29 Kitware Robot Note Added: 0042785
2016-06-10 14:29 Kitware Robot Status new => resolved
2016-06-10 14:29 Kitware Robot Resolution open => moved
2016-06-10 14:29 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed

Copyright © 2000 - 2018 MantisBT Team