[08/10] configure: Only add -FIstdlib.h for msvc/icl if necessary

Message ID 1437904678-19444-8-git-send-email-martin@martin.st
State Committed
Commit 0cff125200ab53fa3ae70d85b4f614f269fe3426
Headers show

Commit Message

Martin Storsjö July 26, 2015, 9:57 a.m.
This is only necessary on MSVC 2010/2012 (and possibly on some
ICL versions). This both avoids an extra hack on newer MSVC
versions, and better documents what the extra compiler option
is used for.
---
 configure | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Luca Barbato July 26, 2015, 10:20 a.m. | #1
On 26/07/15 11:57, Martin Storsjö wrote:
> This is only necessary on MSVC 2010/2012 (and possibly on some
> ICL versions). This both avoids an extra hack on newer MSVC
> versions, and better documents what the extra compiler option
> is used for.
> ---
>   configure | 15 +++++++++++++--
>   1 file changed, 13 insertions(+), 2 deletions(-)
>

Probably Fine.

lu
Jean-Baptiste Kempf July 26, 2015, 11:02 a.m. | #2
On 26 Jul, Martin Storsjö wrote :
> This is only necessary on MSVC 2010/2012 (and possibly on some
> ICL versions). This both avoids an extra hack on newer MSVC
> versions, and better documents what the extra compiler option
> is used for.

LGTM.
With my kindest regards,
Steve Lhomme July 26, 2015, 2:58 p.m. | #3
On Sun, Jul 26, 2015 at 11:57 AM, Martin Storsjö <martin@martin.st> wrote:
> This is only necessary on MSVC 2010/2012 (and possibly on some
> ICL versions). This both avoids an extra hack on newer MSVC
> versions, and better documents what the extra compiler option
> is used for.

Good thing because setting the WINAPI_FAMILY from the command line was
setting it after including stdlib.h and thus likely including a lot of
windows stuff that are not available on WP/WinRT.

Forced includes are evil.

> ---
>  configure | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index 814dfbd..b67c4b5 100755
> --- a/configure
> +++ b/configure
> @@ -3062,7 +3062,7 @@ probe_cc(){
>          _ld_lib='lib%.a'
>          _ld_path='-libpath:'
>          _flags='-nologo'
> -        _cflags='-D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -Dinline=__inline -FIstdlib.h -Dstrtoll=_strtoi64'
> +        _cflags='-D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -Dinline=__inline -Dstrtoll=_strtoi64'
>      elif $_cc 2>&1 | grep -q Intel; then
>          _type=icl
>          _ident=$($_cc 2>&1 | head -n1)
> @@ -3085,7 +3085,7 @@ probe_cc(){
>          _flags='-nologo -Qdiag-error:4044,10157'
>          # -Qvec- -Qsimd- to prevent miscompilation, -GS for consistency
>          # with MSVC which enables it by default.
> -        _cflags='-D_USE_MATH_DEFINES -FIstdlib.h -Dstrtoll=_strtoi64 -Qms0 -Qvec- -Qsimd- -GS'
> +        _cflags='-D_USE_MATH_DEFINES -Dstrtoll=_strtoi64 -Qms0 -Qvec- -Qsimd- -GS'
>      elif $_cc --version 2>/dev/null | grep -q ^cparser; then
>          _type=cparser
>          _ident=$($_cc --version | head -n1)
> @@ -4734,6 +4734,17 @@ elif enabled_any msvc icl; then
>      fi
>      # msvcrt10 x64 incorrectly enables log2, only msvcrt12 (MSVC 2013) onwards actually has log2.
>      check_cpp_condition crtversion.h "_VC_CRT_MAJOR_VERSION >= 12" || disable log2
> +    # The CRT headers contain __declspec(restrict) in a few places, but if redefining
> +    # restrict, this might break. MSVC 2010 and 2012 fail with __declspec(__restrict)
> +    # (as it ends up if the restrict redefine is done before including stdlib.h), while
> +    # MSVC 2013 and newer can handle it fine.
> +    # If this declspec fails, force including stdlib.h before the restrict redefinition
> +    # happens in config.h.
> +    if [ $_restrict != restrict ]; then
> +        check_cc <<EOF || add_cflags -FIstdlib.h
> +__declspec($_restrict) void* foo(int);
> +EOF
> +    fi
>  fi
>
>  case $as_type in
> --
> 1.8.1.2
>
> _______________________________________________
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel
Martin Storsjö July 26, 2015, 4:54 p.m. | #4
On Sun, 26 Jul 2015, Steve Lhomme wrote:

> On Sun, Jul 26, 2015 at 11:57 AM, Martin Storsjö <martin@martin.st> wrote:
>> This is only necessary on MSVC 2010/2012 (and possibly on some
>> ICL versions). This both avoids an extra hack on newer MSVC
>> versions, and better documents what the extra compiler option
>> is used for.
>
> Good thing because setting the WINAPI_FAMILY from the command line was
> setting it after including stdlib.h and thus likely including a lot of
> windows stuff that are not available on WP/WinRT.

Oh, good catch - I hadn't thought about that either, so that's yet another 
reason why this is a good idea to finally get rid of.

// Martin

Patch

diff --git a/configure b/configure
index 814dfbd..b67c4b5 100755
--- a/configure
+++ b/configure
@@ -3062,7 +3062,7 @@  probe_cc(){
         _ld_lib='lib%.a'
         _ld_path='-libpath:'
         _flags='-nologo'
-        _cflags='-D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -Dinline=__inline -FIstdlib.h -Dstrtoll=_strtoi64'
+        _cflags='-D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -Dinline=__inline -Dstrtoll=_strtoi64'
     elif $_cc 2>&1 | grep -q Intel; then
         _type=icl
         _ident=$($_cc 2>&1 | head -n1)
@@ -3085,7 +3085,7 @@  probe_cc(){
         _flags='-nologo -Qdiag-error:4044,10157'
         # -Qvec- -Qsimd- to prevent miscompilation, -GS for consistency
         # with MSVC which enables it by default.
-        _cflags='-D_USE_MATH_DEFINES -FIstdlib.h -Dstrtoll=_strtoi64 -Qms0 -Qvec- -Qsimd- -GS'
+        _cflags='-D_USE_MATH_DEFINES -Dstrtoll=_strtoi64 -Qms0 -Qvec- -Qsimd- -GS'
     elif $_cc --version 2>/dev/null | grep -q ^cparser; then
         _type=cparser
         _ident=$($_cc --version | head -n1)
@@ -4734,6 +4734,17 @@  elif enabled_any msvc icl; then
     fi
     # msvcrt10 x64 incorrectly enables log2, only msvcrt12 (MSVC 2013) onwards actually has log2.
     check_cpp_condition crtversion.h "_VC_CRT_MAJOR_VERSION >= 12" || disable log2
+    # The CRT headers contain __declspec(restrict) in a few places, but if redefining
+    # restrict, this might break. MSVC 2010 and 2012 fail with __declspec(__restrict)
+    # (as it ends up if the restrict redefine is done before including stdlib.h), while
+    # MSVC 2013 and newer can handle it fine.
+    # If this declspec fails, force including stdlib.h before the restrict redefinition
+    # happens in config.h.
+    if [ $_restrict != restrict ]; then
+        check_cc <<EOF || add_cflags -FIstdlib.h
+__declspec($_restrict) void* foo(int);
+EOF
+    fi
 fi
 
 case $as_type in