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
_______________________________________________
Powered by www.kitware.com

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

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

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to