Should cmake-gui restore the previous binary directory when the source directory is empty?

When I start cmake-gui, the “Where is the source code” field is empty, but “Where to build the binaries” still contains the binary directory used during the previous session.

Is this the expected behaviour?

It seems potentially unsafe or confusing because, after selecting a new source directory, the GUI still displays a binary directory associated with a previous and possibly unrelated project. A user could then configure the new project into the old project’s build tree. Indeed I’ve observed students often make this mistake.

I would expect one of the following behaviours:

  1. Both fields start empty (the binary-directory history remains available in the drop-down, but the editable field itself starts empty)
  2. Both source and binary directories are restored as a pair.

Before filing an issue, could someone confirm which behaviour is intended?

CMake version: 3.25.1 (also observed with CMake version 4.3.4)
Operating system: Debian 12 (also observed on Windows 11)

Personally, I would have thought that if the binary directory is restored, so should the source directory. If the binary directory is missing or doesn’t contain a CMakeCache.txt, then restoring the source directory would only make sense if the app actually knew which source directory corresponded to the binary directory, but it might be relying on details that would normally be in the binary directory to do that (I haven’t checked the app’s source code).

It seems reasonable to me to restore neither if the app can’t reliably determine both. As you say, restoring just the binary directory and not the source directory has its dangers.

I agree. I think a UI policy such as “Do not restore the build field unless its corresponding source can also be recovered” would be an improvement.

Another issue occurs when a user with either the build directory, or both directories set, specifies a new source directory. At this point, the build directory is unchanged. As the build directory field is not blank, it is not obvious that a new value is needed. Errors for students often follow here. I suggest that changing the source directory should clear the build directory field.

Returning to the original question: my own preference would be for both fields to be empty on startup. This would present a consistent interface; and encourage users to enter a new, valid build directory.

I’d recommend opening an issue in the issue tracker as a starting point. I don’t know if any of the regular contributors have the bandwidth to work on it, but defining the problem and agreeing on a way forward there would be a good first step. If you’re willing to work on it yourself, we can likely provide some pointers (some familiarity with Qt might help).

https://gitlab.kitware.com/cmake/cmake/-/work_items/new?type=Issue&initialCreationContext=list-route

1 Like