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

cmake_minimum_required(VERSION 2.8.11)

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

{% 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 %}
)
{% endfor %}

{% if resource_files %}
set(YOTTA_AUTO_{{ object_name.upper() }}_RESOURCE_FILES
    {{ resource_files | join('\n    ') }}
)
{% 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 %}
)
{% 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 %}
# if the target has defined a post-processing step, perform it:
if(YOTTA_POSTPROCESS_COMMAND)
    string(REPLACE YOTTA_CURRENT_EXE_NAME "{{ object_name }}" LOCAL_POSTPROCESS_COMMAND "${YOTTA_POSTPROCESS_COMMAND}")
    separate_arguments(LOCAL_POSTPROCESS_COMMAND_SEPARATED UNIX_COMMAND ${LOCAL_POSTPROCESS_COMMAND})
    add_custom_command(
        TARGET {{ object_name }}
        POST_BUILD
        COMMAND ${LOCAL_POSTPROCESS_COMMAND_SEPARATED}
    )
endif()
{% 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 %}
