Can CMake specify the base SDK on Mac OS X?

后端 未结 3 719
我寻月下人不归
我寻月下人不归 2020-12-30 06:06

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

3条回答
  •  隐瞒了意图╮
    2020-12-30 06:42

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

提交回复
热议问题