Saya menggunakan cmake untuk mengkompilasi proyek saya untuk arm cortex m3 (arm-none-eabi-).

Saya ingin menambahkan opsi berikut:

1.) linker harus menghasilkan file .map dari biner.

2.) make (Unix Makefiles) harus menyimpan peringatan dan kesalahan ke dalam file terpisah di samping stderr / stdout apa yang saya lihat saat ini.

3.) konfigurasi "set (CMAKE_EXE_LINKER_FLAGS" -specs = nano.specs -Wl, - gc-section -o myproject.elf "CACHE INTERNAL" ")" tidak menghasilkan elf saya, jadi saya menyalin output ke output secara manual .peri.

dapatkah seseorang membantu saya di sini? selain itu, jika kalian memiliki banyak pengalaman, akan lebih bagus jika Anda bisa memberi saya beberapa petunjuk tentang apa yang bisa dilakukan dengan lebih baik. Saat ini saya menjalankan cmake di windows10 (gnu make, cmake, git bash) dan di linux mint.

compile.sh

cmake \
-G "Unix Makefiles" \
-D CMAKE_BUILD_TYPE=Debug \
..
make -j8

cmake_arm_none_eabi.cmake

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)

set(CMAKE_EXE_LINKER_FLAGS "-specs=nano.specs -Wl,--gc-sections -o myproject.elf" CACHE INTERNAL "")

set(CMAKE_ASM_COMPILER_ID GNU)
set(CMAKE_C_COMPILER_ID GNU)
set(CMAKE_CXX_COMPILER_ID GNU)

set(CMAKE_ASM_COMPILER_FORCED TRUE)
set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)

CMakeLists.txt

include("cmake_arm_none_eabi.cmake")

cmake_minimum_required(VERSION 3.10.1)

project(myproject)

ENABLE_LANGUAGE(ASM)

SET(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp")

set(LINKER_SCRIPT "mylinker.ld")

set(CPU_OPTIONS -mthumb -mcpu=cortex-m3)

SET(CMAKE_ASM_FLAGS_DEBUG "-g")
set(CMAKE_C_FLAGS_DEBUG "-Og -g -DDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g")

add_compile_options(
    ${CPU_OPTIONS}
    $<$<COMPILE_LANGUAGE:C>:-std=gnu11> #c11>
    $<$<COMPILE_LANGUAGE:CXX>:-std=gnu++17> #c++17>
    #$<$<COMPILE_LANGUAGE:CXX>:-fms-extensions>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>
    $<$<COMPILE_LANGUAGE:CXX>:-Wswitch-default>
    $<$<COMPILE_LANGUAGE:CXX>:-Wswitch-enum>
    $<$<COMPILE_LANGUAGE:CXX>:-Wmissing-include-dirs>
    -fstrict-volatile-bitfields
    -ffunction-sections
    -fdata-sections
    -fno-threadsafe-statics
    -fdce

    -Wfatal-errors
    -Wall
    -Wextra
    -Wcast-align
    -Wconversion
    -Wsign-conversion
    -Wold-style-cast
    -Wshadow
    -Wlogical-op
    -Wsuggest-override
    -Wsuggest-final-types
    -Wsuggest-final-methods
    -pedantic
)

include_directories(
    ${CMAKE_SOURCE_DIR}
)

link_directories(
    ${CMAKE_SOURCE_DIR}
)

add_executable(${PROJECT_NAME}
    mysource.c
    mysource2.cpp
    ...

target_link_libraries(${PROJECT_NAME}
    ${CPU_OPTIONS}
    -T${LINKER_SCRIPT}
    -nostartfiles
    m #libm
    gcc #libgcc
)

set_property(TARGET ${PROJECT_NAME} PROPERTY LINK_DEPENDS ${CMAKE_SOURCE_DIR}/${LINKER_SCRIPT})
aphardt
sumber