[CMake] Unknown names of output files - How to add the dependency?

2009-09-03 Thread Swaroop Ramachandra
Hi,
I have a question regarding the ADD_CUSTOM_COMMAND. I have an input file
which is generated on the fly. My ADD_CUSTOM_COMMAND executes a binary file
which takes this input file. My output is a set of files whose names are
based on the contents of my input file. Specifically, I generate ".c" files
on execution of the binary and the names of the ".c" files generated is not
known in advance.

In the above case, how can I specify a set of output files since I do not
know the names of these files before hand?

Again, the ".c" files are used by a second binary file to generate the
required files (Again using ADD_CUSTOM_COMMAND). Is there a nice way of
daisy chaining these items even without knowing the names of files
generated?

Thanks,
-S

-- 

Pablo Picasso
- "Computers are useless. They can only give you answers."
___
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] Compiled file cannot be executed

2009-08-27 Thread Swaroop Ramachandra
I did. The same problem persists. Is there a work-around - maybe some other
command that I can use?

2009/8/27 Michael Wild 

> David is probably right, that you need to add the dependency on "generate".
> However, only add it's target name to both the COMMAND and DEPENDS
> arguments, CMake should figure this out.
>
> Michael
>
>
> On 27. Aug, 2009, at 21:31, Swaroop Ramachandra wrote:
>
>  Still no luck :( . I really wonder why it is trying to execute my
>> "generate"
>> binary even before it is built. Here are my updated lines of code.
>> #Trying to compile and run generate.c. generate.c creates a new file
>> someoutput.txt and copies all data from someinput.txt to someoutput.txt
>> add_executable(generate server/generate.c)
>> add_custom_command(
>> # I want to generate someoutput.txt
>> OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt
>> # using the generate program. cmake knows that "generate" refers to the
>> above target
>> COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt
>> # only run if sominput.txt changed
>> DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt
>> ${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX}
>> # tell to run in current binary dir
>> WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
>> # some nice comment in the output
>> COMMENT "Generating ${CMAKE_BINARY_DIR}/someoutput.txt"
>> VERBATIM
>> )
>>
>>
>> 2009/8/27 David Cole 
>>
>>  Use full path file names as DEPENDS arguments.
>>> Also: depend on the executable file too so that cmake knows not to try to
>>> run the custom command before the executable is built...
>>>
>>> i.e. :
>>>
>>> DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt
>>> ${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX}
>>>
>>>
>>> HTH,
>>> David
>>>
>>>
>>> On Thu, Aug 27, 2009 at 2:41 PM, Swaroop Ramachandra <
>>> swaroo...@gmail.com
>>>
>>>> wrote:
>>>>
>>>
>>>  Hi Michael,
>>>>
>>>> Thanks for your reply.  I still have the same problem.
>>>> *
>>>> *
>>>> gmake-3.81[2]: bin/generate: Command not found
>>>> lin: gmake-3.81[2]: *** [bin/generate] Error 127
>>>> lin: gmake-3.81[1]: *** [CMakeFiles/generate.dir/all] Error 2
>>>>
>>>>
>>>>
>>>> Here's my code as is:
>>>> #Trying to compile and run generate.c. generate.c creates a new file
>>>> someoutput.txt and copies all data from someinput.txt to someoutput.txt
>>>> add_executable(generate server/generate.c)
>>>> add_custom_command(
>>>> # I want to generate someoutput.txt
>>>> OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt
>>>> # using the generate program. cmake knows that "generate" refers to the
>>>> above target
>>>> COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt
>>>> # only run if sominput.txt changed
>>>> DEPENDS server/someinput.txt
>>>> # tell to run in current binary dir
>>>> WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
>>>> # some nice comment in the output
>>>> COMMENT "Generating ${CMAKE_BINARY_DIR}/someoutput.txt"
>>>> VERBATIM
>>>> )
>>>>
>>>>
>>>> Still the same issue. I guess it is trying to execute my "generate" even
>>>> before it is compiled. Does CMake see that in the line "COMMAND"
>>>> generate
>>>> refers to the compiled one? Again, since generate is created in round
>>>> one of
>>>> make, the second run sees the "generate" and runs fine.
>>>>
>>>> Any help is greatly appreciated! Thanks for your time!
>>>>
>>>> Regards,
>>>> Swaroop
>>>>
>>>> 2009/8/27 Michael Wild 
>>>>
>>>>
>>>>  On 27. Aug, 2009, at 0:58, Swaroop Ramachandra wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>>>
>>>>>> I'm trying to do the following in my CMake file:
>>>>>>
>>>>>> 1. Generate a "xyz.txt" file
>>>>>> 2. Compile a "generate.c" file to give out a  "generate" binary in my
>>>>>> bin
>>>>>> directory.
>>>>>> 3. Execute the "generate&quo

Re: [CMake] Compiled file cannot be executed

2009-08-27 Thread Swaroop Ramachandra
Still no luck :( . I really wonder why it is trying to execute my "generate"
binary even before it is built. Here are my updated lines of code.
#Trying to compile and run generate.c. generate.c creates a new file
someoutput.txt and copies all data from someinput.txt to someoutput.txt
add_executable(generate server/generate.c)
add_custom_command(
 # I want to generate someoutput.txt
 OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt
 # using the generate program. cmake knows that "generate" refers to the
above target
 COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt
 # only run if sominput.txt changed
 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt
${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX}
 # tell to run in current binary dir
 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
 # some nice comment in the output
 COMMENT "Generating ${CMAKE_BINARY_DIR}/someoutput.txt"
 VERBATIM
 )


2009/8/27 David Cole 

> Use full path file names as DEPENDS arguments.
> Also: depend on the executable file too so that cmake knows not to try to
> run the custom command before the executable is built...
>
> i.e. :
>
> DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt 
> ${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX}
>
>
> HTH,
> David
>
>
>  On Thu, Aug 27, 2009 at 2:41 PM, Swaroop Ramachandra  > wrote:
>
>>  Hi Michael,
>>
>> Thanks for your reply.  I still have the same problem.
>> *
>> *
>> gmake-3.81[2]: bin/generate: Command not found
>> lin: gmake-3.81[2]: *** [bin/generate] Error 127
>> lin: gmake-3.81[1]: *** [CMakeFiles/generate.dir/all] Error 2
>>
>>
>>
>> Here's my code as is:
>> #Trying to compile and run generate.c. generate.c creates a new file
>> someoutput.txt and copies all data from someinput.txt to someoutput.txt
>> add_executable(generate server/generate.c)
>> add_custom_command(
>>  # I want to generate someoutput.txt
>>  OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt
>>  # using the generate program. cmake knows that "generate" refers to the
>> above target
>>  COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt
>>  # only run if sominput.txt changed
>>  DEPENDS server/someinput.txt
>>  # tell to run in current binary dir
>>  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
>>  # some nice comment in the output
>>  COMMENT "Generating ${CMAKE_BINARY_DIR}/someoutput.txt"
>>  VERBATIM
>>  )
>>
>>
>> Still the same issue. I guess it is trying to execute my "generate" even
>> before it is compiled. Does CMake see that in the line "COMMAND" generate
>> refers to the compiled one? Again, since generate is created in round one of
>> make, the second run sees the "generate" and runs fine.
>>
>> Any help is greatly appreciated! Thanks for your time!
>>
>> Regards,
>> Swaroop
>>
>> 2009/8/27 Michael Wild 
>>
>>
>>> On 27. Aug, 2009, at 0:58, Swaroop Ramachandra wrote:
>>>
>>>  Hi,
>>>>
>>>> I'm trying to do the following in my CMake file:
>>>>
>>>> 1. Generate a "xyz.txt" file
>>>> 2. Compile a "generate.c" file to give out a  "generate" binary in my
>>>> bin
>>>> directory.
>>>> 3. Execute the "generate" binary (The binary just reads contents of
>>>> "xyz.txt" and creates a copy of "xyz.txt"using read() and write()
>>>> functions
>>>> in C)
>>>>
>>>> The problem:
>>>> When I do a fresh build, 1 and 2 succeed. 3 fails with the following
>>>> error
>>>> *"bin/generate: Command not found"*
>>>>
>>>> However, if I *re-run the build immediately* after, since the "generate"
>>>> binary is already created, all 3 successfully execute. Here's a snippet
>>>> of
>>>> what I have written.
>>>>
>>>> 
>>>> 
>>>> /* Code to generate xyz.txt -- Successfully generated each
>>>> time--*/
>>>> --
>>>> -
>>>> ADD_EXECUTABLE(generate ${CMAKE_CURRENT_SOURCE_DIR}/server/generate.c)
>>>>
>>>> set(GEN ${CMAKE_BINARY_DIR}/bin/generate)
>>>>
>>>> ADD_CUSTOM_COMMAND(
>>>>  TARGET generate POST_BUILD
>>>>  COMMAND ${GEN}
>>>>  DEPENDS ${CMAKE_BINARY_DIR}/server/xyz.txt}
>>>>  )
>>

Re: [CMake] Compiled file cannot be executed

2009-08-27 Thread Swaroop Ramachandra
Hi Michael,

Thanks for your reply.  I still have the same problem.
*
*
gmake-3.81[2]: bin/generate: Command not found
lin: gmake-3.81[2]: *** [bin/generate] Error 127
lin: gmake-3.81[1]: *** [CMakeFiles/generate.dir/all] Error 2



Here's my code as is:
#Trying to compile and run generate.c. generate.c creates a new file
someoutput.txt and copies all data from someinput.txt to someoutput.txt
add_executable(generate server/generate.c)
add_custom_command(
 # I want to generate someoutput.txt
 OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt
 # using the generate program. cmake knows that "generate" refers to the
above target
 COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt
 # only run if sominput.txt changed
 DEPENDS server/someinput.txt
 # tell to run in current binary dir
 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
 # some nice comment in the output
 COMMENT "Generating ${CMAKE_BINARY_DIR}/someoutput.txt"
 VERBATIM
 )


Still the same issue. I guess it is trying to execute my "generate" even
before it is compiled. Does CMake see that in the line "COMMAND" generate
refers to the compiled one? Again, since generate is created in round one of
make, the second run sees the "generate" and runs fine.

Any help is greatly appreciated! Thanks for your time!

Regards,
Swaroop

2009/8/27 Michael Wild 

>
> On 27. Aug, 2009, at 0:58, Swaroop Ramachandra wrote:
>
>  Hi,
>>
>> I'm trying to do the following in my CMake file:
>>
>> 1. Generate a "xyz.txt" file
>> 2. Compile a "generate.c" file to give out a  "generate" binary in my bin
>> directory.
>> 3. Execute the "generate" binary (The binary just reads contents of
>> "xyz.txt" and creates a copy of "xyz.txt"using read() and write()
>> functions
>> in C)
>>
>> The problem:
>> When I do a fresh build, 1 and 2 succeed. 3 fails with the following error
>> *"bin/generate: Command not found"*
>>
>> However, if I *re-run the build immediately* after, since the "generate"
>> binary is already created, all 3 successfully execute. Here's a snippet of
>> what I have written.
>>
>> 
>> 
>> /* Code to generate xyz.txt -- Successfully generated each
>> time--*/
>> --
>> -
>> ADD_EXECUTABLE(generate ${CMAKE_CURRENT_SOURCE_DIR}/server/generate.c)
>>
>> set(GEN ${CMAKE_BINARY_DIR}/bin/generate)
>>
>> ADD_CUSTOM_COMMAND(
>>  TARGET generate POST_BUILD
>>  COMMAND ${GEN}
>>  DEPENDS ${CMAKE_BINARY_DIR}/server/xyz.txt}
>>  )
>> In my ADD_CUSTOM_COMMAND, I have specified POST_BUILD, which I understood
>> to
>> be that the command will be executed only after creation of the "generate"
>> binary.
>>
>
> That's the wrong way to go about it. the TARGET form of the
> add_custom_command is intended to "finish" the actual target. What you want
> is something like this:
>
> # no need for absolute paths...
> add_executable(generate server/generate.c)
>
> add_custom_command(
>  # tell cmake you want to generate xyz.c
>  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xyz.c
>  # using the generate program. cmake knows that "generate" refers to the
> above target
>  COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/xyz.txt
>  # only run if xyz.txt changed
>  DEPENDS xyz.txt
>  # tell to run in current binary dir
>  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
>  # some nice comment in the output
>  COMMENT "Generating ${CMAKE_CURRENT_BINARY_DIR}/xyz.c"
>  VERBATIM
>  )
>
>
> And then you simply use ${CMAKE_CURRENT_BINARY_DIR}/xyz.c in one of your
> other targets. CMake will then know that it first needs to create target
> "generate", then run the program on xyz.txt to create
> ${CMAKE_CURRENT_BINARY_DIR}/xyz.c, and finally use that to build the actual
> target.
>
>
> HTH
>
> Michael
>
>


-- 

Samuel Goldwyn<http://www.brainyquote.com/quotes/authors/s/samuel_goldwyn.html>
- "I'm willing to admit that I may not always be right, but I am never
wrong."
___
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

[CMake] Compiled file cannot be executed

2009-08-26 Thread Swaroop Ramachandra
Hi,

I'm trying to do the following in my CMake file:

1. Generate a "xyz.txt" file
2. Compile a "generate.c" file to give out a  "generate" binary in my bin
directory.
3. Execute the "generate" binary (The binary just reads contents of
"xyz.txt" and creates a copy of "xyz.txt"using read() and write() functions
in C)

The problem:
When I do a fresh build, 1 and 2 succeed. 3 fails with the following error
*"bin/generate: Command not found"*

However, if I *re-run the build immediately* after, since the "generate"
binary is already created, all 3 successfully execute. Here's a snippet of
what I have written.



/* Code to generate xyz.txt -- Successfully generated each time--*/
--
-
ADD_EXECUTABLE(generate ${CMAKE_CURRENT_SOURCE_DIR}/server/generate.c)

set(GEN ${CMAKE_BINARY_DIR}/bin/generate)

ADD_CUSTOM_COMMAND(
   TARGET generate POST_BUILD
   COMMAND ${GEN}
   DEPENDS ${CMAKE_BINARY_DIR}/server/xyz.txt}
   )
In my ADD_CUSTOM_COMMAND, I have specified POST_BUILD, which I understood to
be that the command will be executed only after creation of the "generate"
binary.

Any help is greatly appreciated. Thank you in advance for your time.

Regards,
Swaroop
___
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