4

I have a CMakeLists.txt file and am compiling a firmware program with the GCC 68HC11 C compiler.

The issue is that CMake is appending the "-E" compiler flag at the end which I don't want. The other appended flags "-v" "-dD" and '-D___CIDR..." are also unwanted but do not cause a compilation error as "-E" does. How can I turn these appended flags off?

I tried set(CMAKE_C_FLAGS_DEBUG "") with no effect.

Here is my CMakeLists.txt file in full

cmake_minimum_required(VERSION 2.8.4)

# program names
set(HC11C    m6811-elf-gcc.exe)
set(OBJCOPY  m6811-elf-objcopy.exe)
set(OBJDUMP  m6811-elf-objdump.exe)

# Important project paths
set(LIB_INC_PATH "C:/library/gel-hc1x-1.6.1/include"
                    "C:/library/gel-hc1x-1.6.1/include/asm-m68hc11/arch-32k")
set(HC11C_PATH   "C:/GNUHC11/bin")

# Sets the compiler
# Needs to come before the project function
set(CMAKE_SYSTEM_NAME  Generic)
set(CMAKE_C_COMPILER   "${HC11C_PATH}/${HC11C}")

set(MAIN_FILE "TestProgram")                
project(${MAIN_FILE})

# Files to be compiled
set(BASE_PATH    "${${PROJECT_NAME}_SOURCE_DIR}")
set(INC_PATH     "${BASE_PATH}")
set(SRC_PATH     "${BASE_PATH}")

set(SRC_FILES   "${SRC_PATH}/${MAIN_FILE}.c"
                "${SRC_PATH}/Interrupts.c"
                "${SRC_PATH}/Utilities.c")

# Attempt to clear the other spurious compiler flags that I don't want, 
# and which cause a compiler arguments error.
# This doesn't seem to work - the defaults still appear.
set(CMAKE_C_FLAGS_DEBUG             "")
set(CMAKE_C_FLAGS_RELEASE           "")
set(CMAKE_C_FLAGS_RELWITHDEBINFO    "")
set(CMAKE_C_FLAGS_MINSIZEREL        "")

# Compiler flags
set(CWARN     "-Wl,-m,m68hc11elfb")         # build for elf file and use memory.x for memory map
set(CTUNING   "-mshort")                    # consider type int to be 16 bits
set(COPT      "-Os")                        # turn on optimizer
set(CDEFS     "-Dmc6811")                   # Add define to define the processor architecture for gel includes
set(CFILES    "${MAIN_FILE}.c Interrupts.c Utilities.c")

set(CFLAGS   "${CDEFS} ${COPT} ${CWARN} ${CTUNING} ${CFILES}")

set(CMAKE_C_FLAGS   "${CFLAGS}")

# Project setup
include_directories(${INC_PATH} ${LIB_INC_PATH})
add_executable(${MAIN_FILE} ${SRC_FILES})
set_target_properties(${MAIN_FILE} PROPERTIES OUTPUT_NAME "${MAIN_FILE}.elf")

# Compiling targets
add_custom_target(main ALL ${OBJCOPY} -O binary "${MAIN_FILE}.elf" "${MAIN_FILE}.bin"  DEPENDS ${MAIN_FILE})
add_custom_target(dump ALL ${OBJDUMP} -xDC --section=.text --section=.vectors "${MAIN_FILE}.elf" > "${MAIN_FILE}.dump" DEPENDS main)

set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MAIN_FILE}.dump;${MAIN_FILE}.elf;${MAIN_FILE}.bin")

# Config logging
message("* ")
message("* Project Name:\t${PROJECT_NAME}")
message("* Project Source:\t${SRC_PATH}")
message("* Project Include:\t${INC_PATH}")
message("* Library Include:\t${LIB_INC_PATH}")
message("* ")
message("* Project Source Files:\t${SRC_FILES}")
message("* MAIN_FILE variable:\t${MAIN_FILE}")
message("* ")
message("* C Flags:\t${CMAKE_C_FLAGS}")
message("* ")

Here is the generated compiler command

C:\GNUHC11\bin\m6811-elf-gcc.exe "-xc" "-Dmc6811" "-Os" "-Wl,-m,m68hc11elfb" "-mshort" "TestProgram.c" "Interrupts.c" "Utilities.c" "-IC:\\DEVELO~1\\source" "-IC:\\library\\gel-hc1x-1.6.1\\include" "-IC:\\library\\gel-hc1x-1.6.1\\include\\asm-m68hc11\\arch-32k" "-v" "-dD" "-E" "-D___CIDR_IGNORE_DEFINITIONS_START"
dodgy_coder
  • 12,407
  • 10
  • 54
  • 67
  • 1
    There's also `CMAKE_C_FLAGS` (without a configuration). My search for `-E` in CMake's Modules directory only brought up one remotely relevant occurrence: `CMAKE_C_CREATE_PREPROCESSED_SOURCE` in `Compiler/GNU.cmake`; I don't think that one is the source. You could also try listing the property `VARIABLES` from the current directory to see if there's anything else there that might be involved in flag setup. – Angew is no longer proud of SO Jan 30 '15 at 14:23
  • 1
    Did you try to use your CFLAGS as COMPILE_FLAGS property for main? like `set_target_properties(${MAIN_FILE} PROPERTIES OUTPUT_NAME "${MAIN_FILE}.elf" COMPILE_FLAGS ${CFLAGS})` – truschival Jan 31 '15 at 00:30
  • Thanks to [Angew](http://stackoverflow.com/users/1782465/angew) and [truschival](http://stackoverflow.com/users/3714982/truschival) for the suggestions - I didn't get a chance to try these ideas yet, but will try them on monday. Hopefully one or either of these will fix it. – dodgy_coder Jan 31 '15 at 01:32
  • Just a note that the above suggestions didn't work. Those spurious flags are still in the compilation command. – dodgy_coder Feb 02 '15 at 06:05
  • What are the values of the _INIT variables, e.g. CMAKE_C_FLAGS_DEBUG_INIT ? These values are always added to your compiler flags. Are you using a toolchain file or is such a file used by the build env? – Th. Thielemann Jan 11 '17 at 19:17

0 Answers0