Problems forcing 32bit build on OSX with Cmake


#1

Hey guys,

I need a static 32bit lib for an old project, but receive an error while make is building on src/video/cocoa/SDL_cocoametalview.m. The machine is running OSX 10.13.6, with Xcode 9.3.1 and the corresponding Xcode Command Line Tools, cmake 3.13.2 by brew. The project later will use a bigger cmake script, but without a successful compile, I won’t need to adapt the lib into it.

For testing purposes I cutted any parameters to the cmake command, to get it going, so i’m left with:
mkdir build && cd build && cmake -DCMAKE_OSX_ARCHITECTURES=i386 ..” in the freshly downloaded SDL2.0.10 dir.

The error states a problem when using CGSize and NSSize:

[ 87%] Building C object CMakeFiles/SDL2-static.dir/src/video/cocoa/SDL_cocoametalview.m.o
~/Downloads/SDL2-2.0.10/src/video/cocoa/SDL_cocoametalview.m:80:12: error: initializing 'CGSize' (aka 'struct CGSize') with an expression of incompatible type 'NSSize'
      (aka 'struct _NSSize')
    CGSize size = self.bounds.size;
           ^      ~~~~~~~~~~~~~~~~
~/Downloads/SDL2-2.0.10/src/video/cocoa/SDL_cocoametalview.m:34:17: warning: property 'highDPI' requires method 'highDPI' to be defined - use @synthesize, @dynamic or
      provide a method implementation in this class implementation [-Wobjc-property-implementation]
@implementation SDL_cocoametalview
                ^
~/Downloads/SDL2-2.0.10/src/video/cocoa/SDL_cocoametalview.h:50:28: note: property declared here
@property (nonatomic) BOOL highDPI;
                           ^
~/Downloads/SDL2-2.0.10/src/video/cocoa/SDL_cocoametalview.m:34:17: warning: property 'highDPI' requires method 'setHighDPI:' to be defined - use @synthesize, @dynamic
      or provide a method implementation in this class implementation [-Wobjc-property-implementation]
@implementation SDL_cocoametalview
                ^
~/Downloads/SDL2-2.0.10/src/video/cocoa/SDL_cocoametalview.h:50:28: note: property declared here
@property (nonatomic) BOOL highDPI;
                           ^
2 warnings and 1 error generated.
make[2]: *** [CMakeFiles/SDL2-static.dir/src/video/cocoa/SDL_cocoametalview.m.o] Error 1
make[1]: *** [CMakeFiles/SDL2-static.dir/all] Error 2
make: *** [all] Error 2

Going the path with the delivered standalone CC=build-scripts/gcc_fat.sh configure and make works fine, but cmake won’t give me any satisfying result. Am I missing something?


#2

It’s an issue of the 32-bit vs 64-bit ObjectiveC ABI and API. When Apple switched macOS to be fully 64-bit, they took the opportunity to clean up some things in the API, and also since the low level ABI on x86-64 is different than i386/x86-32, they used that break to also clean up the ObjectiveC ABI.

On the API front, when compiling for 64-bit, CGSize and NSSize are typedef’ed to be the same. When compiling for 32-bit, they are different structs (because of legacy reasons).

With the ABI, on 32-bit Objective-C uses what’s called the “fragile” ABI, and on 64-bit it uses a newer, cleaner one. The fragile ABI has some requirements with regards to Objective C properties that aren’t present in the non-fragile ABI (among other things).

Since Apple hasn’t shipped a Mac with a 32-bit-only CPU since maybe 2006/7, and macOS has been 64-bit since like 10.6 (released 2009), it would probably be a better use of your time to get your app compiled as 64-bit. Especially since macOS 10.15 Catalina will drop 32-bit support entirely.


#3

All that being said, that file shouldn’t even be compiled when targeting 32 bit (there’s an #ifdef that’s supposed to prevent that). Metal doesn’t work in 32 bit apps at all.


#4

Oh, yeah. There’s also that. :stuck_out_tongue_winking_eye: