2012-10-22 14 views
8

Sto cercando di utilizzare CMake per la creazione di un progetto che utilizza lo MSPGCC cross-compiler per un microcontrollore MSP430. Per compilare con successo qualsiasi programma semplice con esso, abbiamo bisogno di passare un flag di compilazione che indica il processore target, altrimenti non riesce in questo modo:Come passare un flag di compilazione per cmake test del compilatore iniziale?

$ msp430-gcc -o test test.c 
In file included from test.c:1:0: 
/usr/local/lib/gcc/msp430/4.6.3/../../../../msp430/include/msp430.h:813:2: warning: #warning Unable to identify and include MCU header, use -mmcu=MCU [-Wcpp] 
/usr/local/lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld: cannot open linker script file memory.x: No such file or directory 
collect2: ld returned 1 exit status 

Quindi, se indico il processore utilizzando l'interruttore -mmcu funziona benissimo. Il problema è che, anche se sto già specificare questo nel mio file CMakeLists.txt:

cmake_minimum_required (VERSION 2.6) 

project (test-project C) 

set (SOURCES 
    test.c 
) 

add_executable (test-project ${SOURCES}) 
set (CPU_FLAG "-mmcu=msp430f148") 

set (CMAKE_C_FLAGS ${CPU_FLAG}) 
set (CMAKE_EXE_LINKER_FLAGS ${CPU_FLAG}) 

CMake lamenta il compilatore ha fallito il test di compilare un programma semplice, che scommetto che sta accadendo perché è probabilmente non utilizzare l'interruttore-mmcu (si noti il ​​messaggio di non essere in grado di aprire file di script del linker memory.x):

$ cd ~/git/test-project 
$ mkdir build 
$ cd build 
$ cmake -DCMAKE_TOOLCHAIN_FILE=../msp430.cmake .. 
-- The C compiler identification is GNU 4.6.3 
-- Check for working C compiler: /usr/local/bin/msp430-gcc 
-- Check for working C compiler: /usr/local/bin/msp430-gcc -- broken 
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE): 
    The C compiler "/usr/local/bin/msp430-gcc" is not able to compile a simple 
    test program. 

    It fails with the following output: 

    Change Dir: /home/claudio/git/test-project/build/CMakeFiles/CMakeTmp 



    Run Build Command:/usr/bin/gmake "cmTryCompileExec2889462763/fast" 

    /usr/bin/gmake -f CMakeFiles/cmTryCompileExec2889462763.dir/build.make 
    CMakeFiles/cmTryCompileExec2889462763.dir/build 

    gmake[1]: Entering directory 
    `/home/claudio/git/test-project/build/CMakeFiles/CMakeTmp' 

    /usr/bin/cmake -E cmake_progress_report 
    /home/claudio/git/test-project/build/CMakeFiles/CMakeTmp/CMakeFiles 1 

    Building C object 
    CMakeFiles/cmTryCompileExec2889462763.dir/testCCompiler.c.o 

    /usr/local/bin/msp430-gcc -o 
    CMakeFiles/cmTryCompileExec2889462763.dir/testCCompiler.c.o -c 
    /home/claudio/git/test-project/build/CMakeFiles/CMakeTmp/testCCompiler.c 

    Linking C executable cmTryCompileExec2889462763 

    /usr/bin/cmake -E cmake_link_script 
    CMakeFiles/cmTryCompileExec2889462763.dir/link.txt --verbose=1 

    /usr/local/bin/msp430-gcc 
    CMakeFiles/cmTryCompileExec2889462763.dir/testCCompiler.c.o -o 
    cmTryCompileExec2889462763 -rdynamic 

    /usr/local/lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld: cannot open 
    linker script file memory.x: No such file or directory 

    collect2: ld returned 1 exit status 

    gmake[1]: Leaving directory 
    `/home/claudio/git/test-project/build/CMakeFiles/CMakeTmp' 

    gmake[1]: *** [cmTryCompileExec2889462763] Error 1 

    gmake: *** [cmTryCompileExec2889462763/fast] Error 2 





    CMake will not be able to correctly generate this project. 
Call Stack (most recent call first): 
    CMakeLists.txt:3 (project) 

-- Configuring incomplete, errors occurred! 

Solo per la cronaca, il mio file toolchain è la seguente, e la mia variabile PATH consente di trova i binari del compilatore a /usr/local/bin:

# the name of the target operating system 
#SET(CMAKE_SYSTEM_NAME Linux) 

# which C and C++ compiler to use 
SET(CMAKE_C_COMPILER msp430-gcc) 
SET(CMAKE_CXX_COMPILER msp430-g++) 

# here is the target environment located 
SET(CMAKE_FIND_ROOT_PATH /usr/local/msp430) 

# adjust the default behaviour of the FIND_XXX() commands: 
# search headers and libraries in the target environment, search 
# programs in the host environment 
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 

Detto questo, qualcuno può dirmi come verificare che la compilazione bandiere CMake sta usando per effettuare il test del compilatore, e come possiamo passare bandiere personalizzate (come -mmcu, per esempio) in modo che doesn' fallito?

risposta

6

Secondo la documentazione:

http://www.cmake.org/Wiki/CMake_Cross_Compiling#The_toolchain_file

si dovrebbe usare la cosa CMakeForceCompiler

INCLUDE(CMakeForceCompiler) 

# this one is important 
SET(CMAKE_SYSTEM_NAME eCos) 

# specify the cross compiler 
CMAKE_FORCE_C_COMPILER(arm-elf-gcc GNU) 
CMAKE_FORCE_CXX_COMPILER(arm-elf-g++ GNU) 

# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH /home/alex/src/ecos/install) 

# search for programs in the build host directories 
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 
# for libraries and headers in the target directories 
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 

(copia & incolla dalla documentazione)

Usandolo bene qui per il mio MSP430 anche

+0

quando io w visto che l'uso di MSPGCC4 ha funzionato bene, ma ora che sto usando il MSPGCC più recente, non è in grado di eseguire il test del compilatore (MSPGCC4 è stato interrotto e lo sviluppo è tornato al progetto originale). Il 'INCLUDE (CMakeForceCompiler)' purtroppo non ha avuto effetto. – Claudio

+2

Non è solo l'inclusione, sono anche le due linee CMAKE_FORCE_C_COMPILER (arm-elf-gcc GNU) CMAKE_FORCE_CXX_COMPILER (arm-elf-g ++ GNU) - li hai anche tu? – duselbaer

+0

Sì, era così! Non ho notato che CMAKE_FORCE_C_COMPILER era effettivamente al posto di CMAKE_C_COMPILER. Questo sovrascrive il test del compilatore invece di farlo usare l'opzione -mmcu, giusto? Grazie! – Claudio

Problemi correlati