25

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.

Eric Schmidt
  • 312
  • 1
  • 11
user170317
  • 1,152
  • 2
  • 11
  • 22

2 Answers2

74

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.

Bohdan Ivanov
  • 806
  • 9
  • 28
ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
  • looks like this is solution, but i can't find final Xcode project which include all source files. can u please edit answer, where is located? – user170317 May 24 '13 at 05:34
  • This is determined by the project itself. I would suggest you check the documentation that ships with the source code. – ComicSansMS May 24 '13 at 07:30
  • 1
    Once you've run `cmake -G Xcode ..`, an Xcode project appears in the build folder. From there, how can one export this project as a module/framework/package that can then be imported into other Xcode workspaces? – lurning too koad Mar 20 '23 at 01:07
10

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.

JR Smith
  • 1,186
  • 15
  • 20