I’ve wanted to try out a few little projects based around llvm/clang for a while now. I grabbed the sources from svn last week, and have been perusing them, and their documentation, randomly. Today I caught wind of the supposed support for Xcode (in the form of Xcode project files) via CMake. “Awesome!”, I thought, “I won’t have to deal with the files piece-meal, construct a gigantic workspace manually, nor deal with Xcode’s obnoxious bugs pertaining to project-less files”.
Alas, first you have to install CMake. Easy enough in theory – there’s a pre-built binary wrapped in a pkg which Pacifist handily extracted. Unfortunately when I tried to have it generate the Xcode project file(s), it failed miserably:
The C compiler identification is GNU 4.2.1 The CXX compiler identification is GNU 4.2.1 Checking whether C compiler has -isysroot Checking whether C compiler has -isysroot - yes Checking whether C compiler supports OSX deployment target flag Checking whether C compiler supports OSX deployment target flag - yes Check for working C compiler using: Xcode Check for working C compiler using: Xcode -- broken CMake Error at /Applications/Developer/CMake 2.8-8 copy.app/Contents/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE): The C compiler "/usr/bin/gcc" is not able to compile a simple test program. It fails with the following output: Change Dir: /Users/wadetregaskis/Documents/clang/build/CMakeFiles/CMakeTmp Run Build Command:/Applications/Developer/CMake\ 2.8-8\ copy.app/Contents/bin/cmakexbuild -project CMAKE_TRY_COMPILE.xcode build -target cmTryCompileExec3212381544 -buildstyle Development xcodebuild: error: option '-buildstyle' is no longer supported Usage: xcodebuild [-project ] [[-target ]...|-alltargets] [-configuration ] [-arch ]... [-sdk [|]] [=]... ... xcodebuild [-project ] -scheme [-configuration ] [-arch ]... [-sdk [|]] [=]... ... xcodebuild -workspace -scheme [-configuration ] [-arch ]... [-sdk [|]] [=]... ... xcodebuild -version [-sdk [|]  ] xcodebuild -list [[-project ]|[-workspace ]] xcodebuild -showsdks Options: -usage print full usage -verbose provide additional status output -license Show License agreement! -project NAME build the project NAME -target NAME build the target NAME -alltargets build all targets -workspace NAME build the workspace NAME -scheme NAME build the scheme NAME -configuration NAME use the build configuration NAME for building each target -xcconfig PATH apply the build settings defined in the file at PATH as overrides -arch ARCH build each target for the architecture ARCH; this will override architectures defined in the project -sdk SDK use SDK as the name or path of the base SDK when building the project -parallelizeTargets build independent targets in parallel -jobs NUMBER specify the maximum number of concurrent build operations -showsdks display a compact list of the installed SDKs -list lists the targets and configurations in a project, or the schemes in a workspace -find BINARY display the full path to BINARY in the provided SDK -version display the version of Xcode; with -sdk will display info about one or all installed SDKs CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:3 (project) Configuring incomplete, errors occurred!
Awesome. So it’s off to the interwebs to see if it’s been encountered before. Turns out it had. But it hadn’t been fixed. Bollocks.
So, I grabbed the CMake source, dug about for a while, and found the offending code: it was looking for Xcode in one of only two places, ignoring the fact that it can be installed anywhere and there are tools specifically for the purpose of finding it. Worse, it was silently assuming Xcode 1.5 if it couldn’t find anything installed. 1.5? Really? Why?
Anyway, a five minute patch and an hour fighting with the stupid CMake GUI (which inexplicable uses old versions of cmake longer after you’ve replaced them within its app package), and it’s working. And now I have a slightly ridiculously large Xcode workspace, ready to go.
Of course, a whole bunch of key projects won’t build from the Xcode project. Le sigh… back down another rabbit hole…