From a400e4fe6174f726658a437065dd2b1d933e5d41 Mon Sep 17 00:00:00 2001 From: Dan Mihai Date: Mon, 13 Feb 2017 17:00:50 -0800 Subject: [PATCH] [IOT-1816] Windows: Fix build breaks 1. Most likely the ocrandom compiler error was hiding the RD linker errors. 2. Support both RD Client and Server functionality with octbstack.dll 3. Avoid building sqlite3.obj with several different compiler options, by building it a single time and packaging it in sqlite3.lib Change-Id: I8b9fe95f97d88a28a8b6bb48fd9932f51a65ecdb Signed-off-by: Dan Mihai Reviewed-on: https://gerrit.iotivity.org/gerrit/17253 Tested-by: jenkins-iotivity Reviewed-by: Kevin Kane --- extlibs/sqlite3/SConscript | 7 +++++++ resource/c_common/ocrandom/src/ocrandom.c | 4 ++-- resource/csdk/resource-directory/SConscript | 2 +- resource/csdk/security/provisioning/SConscript | 3 ++- resource/csdk/security/provisioning/sample/SConscript | 5 +++++ resource/csdk/security/provisioning/unittest/SConscript | 2 +- resource/csdk/security/tool/SConscript | 3 ++- resource/csdk/security/unittest/SConscript | 3 +-- resource/csdk/stack/SConscript | 8 +++++++- resource/csdk/stack/test/SConscript | 2 ++ resource/unittests/SConscript | 1 + run.bat | 3 ++- 12 files changed, 33 insertions(+), 10 deletions(-) diff --git a/extlibs/sqlite3/SConscript b/extlibs/sqlite3/SConscript index 6fa46b5..8c563a6 100755 --- a/extlibs/sqlite3/SConscript +++ b/extlibs/sqlite3/SConscript @@ -38,3 +38,10 @@ if target_os in targets_need_sqlite: os.rename(sqlite_h_tmp, sqlite_h) os.remove(sqlite_zip_file) shutil.rmtree(sqlite_tmp_dir) + +if target_os in ['windows']: + libsqlite3 = sqlite_env.StaticLibrary('sqlite3', sqlite_c) + # In multi-threaded builds, SCons appears to proceed to using sqlite3.lib + # before finishing InstallTarget(libsqlite3, 'sqlite3') here. So, use the + # generated LIB directly, without installing it. + env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'extlibs/sqlite3')]) diff --git a/resource/c_common/ocrandom/src/ocrandom.c b/resource/c_common/ocrandom/src/ocrandom.c index 2038520..fb9e4d1 100644 --- a/resource/c_common/ocrandom/src/ocrandom.c +++ b/resource/c_common/ocrandom/src/ocrandom.c @@ -374,10 +374,10 @@ bool OCIsUUID(const char *uuid) char var = uuid[i]; //Check if a hyphen is expected here. - if (i = hyphens[counter] -1) + if (i == (hyphens[counter] - 1)) { //We need a hyphen here. - if('-' != var) + if ('-' != var) { //The character is not a hyphen. return false; diff --git a/resource/csdk/resource-directory/SConscript b/resource/csdk/resource-directory/SConscript index d66a9b2..7d7b167 100755 --- a/resource/csdk/resource-directory/SConscript +++ b/resource/csdk/resource-directory/SConscript @@ -83,7 +83,7 @@ if 'SERVER' in rd_mode: RD_SRC_DIR + 'internal/rd_database.c', RD_SRC_DIR + 'rd_server.c', ] - if target_os not in ['linux', 'tizen'] : + if target_os not in ['linux', 'tizen', 'windows'] : rd_src += [ '../../../extlibs/sqlite3/sqlite3.c' ] if 'CLIENT' in rd_mode: diff --git a/resource/csdk/security/provisioning/SConscript b/resource/csdk/security/provisioning/SConscript index 09f911f..ef2f5f4 100644 --- a/resource/csdk/security/provisioning/SConscript +++ b/resource/csdk/security/provisioning/SConscript @@ -105,7 +105,8 @@ if target_os in ['linux', 'tizen']: provisioning_env.ParseConfig('pkg-config --cflags --libs sqlite3') else: provisioning_env.AppendUnique(CPPPATH = ['#/extlibs/sqlite3']) - provisioning_src = provisioning_src + ['#/extlibs/sqlite3/sqlite3.c' ] + if target_os not in ['windows']: + provisioning_src = provisioning_src + ['#/extlibs/sqlite3/sqlite3.c' ] if target_os in ['android']: provisioning_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,libocpmapi.so']) diff --git a/resource/csdk/security/provisioning/sample/SConscript b/resource/csdk/security/provisioning/sample/SConscript index e9b0e08..b1d1bb4 100644 --- a/resource/csdk/security/provisioning/sample/SConscript +++ b/resource/csdk/security/provisioning/sample/SConscript @@ -67,8 +67,13 @@ provisioning_sample_env.AppendUnique(CPPDEFINES = ['TB_LOG']) if target_os == 'tizen': provisioning_sample_env.AppendUnique(CPPDEFINES = ['__TIZEN__']) + if target_os in ['linux', 'tizen']: provisioning_sample_env.ParseConfig('pkg-config --cflags --libs sqlite3') +else: + if target_os in ['windows']: + provisioning_sample_env.AppendUnique(LIBS = ['sqlite3']) + ###################################################################### # Source files and Targets diff --git a/resource/csdk/security/provisioning/unittest/SConscript b/resource/csdk/security/provisioning/unittest/SConscript index ac6aa2c..659aba4 100644 --- a/resource/csdk/security/provisioning/unittest/SConscript +++ b/resource/csdk/security/provisioning/unittest/SConscript @@ -82,7 +82,7 @@ if sptest_env.get('MULTIPLE_OWNER') == '1': sptest_env.AppendUnique(CPPDEFINES=['MULTIPLE_OWNER']) if target_os in ['msys_nt', 'windows']: - sptest_env.AppendUnique(LIBS = ['octbstack_static']) + sptest_env.AppendUnique(LIBS = ['octbstack_static', 'sqlite3']) else: sptest_env.AppendUnique(LIBS = ['octbstack']) diff --git a/resource/csdk/security/tool/SConscript b/resource/csdk/security/tool/SConscript index 501ab14..fdc5d69 100644 --- a/resource/csdk/security/tool/SConscript +++ b/resource/csdk/security/tool/SConscript @@ -19,6 +19,7 @@ # //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # Import('libocsrm_env') +import os tools_env = libocsrm_env.Clone() src_dir = tools_env.get('SRC_DIR') @@ -55,7 +56,7 @@ SConscript('#/extlibs/cjson/SConscript') if target_os in ['msys_nt', 'windows']: # octbstack.dll doesn't export all the functions called by this app, so use static LIBs instead. tools_env.AppendUnique(LIBS = ['coap', 'tinydtls', 'mbedtls', 'mbedx509', 'mbedcrypto', - 'octbstack_static', 'ocsrm', 'connectivity_abstraction']) + 'octbstack_static', 'ocsrm', 'connectivity_abstraction', 'sqlite3']) elif target_os in ['darwin']: tools_env.AppendUnique(LIBS = ['coap', 'tinydtls', 'mbedtls', 'mbedx509', 'mbedcrypto', 'octbstack', 'ocsrm', 'connectivity_abstraction']) diff --git a/resource/csdk/security/unittest/SConscript b/resource/csdk/security/unittest/SConscript index fa2cf4a..e9d50c3 100644 --- a/resource/csdk/security/unittest/SConscript +++ b/resource/csdk/security/unittest/SConscript @@ -75,8 +75,7 @@ if srmtest_env.get('MULTIPLE_OWNER') == '1': srmtest_env.AppendUnique(CPPDEFINES=['MULTIPLE_OWNER']) if target_os == 'windows': - srmtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE']) - srmtest_env.AppendUnique(LIBS = ['octbstack_static']) + srmtest_env.AppendUnique(LIBS = ['octbstack_static', 'sqlite3']) else: # TODO: Implement feature check. srmtest_env.AppendUnique(CPPDEFINES = ['HAVE_LOCALTIME_R']) diff --git a/resource/csdk/stack/SConscript b/resource/csdk/stack/SConscript index 7ea0e3d..e9a9b24 100644 --- a/resource/csdk/stack/SConscript +++ b/resource/csdk/stack/SConscript @@ -22,6 +22,7 @@ # liboctbstack (share library) build script ## Import('env') +import os liboctbstack_env = env.Clone() @@ -158,8 +159,13 @@ if liboctbstack_env.get('ROUTING') in ['GW', 'EP']: if 'CLIENT' in rd_mode or 'SERVER' in rd_mode: liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/resource-directory/include']) + + if target_os in ['windows']: + liboctbstack_env.AppendUnique(LIBS = ['sqlite3']) + if 'CLIENT' in rd_mode: liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_CLIENT']) + if 'SERVER' in rd_mode: liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_SERVER']) if target_os in ['tizen']: @@ -192,7 +198,7 @@ if with_tcp == True: if 'SERVER' in rd_mode: liboctbstack_src.append(OCTBSTACK_SRC + 'oicresourcedirectory.c') - if target_os not in ['linux', 'tizen']: + if target_os not in ['linux', 'tizen', 'windows']: liboctbstack_src.append('#extlibs/sqlite3/sqlite3.c') if target_os in ['linux']: diff --git a/resource/csdk/stack/test/SConscript b/resource/csdk/stack/test/SConscript index ed3d2e6..8ccaaba 100644 --- a/resource/csdk/stack/test/SConscript +++ b/resource/csdk/stack/test/SConscript @@ -62,6 +62,8 @@ if stacktest_env.get('LOGGING'): if target_os not in ['msys_nt', 'windows']: stacktest_env.PrependUnique(LIBS = ['m']) +else: + stacktest_env.PrependUnique(LIBS = ['sqlite3']) if 'CLIENT' in rd_mode or 'SERVER' in rd_mode: stacktest_env.PrependUnique(LIBS = ['resource_directory']) diff --git a/resource/unittests/SConscript b/resource/unittests/SConscript index e6d27be..44202b8 100644 --- a/resource/unittests/SConscript +++ b/resource/unittests/SConscript @@ -51,6 +51,7 @@ unittests_env.PrependUnique(CPPPATH = [ if target_os in ['windows']: unittests_env.AppendUnique(CPPPATH = ['#extlibs/boost/boost']) + unittests_env.AppendUnique(LIBS = ['sqlite3']) # On Windows, octbstack_test is a static LIB, that makes calls into static LIB ocsrm. # On other platforms, octbstack_test is a shared LIB, that includes static LIB ocsrm. unittests_env.AppendUnique(LIBS = ['ocsrm']) diff --git a/run.bat b/run.bat index cee534b..5a933c3 100644 --- a/run.bat +++ b/run.bat @@ -49,6 +49,7 @@ set THREAD_COUNT=%NUMBER_OF_PROCESSORS% set ROUTING=EP set WITH_UPSTREAM_LIBCOAP=1 set BINDIR=debug +set RD_MODE=CLIENT,SERVER set RUN_ARG=%1 SHIFT @@ -104,7 +105,7 @@ IF "%BUILD_MSYS%" == "" ( set PATH=!PATH!;!BUILD_DIR!;C:\msys64\mingw64\bin ) -set BUILD_OPTIONS= TARGET_OS=%TARGET_OS% TARGET_ARCH=%TARGET_ARCH% RELEASE=%RELEASE% WITH_RA=0 TARGET_TRANSPORT=IP SECURED=%SECURED% WITH_TCP=%WITH_TCP% BUILD_SAMPLE=ON LOGGING=%LOGGING% TEST=%TEST% RD_MODE=CLIENT ROUTING=%ROUTING% WITH_UPSTREAM_LIBCOAP=%WITH_UPSTREAM_LIBCOAP% MULTIPLE_OWNER=%MULTIPLE_OWNER% -j %THREAD_COUNT% +set BUILD_OPTIONS= TARGET_OS=%TARGET_OS% TARGET_ARCH=%TARGET_ARCH% RELEASE=%RELEASE% WITH_RA=0 TARGET_TRANSPORT=IP SECURED=%SECURED% WITH_TCP=%WITH_TCP% BUILD_SAMPLE=ON LOGGING=%LOGGING% TEST=%TEST% RD_MODE=%RD_MODE% ROUTING=%ROUTING% WITH_UPSTREAM_LIBCOAP=%WITH_UPSTREAM_LIBCOAP% MULTIPLE_OWNER=%MULTIPLE_OWNER% -j %THREAD_COUNT% REM Use MSVC_VERSION=12.0 for VS2013, or MSVC_VERSION=14.0 for VS2015. REM If MSVC_VERSION has not been defined here, SCons chooses automatically a VS version. -- 2.7.4