1

How can I check if a CMake target is up-to-date, from the command-line, without actually building it? A target is "up-to-date" if cmake --build <BUILD_DIR> --target <TARGETNAME> would not actually execute any build steps.

In my case, the underlying build system used by CMake is make, although a generic solution would be better.

NicholasM
  • 4,557
  • 1
  • 20
  • 47
  • Related: [Show which files will be rebuilt when building a target in a cmake project](/q/72930560/11107541) – starball Mar 30 '23 at 20:00

2 Answers2

1

There does not appear to be an option to do this with "pure" or generic CMake.

However, when the underlying build system is make, this can be accomplished by passing an option to make after -- on the cmake invocation:

--

Pass remaining options to the native tool.

In this case of make, the --question option answers this question:

“Question”. Silently check whether the targets are up to date, but do not execute recipes; the exit code shows whether any updates are needed.

So overall the CMake invocation is:

cmake --build <BUILD_DIR> --target <TARGETNAME> -- --question
NicholasM
  • 4,557
  • 1
  • 20
  • 47
1

In my case, the underlying build system used by CMake is make, although a generic solution would be better.

As it was answered, CMake can't do that.

One thing many CMake beginners do not understand: CMake is not a build system but a generator of build systems. It doesn't build anything by itself. It delegates this job to the underlaid (generated) build system and has no "access" to its state. Hence, does't "know" what target is up to date and what isn't.

zaufi
  • 6,811
  • 26
  • 34