[CMake] cmake 2.6: add_custom_command - add_custom_target

Spicy spam at lhanke.de
Thu Dec 31 19:57:17 EST 2009


Hi cmakers,

I decided to start a new project using cmake. While I got a lot of
things going quickly, some things are taking me to despair. The current
issue has a couple of web hits, but either I misunderstand something
critical or cmake 2.6 (as of current Debian Lenny) is broken:

--8<-------CMakeLists.txt------------
cmake_minimum_required(VERSION 2.6)
project(test)
add_custom_command(
  OUTPUT bla.txt
  COMMAND touch bla.txt
  )
add_custom_target(bla DEPENDS bla.txt)
--8<-------CMakeLists.txt------------

I'd expect this to produce an effective Makefile like this:
.phony: bla
bla: bla.txt
bla.txt:
    touch bla.txt

Well, cmake Makefiles are somewhat more complicated, but it essentially
misses the final rule, i.e. typing

#~: make bla
make[3]: *** Keine Regel vorhanden, um das Target »../bla.txt«,
  benötigt von »CMakeFiles/bla«, zu erstellen.  Schluss.
make[2]: *** [CMakeFiles/bla.dir/all] Fehler 2
make[1]: *** [CMakeFiles/bla.dir/rule] Fehler 2
make: *** [bla] Fehler 2

(German translation of: No rule for target: ../bla.txt)

Any ideas what is going wrong here?

The whole issue arises in my solution to support GNU gettext, where this
issue is the 'pot' target boiled down to its bare necessities. Extensive
web searches did not reveal any standard gettext solution, did I miss
something by the way?

Another feature, which I have been missing dearly was propagating
variables from subdirs to global scope - I do not want to repeat this
propagation on each level. I worked around this by writing all required
data to ENV and have a macro in the root CMakeLists.txt produce the
variables. It works, but for my taste is unnecessarily complicated and
I'm unsure about length constraints on environments. The latter could be
mitigated using a file, but that's still far from elegant. Is anyone
aware of a smarter solution to define variables in various subdirs and
use those in another subdir added later?

Thanks for your help,
- lars.



More information about the CMake mailing list