# NOTE: This file is generated by yotta: changes will be overwritten!

{% if toplevel %}
cmake_minimum_required(VERSION 2.8.11)

enable_testing()

# add a dummy target for all autogenerated tests, so we can build them all
# even though they are EXCLUDE_FROMALL'd, if you use custom CMakeLists you can
# add a dependency of this target on your test programs, by adding:
# add_dependencies(all_tests your_test_name)
add_custom_target(all_tests)


# always use the CMAKE_MODULE_PATH-provided .cmake files, even when including
# from system directories:
cmake_policy(SET CMP0017 OLD)

# toolchain file for {{ target_name }}
set(CMAKE_TOOLCHAIN_FILE "{{ toolchain_file | replaceBackslashes }}")

{{ set_targets_like }}
{% endif %}

project({{ component_name }})

# include root directories of all components we depend on (directly and
# indirectly, including ourself)
{{ include_root_dirs }}

# recurse into dependencies that aren't built elsewhere
{{ add_depend_subdirs }}

{% if include_sys_dirs %}
# Some components (I'm looking at you, libc), need to export system header
# files with no prefix, these directories are listed in the component
# description files:
{{ include_sys_dirs }}
{% endif %}

{% if include_other_dirs %}
# And others (typically CMSIS implementations) need to export non-system header
# files. Please don't use this facility. Please. It's much, much better to fix
# implementations that import these headers to import them using the full path.
{{ include_other_dirs }}
{% endif %}

# Build targets may define additional preprocessor definitions for all
# components to use (such as chip variant information)
add_definitions({{ yotta_target_definitions }})

# Provide the version of the component being built, in case components want to
# embed this into compiled libraries
set(YOTTA_COMPONENT_VERSION "{{ component_version }}")
add_definitions(-DYOTTA_COMPONENT_VERSION="{{ component_version }}")

{% if delegate_to %}
# delegate to an existing CMakeLists.txt:
add_subdirectory(
    "{{ delegate_to | replaceBackslashes }}"
    "{{ delegate_build_dir | replaceBackslashes }}"
)
{% else %}
# recurse into subdirectories for this component, using the two-argument
# add_subdirectory because the directories referred to here exist in the source
# tree, not the working directory
{% for srcdir, workingdir in add_own_subdirs %}
add_subdirectory(
    "{{ srcdir | replaceBackslashes }}"
    "{{ workingdir | replaceBackslashes }}"
)
{% endfor %}
{% endif %}
