1

I'm working on 3dtk which uses CMake to build. You can find its CMakeLists.txt here: https://sourceforge.net/p/slam6d/code/HEAD/tree/trunk/CMakeLists.txt

In several places it uses the add_subdirectory directive and never supplies a second argument (the binary_dir).

This seems to be no problem when calling ccmake out-of-tree on linux or when using cmake-gui on windows as in both cases, the project configures successfully.

But when I run plain cmake on windows in the command prompt, then I get several errors like this:

CMake Error at Z:/CMakeLists.txt:471 (add_subdirectory):
  add_subdirectory not given a binary directory but the given source
  directory "Z:/src/slam6d" is not a subdirectory of "Z:/". When specifying
  an out-of-tree source a binary directory must be explicitly specified.

I suspect that I'm just missing an option to the cmake command but which one?

Just as with cmake-gui on Windows where I specify a different path for Where to build the binaries than for where is the source code to make an out-of-tree build and just as with ccmake on Linux where I run ccmake in a subdirectory of my source like this ccmake .., I'm running cmake on Windows from within a subdirectory of my source.

So what are cmake-gui and ccmake doing that cmake does not and where manual intervention is required?

Edit: after finding the solution it turns out that the problem was that my source directory was directly a windows drive letter instead of a subdirectory of one.

josch
  • 6,716
  • 3
  • 41
  • 49
  • What is the exact command line (`cmake ...`) which results in that error message? – tamas.kenez Aug 07 '15 at 14:50
  • @tamas.kenez: it turns out that the problem was, that my cmake source was at the top of a drive letter instead of a subdirectory. This information was missing in my original question. – josch Aug 07 '15 at 17:41

2 Answers2

2

It turns out that this is a bug in cmake. Quoting David Cole:

Put your source in a sub-directory. CMake simply does not work at the root of a drive letter on Windows. CMakeLists.txt MUST be in at least one sub-directory underneath a root drive letter path.

There are also some open bugreports about this issue:

josch
  • 6,716
  • 3
  • 41
  • 49
0

Looking at the bug reports josch has given, it does not look like CMake will be fixed with this in some near future. I encountered this problem while using cmake on android NDK project.

My solution was to use junction (I use windows 10), I could not move source folders to sub directories.

To make junction use mklink command (in cmd.exe):

cd z:\
mklink /J MyProjectJp z:\

in explorator you will see a folder z:\MyProjectJpwith exact same view as z:\. Now to build your project enter z:\MyProjectJp.

marcinj
  • 48,511
  • 9
  • 79
  • 100