<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Yes, that works for me too.<br>In add_custom_target, the target name should not be the same as<br>the name of the file one wants to copy, then it works on both cmake versions.<br><br>Thanks Michael.<br>Mahendra<br><br>--- On <b>Thu, 24/12/09, Michael Wild <i><themiwi@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Michael Wild <themiwi@gmail.com><br>Subject: Re: [CMake] Simple CMakeLists.txt file not working with cmake version 2.6<br>To: "Mahendra Ladhe" <lml108@yahoo.com><br>Cc: cmake@cmake.org<br>Date: Thursday, 24 December, 2009, 4:50 AM<br><br><div class="plainMail">This small test project works fine for me:<br><br>cmake_minimum_required(VERSION 2.6 FATAL_ERROR)<br>project(test NONE)<br>add_custom_command(<br> OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/test.bash"<br> COMMAND "${CMAKE_COMMAND}" -E copy_if_different<br> "${CMAKE_CURRENT_SOURCE_DIR}/test.bash"<br> "${CMAKE_CURRENT_BINARY_DIR}/test.bash"<br> COMMENT "Creating ${CMAKE_CURRENT_BINARY_DIR}/test.bash"<br> VERBATIM)<br>add_custom_target(create_test_bash ALL DEPENDS<br> "${CMAKE_CURRENT_BINARY_DIR}/test.bash")<br><br><br>HTH<br><br>Michael<br><br>On 24. Dec, 2009, at 13:27 , Mahendra Ladhe wrote:<br><br>> Thanks Michael for your reply.<br>> I should have mentioned that every time I run 'make' (not cmake) I want to copy file only if <br>> the original file in the source directory has changed.<br>> <br>> I tried your suggestion, it works on cmake 2.4 but it still doesn't work on cmake 2.6<br>> mladhe@linux:~/cmake_expt/bld] make<br>> Built target sample.bash<br>> mladhe@linux:~/cmake_expt/bld] ls<br>> CMakeCache.txt CMakeFiles Makefile
cmake_install.cmake<br>> <br>> So though it says 'Built target sample.bash', the file has not been copied.<br>> Also I believe CONFIGURE_FILE(... COPYONLY) will copy file only when running<br>> 'cmake' and not when running 'make'<br>> <br>> I googled, but didn't find a solution that will work on both cmake versions.<br>> <br>> Thanks,<br>> Mahendra<br>> <br>> --- On Thu, 24/12/09, Michael Wild <<a ymailto="mailto:themiwi@gmail.com" href="/mc/compose?to=themiwi@gmail.com">themiwi@gmail.com</a>> wrote:<br>> <br>> From: Michael Wild <<a ymailto="mailto:themiwi@gmail.com" href="/mc/compose?to=themiwi@gmail.com">themiwi@gmail.com</a>><br>> Subject: Re: [CMake] Simple CMakeLists.txt file not working with cmake version 2.6<br>> To: "Mahendra Ladhe" <<a ymailto="mailto:lml108@yahoo.com" href="/mc/compose?to=lml108@yahoo.com">lml108@yahoo.com</a>><br>> Cc: <a ymailto="mailto:cmake@cmake.org"
href="/mc/compose?to=cmake@cmake.org">cmake@cmake.org</a><br>> Date: Thursday, 24 December, 2009, 1:06 AM<br>> <br>> <br>> On 24. Dec, 2009, at 9:26 , Mahendra Ladhe wrote:<br>> <br>>> Hi,<br>>> shown below is a simplified and relevant part of my CMakeLists.txt file.<br>>> <br>>> add_custom_command<br>> (<br>>> OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sample.bash<br>>> DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/sample.bash<br>>> COMMAND cp ARGS -f ${CMAKE_CURRENT_SOURCE_DIR}/sample.bash .)<br>> <br>> make the last line<br>> <br>> COMMAND "${CMAKE_COMMAND}" -E copy_if_different<br>> "${CMAKE_CURRENT_SOURCE_DIR}/sample.bash"<br>> "${CMAKE_CURRENT_BINARY_DIR}/sample.bash")<br>> <br>> However, if it really is only copying you are interested
in, why don't you use CONFIGURE_FILE(... COPYONLY)?<br>> <br>>> <br>>> add_custom_target (sample.bash ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/sample.bash)<br>> <br>> I don't see why you want this... In any case, you need to rename this custom target, because it probably clashes with the custom command.<br>> <br>>> <br>>> Basically, I want to copy the 'sample.bash' script from source directory to the<br>>> <br>> binary (build) directory when 'make' is run.<br>>> I want this CMakeLists.txt to work on cmake version 2.4 as well as 2.6<br>>> <br>>> On cmake 2.4, this works fine.<br>>> mladhe@linux:~/cmake_expt/bld] make<br>>> [ 0%] Generating sample.bash<br>>> [100%] Built target sample.bash<br>>> mladhe@linux45:~/cmake_expt/bld] ls<br>>> CMakeCache.txt CMakeFiles Makefile cmake_install.cmake sample.bash<br>>>
<br>>> However on cmake 2.6, I get the following.<br>>> <br>>> mladhe@linux:~/cmake_expt/bld] make<br>>> Scanning dependencies of target sample.bash<br>>> make[2]: Circular CMakeFiles/sample.bash <- sample.bash dependency dropped.<br>>> Built target sample.bash<br>>> mladhe@linux45:~/cmake_expt/bld] ls<br>>> CMakeCache.txt CMakeFiles Makefile cmake_install.cmake<br>>> <br>>> As can be seen, sample.bash file has not been copied.<br>>> <br>>> How to make this<br>> CMakeLists.txt work on both cmake versions ?<br>>> <br>>> Thank you,<br>>> Regards,<br>>> Mahendra Ladhe<br>>> <br>> <br>> HTH<br>> <br>> Michael<br>> <br>> <br>> <br>> <br>> The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. <a href="http://in.yahoo.com/"
target="_blank">http://in.yahoo.com/</a><br><br></div></blockquote></td></tr></table><br>
<!--1--><hr size=1></hr>
The INTERNET now has a personality. YOURS! <a href="http://in.rd.yahoo.com/tagline_yyi_1/*http://in.yahoo.com/" target="_blank">See your Yahoo! Homepage</a>.