[CMake] Simple CMakeLists.txt file not working with cmake version 2.6
Mahendra Ladhe
lml108 at yahoo.com
Thu Dec 24 08:16:00 EST 2009
Yes, that works for me too.
In add_custom_target, the target name should not be the same as
the name of the file one wants to copy, then it works on both cmake versions.
Thanks Michael.
Mahendra
--- On Thu, 24/12/09, Michael Wild <themiwi at gmail.com> wrote:
From: Michael Wild <themiwi at gmail.com>
Subject: Re: [CMake] Simple CMakeLists.txt file not working with cmake version 2.6
To: "Mahendra Ladhe" <lml108 at yahoo.com>
Cc: cmake at cmake.org
Date: Thursday, 24 December, 2009, 4:50 AM
This small test project works fine for me:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(test NONE)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.bash"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/test.bash"
"${CMAKE_CURRENT_BINARY_DIR}/test.bash"
COMMENT "Creating ${CMAKE_CURRENT_BINARY_DIR}/test.bash"
VERBATIM)
add_custom_target(create_test_bash ALL DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/test.bash")
HTH
Michael
On 24. Dec, 2009, at 13:27 , Mahendra Ladhe wrote:
> Thanks Michael for your reply.
> I should have mentioned that every time I run 'make' (not cmake) I want to copy file only if
> the original file in the source directory has changed.
>
> I tried your suggestion, it works on cmake 2.4 but it still doesn't work on cmake 2.6
> mladhe at linux:~/cmake_expt/bld] make
> Built target sample.bash
> mladhe at linux:~/cmake_expt/bld] ls
> CMakeCache.txt CMakeFiles Makefile cmake_install.cmake
>
> So though it says 'Built target sample.bash', the file has not been copied.
> Also I believe CONFIGURE_FILE(... COPYONLY) will copy file only when running
> 'cmake' and not when running 'make'
>
> I googled, but didn't find a solution that will work on both cmake versions.
>
> Thanks,
> Mahendra
>
> --- On Thu, 24/12/09, Michael Wild <themiwi at gmail.com> wrote:
>
> From: Michael Wild <themiwi at gmail.com>
> Subject: Re: [CMake] Simple CMakeLists.txt file not working with cmake version 2.6
> To: "Mahendra Ladhe" <lml108 at yahoo.com>
> Cc: cmake at cmake.org
> Date: Thursday, 24 December, 2009, 1:06 AM
>
>
> On 24. Dec, 2009, at 9:26 , Mahendra Ladhe wrote:
>
>> Hi,
>> shown below is a simplified and relevant part of my CMakeLists.txt file.
>>
>> add_custom_command
> (
>> OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sample.bash
>> DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/sample.bash
>> COMMAND cp ARGS -f ${CMAKE_CURRENT_SOURCE_DIR}/sample.bash .)
>
> make the last line
>
> COMMAND "${CMAKE_COMMAND}" -E copy_if_different
> "${CMAKE_CURRENT_SOURCE_DIR}/sample.bash"
> "${CMAKE_CURRENT_BINARY_DIR}/sample.bash")
>
> However, if it really is only copying you are interested in, why don't you use CONFIGURE_FILE(... COPYONLY)?
>
>>
>> add_custom_target (sample.bash ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/sample.bash)
>
> 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.
>
>>
>> Basically, I want to copy the 'sample.bash' script from source directory to the
>>
> binary (build) directory when 'make' is run.
>> I want this CMakeLists.txt to work on cmake version 2.4 as well as 2.6
>>
>> On cmake 2.4, this works fine.
>> mladhe at linux:~/cmake_expt/bld] make
>> [ 0%] Generating sample.bash
>> [100%] Built target sample.bash
>> mladhe at linux45:~/cmake_expt/bld] ls
>> CMakeCache.txt CMakeFiles Makefile cmake_install.cmake sample.bash
>>
>> However on cmake 2.6, I get the following.
>>
>> mladhe at linux:~/cmake_expt/bld] make
>> Scanning dependencies of target sample.bash
>> make[2]: Circular CMakeFiles/sample.bash <- sample.bash dependency dropped.
>> Built target sample.bash
>> mladhe at linux45:~/cmake_expt/bld] ls
>> CMakeCache.txt CMakeFiles Makefile cmake_install.cmake
>>
>> As can be seen, sample.bash file has not been copied.
>>
>> How to make this
> CMakeLists.txt work on both cmake versions ?
>>
>> Thank you,
>> Regards,
>> Mahendra Ladhe
>>
>
> HTH
>
> Michael
>
>
>
>
> The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091224/824af345/attachment.htm>
More information about the CMake
mailing list