[FFmpeg-devel] Enhanced configure to improve compiler options associated with debugging with Visual C++ (MSVC)

Submitted by Aaron Levinson on April 15, 2017, 2:07 a.m.

Details

Message ID 96183910-16da-948c-499e-708fa156a8cc@aracnet.com
State New
Headers show

Commit Message

Aaron Levinson April 15, 2017, 2:07 a.m.
On 4/13/2017 5:03 PM, Aaron Levinson wrote:
> From 558b957eb85a669899750b2e150eba7cdee8dcd9 Mon Sep 17 00:00:00 2001
> From: Aaron Levinson <alevinsn@aracnet.com>
> Date: Thu, 13 Apr 2017 16:46:59 -0700
> Subject: [PATCH] Enhanced configure to improve compiler options associated with debugging with Visual C++ (MSVC) 
> 
> Purpose: Enhanced configure to improve compiler options
> associated with debugging with Visual C++ (MSVC)

Please disregard the earlier version of the patch.  I've included a new version below that eliminates -MTd from the command-line options, based on a discussion that I had on IRC with Hendrik Leppkes.

Thanks,
Aaron Levinson

---------------------------------------------------------------------------------------

From 4e78a20cf811d87f7a16715f3f9f3553a0d56ce3 Mon Sep 17 00:00:00 2001
From: Aaron Levinson <alevinsn@aracnet.com>
Date: Fri, 14 Apr 2017 18:59:46 -0700
Subject: [PATCH] Enhanced configure to improve compiler options associated
 with debugging with Visual C++ (MSVC)

Purpose: Enhanced configure to improve compiler options associated
with debugging with Visual C++ (MSVC)

Comments:

-- configure:
a) In msvc_common_flags() function, replaced the use of -Z7 with -Zi.
   Effectively, there was no point to using -Z7 anymore given than
   -debug is passed to the linker already (per the line "enabled debug
   && add_ldflags -debug" elsewhere in the file), which causes a .pdb
   to be generated anyway.  -Z7 causes Codeview debug info to be
   placed in .obj files, while -Zi causes debug info to be placed in
   .pdb files.  As a result of switching from -Z7 to -Zi, this may
   result in slightly faster builds with MSVC, since it is apparently
   slower to process Codeview debug info.
b) In probe_cc() function, added _cflags_noopt declaration for MSVC.
   This is set to the following: "-Od -Og".  See comments for more
   details.  This is exposed when --disable-optimizations is used with
   configure.  In addition, now adding -Zo (or -d2Zi+, depending on
   the compiler version) to all the different _cflags_ variables to
   make it easier to debug optimized builds.  See changes and comments
   for further details.
---
 configure | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/configure b/configure
index 1703111..c2d8b48 100755
--- a/configure
+++ b/configure
@@ -3844,7 +3844,7 @@  msvc_common_flags(){
             -std=c99)             ;;
             # Common flags
             -fomit-frame-pointer) ;;
-            -g)                   echo -Z7 ;;
+            -g)                   echo -Zi ;;
             -fno-math-errno)      ;;
             -fno-common)          ;;
             -fno-signed-zeros)    ;;
@@ -4153,6 +4153,33 @@  probe_cc(){
         _DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -showIncludes -Zs'
         _cflags_speed="-O2"
         _cflags_size="-O1"
+        # Need to use -Og with -Od because otherwise has link issues with
+        # "if (ARCH_...)" code.  Unfortunately, this isn't quite the same as
+        # a fully debug build.  If the Dead Code Elimination (DCE) compiler
+        # optimization requirement is ever removed, this can be replaced
+        # with just -Od.  Note that the use of -Og results in a compiler
+        # deprecation warning.
+        _cflags_noopt="-Od -Og"
+        cl_major_ver=$(cl 2>&1 | sed -n 's/.*Version \([[:digit:]]\{1,\}\)\..*/\1/p')
+
+        # Make it easier to debug release builds.
+        # See https://msdn.microsoft.com/en-us/library/dn785163.aspx for more
+        # details.
+        # It may not be necessary to add -Zo to _cflags_noopt due to the use
+        # of -Od, but because -Og is also added currently, it is best to
+        # add -Zo for now to make sure the best debugging experience is
+        # possible.  If the DCE compiler optimization requirement is ever
+        # removed, the _cflags_noopt lines can be removed.
+        if [ -z "$cl_major_ver" ] || [ $cl_major_ver -ge 18 ]; then
+            _cflags_speed="${_cflags_speed} -Zo"
+            _cflags_size="${_cflags_size} -Zo"
+            _cflags_noopt="${_cflags_noopt} -Zo"
+        else
+            _cflags_speed="${_cflags_speed} -d2Zi+"
+            _cflags_size="${_cflags_size} -d2Zi+"
+            _cflags_noopt="${_cflags_noopt} -d2Zi+"
+        fi
+
         if $_cc -nologo- 2>&1 | grep -q Linker; then
             _ld_o='-out:$@'
         else