[CMake] Problem with cygwin and CodeSourcery's ARM Toolchain

Alexander Neundorf a.neundorf-work at gmx.net
Sat May 9 16:35:06 EDT 2009


On Thursday 07 May 2009, Thomas Kindler wrote:
> Hendrik Sattler wrote:
> > Zitat von Thomas Kindler <mail+cmake at t-kindler.de>:
> >> cmake tries to use cygwin-style absolute "/home/tkindler.." paths,
> >> which arm-none-eabi-gcc doesn't seem to like (being a native win32
> >> program).
> >>
> >> My old makefile used relative paths to invoke the compiler. How can I
> >> do this in cmake generated makefiles?!
> >>
> >> Prepending "c:/cygwin/" to all paths should also solve the problem.
> >
> > If you have a native compiler, use the native compiled cmake. If you
> > have a compiler/tool that depends on cygwin, use the cygwin-compiled
> > cmake. Living in both worlds (native vs. cygwin) is a major pain. Just
> > don't.
>
> Ok.. that part seems to work after installing the native windows cmake.
>
> The resulting binary is still not usable -- cmake inserts an "-fPIC"
> linker flag.
>
>    arm-none-eabi-gcc.exe  -fPIC $(stm32test_OBJECTS)  [..]
>
> How can I switch that off?

This is when you link an executable, right ?
Please have a look at Modules/Platform/gcc.cmake. There this is set for 
CMAKE_SHARED_LIBRARY_CXX_FLAGS and CMAKE_SHARED_LIBRARY_C_FLAGS. Does it go 
away for you if you remove it there ?

> I also need to specify a special linker script for my target. In my
> plain old makefile I just added -Tstm32f10x.ld to my linker command line.
>
> What's the official cmake way to add custom linker flags?!
>
> Adding it to target_link_libraries( .. )  seems to work, but feels wrong.

Yes.
You can do two things: you could use 
LINK_LIBRARIES(-Tstm32f10x.ld)
early enough in your project, then this should be used for all targets when 
they are linked.
The other, better option is to set the CMAKE_C_LINK_EXECUTABLE, 
CMAKE_C_CREATE_SHARED_LIBRARY, CMAKE_C_CREATE_SHARED_MODULE and 
CMAKE_C_CREATE_STATIC_LIBRARY variables (see Modules/CMakeCInformation.cmake 
for the default settings, which also apply to gcc, and e.g. 
Modules/Platform/Generic-SDCC-C.cmake or Modules/Platform/eCos.cmake for 
files for embedded systems without shared libs).

Please have a look at Modules/Platform/Generic.cmake.
It states that to adjust the commands for your target platform, you should set 
CMAKE_SYSTEM_PROCESSOR to a string value which describes your concrete 
target, e.g. "stm32-kindler" in your toolchain file.
If you do this, then cmake will try to load a 
Generic-GNU-C-stm32-kindler.cmake file, where you can adjust the settings to 
as necessary. If this file is not found, it will try to load 
Generic-gcc-stm32-kindler.cmake.
(if you are using C++, you need to do the same also with "CXX" instead of "C".

Does that help ?

> Also: Right now, I have to invoke cmake by this lengthy command:
>
>    cmake -DCMAKE_TOOLCHAIN_FILE=CodeSourcery.cmake -G"Unix Makefiles" .
>
> when compiling the project for the first time.  How can I specify a
> default toolchain and generator in the CMakeLists.txt itself?

You are right, this is somewhat lengthy. Does your cmake come with cmake-gui 
(I'm not sure whether it's part of the cygwin cmake and since which version 
it is shipped exactly). This makes this easier.

Alex


More information about the CMake mailing list