<div dir="ltr">[Note: this was erroneously sent off-list to Chuck only, sorry for the noise]<br><div><div><div class="gmail_quote"><div dir="ltr"><div><div><div><div><div><br>Hi Chuck,<br><br></div>I can't really post my toolchain file for two reasons: 1) it contains proprietary stuff and 2) I am ashamed of it.<br></div><br></div>OK, here you go. I just renamed whatever was proprietary. Please don't shoot me, I promise my code and the other CMakeLists are better than that :) When I read it again, I don't understand why I have implemented this "flags reset" feature, and don't know if it actually works - but the rest does. Anyway:<br><br># Frobnicator 2 <br>#<br># Cross-compilation toolchain definition file using GNU Tools for ARM Embedded Processors<br># <a href="https://launchpad.net/gcc-arm-embedded" target="_blank">https://launchpad.net/gcc-arm-embedded</a><br>#<br># This toolchain file assumes that the executable 'arm-none-eabi-gcc.exe' is in the path.<br># As you can see, it also assumes that you are running Windows. If not, then please modify<br># this file to make it smarter.<br>#<br># It was written according to the CMake wiki page dedicated to this topic:<br># <a href="http://www.vtk.org/Wiki/CMake_Cross_Compiling" target="_blank">http://www.vtk.org/Wiki/CMake_Cross_Compiling</a><br># (especially important is the CMAKE_FORCE_C_COMPILER stuff, required because<br># the compiler is not able to spit out code without flags, breaking CMake's<br># detection system otherwise)<br>#<br># Copyright (c) 2015 Initrode SA<br><br>include(CMakeForceCompiler)<br><br>set(_should_set_flags FALSE)<br><br>if (NOT CMAKE_SYSTEM_NAME)<br>    <br>    set(CMAKE_SYSTEM_NAME Generic)<br>    set(CMAKE_SYSTEM_VERSION "frob2-r1")<br>    set(CMAKE_SYSTEM_PROCESSOR cortex-m3)<br><br>    CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc.exe GNU)<br>    CMAKE_FORCE_CXX_COMPILER(arm-none-eabi-g++.exe GNU)<br><br>    # To find the location of the toolchain, invoke the compiler asking for the<br>    # path to libc.a. This path is then stripped off of the lib/libc.a part - this<br>    # hopefully points to the root of the toolchain.<br>    execute_process(<br>        COMMAND ${CMAKE_C_COMPILER} -print-file-name=libc.a<br>        OUTPUT_VARIABLE _path_to_toolchain<br>        OUTPUT_STRIP_TRAILING_WHITESPACE<br>    )<br>    # Get rid of the filename<br>    get_filename_component(_path_to_toolchain<br>        "${_path_to_toolchain}" PATH<br>    )<br>    # Get rid of the trailing lib/ (or whatever the dir is)<br>    get_filename_component(_path_to_toolchain<br>        "${_path_to_toolchain}/.." REALPATH<br>    )<br>    set(INITRODE_CROSSCOMPILE_TOOLCHAIN ${_path_to_toolchain} CACHE PATH "Path to the cross compiler toolchain")<br><br>    set(_should_set_flags TRUE)<br>endif()    <br><br>if (NOT _banner_already_printed)<br>    message(STATUS "Cross-compiling using the gcc-arm-embedded toolchain")<br>    message(STATUS "          Toolchain location: ${_path_to_toolchain}")<br>    message(STATUS "              C/C++ compiler: ${CMAKE_C_COMPILER}")<br>    message(STATUS "Frobnicator hardware version: ${CMAKE_SYSTEM_VERSION}")<br>    message(STATUS "                 MCU variant: ${CMAKE_SYSTEM_PROCESSOR}")<br>    set(_banner_already_printed TRUE)<br>endif ()<br><br>set(CMAKE_FIND_ROOT_PATH ${INITRODE_CROSSCOMPILE_TOOLCHAIN})<br><br>set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)<br>set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)<br>set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)<br><br>set(_flags_reset_mode "")<br><br># This should only be used on the command line (i.e. cmake -DINITRODE_RESET_C_CXX_FLAGS=1)<br># and never put in the cache, otherwise changes in the GUI would be erased at each cmake<br># run (which is annoying behaviour to say the least)<br>if (INITRODE_RESET_C_CXX_FLAGS)<br>    set(_should_set_flags TRUE)<br>    set(_flags_reset_mode "FORCE")<br>endif ()<br><br>if (_should_set_flags)<br><br>    # Generic flags<br>    set(_flags "-fno-common -ffunction-sections -fdata-sections -Wall")<br>    <br>    # CPU-specific flags<br>    # These could go into a separate file but since we have no other hardware target<br>    # for the time being, it is kept here.<br>    set(_flags "${_flags} -mcpu=cortex-m3 -march=armv7-m -mthumb -msoft-float")<br><br>    set(CMAKE_C_FLAGS "${_flags}" CACHE STRING "Flags used by the C compiler during all build types." ${_flags_reset_mode})<br>        <br>    # C++ flags<br>    set(_cppflags "${_flags} -fno-rtti -fno-exceptions -std=c++11")<br>    set(CMAKE_CXX_FLAGS "${_cppflags}" CACHE STRING "Flags used by the C++ compiler during all build types." ${_flags_reset_mode})<br><br>    # Debugging flags<br>    set(CMAKE_C_FLAGS_DEBUG "-g -D_DEBUG" CACHE STRING "Flags used by the C compiler during debug builds.")<br>    set(CMAKE_CXX_FLAGS_DEBUG "-g -D_DEBUG" CACHE STRING "Flags used by the C++ compiler during debug builds.")<br>    set(CMAKE_ASM_FLAGS_DEBUG "-g -D_DEBUG" CACHE STRING "Flags used by the assembler during debug builds.")<br><br>    # These are actually set by each target independently, until I manage to understand<br>    # what is generic (i.e. specific to the toolchain) and what is target-specific.<br>    ##set(CMAKE_EXE_LINKER_FLAGS "-lc -lm -lgcc" CACHE STRING "Flags used by the linker.")<br>endif ()<br><br><br><br></div>Cheers,<br></div>Thibault</div><br></div><br></div></div></div>