CMakeLists_template.txt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #${templateWarning}
  2. set(CMAKE_SYSTEM_NAME Generic)
  3. set(CMAKE_SYSTEM_VERSION 1)
  4. ${cmakeRequiredVersion}
  5. # specify cross-compilers and tools
  6. set(CMAKE_C_COMPILER arm-none-eabi-gcc)
  7. set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
  8. set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
  9. set(CMAKE_AR arm-none-eabi-ar)
  10. set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
  11. set(CMAKE_OBJDUMP arm-none-eabi-objdump)
  12. set(SIZE arm-none-eabi-size)
  13. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  14. # project settings
  15. project(${projectName} C CXX ASM)
  16. set(CMAKE_CXX_STANDARD 17)
  17. set(CMAKE_C_STANDARD 11)
  18. #Uncomment for hardware floating point
  19. #add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING)
  20. #add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
  21. #add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
  22. #Uncomment for software floating point
  23. #add_compile_options(-mfloat-abi=soft)
  24. add_compile_options(-mcpu=${mcpu} -mthumb -mthumb-interwork)
  25. add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)
  26. # uncomment to mitigate c++17 absolute addresses warnings
  27. #set(CMAKE_CXX_FLAGS "$${CMAKE_CXX_FLAGS} -Wno-register")
  28. # Enable assembler files preprocessing
  29. add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-x$<SEMICOLON>assembler-with-cpp>)
  30. if ("$${CMAKE_BUILD_TYPE}" STREQUAL "Release")
  31. message(STATUS "Maximum optimization for speed")
  32. add_compile_options(-Ofast)
  33. elseif ("$${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
  34. message(STATUS "Maximum optimization for speed, debug info included")
  35. add_compile_options(-Ofast -g)
  36. elseif ("$${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
  37. message(STATUS "Maximum optimization for size")
  38. add_compile_options(-Os)
  39. else ()
  40. message(STATUS "Minimal optimization, debug info included")
  41. add_compile_options(-Og -g)
  42. endif ()
  43. include_directories(${includes})
  44. add_definitions(${defines})
  45. file(GLOB_RECURSE SOURCES ${sources})
  46. set(LINKER_SCRIPT $${CMAKE_SOURCE_DIR}/${linkerScript})
  47. add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=$${PROJECT_BINARY_DIR}/$${PROJECT_NAME}.map)
  48. add_link_options(-mcpu=${mcpu} -mthumb -mthumb-interwork)
  49. add_link_options(-T $${LINKER_SCRIPT})
  50. add_executable($${PROJECT_NAME}.elf $${SOURCES} $${LINKER_SCRIPT})
  51. set(HEX_FILE $${PROJECT_BINARY_DIR}/$${PROJECT_NAME}.hex)
  52. set(BIN_FILE $${PROJECT_BINARY_DIR}/$${PROJECT_NAME}.bin)
  53. add_custom_command(TARGET $${PROJECT_NAME}.elf POST_BUILD
  54. COMMAND $${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:$${PROJECT_NAME}.elf> $${HEX_FILE}
  55. COMMAND $${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:$${PROJECT_NAME}.elf> $${BIN_FILE}
  56. COMMENT "Building $${HEX_FILE}
  57. Building $${BIN_FILE}")