File: cmakelist_armcc.tmpl

package info (click to toggle)
python-project-generator 0.11.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 768 kB
  • sloc: python: 4,125; makefile: 18; sh: 9
file content (115 lines) | stat: -rw-r--r-- 4,617 bytes parent folder | download | duplicates (3)
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
{#
# 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)

set(CMAKE_C_COMPILER armcc)
set(CMAKE_CXX_COMPILER armcc)
set(CMAKE_ASM_COMPILER armasm)
set(CMAKE_AR armar)
set(CMAKE_LINKER armlink)
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
    --cpu {{core}} --thumb{% 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 %}
    $<$<COMPILE_LANGUAGE:ASM>:--cpreproc>{% for symbol in macros %}
    $<$<COMPILE_LANGUAGE:ASM>:--cpreproc_opts=-D{{symbol}}>{% 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 %}
    --map --list "${OUTPUT_DIR}/{{name}}.map"
    --predefine=-D$<JOIN:$<TARGET_PROPERTY:COMPILE_DEFINITIONS>, --predefine=-D>
    --predefine=-I$<JOIN:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>, --predefine=-I>
    --strict "--scatter={{linker_file}}")

# 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} --bin $<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} --i32 $<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 %}