[CMake] cmake 3.7.2: add_custom_command can't DEPEND on OBJECT library?

Paul Smith paul at mad-scientist.net
Sat Jan 14 18:35:03 EST 2017


If I create an OBJECT library:

  add_library(libIface OBJECT iface.cpp)

Then I create a custom command that depends on this:

  add_custom_command(OUTPUT out.map
      COMMAND touch out.map
      DEPENDS libIface
      VERBATIM)

It doesn't work: the dependency is missing so when I edit the iface.cpp
file the custom command is not run.  I'm using the Makefile generator,
on Linux, and if I look at the generated makefile it's obvious that
there's nothing there representing the OBJECT library:

  out.map:
        @$(CMAKE_COMMAND) -E ... "Generating out.map"
        touch out.map

The documentation for add_custom_command() clearly says that DEPENDS can
specify "any target (created by the ... add_library() command)".

Is there something missing from the docs that should say it doesn't work
with OBJECT libraries, or is this a bug in cmake?


Repro:

--------------------------------------------------------------------
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(MapTest)

add_library(libIface OBJECT iface.cpp)

add_custom_command(OUTPUT out.map
    COMMAND touch out.map
    DEPENDS libIface
    VERBATIM)

add_custom_target(libIfaceMap DEPENDS out.map)

add_library(iface SHARED $<TARGET_OBJECTS:libIface> out.map)

$ touch iface.cpp

$ cmake .

$ make
Scanning dependencies of target libIface
[ 33%] Building CXX object CMakeFiles/libIface.dir/iface.cpp.o
[ 33%] Built target libIface
[ 66%] Generating out.map
Scanning dependencies of target iface
[100%] Linking CXX shared library libiface.so
[100%] Built target iface

$ touch iface.cpp

$ make
Scanning dependencies of target libIface
[ 33%] Building CXX object CMakeFiles/libIface.dir/iface.cpp.o
[ 33%] Built target libIface
[ 66%] Linking CXX shared library libiface.so
[100%] Built target iface
--------------------------------------------------------------------

Note that in the last step the "out.map" file was not recreated even
though iface.cpp was modified.


More information about the CMake mailing list