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.
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to