Commit f8af7607 authored by Dan Mihai's avatar Dan Mihai Committed by Mike Fenelon

[IOT-2011] linker changes for oc_logger

Windows currently has several different copies of oc_logger code and
data in a single process. Other platforms are using a single copy of
shared library oc_logger, in each process/app.

It's better to avoid differences across platforms, because otherwise
changes tested on one platform might not work on the other platforms.

Linker behavior unchanged by this patch:
----------------------------------------

1. On non-Windows platforms: IoTivity sample apps, and apps outside
   IoTivity, link with oc_logger.

2. On Windows: IoTivity sample apps, and apps outside IoTivity,
   continue to link with octbstack.lib.

Linker behavior changed by this patch:
----------------------------------------

1. On all platforms: IoTivity internal tests link with the static LIB
   oc_logger_internal.

2. On Windows: IoTivity sample apps, and apps outside IoTivity,
   no longer link directly with oc_logger.lib. They obtain access to
   oc_logger APIs by linking with octbstack.lib.

3. On Windows: Octbstack.dll links with the static LIB
   oc_logger_internal, and exports public oc_logger APIs.

Change-Id: I3ca36ffcbebea7822918998ac3fced1c5071726e
Signed-off-by: default avatarDan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18769Reviewed-by: default avatarTodd Malsbary <todd.malsbary@intel.com>
Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarMike Fenelon <mike.fenelon@microsoft.com>
parent 23ebc0ff
......@@ -54,8 +54,7 @@ elevator_server_env.PrependUnique(LIBS = [
'oc',
'connectivity_abstraction',
'coap',
'octbstack',
'oc_logger',
'octbstack'
])
if elevator_server_env.get('SECURED') == '1':
......@@ -64,6 +63,8 @@ if elevator_server_env.get('SECURED') == '1':
if target_os in ['msys_nt', 'windows']:
elevator_server_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
else:
elevator_server_env.PrependUnique(LIBS = ['oc_logger'])
######################################################################
# Source files and Targets
......
......@@ -49,14 +49,18 @@ ipca_lib_env.PrependUnique(CPPPATH = [
'#/extlibs/cjson',
])
ipca_lib_env.Replace(WINDOWS_INSERT_DEF = ['1'])
if target_os in ['windows', 'msys_nt']:
ipca_lib_env.Replace(WINDOWS_INSERT_DEF = ['1'])
else:
ipca_lib_env.PrependUnique(LIBS = [
'oc_logger'
])
ipca_lib_env.PrependUnique(LIBS = [
'oc',
'connectivity_abstraction',
'coap',
'octbstack',
'oc_logger'
'octbstack'
])
if ipca_env.get('SECURED') == '1':
......
......@@ -56,7 +56,7 @@ ipcatest_env.AppendUnique(CPPPATH = [
])
ipcatest_env.PrependUnique(LIBS = [
'oc_logger',
'oc_logger_internal',
'octbstack',
'ipca_static'
])
......
......@@ -45,7 +45,7 @@ provisioning_env.AppendUnique(CPPDEFINES= ['__WITH_DTLS__'])
if 'g++' in provisioning_env.get('CXX'):
provisioning_env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
provisioning_env.PrependUnique(LIBS = ['octbstack', 'oc_logger', 'connectivity_abstraction', 'coap'])
provisioning_env.PrependUnique(LIBS = ['octbstack', 'connectivity_abstraction', 'coap'])
if target_os not in ['msys_nt', 'windows']:
# octbstack.dll is exporting ocpmapi and ocsrm APIs on Windows.
......
......@@ -48,16 +48,14 @@ if target_os not in ['msys_nt', 'windows']:
else:
provisioning_sample_env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'csdk')])
provisioning_sample_env.PrependUnique(LIBS = ['oc', 'oc_logger', 'octbstack', 'connectivity_abstraction', 'coap'])
provisioning_sample_env.PrependUnique(LIBS = ['oc', 'octbstack', 'connectivity_abstraction', 'coap'])
if target_os not in ['msys_nt', 'windows']:
# octbstack.dll is exporting ocpmapi and ocsrm APIs on Windows.
provisioning_sample_env.PrependUnique(LIBS = ['ocpmapi', 'ocsrm'])
provisioning_sample_env.PrependUnique(LIBS = ['oc_logger', 'ocpmapi', 'ocsrm'])
if env.get('SECURED') == '1':
provisioning_sample_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto'])
if env.get('MULTIPLE_OWNER') == '1':
provisioning_sample_env.AppendUnique(CPPDEFINES = ['MULTIPLE_OWNER'])
......
......@@ -60,11 +60,12 @@ sptest_env.PrependUnique(CPPPATH = [
'../../../connectivity/common/inc',
'../../../connectivity/api'
])
sptest_env.PrependUnique(LIBS = [ 'ocpmapi',
'oc',
'octbstack_test',
'ocsrm',
'oc_logger',
'oc_logger_internal',
'connectivity_abstraction',
'coap'])
......
......@@ -59,7 +59,7 @@ srmtest_env.PrependUnique(CPPPATH = [
srmtest_env.PrependUnique(LIBS = ['ocsrm',
'octbstack_test',
'oc_logger',
'oc_logger_internal',
'connectivity_abstraction',
'coap'])
......
......@@ -117,6 +117,10 @@ else:
# octbstack.def specifies the list of functions exported by octbstack.dll.
liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
# On Windows, apps don't link directly with oc_logger. oc_logger is linked inside
# octbstack.dll and apps import its APIs by linking with octbstack.lib.
liboctbstack_env.PrependUnique(LIBS = ['oc_logger_internal'])
if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
# On Windows:
# - octbstack.dll is exporting resource_directory C APIs
......@@ -136,7 +140,8 @@ else:
if env.get('SECURED') != '1':
liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp2.def')])
else:
# octbstack.dll is exporting ocpmapi APIs on Windows - there is no ocpmapi.dll.
# On Windows, apps don't link directly with ocpmapi.lib. ocpmapi is linked
# inside octbstack.dll and apps import its APIs by linking with octbstack.lib.
liboctbstack_env.PrependUnique(LIBS = ['ocpmapi'])
liboctbstack_env.Textfile(target = 'octbstack_temp3.def', source = [File('octbstack_temp2.def'), File('octbstack_product_secured.def')])
......
......@@ -120,3 +120,10 @@ OCStop
OCStopPresence
OCStopMulticastServer
OCUnBindResource
oc_log_destroy
oc_log_set_level
oc_log_set_module
oc_log_write
oc_make_console_logger
oc_make_ostream_logger
......@@ -51,8 +51,6 @@ stacktest_env.PrependUnique(LIBS = ['octbstack_test',
'connectivity_abstraction',
'coap',
'mbedcrypto'])
if target_os != 'darwin':
stacktest_env.PrependUnique(LIBS = ['oc_logger'])
if stacktest_env.get('SECURED') == '1':
stacktest_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509'])
......
......@@ -47,7 +47,6 @@ examples_env.AppendUnique(CPPPATH = [
examples_env.AppendUnique(RPATH = [examples_env.get('BUILD_DIR')])
examples_env.PrependUnique(LIBS = ['coap'])
examples_env.AppendUnique(LIBS = ['connectivity_abstraction'])
examples_env.AppendUnique(LIBS = ['oc_logger'])
examples_env.AppendUnique(LIBS = ['octbstack'])
examples_env.AppendUnique(LIBS = ['oc'])
......@@ -57,6 +56,8 @@ if 'g++' in compiler:
if target_os in ['msys_nt', 'windows']:
examples_env.PrependUnique(LIBS = ['mswsock', 'ws2_32', 'iphlpapi', 'ole32'])
else:
examples_env.PrependUnique(LIBS = ['oc_logger'])
if examples_env.get('SECURED') == '1':
examples_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509','mbedcrypto'])
......
......@@ -50,16 +50,13 @@ if target_os not in ['darwin', 'ios', 'windows', 'msys_nt']:
# Source files and Targets
######################################################################
oc_logger_libs = []
oc_logger_libs = liboc_logger_env.StaticLibrary('oc_logger_internal',
['c/oc_logger.c', 'c/oc_console_logger.c', 'cpp/oc_ostream_logger.cpp'])
if target_os in ['windows', 'msys_nt','ios']:
# If oc_logger APIs have to be exported from a Windows DLL, these functions
# should be exported from octbstack.dll. Building a separate oc_logger.dll here
# would result in duplicated code and data across these two DLLs. Using just
# the static oc_logger.lib is good enough for Windows for now.
if target_os in ['ios']:
oc_logger_libs += liboc_logger_env.StaticLibrary('oc_logger',
['c/oc_logger.c', 'c/oc_console_logger.c', 'cpp/oc_ostream_logger.cpp'])
else:
elif target_os not in ['windows', 'msys_nt']:
oc_logger_libs += Flatten(liboc_logger_env.SharedLibrary('oc_logger_core',
['c/oc_logger.c'], OBJPREFIX='core_'))
oc_logger_libs += Flatten(liboc_logger_env.SharedLibrary('oc_logger',
......@@ -76,4 +73,3 @@ liboc_logger_env.UserInstallTargetHeader('include/targets/oc_ostream_logger.h',
if target_os not in ['ios', 'android']:
SConscript('examples/SConscript')
......@@ -32,7 +32,6 @@ examples_env = lib_env.Clone()
# Build flags
######################################################################
examples_env.PrependUnique(CPPPATH = ['../include'])
examples_env.AppendUnique(LIBS = ['oc_logger'])
examples_env.Append(LIBS = ['c_common'])
compiler = env.get('CC')
......@@ -40,13 +39,17 @@ if compiler != 'cl':
examples_env.AppendUnique(LIBS = ['stdc++'])
target_os = env.get('TARGET_OS')
if target_os == 'android':
examples_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
examples_env.AppendUnique(LIBS = ['gnustl_shared'])
if target_os not in ['arduino', 'windows']:
if target_os not in ['arduino', 'msys_nt', 'windows']:
examples_env.AppendUnique(CFLAGS = Split('-Wall -std=c99 -Werror'))
examples_env.AppendUnique(CXXFLAGS = Split('-Wall -std=c++0x'))
examples_env.AppendUnique(LIBS = ['oc_logger'])
if target_os == 'android':
examples_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
examples_env.PrependUnique(LIBS = ['gnustl_shared'])
else:
examples_env.AppendUnique(LIBS = ['octbstack'])
######################################################################
# Source files and Targets
......@@ -56,4 +59,3 @@ examples_cpp = examples_env.Program('examples_cpp', 'test_logging.cpp')
Alias('liboc_logger_examples', [examples_c, examples_cpp])
examples_env.AppendTarget('liboc_logger_examples')
......@@ -58,7 +58,7 @@ if target_os in ['windows']:
unittests_env.PrependUnique(LIBS = [
'oc',
'octbstack_test',
'oc_logger',
'oc_logger_internal',
'connectivity_abstraction',
'coap',
'mbedcrypto'])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment