############################################################################
# Copyright 2016 Intel Corporation
#
# 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.
############################################################################
Import('*')
env.PartName('verifier')

api_headers = Pattern(src_dir='.',
                      includes=['*.h'],
                      recursive=False).files()
src_files = Pattern(src_dir='src',
                    includes=['*.c'],
                    recursive=False).files()
internal_headers = Pattern(src_dir='src',
                           includes=['*.h', '*.inc'],
                           recursive=False).files()
utest_files = Pattern(src_dir='unittests',
                      includes=['*-test.cc', '*-testhelper.cc'],
                      recursive=False).files()
utest_headers = Pattern(src_dir='unittests',
                        includes=['*-testhelper.h',],
                        recursive=False).files()
utest_data_files = Pattern(src_dir='unittests/testdata/sigrl',
                           includes=['*.inc'],
                           excludes=[],
                           recursive=False).files()

epid11_headers = Pattern(src_dir='1.1',
                         includes=['*.h'],
                         recursive=False).files()
epid11_src_files = Pattern(src_dir='1.1/src',
                           includes=['*.c'],
                           recursive=False).files()
epid11_internal_headers = Pattern(src_dir='1.1/src',
                                  includes=['*.h', '*.inc'],
                                  recursive=False).files()
epid11_utest_files = Pattern(src_dir='1.1/unittests',
                             includes=['*-test.cc', '*-testhelper.cc'],
                             recursive=False).files()
epid11_utest_headers = Pattern(src_dir='1.1/unittests',
                               includes=['*-testhelper.h',],
                               recursive=False).files()
epid11_utest_data_files = Pattern(src_dir='1.1/unittests/testdata',
                                  includes=['*.inc'],
                                  recursive=False).files()

build_files = Pattern(src_dir='.',
                      includes=['*.parts', 'Makefile'],
                      recursive=False).files()

if 'install_package' in env['MODE']:
    env.InstallTopLevel(api_headers,
                        sub_dir='epid/${PART_SHORT_NAME}')
    env.InstallTopLevel(src_files + internal_headers,
                        sub_dir='epid/${PART_SHORT_NAME}/src')
    env.InstallTopLevel(utest_files + utest_headers,
                        sub_dir='epid/${PART_SHORT_NAME}/unittests')
    env.InstallTopLevel(
        utest_data_files,
        sub_dir='epid/${PART_SHORT_NAME}/unittests/testdata/sigrl')

    env.InstallTopLevel(epid11_headers,
                        sub_dir='epid/${PART_SHORT_NAME}/1.1')
    env.InstallTopLevel(epid11_src_files + epid11_internal_headers,
                        sub_dir='epid/${PART_SHORT_NAME}/1.1/src')
    env.InstallTopLevel(epid11_utest_files + epid11_utest_headers,
                        sub_dir='epid/${PART_SHORT_NAME}/1.1/unittests')
    env.InstallTopLevel(
        epid11_utest_data_files,
        sub_dir='epid/${PART_SHORT_NAME}/1.1/unittests/testdata')

    env.InstallTopLevel(build_files, sub_dir='epid/${PART_SHORT_NAME}')

else:
    env.DependsOn([
        Component('common'),
    ])

    env.Append(CPPPATH='#')

    testenv = env.Clone()
    outputs = env.Library('${PART_NAME}', src_files + epid11_src_files)
    env.Sdk(outputs)
    env.SdkInclude(api_headers, sub_dir='epid/${PART_SHORT_NAME}')
    env.SdkInclude(epid11_headers, sub_dir='epid/${PART_SHORT_NAME}/1.1')

    if 'install_lib' in env['MODE']:
        env.InstallLib(outputs)
        env.InstallInclude(api_headers, sub_dir='${PART_SHORT_NAME}')
        env.InstallInclude(epid11_headers, sub_dir='${PART_SHORT_NAME}/1.1')

    testenv['UNIT_TEST_TARGET_NAME'] = "${PART_NAME}-${UNIT_TEST_TARGET}"
    testenv.UnitTest("utest",
                     utest_files + epid11_utest_files,
                     command_args=[
                         '--gtest_color=yes',
                         '--gtest_print_time=1',
                         '--gtest_output=xml',
                         '--gtest_filter=**',
                     ],
                     make_pdb=(env.isConfigBasedOn('debug') or
                               env.isConfigBasedOn('static_crt_debug')),
                     depends=[Component('gtest'),
                              Component('common-testhelper'),
                              Component('verifier')],
                     INSTALL_BIN='${INSTALL_TEST_BIN}')
