Re: [CMake] delayed target
On 02/22/2012 05:02 PM, Andrea Crotti wrote: Again I'm having some troubles with the different building stages: I would like to have a target that simply unzips all the files contained in a directory, which can be found with a simple globbing. add_custom_target(unzip_all_eggs file(GLOB eggs RELATIVE ${EGG_BUILD_DIRECTORY}/*egg) COMMAND ${PYTHON_EXECUTABLE} ${UNZIP_SCRIPT} ${egg} ) The problem is that [...] ...FILE(GLOB ...) is a CMake command executed by CMake, whereas the custom target's COMMANDs are executed by the build tool at build time, so this approach fails from the first. A possible solution is to make my UNZIP_SCRIPT smarter and just do the globbing itself, is there any other more CMake-like solution? ADD_CUSTOM_TARGET(unzip_all_eggs ${CMAKE_COMMAND} -DEGGDIR=${EGG_BUILD_DIRECTORY} -P ${CMAKE_SOURCE_DIR}/unzip_all_eggs.cmake) # ${CMAKE_SOURCE_DIR}/unzip_all_eggs.cmake: SET(PYTHON_EXECUTABLE ...) SET(UNZIP_SCRIPT ...) FILE(GLOB eggs RELATIVE ${EGGDIR}/*egg) EXECUTE_PROCESS( COMMAND ${PYTHON_EXECUTABLE} ${UNZIP_SCRIPT} ${eggs} WORKING_DIRECTORY ... ) You might want to provide an unzip_all_eggs.cmake.in template including SET(PYTHON_EXECUTABLE @PYTHON_EXECUTABLE@) SET(UNZIP_SCRIPT @UNZIP_SCRIPT@) use CONFIGURE_FILE(unzip_all_eggs.cmake.in unzip_all_eggs.cmake @ONLY) to generate the actual unzip_all_eggs.cmake after searching Python and your script, and specify -P ${CMAKE_BINARY_DIR}/unzip_all_eggs.cmake. Regards, 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] delayed target
On 02/22/2012 05:14 PM, Michael Hertling wrote: On 02/22/2012 05:02 PM, Andrea Crotti wrote: Again I'm having some troubles with the different building stages: I would like to have a target that simply unzips all the files contained in a directory, which can be found with a simple globbing. add_custom_target(unzip_all_eggs file(GLOB eggs RELATIVE ${EGG_BUILD_DIRECTORY}/*egg) COMMAND ${PYTHON_EXECUTABLE} ${UNZIP_SCRIPT} ${egg} ) The problem is that [...] ...FILE(GLOB ...) is a CMake command executed by CMake, whereas the custom target's COMMANDs are executed by the build tool at build time, so this approach fails from the first. A possible solution is to make my UNZIP_SCRIPT smarter and just do the globbing itself, is there any other more CMake-like solution? ADD_CUSTOM_TARGET(unzip_all_eggs ${CMAKE_COMMAND} -DEGGDIR=${EGG_BUILD_DIRECTORY} -P ${CMAKE_SOURCE_DIR}/unzip_all_eggs.cmake) # ${CMAKE_SOURCE_DIR}/unzip_all_eggs.cmake: SET(PYTHON_EXECUTABLE ...) SET(UNZIP_SCRIPT ...) FILE(GLOB eggs RELATIVE ${EGGDIR}/*egg) EXECUTE_PROCESS( COMMAND ${PYTHON_EXECUTABLE} ${UNZIP_SCRIPT} ${eggs} WORKING_DIRECTORY ... ) You might want to provide an unzip_all_eggs.cmake.in template including SET(PYTHON_EXECUTABLE @PYTHON_EXECUTABLE@) SET(UNZIP_SCRIPT @UNZIP_SCRIPT@) use CONFIGURE_FILE(unzip_all_eggs.cmake.in unzip_all_eggs.cmake @ONLY) to generate the actual unzip_all_eggs.cmake after searching Python and your script, and specify -P ${CMAKE_BINARY_DIR}/unzip_all_eggs.cmake. Thanks, this is really nice in general and I might use it in the future. The problem is that in this specific case it doesn't buy me much and adds complexity, because I would still have only one target unzipping all the eggs. It would be nice to be able to generate N target 1 for each egg. Anyway I think that just modifying the python unzip script to do the globbing is the easier way to go in this case.. -- 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] delayed target
On 02/22/2012 07:21 PM, Andrea Crotti wrote: On 02/22/2012 05:14 PM, Michael Hertling wrote: On 02/22/2012 05:02 PM, Andrea Crotti wrote: Again I'm having some troubles with the different building stages: I would like to have a target that simply unzips all the files contained in a directory, which can be found with a simple globbing. add_custom_target(unzip_all_eggs file(GLOB eggs RELATIVE ${EGG_BUILD_DIRECTORY}/*egg) COMMAND ${PYTHON_EXECUTABLE} ${UNZIP_SCRIPT} ${egg} ) The problem is that [...] ...FILE(GLOB ...) is a CMake command executed by CMake, whereas the custom target's COMMANDs are executed by the build tool at build time, so this approach fails from the first. A possible solution is to make my UNZIP_SCRIPT smarter and just do the globbing itself, is there any other more CMake-like solution? ADD_CUSTOM_TARGET(unzip_all_eggs ${CMAKE_COMMAND} -DEGGDIR=${EGG_BUILD_DIRECTORY} -P ${CMAKE_SOURCE_DIR}/unzip_all_eggs.cmake) # ${CMAKE_SOURCE_DIR}/unzip_all_eggs.cmake: SET(PYTHON_EXECUTABLE ...) SET(UNZIP_SCRIPT ...) FILE(GLOB eggs RELATIVE ${EGGDIR}/*egg) EXECUTE_PROCESS( COMMAND ${PYTHON_EXECUTABLE} ${UNZIP_SCRIPT} ${eggs} WORKING_DIRECTORY ... ) You might want to provide an unzip_all_eggs.cmake.in template including SET(PYTHON_EXECUTABLE @PYTHON_EXECUTABLE@) SET(UNZIP_SCRIPT @UNZIP_SCRIPT@) use CONFIGURE_FILE(unzip_all_eggs.cmake.in unzip_all_eggs.cmake @ONLY) to generate the actual unzip_all_eggs.cmake after searching Python and your script, and specify -P ${CMAKE_BINARY_DIR}/unzip_all_eggs.cmake. Thanks, this is really nice in general and I might use it in the future. The problem is that in this specific case it doesn't buy me much and adds complexity, because I would still have only one target unzipping all the eggs. It would be nice to be able to generate N target 1 for each egg. In order to define one target per egg, you'd need to know the eggs at configuration time since you cannot define targets at build time. So, gathering the eggs with a custom target/command will not work. As an alternative, you might gather the eggs at configuration time with a FILE(GLOB ...) command, loop over the resulting list and define one target per item. However, your Makefiles would not be aware of any changes among the eggs - additions, removals, renamings - and you would need to remember to reconfigure your project by hand if you don't want to miss any changes. That's somewhat error-prone and means relinquishing one of CMake's benefits. Regards, 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] delayed target
On 02/22/2012 09:37 PM, Michael Hertling wrote: In order to define one target per egg, you'd need to know the eggs at configuration time since you cannot define targets at build time. So, gathering the eggs with a custom target/command will not work. As an alternative, you might gather the eggs at configuration time with a FILE(GLOB ...) command, loop over the resulting list and define one target per item. However, your Makefiles would not be aware of any changes among the eggs - additions, removals, renamings - and you would need to remember to reconfigure your project by hand if you don't want to miss any changes. That's somewhat error-prone and means relinquishing one of CMake's benefits. Regards, Michael - Yes sure when there are changes in that sense we need to reconfigure, but it's really not a big deal in our case because it won't almost never happen, and anyway I don't really have any other choice if I want to use the parallelization provided by make -j. -- 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] delayed target
On 02/22/2012 11:55 PM, Andrea Crotti wrote: On 02/22/2012 09:37 PM, Michael Hertling wrote: In order to define one target per egg, you'd need to know the eggs at configuration time since you cannot define targets at build time. So, gathering the eggs with a custom target/command will not work. As an alternative, you might gather the eggs at configuration time with a FILE(GLOB ...) command, loop over the resulting list and define one target per item. However, your Makefiles would not be aware of any changes among the eggs - additions, removals, renamings - and you would need to remember to reconfigure your project by hand if you don't want to miss any changes. That's somewhat error-prone and means relinquishing one of CMake's benefits. Regards, Michael - Yes sure when there are changes in that sense we need to reconfigure, but it's really not a big deal in our case because it won't almost never happen, and anyway I don't really have any other choice if I want to use the parallelization provided by make -j. There is a possibility to dynamically reconfigure/rebuild the project without an intermediate manual step and in a way that you'll have one target per egg, but that approach is disadvantageous in other regards and possibly won't work with generators other than the Makefiles ones. IMO, if you really need one target per egg, you should gather them at configure time and accept the need to reconfigure the project by hand when necessary. If one target per egg isn't a must-do, gather them at build time and use a script - CMake, shell, whatever - to unzip them; this can be done well in parallel also. Regards, 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