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

cmake_minimum_required(VERSION 2.8.11)

include_directories("{{ source_directory | replaceBackslashes }}")

{% if 's' in languages %}
enable_language(ASM)
{% endif %}

{% for lang in languages %}
set(YOTTA_AUTO_{{ object_name.upper() }}_{{ lang | upper }}_FILES
  {% for file_name, language in source_files %}
    {% if language in lang %}
    "{{ file_name | replaceBackslashes }}"
    {% endif %}
  {% endfor %}
)
# force dependency on the config header for {{ lang }} files, which CMake otherwise wouldn't track:
set_property(SOURCE ${YOTTA_AUTO_{{ object_name.upper() }}_{{ lang | upper }}_FILES} PROPERTY OBJECT_DEPENDS "{{ config_include_file | replaceBackslashes }}")
{% endfor %}

{% if resource_files %}
set(YOTTA_AUTO_{{ object_name.upper() }}_RESOURCE_FILES
  {% for file_name in resource_files %}
    "{{ file_name | replaceBackslashes }}"
  {% endfor %}
)
{% endif %}

{% if executable %}
add_executable ({{ object_name }}
{% for lang in languages %}
    ${YOTTA_AUTO_{{ object_name | upper }}_{{ lang | upper }}_FILES}
{% endfor %}
{% if resource_files %}
    ${YOTTA_AUTO_{{ object_name | upper }}_RESOURCE_FILES}
{% endif %}
)
set_target_properties({{ object_name }} PROPERTIES ENABLE_EXPORTS ON)
{% else %}
add_library({{ object_name }}
{% for lang in languages %}
    ${YOTTA_AUTO_{{ object_name | upper }}_{{ lang | upper }}_FILES}
{% endfor %}
{% if resource_files %}
    ${YOTTA_AUTO_{{ object_name | upper }}_RESOURCE_FILES}
{% endif %}
)
{% endif %}

{% if executable %}
yotta_postprocess_target(EXECUTABLE {{ object_name }})
{% else %}
yotta_postprocess_target(LIBRARY {{ object_name }})
{% endif %}

{% if resource_files %}
set_target_properties({{ object_name }}
    PROPERTIES
    RESOURCE "${YOTTA_AUTO_{{ object_name | upper }}_RESOURCE_FILES}"
)
{% endif %}

{% if 'objc' in languages %}
# no proper CMake support for objective-c flags :(
set_target_properties({{ object_name }} PROPERTIES
    COMPILE_FLAGS "${CMAKE_OBJC_FLAGS}"
)
{% endif %}

target_link_libraries({{ object_name }}
    {{ link_dependencies | join('\n    ') }}
)

{% for include in cmake_files %}
include("{{ include | replaceBackslashes }}")
{% endfor %}
