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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Paul Smith
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cmake 3.7.2: add_custom_command can't DEPEND on OBJECT library?

Jakob van Bethlehem
Hej,

CMake experts may correct me if I'm wrong, but this is actually indeed not supported (yet). Even though an object-library looks like any ordinary library, in fact it is just a kind of 'shortcut' for a bunch of object files - it is *not* a proper cmake TARGET. Some additional explanation can be found here:

So, then the question obviously becomes how to achieve the desired result. If the creation of out.map only depends on that one source file, I'd expect you get the wanted result if instead of writing 'DEPENDS liblface', you write 'DEPENDS iface.cpp' - I'm not totally sure though.

Sincerely,
Jakob


On Sun, Jan 15, 2017 at 12:35 AM, Paul Smith <[hidden email]> wrote:
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


--

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