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
|
{#
# Copyright (c) 2015 0xc0170
# 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_PROCESSOR arm)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
set(CMAKE_LINKER arm-none-eabi-gcc-ld)
set(CMAKE_AR arm-none-eabi-gcc-ar)
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
# Do not try to compile for the host
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
{% 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
-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'] %}
-Wl,--start-group{% for library in misc['standard_libraries'] %}
"{{library}}"{% endfor %}
-Wl,--end-group
{% endif %})
target_link_options({{name}} PRIVATE
-mcpu={{core}} -mthumb{% for flag in misc['common_flags'] %}
{{flag}}{% endfor %}{% for flag in misc['ld_flags'] %}
{{flag}}{% endfor %}
"-Wl,-Map=${OUTPUT_DIR}/{{name}}.map" -Wl,--cref)
{% if preprocess_linker_file %}
add_custom_command(OUTPUT "${OUTPUT_DIR}/{{name}}.ld"
MAIN_DEPENDENCY "{{linker_file}}"
COMMAND ${CMAKE_C_COMPILER} -E -x c -P -MMD
{% for path in include_paths %} "-I{{path}}"
{% endfor %}{% for symbol in macros %} "-D{{symbol | replace ('"', '\\"')}}"
{% endfor %} -o "${OUTPUT_DIR}/{{name}}.ld" "{{linker_file}}"
VERBATIM)
add_custom_target({{name}}_linker_script DEPENDS "${OUTPUT_DIR}/{{name}}.ld" VERBATIM)
add_dependencies({{name}} {{name}}_linker_script)
target_link_options({{name}} PRIVATE "-T${OUTPUT_DIR}/{{name}}.ld" -static)
{% else %}
target_link_options({{name}} PRIVATE "-T{{linker_file}}" -static)
{% 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} -O binary $<TARGET_FILE:{{name}}> "${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} -O ihex $<TARGET_FILE:{{name}}> "${OUTPUT_DIR}/{{name}}.hex")
add_custom_target({{name}}_binaries ALL DEPENDS {{name}} DEPENDS {{name}}_bin DEPENDS {{name}}_hex)
{% if pre_build_script %}
add_custom_target({{name}}_pre_build {% for command in pre_build_script %}
COMMAND {{command}}{% endfor %}
WORKING_DIRECTORY ${BUILD_DIR})
add_dependencies({{name}} {{name}}_pre_build)
{% 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 %}
|