3

I am using cmake3 (version 3.6.1) on Centos. In the previous versions of CMake, I was able to specify the build directory using the -B option:

cmake -GNinja -B build

With that, all the temporary files such as CMakeCache.txt are stored in the build folder. Now with the cmake3, I don't see the -B option anymore. Is there a different option?

Kevin
  • 16,549
  • 8
  • 60
  • 74
ssk
  • 9,045
  • 26
  • 96
  • 169
  • 1
    `(cd build && cmake -Gninja ..)`? - but I don't think -B was removed – spectras Nov 12 '19 at 23:11
  • Browsing versions in https://cmake.org/cmake/help/v3.13/manual/cmake.1.html seems to suggest that versions prior to 3.13 did not have that option, but more recent ones do. – jacob Nov 12 '19 at 23:19
  • Missing in https://cmake.org/cmake/help/v3.6/manual/cmake.1.html – ssk Nov 12 '19 at 23:24

1 Answers1

1

In the documentation for the CMake 3.6.X command line options, the -B option is indeed not listed:

cmake [<options>] (<path-to-source> | <path-to-existing-build>)

However, the functionality is still there. You can still use -B to specify a location for the build directory (the current directory is the default). This option, along with -H for specifying the source directory, were two undocumented command line options for many CMake releases (see this answer).

Because the functionality to support the -B option was retained, and is still commonly used, CMake added it back into their documentation in CMake 3.13. The latest documentation describes the -B behavior that has been present all along:

cmake [<options>] -S <path-to-source> -B <path-to-build>

Uses <path-to-build> as the build tree and <path-to-source> as the source tree. The specified paths may be absolute or relative to the current working directory. The source tree must contain a CMakeLists.txt file. The build tree will be created automatically if it does not already exist. For example:

     $ cmake -S src -B build
Kevin
  • 16,549
  • 8
  • 60
  • 74
  • I am stuck on 3.6.1. If I try your suggestion i.e., -S src -B build. I get this error build" does not appear to contain CMakeLists.txt. – ssk Nov 12 '19 at 23:34
  • 1
    @ssk I expanded my answer. The `-S` option to specify the source directory is new, but the undocumented option `-H` also allows you to specify the source directory. This option `-H` should be available in CMake 3.6, and is actually still available in the latest version of CMake (3.16) today. – Kevin Nov 12 '19 at 23:40