1

I am building a cmake application, I'd like to know if there is a simple way to get a return value from cmake BUILD directory when it is up to date?

For example, if I see [100%] Built target blahblah when I type make in that BUILD dir, then I hope to get a value 1.

Daniel
  • 2,576
  • 7
  • 37
  • 51
  • why though? assuming you are on *nix, make wont rebuild anything. my project i just do make clean && cmake . && make. it doesnt rebuild anything it doesnt have to (if i had omitted make clean) – DTSCode Jul 16 '14 at 19:22
  • Say I'd like to do `if [buildStatus==upToDate] then cd .. && rm -rf BUILD`. – Daniel Jul 16 '14 at 19:26
  • http://stackoverflow.com/questions/8626109/how-can-i-get-what-my-main-function-has-returned this might be of some use then. so it would probably be something like: cmake theDirectory; if [$? -eq 1]; then cd .. rm -rf BUILD; fi; – DTSCode Jul 16 '14 at 19:29
  • disclaimer: bash is not my strong suit so there are probably problems with the code i just wrote – DTSCode Jul 16 '14 at 19:30
  • Okay, perhaps I can just do a `make | grep 100%` – Daniel Jul 16 '14 at 19:31
  • You want to know when running `make` will do no work? – Etan Reisner Jul 16 '14 at 19:38

1 Answers1

0
make -q && echo "Up-to-date"

or

make -q || echo "Work to do"

From the make man page:

-q, --question

''Question mode''. Do not run any commands, or print anything; just return an exit status that is zero if the specified targets are already up to date, nonzero otherwise.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • How so? Does make, in fact, have nothing to do? "Something to do" can involved a lot of things before the build output you expect I believe. – Etan Reisner Jul 16 '14 at 19:54
  • Don't know. You can try a cmake test case yourself and see that I am not lying. My make command shows [100%], however this solution gives "Work to do" – Daniel Jul 16 '14 at 19:56
  • I don't know cmake at all. This isn't really related to cmake either (not exactly). What do you get as output if you run `make VERBOSE=1`? – Etan Reisner Jul 16 '14 at 20:00
  • A lot! It covers 1/3 of my screen so that I cannot paste them here. So I guess cmake use a different strategy for makefile, maybe? – Daniel Jul 16 '14 at 20:04
  • @Daniel No, much of that may not matter. It looks like `-q` may not be useful for default/`all`/`.PHONY` targets though since those always need to be "rebuilt". That's a bit unfortunate if I'm interpreting what I'm seeing correctly. If you have a specific target that your default target proxies for you should be able to run `-q` against that and get a meaningful result though. – Etan Reisner Jul 16 '14 at 20:11