Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can CMake specify the base SDK on Mac OS X?

Tags:

c++

macos

cmake

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).

like image 641
Nick Bolton Avatar asked Apr 15 '12 19:04

Nick Bolton


People also ask

Can you use CMake on Mac?

Cygwin, Debian, FreeBSD, OS X MacPorts, Mac OS X Fink, and many others all have CMake distributions. If your system does not have a CMake package, you can find CMake precompiled for many common architectures on the CMake Download page. Select the desired release and follow the download instructions.

How do I use CMake in Terminal Mac?

To install CMake, simply type “brew install cmake” in the terminal. Once you have installed CMake, type “cmake” in your terminal to check if it's installed.


2 Answers

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! :-)

like image 159
Nick Bolton Avatar answered Oct 02 '22 22:10

Nick Bolton


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.

like image 35
vtoukas Avatar answered Oct 02 '22 22:10

vtoukas