View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014288CMakeCMakepublic2013-07-12 06:302016-06-10 14:31
ReporterEmmanuel Blot 
Assigned ToAlex Neundorf 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionmoved 
PlatformEmbeddedOSeCosOS Version3.x
Product VersionCMake 2.8.11.2 
Target VersionFixed in Version 
Summary0014288: eCos platform enforces GNU compiler
DescriptionI am building eCos kernel and eCos-based project with Clang (3.3), but share/cmake/Modules/Platform/eCos.cmake enforces a GNU compiler, whereas it should tolerate a Clang compiler:

CMAKE_FORCE_C_COMPILER (${xcc} Clang)
CMAKE_FORCE_CXX_COMPILER (${xcc} Clang)

should be used, but

CMAKE_FORCE_C_COMPILER (${xcc} GNU)
CMAKE_FORCE_CXX_COMPILER (${xcc} GNU)

is mandatory due to these lines in share/cmake/Modules/Platform/eCos.cmake

if(CMAKE_C_COMPILER AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "GNU" AND NOT _IN_TC)
  message(FATAL_ERROR "GNU gcc is required for eCos")
endif()
if(CMAKE_CXX_COMPILER AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" AND NOT _IN_TC)
  message(FATAL_ERROR "GNU g++ is required for eCos")
endif()

TagsNo tags attached.
Attached Filespatch file icon ecos_clang.patch [^] (742 bytes) 2013-07-15 05:11 [Show Content]

 Relationships

  Notes
(0033533)
Alex Neundorf (developer)
2013-07-12 15:52

Can you modify eCos.cmake so that it works for you ?
I'll commit it then.
Currently I'm neither working with eCos nor with clang, so your help would be appreciated.

Thanks
(0033536)
Emmanuel Blot (reporter)
2013-07-12 17:03

Ok, I'll try to submit a patch by the end of next week.

BR,
Manu
(0033537)
Emmanuel Blot (reporter)
2013-07-15 05:13

See attached patch.

The original regex does not try to perform an exact match - which seems a bit awkward as something like 'anyGNUfit' would match - the proposed patch preserves this logic.
(0033560)
Alex Neundorf (developer)
2013-07-16 15:41

Oh, that's all ?
No other compiler or linker flags ?
(0033562)
Emmanuel Blot (reporter)
2013-07-17 04:11

That's all to let CMake accepting eCos project builds with Clang.

I'm not sure it is *enough* to make it work, as I've never been able to make it work out-of-the-box with GCC either.

I gave up a long time ago (and several times) trying to only use eCos.cmake file to actually perform the compile and link stages of our eCos projects. After many tries and failures, I've been able to use CMake and eCos with some custom macros.

I'm far from being sure this is the "right" way to do it, but the lack of knowledge & documentation about the mysterious ways of CMake internals did not help to make it better - no offence here but I'm not a CMake developer, and many parameters and syntaxes are still out of my reach, even if I've been using CMake & eCos since the late 2.5.x versions.

The proposed change above is to prevent CMake from rejecting clang as a valid compiler for eCos target. GCC or Clang can be used.

For the records, here is a list of hacks I use. Some of them may be not useful anymore, if last versions of CMake have addressed the issues. Note that the comments or even the hack may be wrong because I understood CMake behaviour the wrong way, please let me know if I'm wrong... The comments are just there so I can remember about the "rationale" of the hack.

#----------------------------------------------------------------------------

SET (XTOOLCHAIN "arm-eabi")
SET (XTOOLCHAIN_ROOT ...) # defined on the command line
SET (CLANG ...) # ditto

IF (NOT _CMAKE_TOOLCHAIN_PREFIX)
  # CMake is in trouble to define the proper prefix when a specific
  # compiler version is defined. This is a workaround.
  SET (_CMAKE_TOOLCHAIN_PREFIX ${XTOOLCHAIN}-)
ENDIF (NOT _CMAKE_TOOLCHAIN_PREFIX)


#-----------------------------------------------------------------------------
# eCos project
# Define required configuration for proper eCos support
#-----------------------------------------------------------------------------
MACRO (use_ecos)
  SET (CMAKE_SYSTEM_NAME eCos)
  SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY LAST)
  SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE LAST)
  # Hack ahead: CMake may add the eCos system directory, but there is no way
  # to add the compiler system directory (newlib) AFTER the eCos system
  # directory, only beforehand. This causes the wrong headers to be included
  # first. The hack here is to force eCos system directory manually, then the
  # compiler sysroot dir. Finally, CMake will append once more the eCos system
  # directory, but the compiler does not care about multiple definitions.
  # This weird behaviour is due to the way CMake evaluates rules:
  # CMAKE_SYSTEM_NAME evaluation is delayed, so any inclusion before this
  # evaluation makes the inclusion appears before the CMake-generated PATH, and
  # CMake does not provide any post-evaluation anchor.
  SET (ECOS_SYSTEM_INC_DIR "${CMAKE_FIND_ROOT_PATH}/include")
  FIND_PATH (ECOS_SYSTEM_CHECK NAMES "pkgconf/system.h"
             PATHS ${ECOS_SYSTEM_INC_DIR})
  IF (ECOS_SYSTEM_CHECK)
    INCLUDE_DIRECTORIES(${ECOS_SYSTEM_INC_DIR} "${XTOOLCHAIN_ROOT}/include")
  ELSE ()
    MESSAGE (FATAL_ERROR
             "Cannot locate eCos system directory from ${ECOS_SYSTEM_INC_DIR}")
  ENDIF ()
ENDMACRO ()


#-----------------------------------------------------------------------------
# Use Clang compiler
#-----------------------------------------------------------------------------
MACRO (use_clang)
  SET (XCOMPILER "clang") # to distinguish from GCC in other macros
  IF (NOT XTOOLCHAIN_ROOT)
    MESSAGE (FATAL "Toolchain root directory not defined")
  ENDIF ()
  INCLUDE (CMakeForceCompiler)
  #CMAKE_FORCE_C_COMPILER (${CLANG} Clang)
  #CMAKE_FORCE_CXX_COMPILER (${CLANG} Clang)
  # CMake enforces GNU compiler for eCos, although it is not mandatory...
  # see http://public.kitware.com/Bug/view.php?id=14288 [^]
  CMAKE_FORCE_C_COMPILER (${CLANG} GNU)
  CMAKE_FORCE_CXX_COMPILER (${CLANG} GNU)
  SET (CMAKE_ASM-ATT_COMPILER ${CLANG})
  SET (CMAKE_NOT_USING_CONFIG_FLAGS 1) # allow custom DEBUG/RELEASE flags
  # enable clang colorised warning message output
  ADD_DEFINITIONS (-fcolor-diagnostics)
  IF (SA_CHECK)
    # when static analyser is enabled, clang is forced to use the native
    # system header path, which breaks the cross compilation. Disable all the
    # default paths, and add back the target one
    EXECUTE_PROCESS (COMMAND ${CLANG} -print-search-dirs
                     COMMAND grep libraries
                     # do not use quote for separator (for CMake)
                     COMMAND cut -d= -f2
                     # strip the extra empty line CMake adds
                     OUTPUT_STRIP_TRAILING_WHITESPACE
                     OUTPUT_VARIABLE clang_lib_root)
    ADD_DEFINITIONS (-nostdsysteminc)
    ADD_DEFINITIONS (-nobuiltininc)
    ADD_DEFINITIONS (-nostdinc)
    ADD_DEFINITIONS (-I${clang_lib_root}/include)
  ENDIF ()
ENDMACRO ()


#-----------------------------------------------------------------------------
# Define the SoC target
#-----------------------------------------------------------------------------
MACRO (use_target target)
  IF (${target} STREQUAL "ARM926")
    SET (ARCH "-mcpu=arm926ej-s")
  ELSEIF (${target} STREQUAL "ARM7TDMI")
    SET (ARCH "-mcpu=arm7tdmi-s")
  ELSEIF (${target} STREQUAL "ARM1176")
    SET (ARCH "-mcpu=arm1176jzf-s")
  ELSE ()
    MESSAGE (FATAL_ERROR "Unsupported target: ${target}")
  ENDIF ()
  IF (NOT XCOMPILER STREQUAL "clang")
    SET (ARCH "${ARCH} -mno-thumb-interwork")
  ELSE ()
    SET (CLANG_ARCH "-target ${XTOOLCHAIN}")
    SET (CLANG_SYSROOT "--sysroot ${XTOOLCHAIN_ROOT}")
    SET (ARCH "${CLANG_ARCH} ${CLANG_SYSROOT}")
  ENDIF ()
  SET (CMAKE_C_FLAGS "${ARCH})
ENDMACRO ()


#-----------------------------------------------------------------------------
# Workaround till CMake issue is fixed:
# CMake 2.8.10- behavior is to force CFLAGS to appear as LDFLAGS, which breaks
# the linker that receives --sysroot unknown option switch w/ clang-based builds
#-----------------------------------------------------------------------------
MACRO (ecos_link)
  IF (XCOMPILER STREQUAL "clang")
    SET (CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> ${CLANG_ARCH} -g -std=gnu99 <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostdlib -nostartfiles -L${ECOS_LIBTARGET_DIRECTORY} -Ttarget.ld <LINK_LIBRARIES>")
  ENDIF ()
ENDMACRO ()
(0033892)
Alex Neundorf (developer)
2013-09-25 16:24

How do you use this file ?
Is this part of your toolchain file ?
Can you also attach a simple hello-world-style project, or at least the CMakeLists.txt ?
(0042319)
Kitware Robot (administrator)
2016-06-10 14:29

Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2013-07-12 06:30 Emmanuel Blot New Issue
2013-07-12 15:51 Alex Neundorf Assigned To => Alex Neundorf
2013-07-12 15:51 Alex Neundorf Status new => assigned
2013-07-12 15:52 Alex Neundorf Note Added: 0033533
2013-07-12 17:03 Emmanuel Blot Note Added: 0033536
2013-07-15 05:11 Emmanuel Blot File Added: ecos_clang.patch
2013-07-15 05:13 Emmanuel Blot Note Added: 0033537
2013-07-16 15:41 Alex Neundorf Note Added: 0033560
2013-07-17 04:11 Emmanuel Blot Note Added: 0033562
2013-09-25 16:24 Alex Neundorf Note Added: 0033892
2016-06-10 14:29 Kitware Robot Note Added: 0042319
2016-06-10 14:29 Kitware Robot Status assigned => resolved
2016-06-10 14:29 Kitware Robot Resolution open => moved
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team