#******************************************************************
#
# Copyright 2016 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# 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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# Notification build script
##

Import('env')

lib_env = env.Clone()
SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
notification_sample_env = lib_env.Clone()

target_os = env.get('TARGET_OS')
######################################################################
# Build flags
######################################################################
notification_sample_env.AppendUnique(CPPPATH = [
    '../../../include',
    '../../provider/inc',
    '../../consumer/inc',
    '../../common',
    '#/resource/csdk/include',
    '#/resource/csdk/stack/include',
    '#/resource/csdk/connectivity/api',
    '#/resource/include',
    '#/resource/oc_logger/include'
    '../../../src/common'
    ])

notification_sample_env.PrependUnique(LIBS = [
    'resource_directory',
    'oc',
    'liboctbstack',
    'oc_logger',
    'connectivity_abstraction',
    'libcoap',
    ])

notification_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x','-frtti'])
if target_os not in ['windows', 'winrt']:
    notification_sample_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0'])

if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
    notification_sample_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])

if target_os == 'linux':
    notification_sample_env.AppendUnique(LIBS = ['pthread'])

if target_os == 'android':
    notification_sample_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
    notification_sample_env.AppendUnique(LIBS = ['gnustl_shared','log'])

if not env.get('RELEASE'):
    notification_sample_env.PrependUnique(LIBS = ['gcov'])
    notification_sample_env.AppendUnique(CCFLAGS = ['--coverage'])

if env.get('WITH_CLOUD') == True:
    notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])

with_mq = env.get('WITH_MQ')
if 'SUB' in with_mq:
    notification_sample_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
    print "MQ SUB support"

if 'PUB' in with_mq:
    notification_sample_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
    print "MQ PUB support"

if 'BROKER' in with_mq:
    notification_sample_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
    print "MQ Broker support"

if env.get('WITH_TCP') == True:
    notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
if env.get('SECURED') == '1':
    notification_sample_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])

####################################################################
# Source files and Targets
######################################################################
notification_sample_provider_env = notification_sample_env.Clone()

notification_sample_provider_env.AppendUnique(LIBS = 'libnotification_provider_wrapper')
notification_sample_provider_env.AppendUnique(LIBS = 'libnotification_provider')
notificationproviderwrapper = notification_sample_provider_env.Program('notificationproviderwrapper', 'notificationserviceprovider.cpp')
i_notificationprovider = notification_sample_provider_env.Install(env.get('BUILD_DIR'), notificationproviderwrapper)

notification_sample_consumer_env = notification_sample_env.Clone()
notification_sample_consumer_env.AppendUnique(LIBS = 'libnotification_consumer_wrapper')
notification_sample_consumer_env.AppendUnique(LIBS = 'libnotification_consumer')
notificationconsumerwrapper = notification_sample_consumer_env.Program('notificationconsumerwrapper', 'notificationserviceconsumer.cpp')
i_notificationconsumer = notification_sample_consumer_env.Install(env.get('BUILD_DIR'), notificationconsumerwrapper)
