MantisBT - CMake
View Issue Details
0009466CMakeCMakepublic2009-08-31 19:212009-09-17 12:12
Yves Starreveld 
Bill Hoffman 
normalmajoralways
closedfixed 
CMake-2-6 
 
0009466: CMAKE_OSX_ARCHITECTURES does not properly set architecture on Mac OS 10.6
Setting CMAKE_OSX_ARCHITECTURES to i386 still produces 64 bit code
No tags attached.
Issue History
2009-08-31 19:21Yves StarreveldNew Issue
2009-09-01 13:29Bill HoffmanNote Added: 0017282
2009-09-01 13:35Sean McBrideNote Added: 0017283
2009-09-05 10:05Bill HoffmanNote Added: 0017313
2009-09-05 10:05Bill HoffmanStatusnew => assigned
2009-09-05 10:05Bill HoffmanAssigned To => Bill Hoffman
2009-09-05 11:38Sean McBrideNote Added: 0017314
2009-09-05 12:09Bill HoffmanNote Added: 0017315
2009-09-05 17:26Mike JacksonNote Added: 0017319
2009-09-08 11:25Sean McBrideNote Added: 0017329
2009-09-08 13:17Bill HoffmanNote Added: 0017334
2009-09-08 13:30Yves StarreveldNote Added: 0017335
2009-09-08 15:05Sean McBrideNote Added: 0017342
2009-09-08 15:08Bill HoffmanNote Added: 0017343
2009-09-08 15:11Sean McBrideNote Added: 0017344
2009-09-17 12:12Bill HoffmanNote Added: 0017592
2009-09-17 12:12Bill HoffmanStatusassigned => closed
2009-09-17 12:12Bill HoffmanResolutionopen => fixed

Notes
(0017282)
Bill Hoffman   
2009-09-01 13:29   
Any more information on this? Possible fixes?
(0017283)
Sean McBride   
2009-09-01 13:35   
Bill, might want to review 0003618.
(0017313)
Bill Hoffman   
2009-09-05 10:05   
If you do a make VERBOSE=1 with makefiles what flags are being passed? I am thinking that the default was changed from 32 to 64, so with the default we don't add any flags because adding might cause non-default things to happen...

That is done here:
    if(osxArch && sysroot && lang && (lang[0] =='C' || lang[0] == 'F'))
      {
      std::vector<std::string> archs;
      cmSystemTools::ExpandListArgument(std::string(osxArch),
                                        archs);
      bool addArchFlag = true;
      if(archs.size() == 1)
        {
        const char* archOrig =
          this->Makefile->GetSafeDefinition("CMAKE_OSX_ARCHITECTURES_DEFAULT");

        if(archs[0] == archOrig)
          {
          addArchFlag = false;
          }
        }

So, if you were to change CMAKE_OSX_ARCHITECTURES_DEFAULT to be 64 bit, then the 32 bit should force a 32 bit build. See Platforms/Darwin.cmake. I don't have this OS to try, so if one of you can figure this out that would be good. CMake 2.8.0 is very close now, so....
(0017314)
Sean McBride   
2009-09-05 11:38   
How about the following behaviour:
 - CMake never attempts to guess any architecture
 - CMake does not treat one item in CMAKE_OSX_ARCHITECTURES differently from 2 or more.
 - If CMAKE_OSX_ARCHITECTURES is _not_ set by the user, CMake does not pass any -arch at all, allowing the compiler to use whatever its default is (32 bit on 10.5, 64 bit on 10.6)
 - If CMAKE_OSX_ARCHITECTURES _is_ set by the user, CMake uses exactly those for -arch
(0017315)
Bill Hoffman   
2009-09-05 12:09   
No, that won't work. I want cmake to not add any -arch stuff if it does not need to. It should just use the compiler like it does on any other platform, or any makefile with gcc in it on the Mac would. The cache has to be initialized with CMAKE_OSX_ARCHITECTURES however it only needs to be used when it will change the default.

There is no easy way to tell if CMAKE_OSX_ARCHITECTURES has been set by the user or by the default in the cache. We have something that works, the only problem is the DEFAULT value computation is wrong for this new version of the OS, fix that and it starts working. Change everything right before a release, and there is a good chance nothing works... :)
(0017319)
Mike Jackson   
2009-09-05 17:26   
Can you run a simple try-compile and then examine the output with the "File" command. the "file" command will tell you all the archs that are in the output file/object file. I don't have 10.6 to test but I would think compiling something with the default behaviors would give you the answer that you want.

 The other way would be to start looking at system/os configurations and have some sort of "guessing" game:

if (OS_X_VERSION < 10.6 and CMAKE_OSX_ARCHITECTURES STREQUAL "")
 set (CMAKE_OSX_ARCHITECTURES "i386;ppc"
endif

of course, now figure out if we are on a PPC or Intel box and set the CMAKE_OSX_ARCHITECTURES in the above if() block correctly.

 The following was on 10.5:

$ gcc -o main.o main.c
$ file main.o
 main.o: Mach-O executable i386
$ gcc -arch x86_64 -o main.o main.c
$ file main.o
main.o: Mach-O 64-bit executable x86_64
$ gcc -arch i386 -arch x86_64 -o main.o main.c
$file main.o
main.o: Mach-O universal binary with 2 architectures
main.o (for architecture i386): Mach-O executable i386
main.o (for architecture x86_64): Mach-O 64-bit executable x86_64

So it would seem that on 10.6 the defaults are just reversed. Not sure how long the 'file' command has been around but I am guessing since at least 10.4 since it seems to be a standard unix command and not anything OS X specific.

 This could probably all be done in the darwin.cmake file.
(0017329)
Sean McBride   
2009-09-08 11:25   
I guess since we are close to release a conservative change is in order. However, it seems to me the current scheme is fragile, and 10.7 will probably require another change to the guessing scheme.

I understand and agree with not passing -arch all the time. I guess I don't understand why CMAKE_OSX_ARCHITECTURES has to be initialised in the cache. If it were not, then its absence could mean 'don't pass -arch'; if it were set, its presence could mean 'pass -arch'. How come things like CMAKE_BUILD_TYPE are not autoset but CMAKE_OSX_ARCHITECTURES need be?
(0017334)
Bill Hoffman   
2009-09-08 13:17   
So, Yevs the only one who has this machine? Without someone testing the changes whatever they end up being we are shooting in the dark. So, does anyone have a 10.6 machine available for testing? How do you get one?
(0017335)
Yves Starreveld   
2009-09-08 13:30   
I am willing to test any changes. This is only a problem with 10.6, so until others start updating, I will be the only one.
In essence the only bug is that specifying i386 gets translated by CMake to 'do the default' which under 10.6 has become x64.
(0017342)
Sean McBride   
2009-09-08 15:05   
I've been running 10.6 for almost a year; I can test also.
(0017343)
Bill Hoffman   
2009-09-08 15:08   
OK, so I am going to try the empty CMAKE_OSX_ARCHITECTURES default cache, and get rid of the _DEFAULT one. Turns out we have a machine here, and I will be getting a mac mini updated to 10.6 so we can run dashboards on it.
(0017344)
Sean McBride   
2009-09-08 15:11   
and BTW: we have have some 10.6 dashboards probably later this week.
(0017592)
Bill Hoffman   
2009-09-17 12:12   
Committer: Bill Hoffman <bill.hoffman@kitware.com>
Committer: Bill Hoffman <bill.hoffman@kitware.com>
/cvsroot/CMake/CMake/Modules/Platform/Darwin.cmake,v <-- Modules/Platform/Darwin.cmake
new revision: 1.59; previous revision: 1.58
/cvsroot/CMake/CMake/Source/cmGlobalXCodeGenerator.cxx,v <-- Source/cmGlobalXCodeGenerator.cxx
new revision: 1.225; previous revision: 1.224
/cvsroot/CMake/CMake/Source/cmLocalGenerator.cxx,v <-- Source/cmLocalGenerator.cxx
new revision: 1.310; previous revision: 1.309