0

Suppose I have a project named foo, with sources under /foo/src. Also suppose that at some point in the past, someone ran cmake /foo/src, so there are build files there.

Now, I want to perform a build of foo, in /foo/build. But if I cd /foo/build; cmake /foo/src - it treats /foo/src as the build directory, and configures and generates that build files there rather than in the current directory.

Questions:

  1. What is the minimal set of files in /foo/src to delete in order for cmake to configure and generate build files in /foo/build?
  2. Can I force cmake to use /foo/build without deleting anything from /foo/src?
einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

1

1. A sufficient set of files to delete

A sufficient, though perhaps not minimal, set of files to delete:

CMakeCache.txt
Makefile
cmake_install.cmake
CMakeFiles/

and if you also have tests enabled, then

CTestTestfile.cmake
Testing/
tests/CTestTestfile.cmake
tests/Makefile
tests/cmake_install.cmake
tests/CMakeFiles/

2. How to force a different build location without deletions:

If you execute

cmake -B /foo/build -S /foo/src

(for non-ancient versions of CMake), CMake will ignore the previous build and build under /foo/build. You don't need it to be your current working directory when issuing this command.

The second part of this answer can actually be found within this answer

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • If you are Using Git, then you could just do git clean -fd to remove untracked files generated by previous configure/build. – sanjivgupta Nov 15 '22 at 15:46
  • 1
    @sanjivgupta: 1. I may not be using git. 2. Some of the generated files may be covered by `.gitignore`. – einpoklum Nov 15 '22 at 21:13
  • @einpklum agree. git clean -fd may not do a full job always. It just worked for me, so just wanted to mention that it may save time for someone. But it's good to know anyways what files were generated by cmake , so it's good that you mentioned them in the first place. – sanjivgupta Nov 15 '22 at 21:45