16

Does anyone know how to do specify the Mac OS X SDK to build against with CMake? I have searched for cmake mac "base sdk" but this turned up nothing.

I am using CMake to generate Unix makefiles.

Update

On my 10.6 install, I see that /Developer/SDKs has the following:

  • MacOSX10.4u.sdk
  • MacOSX10.5.sdk
  • MacOSX10.6.sdk

Perhaps I can get CMake to pass one of these paths to the compiler somehow?

Also, my 10.7 install only has:

  • MacOSX10.6.sdk
  • MacOSX10.7.sdk

Does this mean that it can only build for these platforms?

Update 2

Damn, I just realised that actually I'm not using Xcode -- so this may affect some answers. Also, I am now trying with Mac OS X 10.8 developer preview (with some weird results, see my answer).

Community
  • 1
  • 1
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
  • 1
    Regarding the last part of your question, XCode4 does not support building targets for 10.4 or 10.5 (PPC targets) - it's Intel only. There's some reading [here](http://www.macstories.net/news/developers-xcode-4-will-drop-support-for-10-5-sdk/). This StackOverflow question [here](http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4) discusses building for 10.4 or 10.5 under 10.7 Xcode 4. – simont Apr 16 '12 at 00:05
  • Interesting point, thanks for the heads up. – Nick Bolton May 11 '12 at 21:37

3 Answers3

33

After trying sakra's valid answer (valid as far as CMake is suposed to behave) unsucessfully, I had a dig around and found that if I specify the --sysroot flag to the compiler, it seems to use the correct SDK!

However, I now see this error when I compile against 10.7 (which I don't see with 10.8):

Undefined symbols for architecture i386:
  "_NXArgv", referenced from:
      execSelfNonDaemonized() in libarch.a(CArchDaemonUnix.o)
      CArchDaemonUnix::daemonize(char const*, int (*)(int, char const**)) in libarch.a(CArchDaemonUnix.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/synergyc] Error 1
make[1]: *** [src/cmd/synergyc/CMakeFiles/synergyc.dir/all] Error 2
make: *** [all] Error 2

Note: CArchDaemonUnix is a class in Synergy (an open source project I'm working on).

Update:

Just tried this on my 10.6 install, and I was getting a linker error when trying to compile for 10.5 -- turns out you also need to specify the MACOSX_DEPLOYMENT_TARGET environment variable!

Anyway, here's what I'm doing when running on Mountain Lion (OSX 10.8) to compile for 10.7:

Command line:

MACOSX_DEPLOYMENT_TARGET=10.7

cmake -G "Unix Makefiles" -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.7.sdk/ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.7 ../..

CMakeLists.txt:

set(CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS}")

I hope this helps someone! :-)

Community
  • 1
  • 1
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
  • 1
    nice to see somebody trying to fix synergy on the mac! ;) – hopia Sep 22 '12 at 19:38
  • This is excellent. As an additional note, CMake seems to ignore whether `CMAKE_OSX_DEPLOYMENT_TARGET` is set, overriding it with whatever is in `MACOSX_DEPLOYMENT_TARGET`. The former may be meant to be for internal use by CMake or something. – Matthew Read Nov 12 '13 at 20:35
  • Appending the flag `-mmacosx-version-min=10.15` manually to each of CMake's "..._FLAGS" variables is hard (unless you develop a [custom tool-chain](https://github.com/top-master/xcode-cmake-support), hence thanks for sharing). – Top-Master Jul 21 '23 at 18:45
7

Add the following commands on your CMakeLists.txt

set(CMAKE_OSX_SYSROOT macosx10.10)

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5")

This should be fine.

vtoukas
  • 81
  • 1
  • 4
3

You can set the variable CMAKE_OSX_SYSROOT to the chosen SDK upon configuring the project. E.g.:

cmake -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.4u.sdk/ ..

See the documentation here.

Also note that CMake versions before 2.8.8 do not support Xcode 4.3.

sakra
  • 62,199
  • 16
  • 168
  • 151
  • This didn't seem to work for me. I am appending this to my cmake command: `-DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.7.sdk/` -- however, the `MAC_OS_X_VERSION_10_8` macro is still defined. – Nick Bolton May 11 '12 at 21:55
  • I have also tried setting `CMAKE_OSX_DEPLOYMENT_TARGET` but this didn't make a difference either. – Nick Bolton May 11 '12 at 21:57
  • Interestingly, I've added `message("sysroot=${CMAKE_OSX_SYSROOT}")` to Darwin.cmake and it does indeed print out the path that I specify. So your answer seems correct, but perhaps something weird is happening with CMake? – Nick Bolton May 11 '12 at 22:18