[06/10] configure: Automatically add -MD when targeting the windows phone/app subsets

Message ID 1437904678-19444-6-git-send-email-martin@martin.st
State New
Headers show

Commit Message

Martin Storsjö July 26, 2015, 9:57 a.m.
The static CRT (libcmt.lib, as used by default or with -MT) doesn't
work when targeting these API subsets.

Only do this if no cflags for CRT selection have been specified,
to allow users to override this default if the user knows better.
---
 configure | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Jean-Baptiste Kempf July 26, 2015, 11:01 a.m. | #1
On 26 Jul, Martin Storsjö wrote :
> The static CRT (libcmt.lib, as used by default or with -MT) doesn't
> work when targeting these API subsets.
> 
> Only do this if no cflags for CRT selection have been specified,
> to allow users to override this default if the user knows better.

Isn't that dangerous, licenses-wise?

With my kindest regards,
Martin Storsjö July 26, 2015, 11:14 a.m. | #2
On Sun, 26 Jul 2015, Jean-Baptiste Kempf wrote:

> On 26 Jul, Martin Storsjö wrote :
>> The static CRT (libcmt.lib, as used by default or with -MT) doesn't
>> work when targeting these API subsets.
>>
>> Only do this if no cflags for CRT selection have been specified,
>> to allow users to override this default if the user knows better.
>
> Isn't that dangerous, licenses-wise?

I'm not sure, can you clarify which way you mean?

In the cases where this is supposed to happen at all, you can't 
successfully link a binary at all unless you add -MD. (For winphone SDKs, 
there's either no libcmt.lib at all, or you can't really link anything 
with it.)

I could change this so that it only is added if -M[TD]* is missing, and if 
linking actually fails. For WinRT, linking would probably succeed 
(although you can't really ship code built that way) with -MT though, so 
you'd manually need to enforce -MD anyway - I think?

// Martin
Martin Storsjö July 28, 2015, 4:37 p.m. | #3
On Sun, 26 Jul 2015, Martin Storsjö wrote:

> On Sun, 26 Jul 2015, Jean-Baptiste Kempf wrote:
>
>> On 26 Jul, Martin Storsjö wrote :
>>> The static CRT (libcmt.lib, as used by default or with -MT) doesn't
>>> work when targeting these API subsets.
>>> 
>>> Only do this if no cflags for CRT selection have been specified,
>>> to allow users to override this default if the user knows better.
>> 
>> Isn't that dangerous, licenses-wise?
>
> I'm not sure, can you clarify which way you mean?
>
> In the cases where this is supposed to happen at all, you can't successfully 
> link a binary at all unless you add -MD. (For winphone SDKs, there's either 
> no libcmt.lib at all, or you can't really link anything with it.)

To add on this; I guess the license concern is that msvcr*.dll aren't 
technically a part of the OS (i.e. shipped along with the app) and thus 
normally avoided when shipping e.g. GPL apps. For the winrt/winphone 
targets, you don't ship msvcr*.dll with your app but they are considered a 
system component, and this is the only case where we'd be auto-enabling 
-MD, so I don't think it's an issue here.

// Martin

Patch

diff --git a/configure b/configure
index 77eb8f5..541d6ce 100755
--- a/configure
+++ b/configure
@@ -3460,6 +3460,29 @@  if [ "$cpu" != generic ]; then
     add_asflags $cpuflags
 fi
 
+# Set the right default MSVC CRT if necessary
+if enabled_any msvc icl && check_cpp_condition stdlib.h "defined(WINAPI_FAMILY)"; then
+    if check_cpp <<EOF
+#include <winapifamily.h>
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#error desktop
+#endif
+EOF
+    then
+        for flag in $CFLAGS; do
+            case $flag in
+            -M[TD]*)
+                crtflag=$flag
+                ;;
+            esac
+        done
+        # If targeting the app/phone subsets, add -MD by default if no -MD/-MT flags have been specified
+        if [ -z "$crtflag" ]; then
+            add_cflags -MD
+        fi
+    fi
+fi
+
 # compiler sanity check
 check_exec <<EOF
 int main(void){ return 0; }