MantisBT - CMake
View Issue Details
0014572CMakeCMakepublic2013-11-16 18:242014-11-03 08:38
Clinton Stimpson 
Clinton Stimpson 
normalminorhave not tried
closedfixed 
MacOS X10.9
 
 
0014572: Xcode 4.6 gcc problems on Mac OS X 10.9
CMake doesn't work well when trying to use gcc from Xcode 4.6 on Mac OS X 10.9.

I've installed Xcode 4.6 from the developer website.
Then did xcode-select /Applications/Xcode-4.6.app

Running
cmake -G Xcode
gives
CMake Warning at .../Modules/Platform/Darwin.cmake:179 (message):
  Ignoring CMAKE_OSX_SYSROOT value:
   /Applications/Xcode-4.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
  because the directory does not exist.


But, if I want to use the gcc compiler instead, by running:
cmake -G Xcode -T com.apple.compilers.llvmgcc42
it gives:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- broken
....

To help that, I set
export SDKROOT=/Applications/Xcode-4.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
then try again with a clean build dir to get:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- works

The compiler id test failed.
I go into CMakeFiles/<version>/CompilerIdC and run xcodebuild -project CompierIdC.xcodeproj and it fails to link because of this error:
ld: library not found for -lcrt1.10.6.o

If the xcodeproj is manually edited to include
SDKROOT = "/Applications/Xcode-4.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk";

Then the problem goes away.


Using the Makefile generator didn't have these issues.
I could set the environment variables CC, CXX, SDKROOT and things worked fine.
CMake knows how to avoid the linker error about not finding -lcrt1.10.6.o when using the Makefile generator by using -sysroot on the compiler id test. The xcode generator needs the same.
No tags attached.
Issue History
2013-11-16 18:24Clinton StimpsonNew Issue
2013-11-18 08:43Brad KingNote Added: 0034459
2013-11-18 10:18Brad KingNote Added: 0034462
2013-11-18 10:29Clinton StimpsonNote Added: 0034463
2013-11-18 11:17Sean McBrideNote Added: 0034469
2013-11-18 11:41Clinton StimpsonNote Added: 0034471
2013-11-18 11:45Sean McBrideNote Added: 0034472
2013-12-30 15:34Clinton StimpsonNote Added: 0034890
2014-04-29 11:34Clinton StimpsonNote Added: 0035803
2014-04-29 11:43Brad KingNote Added: 0035804
2014-04-30 09:03Clinton StimpsonNote Added: 0035808
2014-04-30 10:27Brad KingNote Added: 0035810
2014-05-05 15:38Clinton StimpsonNote Added: 0035817
2014-05-06 11:21Clinton StimpsonNote Added: 0035829
2014-05-06 11:21Clinton StimpsonAssigned To => Clinton Stimpson
2014-05-06 11:21Clinton StimpsonStatusnew => assigned
2014-05-06 11:21Clinton StimpsonStatusassigned => resolved
2014-05-06 11:21Clinton StimpsonResolutionopen => fixed
2014-11-03 08:38Robert MaynardNote Added: 0037130
2014-11-03 08:38Robert MaynardStatusresolved => closed

Notes
(0034459)
Brad King   
2013-11-18 08:43   
The Modules/CompilerId/Xcode-3.pbxproj.in template and Modules/CMakeDetermineCompilerId.cmake may need to be taught how to add SDKROOT to the test project.
(0034462)
Brad King   
2013-11-18 10:18   
Re 0014572:0034459: As a follow up to my previous comment, the CMakeDetermineCompilerId.cmake Xcode support currently assumes that Xcode is capable of building for the host OS X version with no special flags. That assumption is violated for Xcode < 5.0.1 on OS X 10.9.
(0034463)
Clinton Stimpson   
2013-11-18 10:29   
When using the default compiler in Xcode 4.6 under OS X 10.9, it works fine except for that one warning. I'm not sure why gcc would be picky about having SDKROOT if clang isn't.
(0034469)
Sean McBride   
2013-11-18 11:17   
It should be noted that (according to Apple) OS X 10.9 *requires* Xcode 5.0 or later. 4.6 largely works, as reported on various mailing lists, but has trouble even without CMake.
(0034471)
Clinton Stimpson   
2013-11-18 11:41   
Thanks Sean. What does required mean here? If I built a program using Xcode 4.6 on OS X 10.7, will it not work on OS X 10.9?
Or, do you simply mean that to develop on 10.9, you must have Xcode 5?

I have a 3rd party library compiled with gcc on OS X 10.4, and in the past, clang did not work and the application would crash. This is my reason for getting Xcode 4.6.
But, I have an updated version of this 3rd party library built with gcc on OS X 10.7, and have just found that Xcode 5/clang seems to work, so maybe that is an option for me.
(0034472)
Sean McBride   
2013-11-18 11:45   
I mean that to develop on on 10.9, you must use Xcode 5 or later.

If you build a program using Xcode 4.6 on OS X 10.7 it will generally work. Backwards compatibility of compiled binaries is something Apple tried to maintain.

If, for whatever reason, you really need to use Xcode 4.6, you should do so on OS X 10.7 or 10.8.
(0034890)
Clinton Stimpson   
2013-12-30 15:34   
Regardless of Xcode 4.6 not being supported on OS X 10.9, I do think it correct to have the SDKROOT in CompilerId/Xcode-3.pbxproj, but Platforms/Darwin.cmake, where the SDKROOT is determined, is processed too late after the compiler id checks.

If the user sets CMAKE_OSX_SYSROOT initially, then a patch to CompilerId/Xcode-3.pbxproj/CMakeDetermineCompilerId.cmake will work.
cmake -G Xcode -DCMAKE_OSX_SYSROOT=... -T com.apple.compilers.llvmgcc42

How does this compare to the new CMAKE_SYSROOT feature in this situation?
(0035803)
Clinton Stimpson   
2014-04-29 11:34   
Some fixes appear to help this situation:
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0cce556b [^]

Without testing, the last remaining piece might be to fix this warning:
CMake Warning at .../Modules/Platform/Darwin.cmake:179 (message):
  Ignoring CMAKE_OSX_SYSROOT value:
   /Applications/Xcode-4.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
  because the directory does not exist.
(0035804)
Brad King   
2014-04-29 11:43   
Re 0014572:0035803: In what is now Darwin-Initialize.cmake look for this comment:

    # Select SDK for current OSX version accounting for the known
    # specially named SDKs.

Two code paths in there try to select the SDK for the current OSX version. That should be refactored and taught to search back from the current version for the most recent SDK that exists.
(0035808)
Clinton Stimpson   
2014-04-30 09:03   
Brad, can you review proposed patches on stage/xcode-sdkroot?
(0035810)
Brad King   
2014-04-30 10:27   
Re 0014572:0035808: As I mentioned in 0014572:0035804 there were two code paths that set the default to the current OS X version:

 set(_CMAKE_OSX_SYSROOT_DEFAULT "${_CMAKE_OSX_SDKS_DIR}/MacOSX${_CMAKE_OSX_SDKS_VER}.sdk")

but you updated only one of them with the search. The logic should first be re-organized to not duplicate the default. Then the default can be updated in one place to do the search.

On the change using "xcrun --show-sdk-path": xcrun honors SDKROOT from the environment. However, it also converts names like SDKROOT=macosx10.8 into their paths, but we support (for the Xcode generator) setting CMAKE_OSX_SYSROOT to the logical name. Therefore we need to honor ENV{SDKROOT} first to avoid converting to a path until later.
(0035817)
Clinton Stimpson   
2014-05-05 15:38   
Brad, does stage/xcode-sdkroot look better now?

I've leaving the xcrun --show-sdk-path for another time as it is not directly related to this bug report.
(0035829)
Clinton Stimpson   
2014-05-06 11:21   
Fixed.

5dfe9b7d Xcode: Find fallback SDK if one matching the OS version doesn't exist.
(0037130)
Robert Maynard   
2014-11-03 08:38   
Closing resolved issues that have not been updated in more than 4 months.