MantisBT - CMake
View Issue Details
0012987CMakeCMakepublic2012-02-21 09:592012-04-19 15:51
Emmanuel Blot 
Alex Neundorf 
lowminoralways
closedfixed 
AppleOS X10.7.3
CMake 2.8.7 
CMake 2.8.8CMake 2.8.8 
0012987: Multiple redefinitions with cross compilation for eCos
Using the following sequence to enable eCos cross-compilation (from any host):

INCLUDE (CMakeForceCompiler)
SET (CMAKE_SYSTEM_NAME eCos)
CMAKE_FORCE_C_COMPILER (arm-eabi-gcc GNU)
CMAKE_FORCE_CXX_COMPILER (arm-eabi-gcc GNU)

whenever the PROJECT() command is invoked,
the file Modules/Platform/eCos.cmake is parsed and "executed" several times (3 times on my current configuration).

The net result is that line 45
ADD_DEFINITIONS(-D__ECOS__=1 -D__ECOS=1)
is executed 3 times, and the definitions are appended to each other.

Running CMake with the VERBOSE flag enables shows that the command line is filled in with the same definitions:
arm-eabi-gcc -D__ECOS__=1 -D__ECOS=1 -D__ECOS__=1 -D__ECOS=1 -D__ECOS__=1 -D__ECOS=1 ....
No tags attached.
? eCos.cmake (2,973) 2012-03-20 17:16
https://public.kitware.com/Bug/file/4257/eCos.cmake
Issue History
2012-02-21 09:59Emmanuel BlotNew Issue
2012-02-21 11:15Eric NOULARDNote Added: 0028681
2012-02-21 12:19Alex NeundorfAssigned To => Alex Neundorf
2012-02-21 12:19Alex NeundorfStatusnew => assigned
2012-02-21 12:29Emmanuel BlotNote Added: 0028683
2012-02-21 12:29Emmanuel BlotNote Added: 0028684
2012-03-20 17:16Alex NeundorfFile Added: eCos.cmake
2012-03-20 17:17Alex NeundorfNote Added: 0028945
2012-03-26 15:48Alex NeundorfNote Added: 0028973
2012-03-27 05:09Emmanuel BlotNote Added: 0028977
2012-03-27 05:21Emmanuel BlotNote Added: 0028978
2012-03-28 15:41Alex NeundorfNote Added: 0028992
2012-03-28 15:41Alex NeundorfStatusassigned => closed
2012-03-28 15:41Alex NeundorfResolutionopen => fixed
2012-04-19 15:51David ColeFixed in Version => CMake 2.8.8
2012-04-19 15:51David ColeTarget Version => CMake 2.8.8

Notes
(0028681)
Eric NOULARD   
2012-02-21 11:15   
From algorithm described here:
Source/cmGlobalGenerator.cxx
lines 225-265
right before void cmGlobalGenerator::EnableLanguage

I would says that the multiple load is "normal"

1 for each enables languages (C and C++ may be)
1 other for ???

That said eCos.cmake is the only Platform/*.cmake file which is using
ADD_DEFINITION
$ cd Modules/Platform
$ grep ADD_DEFINITION *
eCos.cmake:ADD_DEFINITIONS(-D__ECOS__=1 -D__ECOS=1)

does ADD_DEFINITIONS belongs to a Platform file?

If this is the case
may be that call should be protected against multiple inclusion
with some guard VARIABLE like

if (NOT ECOS_CMAKE_INCLUDED)
   ADD_DEFINITIONS(-D__ECOS__=1 -D__ECOS=1)
   set(ECOS_CMAKE_INCLUDED 1)
endif(NOT ECOS_CMAKE_INCLUDED)

would this work in your case?
(0028683)
Emmanuel Blot   
2012-02-21 12:29   
> does ADD_DEFINITIONS belongs to a Platform file?
I cant' tell :-)

> would this work in your case?
Indeed, it works fine, I just tested it.
(0028684)
Emmanuel Blot   
2012-02-21 12:29   
> 1 other for ???
ASM-ATT I would say.
(0028945)
Alex Neundorf   
2012-03-20 17:17   
Can you please give the attached eCos.cmake a try ?
It has an include-guard at the top and should also work.

Please let me know here whether it works for you or not.

Alex
(0028973)
Alex Neundorf   
2012-03-26 15:48   
Did you already find the time to give the attached file a try ?
(0028977)
Emmanuel Blot   
2012-03-27 05:09   
Sorry, I forgot. You are right to ping me back, I'll give a try today.
(0028978)
Emmanuel Blot   
2012-03-27 05:21   
Hi Alex,

Yes it works, the __ECOS__ and __ECOS flags are now only defined once, and I saw no regression while building a typical eCos project.

Thanks,
Emmanuel.
(0028992)
Alex Neundorf   
2012-03-28 15:41   
Merged into master, and fix confirmed by reporter.