Build OICMiddle using Scons on CA branch
authorSashi Penta <sashi.kumar.penta@intel.com>
Thu, 29 Jan 2015 22:56:08 +0000 (14:56 -0800)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Sat, 31 Jan 2015 20:49:25 +0000 (20:49 +0000)
Change-Id: I63ad62700ee87b13c316fcf04d8e2c1fa42f4cc0
Signed-off-by: Sashi Penta <sashi.kumar.penta@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/274
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: John Light <john.j.light@intel.com>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
SConstruct
examples/OICMiddle/Client.cpp
examples/OICMiddle/SConscript [new file with mode: 0644]
examples/OICMiddle/SConstruct [deleted file]

index 92eac38..3ffc00c 100644 (file)
@@ -27,6 +27,8 @@ build_dir = env.get('BUILD_DIR')
 # Build 'resource' sub-project
 SConscript(build_dir + 'resource/SConscript')
 
+SConscript(build_dir + 'examples/OICMiddle/SConscript')
+
 # Build 'service' sub-project
 SConscript(build_dir + 'service/SConscript')
 
index 8d6e7d1..1aafde9 100644 (file)
@@ -38,7 +38,7 @@ void MiddleClient::findResources()
 {
     m_resourceMap.clear();
 
-    OC::OCPlatform::findResource("", OC_WELL_KNOWN_QUERY, m_findCB);
+    OC::OCPlatform::findResource("", OC_WELL_KNOWN_QUERY, OC_WIFI, m_findCB);
 }
 
 void MiddleClient::foundOCResource(shared_ptr<OCResource> resource)
diff --git a/examples/OICMiddle/SConscript b/examples/OICMiddle/SConscript
new file mode 100644 (file)
index 0000000..56c42ea
--- /dev/null
@@ -0,0 +1,60 @@
+##
+# Examples build script
+##
+Import('env')
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/resource/third_party_libs.scons', 'lib_env')
+
+examples_env = lib_env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+examples_env.AppendUnique(CPPPATH = [
+               '../../resource/include/',
+               '../../resource/csdk/stack/include',
+               '../../resource/csdk/ocsocket/include',
+               '../../resource/csdk/ocrandom/include',
+               '../../resource/csdk/logger/include',
+               '../../resource/csdk/libcoap',
+               '../../resource/oc_logger/include'
+               ])
+
+target_os = env.get('TARGET_OS')
+if target_os not in ['windows', 'winrt']:
+       examples_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+
+       # Note: 'pthread' is in libc for android. On other platform, if use
+       # new gcc(>4.9?) it isn't required, otherwise, it's required
+       if target_os != 'android':
+               examples_env.AppendUnique(LIBS = ['-lpthread'])
+
+examples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+examples_env.PrependUnique(LIBS = ['oc', 'octbstack', 'coap', 'coap_csdk', 'oc_logger', 'connectivity_abstraction'])
+if env.get('SECURED') == '1':
+    examples_env.AppendUnique(LIBS = ['tinydtls'])
+
+examples_env.ParseConfig('pkg-config --libs glib-2.0');
+
+if target_os == 'android':
+       examples_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+       examples_env.AppendUnique(LIBS = ['gnustl_static'])
+
+       if not env.get('RELEASE'):
+               examples_env.AppendUnique(LIBS = ['log'])
+
+if target_os in ['darwin', 'ios']:
+       examples_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+
+examples_env.AppendUnique(CPPDEFINES = ['CA_INT'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+OICMiddle = examples_env.Program('OICMiddle', ['OICMiddle.cpp', 'Client.cpp', 'LineInput.cpp', 'RestInput.cpp', 'Server.cpp', 'WrapResource.cpp'])
+
+Alias("examples", [OICMiddle])
+env.AppendTarget('examples')
+
+
diff --git a/examples/OICMiddle/SConstruct b/examples/OICMiddle/SConstruct
deleted file mode 100644 (file)
index 02a2d8e..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-#For Yocto builds, set OS=yocto as a command-line argument to scons once
-#the Yocto toolchain is installed and configured.
-
-#For Linux builds, set the following two variables:
-#Set OIC_RESOURCE_PATH to the root of oic-resource on Ubuntu.
-
-OIC_RESOURCE_PATH = '../..'
-
-#Set OIC_LIBS_PATH to path on Ubuntu that contains liboc.so, liboctbstack.so,
-#liboc_logger.so and libcoap.so.
-
-OIC_LIBS_PATH = '../../out/linux/x86_64/release'
-
-env = DefaultEnvironment()
-target_os = ARGUMENTS.get("OS", "linux").lower()
-output_dir = env.GetLaunchDir() + "/out/" + target_os
-env.VariantDir(output_dir, env.GetLaunchDir(), duplicate=0)
-env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
-env.AppendUnique(LINKFLAGS = ['-pthread'])
-env.AppendUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'coap'])
-env.Program(output_dir + '/OICMiddle', [output_dir + '/OICMiddle.cpp',
-                          output_dir + '/Client.cpp',
-                          output_dir + '/Server.cpp',
-                          output_dir + '/WrapResource.cpp',
-                          output_dir + '/LineInput.cpp',
-                          output_dir + '/RestInput.cpp'])
-
-if target_os == "yocto":
-    '''
-    This code injects Yocto cross-compilation flags into scons' default environment
-    in order to invoke the relevant tools while performing a build.
-    '''
-    import os.path, re
-    sdk_root = ''
-    try:
-        CC = os.environ['CC']
-        sdk_root = re.search(r'--sysroot=\S+', CC).group().split('=')[1]
-        target_prefix = CC.split()[0]
-        target_prefix = target_prefix[:len(target_prefix)-3]
-        tools = {"CC" : target_prefix+"gcc",
-                 "CXX" : target_prefix+"g++",
-                 "AS" : target_prefix+"as",
-                 "LD" : target_prefix+"ld",
-                 "GDB" : target_prefix+"gdb",
-                 "STRIP" : target_prefix+"strip",
-                 "RANLIB" : target_prefix+"ranlib",
-                 "OBJCOPY" : target_prefix+"objcopy",
-                 "OBJDUMP" : target_prefix+"objdump",
-                 "AR" : target_prefix+"ar",
-                 "NM" : target_prefix+"nm",
-                 "M4" : "m4",
-                 "STRINGS": target_prefix+"strings"}
-        PATH = os.environ['PATH'].split(os.pathsep)
-        for tool in tools:
-            if tool in os.environ:
-                for path in PATH:
-                   if os.path.isfile(os.path.join(path, tools[tool])):
-                       env[tool] = os.path.join(path, os.environ[tool])
-        env.AppendUnique(CPPPATH = [
-                sdk_root + '/usr/include/oic/',
-                sdk_root + '/usr/include/oic/stack/',
-                sdk_root + '/usr/include/oic/ocsocket/',
-                sdk_root + '/usr/include/oic/oc_logger/',
-                ])
-    except:
-        print "ERROR configuring Yocto cross-toolchain environment."
-        Exit(1)
-elif target_os == "linux":
-    if OIC_RESOURCE_PATH == '' or OIC_LIBS_PATH == '':
-        print "ERROR Please set both OIC_RESOURCE_PATH and OIC_LIBS_PATH in SConstruct"
-        Exit(1)
-    env.AppendUnique(CPPPATH = [
-                OIC_RESOURCE_PATH + '/resource/include',
-                OIC_RESOURCE_PATH + '/resource/csdk/stack/include',
-                OIC_RESOURCE_PATH + '/resource/csdk/ocsocket/include',
-                OIC_RESOURCE_PATH + '/resource/oc_logger/include',
-                ])
-    env.AppendUnique(LIBPATH = [OIC_LIBS_PATH])
-else:
-    print "ERROR ", target_os, " is an unsupported target"
-    Exit(1)