Compiling ScummVM/Visual Studio/Compiling Libraries

From ScummVM :: Wiki
< Compiling ScummVM‎ | Visual Studio
Revision as of 18:47, 3 January 2015 by Md5 (talk | contribs) (→‎libmpeg2: Remove a define instead of changing the libmpeg2 code)
Jump to navigation Jump to search

Instructions for compiling the needed libraries for Visual Studio yourself

Libraries needed

  • SDL 1.2, file SDL-devel-1.2.XX-VC8.zip (where XX is the current release number)

Latest stable version at the time of writing this: 1.2.14

Latest stable version at the time of writing this: 2.09.10

Note that the libraries included in the "vorbis" package won't work. You need libogg and libvorbis, not vorbis. Latest stable versions at the time of writing this: 1.3.0 and 1.3.2.

Latest stable version at the time of writing this: 0.15.1b

Latest stable version at the time of writing this: 1.2.1

You need the latest zlib source code. If you wish to compile ScummVM 0.8.0 or earlier with zlib support, you'll also need crtdll.lib. Latest stable version at the time of writing this: 1.2.5

You need the latest libpng source code. Latest Windows stable version at the time of writing this: 1.5.5

You need the latest libfaad source code.

You need the latest libmpeg2 source code from the downloads section.

Building the libraries

Now, we need to compile the required libraries.

Note that you'll need to build all libraries with the same configuration settings (debug or release). If you don't need a specific library, you can remove it from your build by going to Project->Properties, Configuration Properties->C/C++->Preprocessor and remove the "USE_XXX" directive for that library from there. For example, to remove OGG support, remove the USE_VORBIS directive.

Also, make sure to disable the inclusion of default libraries in all libraries. You can do this from the project properties->Librarian->General and setting "Ignore all default libraries" to "Yes (/NODEFAULTLIB)" (special thanks to nolange for this tip). Finally, make sure that optimization is set to "Maximize speed" (or anything other than "Full optimization"), otherwise it will be impossible to build incremental debug builds later on (you'll get a warning saying "ignoring '/INCREMENTAL' due to '/LTCG' specification"). You can do this from the project properties->C/C++->Optimization, and set "Optimization" to "Maximize Speed (/O2)"


A note about VS2008

If you're building the libraries with VS2008, you will get a lot of deprecation warnings. These are normal and nothing to worry about, they're just Microsoft's way of saying "This is a bad code practice. Use this instead". It's not easy to turn these off without several modifications to the code, so just ignore them.

Read more here:

http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/

http://www.gamedev.net/community/forums/topic.asp?topic_id=361433

http://blogs.msdn.com/oldnewthing/archive/2005/01/07/348437.aspx

If you do wish to make them disappear, you need to include on top the main function of each library, before the includes, the following lines:

 #if (_MSC_VER >= 1400) /* VC8+ (VS2005) */
 #pragma warning(disable : 4996) /* Disable all deprecation warnings */ 
 #endif /* VC8+ (VS2005) */


NASM

First of all, we need nasm. So unzip the nasm archive in a directory, copy "nasmw.exe" to "nasm.exe" (because some projects call one and others call the other) and include it in the executable path of VS. To do this, go to Tools->Options->Projects and solutions->VC++ directories. Select "Executable files" from the top right and include the directory where you unzipped nasm into.


SDL

SDL is already compiled and needs no further changes, so we can skip the compilation step for it.

Note for x64: You will need to compile SDL for x64 on your own (as of the time of this writing), to do so you will also need to install the DirectX SDK found here. You will also need to apply the following patch (gladly taken from the SDL mailing list):

--- src/video/windx5/SDL_dx5video.c	Tue Oct 13 00:07:16 2009
+++ src/video/windx5/SDL_dx5video.c	Tue Nov 03 21:14:38 2009
@@ -332,7 +332,7 @@
 	{ &GUID_Key, 255, 0x8000FF0C, 0x00000000 },
 };
 
-const DIDATAFORMAT c_dfDIKeyboard = { sizeof(DIDATAFORMAT), sizeof(DIOBJECTDATAFORMAT), 0x00000002, 256, 256, KBD_fmt };
+const DIDATAFORMAT c_dfDIKeyboard = { sizeof(DIDATAFORMAT), sizeof(DIOBJECTDATAFORMAT), DIDF_RELAXIS, 256, sizeof(KBD_fmt)/sizeof(KBD_fmt[0]), KBD_fmt };
 
 
 /* Mouse */
@@ -347,7 +347,7 @@
 	{ NULL,       15, 0x80FFFF0C, 0x00000000 },
 };
 
-const DIDATAFORMAT c_dfDIMouse = { sizeof(DIDATAFORMAT), sizeof(DIOBJECTDATAFORMAT), 0x00000002, 16, 7, PTR_fmt };
+const DIDATAFORMAT c_dfDIMouse = { sizeof(DIDATAFORMAT), sizeof(DIOBJECTDATAFORMAT), DIDF_RELAXIS, sizeof(DIMOUSESTATE), sizeof(PTR_fmt)/sizeof(PTR_fmt[0]), PTR_fmt };
 
 static DIOBJECTDATAFORMAT PTR2_fmt[] = {
 	{ &GUID_XAxis, 0, 0x00FFFF03, 0x00000000 },
@@ -363,7 +363,7 @@
 	{ NULL,       19, 0x80FFFF0C, 0x00000000 }
 };
 
-const DIDATAFORMAT c_dfDIMouse2 = { sizeof(DIDATAFORMAT), sizeof(DIOBJECTDATAFORMAT), 0x00000002, 20, 11, PTR2_fmt };
+const DIDATAFORMAT c_dfDIMouse2 = { sizeof(DIDATAFORMAT), sizeof(DIOBJECTDATAFORMAT), DIDF_RELAXIS, sizeof(DIMOUSESTATE), sizeof(PTR2_fmt)/sizeof(PTR2_fmt[0]), PTR2_fmt };
 
 
 /* Joystick */
@@ -415,7 +415,7 @@
 	{ NULL, 79, 0x80FFFF0C, 0x00000000 },
 };
 
-const DIDATAFORMAT c_dfDIJoystick = { sizeof(DIDATAFORMAT), sizeof(DIOBJECTDATAFORMAT), 0x00000001, 80, 44, JOY_fmt };
+const DIDATAFORMAT c_dfDIJoystick = { sizeof(DIDATAFORMAT), sizeof(DIOBJECTDATAFORMAT), DIDF_ABSAXIS, sizeof(DIJOYSTATE), sizeof(JOY_fmt)/sizeof(JOY_fmt[0]), JOY_fmt };
 
 
 /* Initialization/Query functions */

After adding a new x64 configuration option in the project files, you may also need to remove "/MACHINE:I386" as additional linker command in Project->Properties, Configuration Properties->Linker->Command Line.

zlib

You'll need the zlib source package. After unzipping it, go into the projects directory in the zlib source and open the solution under projects\vstudio. Right click on the "zlib" project, and go to its properties. Then, go to Configuration Properties->C/C++->Code Generation and change the Runtime library from "Multi-Threaded DLL (/MD)" to "Multi-Threaded (/MT)" (if you don't do this step, you'll have issues compiling ScummVM later on). Then, compile the "zlib" project using the LIB release configuration.

libogg

Compile this first, as many other libraries need it. Go to the win32 directory and build the "libogg_static" solution of your MSVC version (which should be found in one of the sub-directories). The solution should feature working x86 (Win32) and x64 (x64) targets by default, so you can compile either of those depending on whether you decide to build an x86 or x64 ScummVM.

libvorbis

You will need to use the "vorbis_static" solution. It should feature working x86 (Win32) and x64 (x64) targets by default.

Note: When you do not include your ogg headers/libraries in your global MSVC path settings you will need to do the following: include the libogg include and library paths in VS. To do this, go to Tools->Options->Projects and solutions->VC++ directories and include the include directory of libogg as well as the directory with the compiled ogg library. You'll need vorbis, vorbisfile and also vorbisenc for ScummVM tools.

libmad

Open and compile the "libmad" solution

Note for x64: When you want to build a x64 library for libmad you will need to create your own x64 config for it. You can do so by easy conversion of the existing libmad solution files for x86. For Release mode you will also need to edit the preprocessor definitons via: Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions: there you will need to replace "FPM_INTEL" with "FPM_64BIT".

You will also need to apply the following patch to mad.h:

--- mad.h	Tue Nov 03 18:29:06 2009
+++ mad.h	Tue Nov 03 18:29:14 2009
@@ -24,7 +24,11 @@
 extern "C" {
 # endif
 
+#ifdef _WIN64
+# define FPM_64BIT
+#else
 # define FPM_INTEL
+#endif

FLAC

Open its solution and compile the libFLAC_static project. By default, optimization for this library is set to "full" in release builds, which will prevent you from performing incremental debug builds later on, so make sure to set it to "Maximize speed" (or anything other than "Full optimization"), otherwise it will be impossible to build incremental debug builds later on. Check the introductory section for more information. Also, FLAC OGGs are not needed, so support for these can be dropped by going to the libFLAC_static project settings and removing the FLAC__HAS_OGG switch from C/C++->Preprocessor->Preprocessor Definitions.

Note for x64: After converting the Win32 target to x64 you will need to adapt some file settings. First of all you will need to disable all *.nasm files in the "libFLAC_static" project, this can be easily done by right clicking on them and selecting "Properties", now set "Excluded From Build" to "true". Next you will need to adapt the Preprocessor Definitions: First of all remove the following defintions: "FLAC__CPU_IA32", "FLAC__HAS_NASM" and "FLAC__USE_3DNOW", now also add "FLAC__NO_ASM". Last but not least you will need to apply the following patch file to "bitreader.c" of the "libFLAC_static" project:

--- src/libFLAC/bitreader.c	Tue Sep 11 05:48:56 2007
+++ src/libFLAC/bitreader.c	Tue Nov 03 19:19:37 2009
@@ -149,13 +149,23 @@
 	FLAC__CPUInfo cpu_info;
 };
 
-#ifdef _MSC_VER
+#if defined (_MSC_VER)
 /* OPT: an MSVC built-in would be better */
 static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
 {
 	x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
 	return (x>>16) | (x<<16);
 }
+
+#ifdef _WIN64
+static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
+{
+	while (len--) {
+		*start = local_swap32_(*start);
+		++start;
+	}
+}
+#else
 static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
 {
 	__asm {
@@ -173,6 +183,7 @@
 done1:
 	}
 }
+#endif
 #endif
 
 static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)

libpng

Open the solution under projects\vstudio. You also need zlib to compile this library, which must be placed in a folder named "zlib" outside libpng's directory. You need to change the settings of zlib like you have done before (i.e. from "Multi-Threaded DLL (/MD)" to "Multi-Threaded (/MT)"). Check the zlib section for more information.

libfaad

Open and compile the "libfaad" solution. You need to change the settings of libfaad like you have done before (i.e. from "Multi-Threaded DLL (/MD)" to "Multi-Threaded (/MT)"). Check the zlib section for more information.

Note for x64: When you want to build a x64 library for libfaad you will need to create your own x64 config for it. You can do so by easy conversion of the existing libfaad solution files for x86.

You will also need to apply the following patch to common.h, taken from mixxx's wiki:

--- common.h	Fri Jan 02 14:19:06 2015
+++ common.h	Fri Jan 02 14:19:06 2015
@@ -313,7 +313,9 @@ char *strchr(), *strrchr();
   }
 
 
-  #if defined(_WIN32) && !defined(__MINGW32__)
+  #if defined(_WIN64) && !defined(__MINGW64__)
+	// No LRINTF until someone writes an .asm file
+  #elif defined(_WIN32) && !defined(__MINGW32__)
     #define HAS_LRINTF
     static INLINE int lrintf(float f)
     {

libmpeg2

The VC6 solution files (inside the vc++ folder) need to be used for this library, but first they all need to be changed to DOS format, otherwise Visual Studio will complain that the project files are corrupted. For libmpeg2, ALL the MMX optimizations have to be disabled, as libmpeg2 is using AT&T ASM syntax (GCC style), whereas MSVC uses the Intel syntax.

In order to create the project files, do the following:

  • Copy inttypes.h and config.h from the vc++ directory into the libmpeg2 directory
  • Copy attributes.h and mpeg2.h from the include directory into the libmpeg2 directory
  • Make sure that your project includes these files, and remove the included project files:
    • alloc.c
    • config.h
    • decode.c
    • header.c
    • idct.c
    • inttypes.h
    • motion_comp.c
    • mpeg2.h
    • mpeg2_internal.h
    • slice.c
  • Find all occurences of:
* #include <inttypes.h>

and change them to:

* #include "inttypes.h"
  • Open config.h and comment out these lines:
#define ARCH_X86
#define restrict __restrict
  • Change configuration to "Release"
  • Right click project->Properties, and make sure that the following are set correctly:
    • Configuration Properties->General, "Configuration type" should be "Static library(.lib)"
    • Configuration Properties->C/C++->Code Generation, "Runtime Library" should be "Multi-threaded (/MT)"

Now, we'll remove all the MMX optimization references from the files that have been added to the project. Perform the following:

  • Open slice.c, replace these lines:
extern void (* mpeg2_cpu_state_save) (cpu_state_t * state);
extern void (* mpeg2_cpu_state_restore) (cpu_state_t * state);

with:

void (* mpeg2_cpu_state_save) (cpu_state_t * state) = 0;
void (* mpeg2_cpu_state_restore) (cpu_state_t * state) = 0;
uint32_t mpeg2_detect_accel (uint32_t accel) { return 0; }
void mpeg2_cpu_state_init (uint32_t accel) {}

After you compile the library, go to its include directory, create a folder "mpeg2dec" in there and copy all files from the include folder in this subfolder. You will end up with 2 directories, "include" and "include\mpeg2dec" with the same files. This is needed, as ScummVM includes files from the "mpeg2dec" directory