Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake generate Xcode project from existing sources

Tags:

macos

cocoa

cmake

This is what I have, when I started generation:

iMac:IXCSoftswitch alex$ /usr/bin/cmake -G Xcode .
-- CMAKE_SOURCE_DIR = /Users/alex/Desktop/ixc-v/IXCSoftswitch,   CMAKE_BINARY_DIR = /Users/alex/Desktop/ixc-v/IXCSoftswitch
CMake Error at CMakeLists.txt:25 (MESSAGE):
  Binary and source directory cannot be the same


-- Configuring incomplete, errors occurred!

How can I fix it? I'm new to CMake, samples appreciated.

like image 256
user170317 Avatar asked May 22 '13 19:05

user170317


2 Answers

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.

like image 195
ComicSansMS Avatar answered Nov 14 '22 00:11

ComicSansMS


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.

like image 8
JR Smith Avatar answered Nov 14 '22 02:11

JR Smith