[CMake] [Dev] CMake 2.5 tool chain support example

Alexander Neundorf a.neundorf-work at gmx.net
Mon Jun 11 09:13:32 EDT 2007


Hi,

On Sunday 10 June 2007 17:38, Trevor Kellaway wrote:
> Alex,
>
> > I checked in a change in cvs yesterday.
> >
> > Now cmake tries to load:
> >
> > Platform/CMAKE_SYSTEM.cmake
> > Platform/CMAKE_SYSTEM-<COMPILER_BASENAME>.cmake
> > Platform/CMAKE_SYSTEM-<COMPILER_BASENAME>-CMAKE_SYSTEM_PROCESSOR.cmake
> >
> > Let me know how this works for you.
>
> I've tried it with cmake version 2.5-20070609. When running this:
>  "CMake -G"NMake Makefiles"
> -DCMAKE_MODULE_PATH:string=m:\freescale-hc12-demo\toolchain
> -DCMAKE_TOOLCHAIN_FILE:string=Toolchain-Freescale-HC12 ..\source"
>
> It fails with:
>
>  -- Check size of void*
>  CMake Error: Invalid escape sequence \f
>  Syntax error in cmake code at
>  M:/freescale-hc12-demo/build1/CMakeFiles/CMakeTmp/CMakeLists.txt:1:
>  syntax error, unexpected cal_ERROR, expecting $end (4), when parsing
> string "m:\freescale-hc12-demo\toolchain"
>
> It appears that the module path has to now use forward slashes, this is
> a bit unfriendly for native Windows users. 

Paths in cmake files should always have forward slashes, also on Windows. If 
they come from the "outside" (files, env vars, etc.), they have to be 
converted using FILE(TO_CMAKE_PATH ...)

> Changing the slashes to
> forward seems to work with my example, unchanged, however this isn't
> representative of the intended use of the new includes.
>
> I'm assuming you intend that I don't set CMAKE_SYSTEM_INFO_FILE anymore,
> using the new file inclusions instead?
>
> I was hoping that the tool chain file would now only need to include
> these lines:
>
>  SET (CMAKE_SYSTEM_NAME	"Freescale")
>  SET (CMAKE_SYSTEM_PROCESSOR 	"hc12")
>  SET (CMAKE_C_COMPILER "chc12" CACHE STRING "Tool chain C compiler")

Yes, that's the goal (as long as you don't use the FIND_XXX() commands). But 
with a toolchain which can't link an executable by default this probably 
won't work.

> However, this doesn't work, I still have to include other items (see
> attachment).
>
>
> It now isn't possible to suppress the check for the size of "void *" in
> CMakeTestCCompiler.cmake, I suggest wrapping this in a test if it is
> already defined, I've had to do this.

Because it can't link an application, right ?
You have to set two variables:
CMAKE_SIZEOF_VOID_P
and 
HAVE_CMAKE_SIZEOF_VOID_P

The second one is used to indicate whether the test has already run.
Also both should go into the cache. Do you think it may make sense to provide 
a macro which does that ?


> When I first run CMake to generate the config it seems to include the
> files multiple times, have you any idea what is causing this? 

Without checking, I'd say it's loaded once for C and once for C++.
Do you use C++ with this toolchain ?
If not, you could use PROJECT(name C) and then only C support will be loaded, 
not C++.
Or you could put some logic in the file, like ifdefs in C headers:

IF(NOT _Freescale-chc12_LOADED)
  SET(_Freescale-chc12_LOADED TRUE)
... all the other code

ENDIF(NOT _Freescale-chc12_LOADED)

...
> Note that in my example Freescale.cmake and Freescale-chc12-hc12.cmake
> are effectively empty, as all content seems to logically belong in
> Freescale-chc12.cmake in this case.

Yes, the system file will be empty and I'll add a "Generic.cmake" to cvs, so 
you don't have to provide that file yourself.

> I think the new style naming makes sense, although it's a shame we can't
> push more content down out of the top level tool chain file. Anyway,

From your toolchain file:

SET (HC12_PIPER		"piper"		CACHE STRING "Freescale tool to capture ...")
SET (CMAKE_C_COMPILER 	"chc12" 	CACHE STRING "Tool chain C compiler")
SET (CMAKE_CXX_COMPILER	"chc12"		CACHE STRING "Tool chain C++ compiler")
SET (CMAKE_AR 		"libmaker"	CACHE STRING "Tool chain library archiver")
SET (CMAKE_LINKER 	"linker"	CACHE STRING "Tool chain linker")

Does it work if you put piper, linker and libmaker into the 
Generic-chc12.cmake ?

SET (CMAKE_C_OUTPUT_EXTENSION 	".o" 	CACHE STRING "C ...")
SET (CMAKE_CXX_OUTPUT_EXTENSION	".o"    CACHE STRING "C++ ...")


Let me see if I find a way to define this later.


SET (CMAKE_C_COMPILER_ID_RUN	TRUE)
SET (CMAKE_C_COMPILER_WORKS 	TRUE)
SET (CMAKE_CXX_COMPILER_ID_RUN 	TRUE)
SET (CMAKE_CXX_COMPILER_WORKS 	TRUE)
...
SET (CMAKE_SIZEOF_VOID_P 2)


This is basically "skip all tests". Maybe we can shorten this to one line.


Thanks
Alex


More information about the CMake mailing list