Re: [CMake] ADD_CUSTOM_COMMAND and Dependencies
On 08/01/2011 09:32 AM, Micha Renner wrote: > Am Montag, den 25.07.2011, 15:49 +0200 schrieb Michael Wild: >> On 07/25/2011 03:24 PM, Micha Renner wrote: >>> There is following sequence: >>> >>> ADD_EXECUTEABLE(generator gen.c) >>> >>> ADD_CUSTOM_COMMAND(OUTPUT tlib.h >>> COMMAND generator > tlib.h) >>> >>> ADD_LIBRARY(tlib tlib.c tlib.h) >>> >>> The question: Is it sure that ADD_EXECUTEABLE is invoked before the >>> library is build or is here an ADD_DEPENDENCIES(tlib generator) >>> necessary? >>> >>> Greetings >>> >>> Micha >>> >> >> Yes, CMake should recognize that "generator" is a target and create the >> dependency of tlib.h on "generator" automagically. And since it knows >> that tlib.h is GENERATED, it will also add a dependency of tlib on >> tlib.h. If you want to make really sure that CMake understands that >> "generator" is a target, use generator expressions, like >> "$", but that works only since 2.8.4. > > So really clear is this not. > After studying the documentation, to get more information for > target_file, I found this line in the add_custom_command documentation: > "Additionally, if the target is an executable or library a file-level > dependency is created to cause the custom command to re-run whenever the > target is recompiled." > > ADD_CUSTOM_COMMAND(OUTPUT tlib.h COMMAND generator > tlib.h DEPENDS > generator) should solve my problem. You don't need the DEPENDS option, since CMake automatically determines that "generator" is a executable target, and adds the dependency by itself. > > But what is the difference to > ADD_CUSTOM_COMMAND(OUTPUT tlib.h COMMAND $ > generator > tlib.h)? None, it is just more explicit, and allows for greater flexibility. The $<...:...> notation also allows one to retrieve other paths, not just target output files. Michael ___ 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
Re: [CMake] ADD_CUSTOM_COMMAND and Dependencies
Am Montag, den 25.07.2011, 15:49 +0200 schrieb Michael Wild: > On 07/25/2011 03:24 PM, Micha Renner wrote: > > There is following sequence: > > > > ADD_EXECUTEABLE(generator gen.c) > > > > ADD_CUSTOM_COMMAND(OUTPUT tlib.h > > COMMAND generator > tlib.h) > > > > ADD_LIBRARY(tlib tlib.c tlib.h) > > > > The question: Is it sure that ADD_EXECUTEABLE is invoked before the > > library is build or is here an ADD_DEPENDENCIES(tlib generator) > > necessary? > > > > Greetings > > > > Micha > > > > Yes, CMake should recognize that "generator" is a target and create the > dependency of tlib.h on "generator" automagically. And since it knows > that tlib.h is GENERATED, it will also add a dependency of tlib on > tlib.h. If you want to make really sure that CMake understands that > "generator" is a target, use generator expressions, like > "$", but that works only since 2.8.4. So really clear is this not. After studying the documentation, to get more information for target_file, I found this line in the add_custom_command documentation: "Additionally, if the target is an executable or library a file-level dependency is created to cause the custom command to re-run whenever the target is recompiled." ADD_CUSTOM_COMMAND(OUTPUT tlib.h COMMAND generator > tlib.h DEPENDS generator) should solve my problem. But what is the difference to ADD_CUSTOM_COMMAND(OUTPUT tlib.h COMMAND $ generator > tlib.h)? Greetings Micha ___ 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
Re: [CMake] ADD_CUSTOM_COMMAND and Dependencies
On 07/25/2011 03:24 PM, Micha Renner wrote: > There is following sequence: > > ADD_EXECUTEABLE(generator gen.c) > > ADD_CUSTOM_COMMAND(OUTPUT tlib.h > COMMAND generator > tlib.h) > > ADD_LIBRARY(tlib tlib.c tlib.h) > > The question: Is it sure that ADD_EXECUTEABLE is invoked before the > library is build or is here an ADD_DEPENDENCIES(tlib generator) > necessary? > > Greetings > > Micha > Yes, CMake should recognize that "generator" is a target and create the dependency of tlib.h on "generator" automagically. And since it knows that tlib.h is GENERATED, it will also add a dependency of tlib on tlib.h. If you want to make really sure that CMake understands that "generator" is a target, use generator expressions, like "$", but that works only since 2.8.4. HTH Michael ___ 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
[CMake] ADD_CUSTOM_COMMAND and Dependencies
There is following sequence: ADD_EXECUTEABLE(generator gen.c) ADD_CUSTOM_COMMAND(OUTPUT tlib.h COMMAND generator > tlib.h) ADD_LIBRARY(tlib tlib.c tlib.h) The question: Is it sure that ADD_EXECUTEABLE is invoked before the library is build or is here an ADD_DEPENDENCIES(tlib generator) necessary? Greetings Micha ___ 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
RE: [CMake] ADD_CUSTOM_COMMAND and dependencies
It sounds like CMake is doing exactly what any good build system should do. A better solution is to modify your macro to accept some extra depends to add to the custom command. MACRO(GENERATE directory dependencies) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.cpp DEPENDS ${GENERATOR} ${dependencies} COMMAND ${GENERATOR} ARGS -o generated.cpp ${directory} ) SET(SOURCES ${SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/gomgenerated.cpp) ENDMACRO(GENERATE) GENERATE(myDir "target1 target2") If you insist on running the command every time, an old build trick you may try is to make a target that never builds a file. That way it will run every time. ADD_CUSTOM_COMMAND( OUTPUT NotAFile COMMAND ${CMAKE_COMMAND} ARGS -E echo "Forcing Target" ) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.cpp DEPENDS NotAFile COMMAND ${GENERATOR} ARGS -o generated.cpp ${directory} ) -Ken > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of cedric > Sent: Thursday, February 09, 2006 7:50 AM > To: cmake@cmake.org > Subject: [CMake] ADD_CUSTOM_COMMAND and dependencies > > Hello, > > I'm using cmake in a project and have some trouble with > ADD_CUSTOM_COMMAND. > What I need is generate a source file with a binary > previously generated by the project and then add it in the project. > > It works with this code : > > MACRO(GENERATE directory) > ADD_CUSTOM_COMMAND( > OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.cpp > DEPENDS ${GENERATOR} > COMMAND ${GENERATOR} > ARGS -o generated.cpp ${directory} > ) > SET(SOURCES ${SOURCES} > ${CMAKE_CURRENT_BINARY_DIR}/gomgenerated.cpp) > ENDMACRO(GENERATE) > > it works well but it run only when ${GENERATOR} is modified. > I canot add other dependecies because this macro is run on > many directories that change often. > The generator parse all files in ${directory} to check what > it have to generate and if it need to generate something. > What I need is to run that command every time I run make. I > tryed to remove the DEPENDS line but it doesn't work better. > There is a way to do what I need with CMake (in a portable > way if possible) ? > Thanks for your help. > > ___ > CMake mailing list > CMake@cmake.org > http://www.cmake.org/mailman/listinfo/cmake > > ___ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake
[CMake] ADD_CUSTOM_COMMAND and dependencies
Hello, I'm using cmake in a project and have some trouble with ADD_CUSTOM_COMMAND. What I need is generate a source file with a binary previously generated by the project and then add it in the project. It works with this code : MACRO(GENERATE directory) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.cpp DEPENDS ${GENERATOR} COMMAND ${GENERATOR} ARGS -o generated.cpp ${directory} ) SET(SOURCES ${SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/gomgenerated.cpp) ENDMACRO(GENERATE) it works well but it run only when ${GENERATOR} is modified. I canot add other dependecies because this macro is run on many directories that change often. The generator parse all files in ${directory} to check what it have to generate and if it need to generate something. What I need is to run that command every time I run make. I tryed to remove the DEPENDS line but it doesn't work better. There is a way to do what I need with CMake (in a portable way if possible) ? Thanks for your help. ___ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake