[CMake] Tag Variable <OBJECTS>

Matthias Goesswein tisi at sbox.tugraz.at
Thu Apr 22 08:47:43 EDT 2010


Am 22.04.2010 08:56, schrieb Michael Wild:
>
> On 22. Apr, 2010, at 7:52 , Matthias Goesswein wrote:
>
>> Am 21.04.2010 18:56, schrieb Alexander Neundorf:
>>> On Wednesday 21 April 2010, Matthias Goesswein wrote:
>>>> Hello!
>>>>
>>>> My libarian-tool needs a flag before each object file:
>>>>
>>>> e.g.
>>>>
>>>> libarian -a file1.o -a file2.o -a file3.o library.a
>>>>
>>>> CMake provides the<OBJECTS>   tag variable for use within the rule
>>>> variable of the libarian, but i didn't fond a way to insert the "-a"
>>>> flags before each object file.
>>>>
>>>> Is there any way for doing that?
>>>
>>> AFAIK no.
>>> Please put it as feature request in the bug tracker.
>>> What kind of toolchain are you using ?
>>>
>>> Alex
>>
>> I'd like to use the Softune toolchain (for Fujitsu Microcontrollers), and the librarian can only add object files to an library with the "-a" command line option. All object files must have that flag. It could be done with wrapper shell scripts, but shells are platform specific and so it's for me a no go. It's no problem if you use only one build plattform, but if not so, you would have to write several shell scripts, or add the shell executable for each build plattform.
>>
>> I've already put it in as a feature request yesterday (http://public.kitware.com/Bug/view.php?id=10588)
>>
>> I also want to use Keil Compiler with CMake, but i would also need wrapper scripts for the compiler, librarian and linker, because of the non standard way of command line options. (It uses brackets, something like: cc -o{obj1.o,obj2.o,...})
>>
>> It would be nice to have the latter approach of my feature request (with regular expressions), because it would be highly customizable. Someone could even change slashes to backslashes, which could be handy if a windows tool is used within cygwin or msys, which requires backslashes (slashes are standard on cygwin or msys).
>>
>> Matthias.
>
> You don't have to use shell wrapper scripts. CMake is a portable (rather quirky) scripting language ;-) I often do something like this:
>
> add_custom_command(OUTPUT something
>    COMMAND "${CMAKE_COMMAND}" -DSOME=VALUE -P "${CMAKE_CURRENT_BINARY_DIR}/some_configured_script.cmake"
>    DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/some_configured_script.cmake"
>    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
>    COMMENT "Doing something incredibly smart"
>    VERBATIM
>    )
>
>
> You can also modify CMAKE_<LANG>_CREATE_STATIC_LIBRARY to suit your needs, perhaps something like this:
>
> set(CMAKE_C_CREATE_STATIC_LIBRARY
>    "${CMAKE_COMMAND} -DOBJECTS=\"<OBJECTS>\" -DLIBRARY=\"<TARGET>\" -P ${CMAKE_BINARY_DIR}/create_archive.cmake")
>
>
> where create_archive.cmake is configured to contain the full path to the librarian tool (using @ONLY) and perhaps with other things. E.g. create_archive.cmake.in might contain (untested):
>
> set(ARGS)
> foreach(o IN LISTS OBJECTS)
>    set(ARGS "${ARGS} -a ${o}")
> endforeach()
> set(ARGS "${ARGS} ${LIBRARY}")
>
> execute_process(
>    COMMAND "@LIBRARIAN_EXECUTABLE@" ${ARGS}
>    RESULT_VARIABLE RES
>    OUTPUT_VARIABLE OUT
>    ERROR_VARIABLE OUT)
>
> if(RES)
>    message(FATAL_ERROR "@LIBRARIAN_EXECUTABLE@ failed to create archive ${LIBRARY}."
>      "The output message was\n"
>      "${OUT}")
> endif()

I tried that, and could get it working. I needed seperate_arguments to 
get a list of the objects and had to remove the quotes, so that every 
option was a list element. Otherwise it didn't work.

It's not very compfortable (you need a seperate cmake file, and you must 
be careful with the quotes), but it doesn't depend on the platform and 
it works. :)

Thanks,
Matthias.






More information about the CMake mailing list