[CMake] problem with add_custom command

ankit jain ankitguddu at gmail.com
Wed Mar 25 04:33:05 EDT 2009


2009/3/25 Michael Wild <themiwi at gmail.com>

>
> On 25. Mar, 2009, at 7:51, ankit jain wrote:
>
> 2009/3/25 Alexander Neundorf <a.neundorf-work at gmx.net>
>>
>> On Tuesday 24 March 2009, ankit jain wrote:
>>>
>>>> hi all,
>>>>
>>>> Iam doing the following through my cmakelist.txt
>>>>
>>>> add_custom_target(mytarget)
>>>> add_custom_command(TARGET mytarget POST_BUILD
>>>> COMMAND ${CMAKE_COMMAND} -E tar xvf ${CMAKE_CURRENT_SOURCE_DIR}/t1.tar)
>>>> this cmakelist is written in subfolder of a mainfolder..
>>>>
>>>> But the problem is that files are not extracted and it is not showing
>>>> any
>>>> error.
>>>>
>>>
>>> Hm, I never tried to use add_custom_command(TARGET ... ) with a custom
>>> target.
>>> So if you do "make mytarget" then tar is not executed ?
>>> Did you try to do this directly using add_custom_target(), i.e. put the
>>> tar-command in the add_custom_target() ?
>>>
>>> Alex
>>>
>>
>>
>> I followed this approach becoz add_cutom_command with outptu option deos
>> not
>> seems to work but actually i want to do it by that way only because from
>> the
>> main tree i issue make only so thats why that target will not build.
>>
>> Do anyone know what is the problem if i do like this and then run make:
>>
>> add_custom_command(OUTPUT {TARDIR}/t2 {TARDIR}/t3
>> {TARDIR}/t1
>> COMMAND tar ARGS -xvf $(TARDIR)/mytar.tar
>>
>
> -------------------------^------^
> those should probably be { and } instead of ( and )...
>
>
>> WORKING_DIRECTORY ${TARDIR})
>>
>>
>> Here i want to extract the files in the same folder where tar exists..
>>>
>>
>> the extraction will actually should give these t1, t2, t3 folder which i
>> mention in output ..
>>
>> Is iam doing something wrong....
>>
>> Ankit
>>
>>
>>
>
> What I usually do is this:
>
> add_custom_command( OUTPUT ${TARDIR}/t1
>  COMMAND ${CMAKE_COMMAND} -E tar xvf ${TARDIR}/mytar.tar
>  WORKING_DIRECTORY ${TARDIR}
>  COMMENT "Extracting ${TARDIR}/mytar.tar"
>  VERBATIM
>  )
>
> add_custom_target( extract_mytar
>  DEPENDS ${TARDIR}/t1
>  )
>
> This tells CMake how to obtain the file ${TARDIR}/t1 by unpacking
> mytar.tar. Then it adds a target which depends on that file. You then can
> have other targets depend on that by using add_dependencies.
>


Thanks for your suggestions it works but the problem is that iam making a
library which requires some source files which will come after extracting it
from tar.

In that making an custom target for it and then add_dependencies to that
library to this custom build target does not solve the purpose.

then how to include those files which is required by the library which came
from tar.


Ankit

>
> Another thing: Please make sure that TARDIR is in the build tree (i.e.
> somewhere below CMAKE_BINARY_DIR). Extracting tar-balls in the source tree
> is a pretty bad idea.
>
> HTH
>
> Michael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090325/e30ec696/attachment.htm>


More information about the CMake mailing list