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

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


# add include path definitions needed only for tests (from testDependencies):
{% for component in test_dependencies %}
    include_directories("{{ component.path | replaceBackslashes }}")
{% endfor %}

{% for component in test_dependencies %}
    {% for d in component.getExtraSysIncludes() %}
        include_directories(SYSTEM "{{ d | replaceBackslashes }}")
    {% endfor %}
{% endfor %}

{% for component in test_dependencies %}
    {% for d in component.getExtraIncludes() %}
        include_directories("{{ d | replaceBackslashes }}")
    {% endfor %}
{% endfor %}


# define the tests themselves:

{% for file_names, object_name, languages in tests %}
add_executable({{ object_name }} {{ 'EXCLUDE_FROM_ALL' if exclude_from_all else '' }}
    {{ file_names | join('\n    ') | replaceBackslashes }}
)
{% 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    ') }}
)
# 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()
add_test({{ object_name }} {{ object_name }})
add_dependencies(all_tests {{ object_name }})

{% endfor %}

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