[IOT-2234] Fix libcoap configure for Windows UWP 67/26067/4
authorMats Wichmann <mats@linux.com>
Sat, 30 Jun 2018 23:41:33 +0000 (17:41 -0600)
committerMats Wichmann <mats@linux.com>
Thu, 12 Jul 2018 13:23:52 +0000 (13:23 +0000)
The libcoap sconscript has a special case for Windows UWP because it
did not configure right. The problem is the list of libraries set by the
Windows build_common script is cleared before running the configure test,
and that is not the right answer for UWP, which needs one particular
library in order to access the standard Windows library functions.
Rather than building the exact knowledge into this script, the required
list is saved in the Windows build script, and retrieved here for use
for the UWP platform.

Bugs: https://jira.iotivity.org/browse/IOT-2234
Change-Id: I70016d81c5d51c7454b1794280e12f5574a5fd41
Signed-off-by: Mats Wichmann <mats@linux.com>
build_common/windows/SConscript [changed mode: 0644->0755]
extlibs/libcoap/SConscript [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index f023e86..0af75d6
@@ -251,6 +251,8 @@ if env['CC'] == 'cl':
         env.AppendUnique(CPPDEFINES=['UWP_APP', '__WRL_NO_DEFAULT_LIB__'])
         env.AppendUnique(LINKFLAGS=['/MANIFEST:NO', '/WINMD:NO', '/APPCONTAINER'])
         env.AppendUnique(LIBS=['WindowsApp', 'bcrypt', 'ws2_32', 'iphlpapi', 'crypt32'])
+        # save the required lib for config tests where LIBS is cleared first
+        env.AppendUnique(UWP_LIBS=['WindowsApp'])
 
 elif env['CC'] == 'gcc':
     msg = "\nError: gcc not supported on Windows.  Use Visual Studio!\n"
old mode 100644 (file)
new mode 100755 (executable)
index dcd3036..bed92e5
@@ -182,7 +182,10 @@ else:
     lib_prefix = '' + str(libcoap_env.get('LIBPREFIX'))
 
     if not os.path.isfile(config_h_file) and env.GetOption not in ('clean', 'help'):
-        conf = Configure(libcoap_env.Clone(LIBS=[]))
+        if ((target_os == 'windows') and (libcoap_env.get('MSVC_UWP_APP') == '1')):
+            conf = Configure(libcoap_env.Clone(LIBS=libcoap_env.get('UWP_LIBS')))
+        else:
+            conf = Configure(libcoap_env.Clone(LIBS=[]))
 
         config_h_header = '''
 /* ****************************************************************************
@@ -223,85 +226,54 @@ else:
 
         config_h_body = ''
 
-        if ((target_os == 'windows') and (libcoap_env.get('MSVC_UWP_APP') == '1')):
-            # Workaround for libcoap config [Investigation in IOT-2234]:
-            # libcoap builds its config file by trying to create a small program to see if an API is
-            # available. However, when building with store libraries on windows, it doesn't seem
-            # to find malloc or strnlen APIs. On Windows, those APIs are guaranteed to be there,
-            # therefore, create the libcoap config_h_body with what is needed and expected to be
-            # there.
-            config_h_body = '''
-#define HAVE_ASSERT_H 1
-
-#define HAVE_LIMITS_H 1
-
-#define HAVE_STDIO_H 1
-
-#define HAVE_SYS_TYPES_H 1
-
-#define HAVE_TIME_H 1
-
-#define HAVE_WINSOCK2_H 1
-
-#define HAVE_WS2TCPIP_H 1
-
-#define HAVE_MALLOC 1
-
-#define HAVE_STRNLEN 1
-
-#define ssize_t SSIZE_T
-
-#define in_port_t uint16_t
-'''
-        else:
-            cxx_headers = [
-                'arpa/inet.h',
-                'assert.h',
-                'limits.h',
-                'netinet/in.h',
-                'stdio.h',
-                'strings.h',
-                'sys/select.h',
-                'sys/socket.h',
-                'sys/time.h',
-                'sys/types.h',
-                'sys/uio.h',
-                'sys/unistd.h',
-                'syslog.h',
-                'time.h',
-                'unistd.h',
-                'winsock2.h',
-                'ws2tcpip.h'
-            ]
-
-            cxx_functions = [
-                'malloc',
-                'snprintf',
-                'strnlen',
-                'vprintf',
-                'fls',
-                'flsll',
-            ]
-
-            def get_define_from_string(string_):
-                string_converted = string_.replace("/", "_").replace(".", "_").upper()
-                return "HAVE_" + string_converted
-
-            for header_file_name in cxx_headers:
-                if conf.CheckCXXHeader(header_file_name):
-                    config_h_body += "#define %s 1\n\n" % get_define_from_string(
-                        header_file_name)
-
-            for function_name in cxx_functions:
-                if conf.CheckFunc(function_name):
-                    config_h_body += "#define %s 1\n\n" % get_define_from_string(
-                        function_name)
-
-            if conf.CheckCXXHeader('windows.h'):
-                config_h_body += "#define ssize_t SSIZE_T\n\n"
-                config_h_body += "#define in_port_t uint16_t\n\n"
-
-            conf.Finish()
+        cxx_headers = [
+            'arpa/inet.h',
+            'assert.h',
+            'limits.h',
+            'netinet/in.h',
+            'stdio.h',
+            'strings.h',
+            'sys/select.h',
+            'sys/socket.h',
+            'sys/time.h',
+            'sys/types.h',
+            'sys/uio.h',
+            'sys/unistd.h',
+            'syslog.h',
+            'time.h',
+            'unistd.h',
+            'winsock2.h',
+            'ws2tcpip.h'
+        ]
+
+        cxx_functions = [
+            'malloc',
+            'snprintf',
+            'strnlen',
+            'vprintf',
+            'fls',
+            'flsll',
+        ]
+
+        def get_define_from_string(string_):
+            string_converted = string_.replace("/", "_").replace(".", "_").upper()
+            return "HAVE_" + string_converted
+
+        for header_file_name in cxx_headers:
+            if conf.CheckCXXHeader(header_file_name):
+                config_h_body += "#define %s 1\n\n" % get_define_from_string(
+                    header_file_name)
+
+        for function_name in cxx_functions:
+            if conf.CheckFunc(function_name):
+                config_h_body += "#define %s 1\n\n" % get_define_from_string(
+                    function_name)
+
+        if conf.CheckCXXHeader('windows.h'):
+            config_h_body += "#define ssize_t SSIZE_T\n\n"
+            config_h_body += "#define in_port_t uint16_t\n\n"
+
+        conf.Finish()
 
         with open(config_h_file, "w") as configfile:
             configfile.write(config_h_header + config_h_body + config_h_footer)