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.
On my 10.6 install, I see that /Developer/SDKs
has the following:
Perhaps I can get CMake to pass one of these paths to the compiler somehow?
Also, my 10.7 install only has:
Does this mean that it can only build for these platforms?
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).
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.
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.
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).
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! :-)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With