cmake generate Xcode project from existing sources

From the root of your project directory.

cmake -G Xcode -H. -B_build

This is similar to the answer above. However, you are manually managing the out of source build. -B sets your target build directory (I happen to prefer _build). I tried looking up -H to double check, but couldn't find it. If memory serves, it specifies where your CMakeLists.txt lives.

I keep this command in a .sh/.bat file (depending). This way, I can keep my scripts that build my project in the root where a new person can easily find them.


CMake is used to produce out-of-source builds.

The idea here is that you don't mix the files created during compilation with the original source files. In practice, you usually run CMake from a new, empty build directory and give the path to the source directory as an argument.

cd IXCSoftswitch
mkdir build
cd build
cmake -G Xcode ..

All of the files generated by CMake (which could be a lot) will now go into the build subdirectory, while your source directory stays clean of build artifacts.

The concept of out-of-source builds may seem strange at first, but it is actually a very convenient way of working once you get used to it.

Tags:

Macos

Cocoa

Cmake