#******************************************************************
#
# Copyright 2015 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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# ResourceDirectory Sample Apps build script
##

Import('env')

lib_env = env.Clone()
SConscript('#resource/third_party_libs.scons', 'lib_env')

rd_sample_app_env = lib_env.Clone()

target_os = env.get('TARGET_OS')
src_dir = env.get('SRC_DIR')
######################################################################
# Build flags
######################################################################
rd_sample_app_env.AppendUnique(CPPPATH = ['../include',
                                          '../src/internal',
                                          src_dir + '/resource/csdk/stack/include',
                                          src_dir + '/resource/include',
                                          src_dir + '/resource/oc_logger/include',])

if target_os not in ['windows']:
    rd_sample_app_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-Wextra', '-std=c++0x'])
rd_sample_app_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
rd_sample_app_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
rd_sample_app_env.PrependUnique(LIBS = ['resource_directory', 'octbstack'])

if env.get('SECURED') == '1':
    rd_sample_app_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])

if env.get('LOGGING'):
    rd_sample_app_env.AppendUnique(CPPDEFINES = ['TB_LOG'])

if rd_sample_app_env.get('RD_MODE'):
    rd_mode = rd_sample_app_env.get('RD_MODE')
    if 'CLIENT' in rd_mode:
        rd_sample_app_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
    if 'SERVER' in rd_mode:
        rd_sample_app_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])

####################################################################
# Source files and Targets
######################################################################
rd_queryClient = rd_sample_app_env.Program('rd_queryClient', 'rd_queryClient.cpp')

if 'SERVER' in rd_sample_app_env.get('RD_MODE'):
    rd_server = rd_sample_app_env.Program('rd_server', 'rd_main.c')
    Alias("resource_directory", [rd_server, rd_queryClient])

if 'CLIENT' in rd_sample_app_env.get('RD_MODE'):
    rd_publishingClient = rd_sample_app_env.Program('rd_publishingClient', 'rd_publishingClient.cpp')
    Alias("resource_directory", [rd_publishingClient, rd_queryClient])

env.AppendTarget('resource_directory')
