1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
{#
# Copyright (c) 2020 Mathias Brossard
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#}
# This project was exported via the project generator.
# More information https://github.com/project-generator/project_generator
CMAKE_MINIMUM_REQUIRED(VERSION 3.6)
{% if singular %}
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_ARCH arm-arm-none-eabi)
################## Ignore this section ##################
# This section works around some of the problems of armclang
# support in CMake (some of them are mentioned in this ticket
# https://gitlab.kitware.com/cmake/cmake/-/issues/21173)
# Disable default of CMAKE_SYSTEM_PROCESSOR mandatory
set(__march_flag_set True FORCE)
set(__mcpu_flag_set True FORCE)
# Do not try to check that the compiler works
set(CMAKE_C_COMPILER_WORKS True)
set(CMAKE_CXX_COMPILER_WORKS True)
set(CMAKE_ASM_COMPILER_WORKS True)
set(CMAKE_C_COMPILER_FORCED True)
set(CMAKE_CXX_COMPILER_FORCED True)
set(CMAKE_ASM_COMPILER_FORCED True)
# Do not try to compile for the host
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
################## /Ignore this section ##################
set(CMAKE_C_COMPILER armclang)
set(CMAKE_CXX_COMPILER armclang)
set(CMAKE_ASM_COMPILER armclang)
set(CMAKE_AR armar)
set(CMAKE_LINKER armlinker)
set(CMAKE_OBJCOPY fromelf)
set(CMAKE_EXECUTABLE_SUFFIX_C ".axf")
{% endif %}
# Start project
project({{name}} LANGUAGES C CXX ASM)
{% if output_type == 'exe' %}# Add Executable
add_executable({{name}}){% else %}# Add Library
add_library({{name}} STATIC){% endif %}
{% if singular %}
set(OUTPUT_DIR "${CMAKE_BINARY_DIR}")
set(BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
{% else %}
set_target_properties({{name}}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/{{name}}/build"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/{{name}}/build"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/{{name}}/build"
)
set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/{{name}}/build")
set(BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/{{name}}")
{% endif %}
# Set source files
target_sources({{name}} PUBLIC{% for file in source_files_c %}
"{{file}}"{% endfor %}{% for file in source_files_cpp %}
"{{file}}"{% endfor %}{% for file in source_files_s %}
"{{file}}"{% endfor %}{% for file in source_files_obj %}
"{{file}}"{% endfor %})
# Set macros
target_compile_definitions({{name}} PRIVATE{% for symbol in macros %}
"{{symbol | replace ('"', '\\"') }}"{% endfor %})
# Set include_paths
target_include_directories({{name}} PRIVATE{% for path in include_paths %}
"{{path}}"{% endfor %})
# Set compilation options
target_compile_options({{name}} PRIVATE
--target=arm-arm-none-eabi -mcpu={{core}} -mthumb{% for flag in misc['common_flags'] %}
{{flag}}{% endfor %}{% for flag in misc['cxx_flags'] %}
$<$<COMPILE_LANGUAGE:Cxx>:{{flag}}>{% endfor %}{% for flag in misc['c_flags'] %}
$<$<COMPILE_LANGUAGE:C>:{{flag}}>{% endfor %}{% for flag in misc['asm_flags'] %}
$<$<COMPILE_LANGUAGE:ASM>:{{flag}}>{% endfor %})
set_target_properties({{name}} PROPERTIES LINKER_LANGUAGE C)
target_link_directories({{name}} PRIVATE{% for path in lib_paths %}
"{{path}}"{% endfor %})
target_link_libraries({{name}} PRIVATE{% for library in source_files_lib %}
"{{library}}"{% endfor %}{% if misc['standard_libraries'] %}{% for library in misc['standard_libraries'] %}
"{{library}}"{% endfor %}{% endif %})
target_link_options({{name}} PRIVATE
--cpu={{core}}{% for flag in misc['ld_flags'] %}
{{flag}}{% endfor %}
--strict --map --list ${OUTPUT_DIR}/{{name}}.map)
{% if preprocess_linker_file %}
add_custom_command(OUTPUT "${OUTPUT_DIR}/{{name}}.sct"
MAIN_DEPENDENCY "{{linker_file}}"
COMMAND ${CMAKE_C_COMPILER} -E -xc --target=arm-arm-none-eabi -mcpu={{core}}
{% for path in include_paths %} "-I{{path}}"
{% endfor %}{% for symbol in macros %} "-D{{symbol | replace ('"', '\\"')}}"
{% endfor %}-o "${OUTPUT_DIR}/{{name}}.sct" "{{linker_file}}"
VERBATIM)
add_custom_target({{name}}_linker_script DEPENDS "${OUTPUT_DIR}/{{name}}.sct" VERBATIM)
add_dependencies({{name}} {{name}}_linker_script)
target_link_options({{name}} PRIVATE "--scatter=${OUTPUT_DIR}/{{name}}.sct")
{% else %}
target_link_options({{name}} PRIVATE "--scatter={{linker_file}}")
{% endif %}
# Create bin and hex
add_custom_target({{name}}_bin DEPENDS "${OUTPUT_DIR}/{{name}}.bin")
add_custom_command(OUTPUT "${OUTPUT_DIR}/{{name}}.bin" DEPENDS {{name}}
COMMAND ${CMAKE_OBJCOPY} --bincombined $<TARGET_FILE:{{name}}> --output "${OUTPUT_DIR}/{{name}}.bin")
add_custom_target({{name}}_hex DEPENDS "${OUTPUT_DIR}/{{name}}.hex")
add_custom_command(OUTPUT "${OUTPUT_DIR}/{{name}}.hex" DEPENDS {{name}}
COMMAND ${CMAKE_OBJCOPY} --i32combined $<TARGET_FILE:{{name}}> --output "${OUTPUT_DIR}/{{name}}.hex")
add_custom_target({{name}}_binaries ALL DEPENDS {{name}} DEPENDS {{name}}_bin DEPENDS {{name}}_hex)
{% if pre_build_script %}
add_custom_command(TARGET {{name}} PRE_BUILD {{name}} {% for command in pre_build_script %}
COMMAND {{command}}{% endfor %}
WORKING_DIRECTORY ${BUILD_DIR})
{% endif %}
{% if post_build_script %}
add_custom_command(TARGET {{name}}_binaries POST_BUILD {% for command in post_build_script %}
COMMAND {{command}}{% endfor %}
WORKING_DIRECTORY ${BUILD_DIR})
{% endif %}
|