[CMake] Add pre-existing object file to linker line?

Bill Hoffman bill.hoffman at kitware.com
Sun May 27 22:45:55 EDT 2007


Trevor Kellaway wrote:
> Bill,
>
>   
>>>> You want to create your own rules for CMAKE_(LANG)_COMPILE_OBJECT:
>>>>         
>> It should be like this:
>> "command ..."
>> "command2 .."
>> "command3 .."
>>     
>
> Thanks, as you say you can have multiple commands. Alas, I've fallen
> down another hole which rules this solution out.
>
> For any lurkers there are a few caveats:
>
> 1) The command invoked must have native style slashes, under Windows
> forward slashes in the command caused it to be ignored.
>
> 2) Any variable arguments can't be lists, as they cause a line split,
> which is then interpreted as another command. The solution is to undo
> the list:
>
>   FOREACH (_arg ${MY_LIST})
> 	SET (MY_ARGS "${MY_ARGS} ${_arg}")
>   ENDFOREACH (_arg ${MY_LIST})
>  
>   "command ${_arg} <SOURCE>"
>
> 3) Be aware that the command's current directory will be in the binary
> tree.
>
>
> Because of (3) I can't use this solution, as I need to run the command
> in the source directory.
>
> The ADD_CUSTOM_COMMAND solution is still the best (I can also the have
> source file specific args which CMAKE_(LANG)_COMPILE_OBJECT won't
> support), if only I could determine the object file directory. 
>
> I notice that GET_SOURCE_FILE_PROPERTIES has a LOCATION property that
> returns the source file location. How hard would it be to add the same
> for an object file based on cmGetSourceFilePropertyCommand?
>
> Your assistance is much appreciated.
>   
You could potentially create a cmake -P script file that does anything 
you want in it.
It could cd to the source directory and run any command that you want.  
The script
could be configured at cmake time with the source and binary 
directories.  -DVAR=value
options could be used to pass in stuff to the script.

-Bill



More information about the CMake mailing list