[CMake] How to use OBJECT_DEPENDS

elizabeta petreska elizabeta.petreska at gmail.com
Wed Apr 8 11:01:42 EDT 2009


Hello all

I want to make my target dependent on existing non source file on disk.
So far I have the following :

SET_SOURCE_FILES_PROPERTIES(main.cpp OBJECT_DEPENDS
${CMAKE_SOURCE_DIR}/myfile.txt)
ADD_EXECUTABLE(MyTarget main.cpp)

But the this does NOT work, if I touch myfile.txt  MyTarget is not rebuild.


I was searching the posts and I found that this can be solved with something
like this :

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp

                   COMMAND echo "/* this file is empty */" >
${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
                   DEPENDS ${CMAKE_SOURCE_DIR}/myfile.txt )

add_executable(MyTarget main.cpp ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp )

But this solution is not the most elegant becauseit requires generating of
dummy file which need to be added as input to add_executable.

Also the following works :

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp

                   COMMAND echo "/* this file is empty */" >
${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
                   DEPENDS ${CMAKE_SOURCE_DIR}/myfile.txt )

add_custom_target(CustomTarget ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)

add_dependencies(MyTarget CustomTarget)

But again this creates new target which shows up in my Visual Studio
solution.

So I found the first code with OBJECT_DEPENDS most acceptable. Can someone
through light on this and say why it does not works? What I am doing wrong?

Thanks for the help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090408/26a69db3/attachment-0001.htm>


More information about the CMake mailing list