1

I am attempting to replicate the following behaviour in CMake and need a little assistance...

I am compiling using gcc then linking using ld explicity. The original makefile carries out the following:

arm-linux-gcc -MD -Wa,-mcpu=arm7tdmi -Dgcc -c init.S arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c serial.c arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c timer.c arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c amd.c arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c intel.c arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c at25f1024.c arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c sst25vf020.c arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c main.c arm-linux-ld -q --defsym ROBASE=0x00000000 -T init.lds -o init.elf init.o serial.o timer.o amd.o intel.o at25f1024.o sst25vf020.o main.o 

My CMakefileLists.txt looks like this

cmake_minimum_required(VERSION 2.8) project(bootStage2) #add_definitions(ROBASE set(CMAKE_C_FLAGS "-MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -Wl,-q -Wl,--defsym=ROBASE=0x00000000 -T ${bootStage2_SOURCE_DIR}/init.lds") #add_definitions(ROBASE=0x00000000) set(SRCFILES serial.c timer.c amd.c intel.c at25f1024.c sst25vf020.c main.c ) set(CMAKE_init.elf_LINK_EXECUTABLE "/usr/bob/arm920t/usr/bin/arm-linux-ld") add_executable( init.elf ${SRCFILES}) SET_TARGET_PROPERTIES(init.elf PROPERTIES LINKER_LANGUAGE C) add_dependencies( init.elf assemble_S ) add_custom_target(assemble_S COMMAND /usr/bob/arm920t/usr/bin/arm-linux-gcc -MD -Wa,-mcpu=arm7tdmi -Dgcc -c init.S COMMENT "Assembling init.S" WORKING_DIRECTORY ${bootStage2_SOURCE_DIR} 

If I don't define the linker exe then CMake attempts to use gcc to link and seg faults on linking.

The cmake output complains that there are no files to link against when I tell it to use arm-linux-ld, I'm sure there is a better way of doing this does anyone have any useful hints?

Cheers,

Chris.

2
  • Did you try setting the compiler on the command line before invoking cmake? CC=/usr/bob/arm920t/usr/bin/arm-linux-gcc cmake ../path/to/src? Commented Jan 29, 2013 at 14:14
  • Did you try these? cmake.org/Wiki/… Commented May 7, 2013 at 10:07

1 Answer 1

1

The way we found when we have faced this problem some years ago was the following:

We replaced the link-template in cmake (we used our own linker, but it also should work with only adding arguments):

set(CMAKE_CXX_LINK_EXECUTABLE "${LINKER} ... <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>") set(CMAKE_C_LINK_EXECUTABLE ${CMAKE_CXX_LINK_EXECUTABLE}) 

The ... I omitted our custom arguments. The key here is the <>-elements which are filled in by cmake for each target to be linked.

See also here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.