[CMake] Execute a custom command without any dependency

Sergey Prokhorenko sergey.prokhorenko at gmail.com
Mon Dec 17 14:04:48 EST 2012


Hello.

I want to run a custom command that parses a whole source tree, so I
can't list dependencies to add_custom_command/target. Is there another
way? Just always run a program, that's all.

I tried a "solution" which is to re-touch the dependency file in
POST_BUILD of the target, but it does not work reliably. Below is the
sample CMakeLists.txt file, it doesn't show "generating file1" always
- every 2nd, sometimes 3rd or 4th run it is not shown/generated. E.g.
first 3 times it is generated, 4th is not, then 2 times generated,
then not... Can it be a bug in cmake?

Here's the sample CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)

project(main)

add_custom_command(
   OUTPUT file1
   COMMAND echo touching file1
   COMMAND touch file1
   DEPENDS file2)
add_custom_target(dep ALL DEPENDS file1 file2)

# this command re-touches file2 after dep target is "built"
# and thus forces its rebuild
ADD_CUSTOM_COMMAND(TARGET dep
          POST_BUILD
          COMMAND echo touching file2
          COMMAND touch file2
)

Thanks, Sergey.


More information about the CMake mailing list