Re: [CMake] Use of ADD_CUSTOM_COMMAND
On 04/20/2011 05:40 AM, Fraser Hutchison wrote: Hi Gib, Try the following: GET_TARGET_PROPERTY(FUBAR_EXE fubar LOCATION) ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${FUBAR_EXE} somepath) Cheers, Fraser. Don't use the obsolete LOCATION property since it might have subtle side effects, see [1]. Instead, use the new generator expressions ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $TARGET_FILE:fubar somepath) or follow the advice Michael W. has provided in the meantime. Regards, Michael H. [1] http://www.mail-archive.com/cmake@cmake.org/msg33675.html On 20/04/2011 03:31, Gib Bogle wrote: I'm a real cmake novice, and I find the cmake documentation hard to follow, because it assumes that you know what you're doing (and I obviously don't) and doesn't provide examples. I simply want to add to CMakeLists.txt an instruction to copy the executable created to another directory. I gather that I want to use ADD_CUSTOM_COMMAND, and naively I thought this might do it: ADD_CUSTOM_COMMAND( TARGET fubar POST_BUILD COMMAND copy fubar.exe somepath/fubar.exe) but although this doesn't trigger a cmake error, it doesn't do anything either, and doesn't even seem to change Makefile. Can someone point me in the right direction? I'm using MinGW tools on Windows. Thanks Gib ___ 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] Use of ADD_CUSTOM_COMMAND
Quoting Michael Hertling mhertl...@online.de: On 04/20/2011 05:40 AM, Fraser Hutchison wrote: Hi Gib, Try the following: GET_TARGET_PROPERTY(FUBAR_EXE fubar LOCATION) ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${FUBAR_EXE} somepath) Cheers, Fraser. Don't use the obsolete LOCATION property since it might have subtle side effects, see [1]. Instead, use the new generator expressions ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $TARGET_FILE:fubar somepath) or follow the advice Michael W. has provided in the meantime. Regards, Michael H. OK, I'll take your word for it :-). One line is better than two, anyway. Thanks Gib This message was sent using IMP, the Internet Messaging Program. ___ 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] Use of ADD_CUSTOM_COMMAND
On 04/20/2011 11:56 PM, Gib Bogle wrote: Quoting Michael Hertling mhertl...@online.de: On 04/20/2011 05:40 AM, Fraser Hutchison wrote: Hi Gib, Try the following: GET_TARGET_PROPERTY(FUBAR_EXE fubar LOCATION) ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${FUBAR_EXE} somepath) Cheers, Fraser. Don't use the obsolete LOCATION property since it might have subtle side effects, see [1]. Instead, use the new generator expressions ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $TARGET_FILE:fubar somepath) or follow the advice Michael W. has provided in the meantime. Regards, Michael H. Hi Michael, I wonder if something went amiss in your post. This command: ADD_CUSTOM_COMMAND(TARGET threshold POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $TARGET_FILE:threshold ../bin) gives an error: C:\Users\Gib\LN_structure\code\thresholdmake Linking CXX executable threshold.exe Creating library file: libthreshold.dll.a Access is denied. mingw32-make[2]: *** [threshold.exe] Error 1 mingw32-make[1]: *** [CMakeFiles/threshold.dir/all] Error 2 mingw32-make: *** [all] Error 2 while this one works OK: ADD_CUSTOM_COMMAND(TARGET threshold POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy threshold.exe ../bin) Any ideas? Gib Which version of CMake do you use? IIRC, the generator expressions for custom commands have been added quite recently in 2.8.4. Moreover, if the directory ../bin doesn't exist at the time the custom command is run, the executable will be copied to a file named bin in the directory .., so you need to ensure the directory ../bin does exist, cf. FILE(MAKE_DIRECTORY ...) or cmake -E make_directory. Besides, don't use the .. path in that way; use variables like CMAKE_BINARY_DIR instead, i.e. ${CMAKE_BINARY_DIR}/../bin, e.g. If the issue still persists, could you check whether the following CMakeLists.txt file also fails on your system? It works on mine: CMAKE_MINIMUM_REQUIRED(VERSION 2.8.4 FATAL_ERROR) PROJECT(GENEXP C) SET(CMAKE_VERBOSE_MAKEFILE ON) FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin) FILE(WRITE ${CMAKE_BINARY_DIR}/main.c int main(void){return 0;}\n) ADD_EXECUTABLE(main main.c) ADD_CUSTOM_COMMAND(TARGET main POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $TARGET_FILE:main ${CMAKE_BINARY_DIR}/bin) If it fails, please post [C]Make's output for further investigation. Regards, Michael PS: Always reply to the ML, so others may benefit from the discussion. ___ 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] Use of ADD_CUSTOM_COMMAND
On 21/04/2011 11:38 a.m., Michael Hertling wrote: On 04/20/2011 11:56 PM, Gib Bogle wrote: Quoting Michael Hertlingmhertl...@online.de: On 04/20/2011 05:40 AM, Fraser Hutchison wrote: Hi Gib, Try the following: GET_TARGET_PROPERTY(FUBAR_EXE fubar LOCATION) ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${FUBAR_EXE} somepath) Cheers, Fraser. Don't use the obsolete LOCATION property since it might have subtle side effects, see [1]. Instead, use the new generator expressions ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $TARGET_FILE:fubar somepath) or follow the advice Michael W. has provided in the meantime. Regards, Michael H. Hi Michael, I wonder if something went amiss in your post. This command: ADD_CUSTOM_COMMAND(TARGET threshold POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $TARGET_FILE:threshold ../bin) gives an error: C:\Users\Gib\LN_structure\code\thresholdmake Linking CXX executable threshold.exe Creating library file: libthreshold.dll.a Access is denied. mingw32-make[2]: *** [threshold.exe] Error 1 mingw32-make[1]: *** [CMakeFiles/threshold.dir/all] Error 2 mingw32-make: *** [all] Error 2 while this one works OK: ADD_CUSTOM_COMMAND(TARGET threshold POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy threshold.exe ../bin) Any ideas? Gib Which version of CMake do you use? IIRC, the generator expressions for custom commands have been added quite recently in 2.8.4. Moreover, if the directory ../bin doesn't exist at the time the custom command is run, the executable will be copied to a file named bin in the directory .., so you need to ensure the directory ../bin does exist, cf. FILE(MAKE_DIRECTORY ...) or cmake -E make_directory. Besides, don't use the .. path in that way; use variables like CMAKE_BINARY_DIR instead, i.e. ${CMAKE_BINARY_DIR}/../bin, e.g. If the issue still persists, could you check whether the following CMakeLists.txt file also fails on your system? It works on mine: CMAKE_MINIMUM_REQUIRED(VERSION 2.8.4 FATAL_ERROR) PROJECT(GENEXP C) SET(CMAKE_VERBOSE_MAKEFILE ON) FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin) FILE(WRITE ${CMAKE_BINARY_DIR}/main.c int main(void){return 0;}\n) ADD_EXECUTABLE(main main.c) ADD_CUSTOM_COMMAND(TARGET main POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $TARGET_FILE:main ${CMAKE_BINARY_DIR}/bin) If it fails, please post [C]Make's output for further investigation. Regards, Michael PS: Always reply to the ML, so others may benefit from the discussion. I'm using cmake 2.8.2, which presumably explains the failure. The directory ../bin exists (otherwise the other form of the command would have failed). Cheers Gib ___ 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] Use of ADD_CUSTOM_COMMAND
Hi Gib, Try the following: GET_TARGET_PROPERTY(FUBAR_EXE fubar LOCATION) ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${FUBAR_EXE} somepath) Cheers, Fraser. On 20/04/2011 03:31, Gib Bogle wrote: I'm a real cmake novice, and I find the cmake documentation hard to follow, because it assumes that you know what you're doing (and I obviously don't) and doesn't provide examples. I simply want to add to CMakeLists.txt an instruction to copy the executable created to another directory. I gather that I want to use ADD_CUSTOM_COMMAND, and naively I thought this might do it: ADD_CUSTOM_COMMAND( TARGET fubar POST_BUILD COMMAND copy fubar.exe somepath/fubar.exe) but although this doesn't trigger a cmake error, it doesn't do anything either, and doesn't even seem to change Makefile. Can someone point me in the right direction? I'm using MinGW tools on Windows. Thanks Gib ___ 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 ___ 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] Use of ADD_CUSTOM_COMMAND
It worked! Brilliant! Thanks very much. I have a lot to learn ... Gib Quoting Fraser Hutchison fraser.hutchi...@googlemail.com: Hi Gib, Try the following: GET_TARGET_PROPERTY(FUBAR_EXE fubar LOCATION) ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${FUBAR_EXE} somepath) Cheers, Fraser. On 20/04/2011 03:31, Gib Bogle wrote: I'm a real cmake novice, and I find the cmake documentation hard to follow, because it assumes that you know what you're doing (and I obviously don't) and doesn't provide examples. I simply want to add to CMakeLists.txt an instruction to copy the executable created to another directory. I gather that I want to use ADD_CUSTOM_COMMAND, and naively I thought this might do it: ADD_CUSTOM_COMMAND( TARGET fubar POST_BUILD COMMAND copy fubar.exe somepath/fubar.exe) but although this doesn't trigger a cmake error, it doesn't do anything either, and doesn't even seem to change Makefile. Can someone point me in the right direction? I'm using MinGW tools on Windows. Thanks Gib ___ 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 This message was sent using IMP, the Internet Messaging Program. ___ 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] Use of ADD_CUSTOM_COMMAND
On 04/20/2011 05:47 AM, Gib Bogle wrote: It worked! Brilliant! Thanks very much. I have a lot to learn ... Gib Quoting Fraser Hutchison fraser.hutchi...@googlemail.com: Hi Gib, Try the following: GET_TARGET_PROPERTY(FUBAR_EXE fubar LOCATION) ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${FUBAR_EXE} somepath) Cheers, Fraser. OTOH, do you really want to copy the executable, or do you want it to be generated somewhere else in the first place? In that case, there is the CMAKE_RUNTIME_OUTPUT_DIRECTORY variable and the RUNTIME_OUTPUT_DIRECTORY target property. Also, there are configuration specific versions, e.g. CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG. 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