Difference between revisions of "Building SourceMod"
m |
|||
Line 24: | Line 24: | ||
*Microsoft Visual C++ 2012 (Express or higher) will work for some games; notably, not Dota 2. | *Microsoft Visual C++ 2012 (Express or higher) will work for some games; notably, not Dota 2. | ||
*Microsoft Visual C++ 2010 (Express or higher) is supported and used for official builds. | *Microsoft Visual C++ 2010 (Express or higher) is supported and used for official builds. | ||
+ | |||
+ | Grab the necessary SourceMod Windows dependencies by running <tt>tools\buildbot\checkout-windows-deps.bat</tt>. It should be run in the folder above sourcemod-central. Note that it will download quite a few HL2SDK copies. Example: | ||
+ | <pre> | ||
+ | C:\Users\dvander> sourcemod-central\tools\buildbot-checkout-windows-deps.bat | ||
+ | </pre> | ||
==Linux== | ==Linux== |
Revision as of 14:12, 14 November 2013
Compiling SourceMod is not difficult, but requires a number of prerequisites. This article details the requirements and steps to being able to build working SourceMod binaries.
Note that specific compiler versions are required to maintain ABI compatibility with Source engine binaries.
Contents
Requirements
No matter what platform you're on, you will need to install some baseline software to get going.
- Install Mercurial.
- Install AMBuild (You may need to run the install line as administrator):
hg clone http://hg.alliedmods.net/ambuild cd ambuild python setup.py install
- Checkout the SourceMod source code. There are many ways to get it, but via the command-line is easiest:
hg clone http://hg.alliedmods.net/sourcemod-central
Windows
You need one of the following Visual Studio versions:
- Microsoft Visual C++ 2012 (Express or higher) will work for some games; notably, not Dota 2.
- Microsoft Visual C++ 2010 (Express or higher) is supported and used for official builds.
Grab the necessary SourceMod Windows dependencies by running tools\buildbot\checkout-windows-deps.bat. It should be run in the folder above sourcemod-central. Note that it will download quite a few HL2SDK copies. Example:
C:\Users\dvander> sourcemod-central\tools\buildbot-checkout-windows-deps.bat
Linux
For Linux, SourceMod requires the GNU C/C++ Compiler (from GCC):
- Version 4.4 is used for official binaries and is guaranteed to build.
- Versions 3.4 through 4.3 are guaranteed to be binary (ABI) compatible, although SourceMod may not necessarily build out-of-box against them.
- Any GCC version below 3.4 cannot be used.
CPU
SourceMod is strictly a 32-bit x86 (IA32) product. You should not try to force a compiler to build 64-bit binaries of SourceMod.
Your CPU and its compiler must support SSE in order to build SourceMod. To build without needing or having a dependency against SSE, please see the Removing SSE section near the bottom.
Approximate compiling times for SourceMod's Core are roughly in September 2008:
- Windows, Core 2 Quad E6600: 30 seconds (using /MP)
- Windows, Core 2 Duo E6600: 75 seconds
- Windows, Centrino 1.8GHz: 5 minutes
- Linux, Core 2 Duo E6600: <= 1 minute
- Linux, P3 Dual 500MHz: >= 7 minutes
Setup
This section describes how to set up your computer for compiling.
Getting the Files
This section describes which files you must obtain and how to obtain them. Do not worry about where to place them yet -- that will be discussed on a per-platform basis. You can download the files anywhere you'd like.
The recommended method of getting the required files is via Mercurial. We have our own Mercurial_Tutorial if you prefer that method. Although you do not need all HL2SDK versions (unless you wish to build binaries against all of them), you do need Metamod:Source. Extensions don't necessarily require Metamod:Source (or even the Source Engine) but its template library is used extensively in SourceMod.
- SourceMod. For full download options, see the SourceMod Downloads page. Obviously, you must download the source code and not a binary package.
- Download the appropriate Source SDK for the game you want to compile for or download it from the list below:
- HL2SDK Original/Episode 1. As of this writing (Dec 2012) this engine is only used by Half-Life: Source Deathmatch (not HL2:DM) and third-party mods. Repository: hl2sdk
- HL2SDK OrangeBox. As of this writing (Dec 2012) this engine is only used by third-party mods. Repository: hl2sdk-ob
- HL2DSK OrangeBox Valve. As of this writing (Dec 2012) this engine is used for Source 2009 games (HL2:DM, DoD:S, and TF2). Repository: hl2sdk-ob-valve
- HL2SDK Alien Swarm. This engine is used for Alien Swarm. As of this writing (Dec 2012), this is only supported on SourceMod for Windows. Repository: hl2sdk-swarm
- HL2SDK BGT. This engine is used for Bloody Good Time. As of this writing (Dec 2012), this is only supported on SourceMod for Windows. Repository: hl2sdk-bgt
- HL2SDK CS:GO. This engine is used for CS:GO. Repository: hl2sdk-csgo
- HL2SDK CS:S. This engine is used for CS:S. Repository: hl2sdk-css
- HL2SDK DarkM. This engine is used for Dark Messiah. As of this writing (Dec 2012), this is only supported on SourceMod for Windows. Repository: hl2sdk-darkm
- HL2SDK EYE. This engine is used for E.Y.E. Divine Cybermancy. As of this writing (Dec 2012), this is only supported on SourceMod for Windows. Repository: hl2sdk-eye
- HL2SDK Gmod12. This engine is used for GMod12. As of this writing (Dec 2012), SourceMod does not support GMod13. Repository: hl2sdk-gmod
- HL2SDK Left4Dead. This engine is used for L4D. Repository: hl2sdk-l4d
- HL2SDK Left4Dead2. This engine is used for L4D2. Repository: hl2sdk-l4d2
- HL2SDK Portal 2. This engine is used for Portal 2. As of this writing (Dec 2012), SourceMod does not support Portal 2. Repository: hl2sdk-portal2
- HL2SDK Dota 2. Repository: hl2sdk-dota
- Metamod:Source Source Code. Visit Metamod:Source downloads. Right now SourceMod builds against Metamod:Source 1.9.
Note that when we refer to "Metamod:Source" in this article, we are referring to its source code tree, not a binary package.
If you intend to compile the MySQL extension, you must also download MySQL 5.0. You can use any version. For simplicity, here are the versions we use:
- Linux: We use the 5.0.45 binary from the "Linux (non RPM packages)" for "Linux (x86)." You can also use this direct link (may not be valid in the future).
- Windows: Due to a MySQL build change we use 5.0.24a which is an older download. The file name was "mysql-5.0.24a-win32.zip," if you can't find it you can use this direct link (may not be valid in the future).
You can remove all folders from the distribution except for the "lib" and "include" folders which comprise the MySQL SDK.
Linux
As of this writing, SourceMod's Makefiles are hardcoded to use a binary called "gcc" You can override this, for example:
make CPP=gcc-4.4
Note that you must use gcc and not g++.
SourceMod's Makefiles have strict directory organizational rules. You must have a top-level folder. For this document, we'll assume it is called sourcemod, though it can be named anything. The layout of sourcemod must be:
- sourcemod/
- hl2sdk - symlink or folder containing the HL2SDK for Original/Episode 1
- hl2sdk-ob - symlink or folder containing the HL2SDK for Orange Box
- hl2sdk-css - symlink or folder containing the HL2SDK for CS:S
- hl2sdk-ob-valve - symlink or folder containing the HL2SDK for Source 2009 (HL2:DM, DoD:S, TF2)
- hl2sdk-l4d - symlink or folder containing the HL2SDK for Left 4 Dead
- hl2sdk-l4d2 - symlink or folder containing the HL2SDK for Left 4 Dead 2
- hl2sdk-csgo - symlink or folder containing the HL2SDK for CS:GO
- hl2sdk-dota - symlink or folder containing the HL2SDK for Dota 2
- mmsource-central - symlink or folder containing any Metamod:Source version 1.7 or higher (1.9 or newer recommended for CS:S and CS:GO support)
- sourcemod-central - folder containing SourceMod's source code tree. This can be named anything, as long as it's a valid SourceMod tree (like sourcemod-central). You can also use sourcemod-1.1.
- mysql-5.0 - symlink or folder containing a MySQL 5.0 distribution
If you are using a 64-bit version of Linux, you may need to install extra packages to be able to compile SourceMod. On Debian-based distros, these are typically:
#prerequisites #apt-get install g++-4.1 gcc-4.1 make subversion #apt-get install libz libz-dev #only needed if you want to use the build tool #apt-get install mono mono-devel #32-bit support apt-get install ia32-libs apt-get install lib32z1 lib32z1-dev apt-get install libc6-dev-i386 libc6-i386
Windows
On Windows we don't require a particular directory layout. Instead, environment variables are used. The directions below apply to Windows XP, and are assumed to be similar for other versions of Windows.
- Open the Control Panel (for example, via Start -> Settings).
- Open the System control. If you don't see it, you may need to switch to "Classic view" (either via the left-hand pane or by going to Tools -> Folder Options).
- Click the Advanced tab.
- Click the Environment Variables button.
You can add your environment variables to either your User settings or your System settings. Create a new variable for each item in the list below. The item names are in fixed-width font and their value descriptions follow.
- MMSOURCE19 - Path to Metamod:Source 1.9+
- HL2SDK - Path to HL2SDK Ep1/Original
- HL2SDKOB - Path to HL2SDK Ep2/OrangeBox for mods
- HL2SDKOBVALVE - Path to HL2SDK Source 2009 (HL2:DM, DoD:S, TF2)
- HL2SDK-SWARM - Path to HL2SDK Alien Swarm
- HL2SDK-BGT - Path to HL2SDK for Bloody Good Time
- HL2SDKCSGO - Path to HL2SDK CS:GO
- HL2SDKCSS - Path to HL2SDK CS:S
- HL2SDK-DARKM - Path to HL2SDK Dark Messiah
- HL2SDK-EYE - Path to HL2SDK E.Y.E.: Divine Cybermancy
- HL2SDKL4D - Path to HL2SDK L4D1
- HL2SDKL4D2 - Path to HL2SDK L4D2
- HL2SDK-DOTA - Path to HL2SDK DOTA 2
Note that the Windows project does not have entries for Portal 2 or GMod.
Building
Binaries have seven build modes, each paired with either Release or Debug, meaning there are fourteen build options total. They build modes are:
- original - Building against HL2SDK_ORIG with MM:S 1.4 API (aka core-legacy)
- orangebox - Building against HL2SDK_OB with MM:S 1.6 API or higher
- css - Building against HL2SDK_CSS with MM:S 1.9 API or higher
- orangeboxvalve - Building against HL2SDK_OB_VALVE with MM:S 1.6 API or higher
- left4dead - Building against HL2SDK_L4D with MM:S 1.6 API or higher
- left4dead2 - Building against HL2SDK_L4D2 with MM:S 1.6 API or higher
- csgo - Building against HL2SDK_CSGO with MM:S 1.9 API or higher
Linux
The object files and the final binary are placed in a folder called Release or Debug (in the same level as the Makefile) depending on which building mechanism you chose.
Note: Our Makefiles are not set up to detect changes in header files. If you change a header file, you must clean your build.
Note that the Linux Makefile does not have entries for Dark Messiah, E.Y.E. Divine Cybermancy, Bloody Good Time, Portal 2, or GMod.
make has one required argument, ENGINE. It must be original, orangebox, css, orangeboxvalve, left4dead, left4dead2, or csgo. For example, to build a TF2-compatible binary in debug mode:
make ENGINE=orangeboxvalve DEBUG=true
Dependent binaries are dropped into one of the following folders:
- Debug.original
- Debug.orangebox
- Debug.css
- Debug.orangeboxvalve
- Debug.left4dead
- Debug.left4dead2
- Debug.csgo
- Release.original
- Release.orangebox
- Release.css
- Release.orangeboxvalve
- Release.left4dead
- Release.left4dead2
- Release.csgo
Windows
Windows solution files end with .sln and are found in an msvc10 folder that resides inside each binary's main source folder. For example, Core is located in core/msvc10/sourcemod_mm.sln.
Once the file is opened, you can select which build to use by using the Solution Configurations listbox near the top of the screen. As of MetaMod: Source 1.9, those are:
- CrazyDebug - Alien Swarm
- CrazyDebug - Bloody Good Time
- CrazyDebug - CS GO
- CrazyDebug - CSS
- CrazyDebug - Dark Messiah
- CrazyDebug - Episode 1
- CrazyDebug - EYE
- CrazyDebug - Left 4 Dead 2
- CrazyDebug - Left 4 Dead
- CrazyDebug - Old Metamod
- CrazyDebug - Orange Box Valve
- CrazyDebug - Orange Box
- Debug - Alien Swarm
- Debug - Bloody Good Time
- Debug - CS GO
- Debug - CSS
- Debug - Dark Messiah
- Debug - Episode 1
- Debug - EYE
- Debug - Left 4 Dead 2
- Debug - Left 4 Dead
- Debug - Old Metamod
- Debug - Orange Box Valve
- Debug - Orange Box
- Release - Alien Swarm
- Release - Bloody Good Time
- Release - CS GO
- Release - CSS
- Release - Dark Messiah
- Release - Episode 1
- Release - EYE
- Release - Left 4 Dead 2
- Release - Left 4 Dead
- Release - Old Metamod
- Release - Orange Box Valve
- Release - Orange Box
Once you have selected a configuration, you can compile by going to Build -> Build Solution. The binaries and object files will be written to a folder inside msvc10 named after the full configuration name. For example, using "Debug - Old Metamod" with the "sdktools" extension will result in the binary: extensions/sdktools/msvc10/Debug - Old Metamod/sdktools.ext.dll
Note: Visual Studio detects changes to header files intelligently. It is usually not necessary to rebuild a solution.
Binary Organization
Although SourceMod has a somewhat unified building mechanism, each of the binaries has a different purpose. They can be separated into the following classes:
- Core-Related: Binaries which are required or loaded intrinsically by Core.
- Extensions: Binaries which are loaded via the extension mechanism.
- External: Binaries which are standalone or unrelated to SourceMod's live operation (for example, the compiler).
This article is only concerned with the first two types.
Core-Related Binaries
Binaries related to Core are spread throughout the source code tree. They are always placed in sourcemod/bin for packaging. The projects files related to Core are:
- loader - This is a very small wrapper binary responsible for detecting the MM:S version and game engine, and deciding which SourceMod version to load. The output binary is sourcemod_mm_i486.so or sourcemod_mm.dll.
- core - This is Core itself, and is a dependent binary. It has eleven outputs:
- Original/Episode 1: sourcemod.1.ep1.so/sourcemod.1.ep1.dll
- Orange Box: sourcemod.2.ep2.so/sourcemod.2.ep2.dll
- Orange Box Valve: sourcemod.2.ep2v.so/sourcemod.2.ep2v.dll
- Alien Swarm: sourcemod.2.swarm.so/sourcemod.2.swarm.dll
- Bloody Good Time: sourcemod.2.bgt.so/sourcemod.2.bgt.dll
- CS:GO: sourcemod.2.csgo.so/sourcemod.2.csgo.dll
- CS:S: sourcemod.2.css.so/sourcemod.2.css.dll
- Dark Messiah: sourcemod.2.darkm.so/sourcemod.2.darkm.dll
- E.Y.E.: sourcemod.2.eye.so/sourcemod.2.eye.dll
- Left 4 Dead: sourcemod.2.l4d.so/sourcemod.2.l4d.dll
- Left 4 Dead 2: sourcemod.2.l4d2.so/sourcemod.2.l4d2.dll
- sourcepawn/jit/x86 - This is the SourcePawn JIT for generating IA32/x86 instructions from .smx files. Currently the source code for this is not made available. It is built as sourcepawn.jit.x86.so/sourcepawn.jit.x86.dll.
It is technically not necessary to use the loader. It is provided as a convenience so users do not have to perform extra steps while installing SourceMod. However, it is highly recommend that you do use it in order to maintain similarity with the default SourceMod package.
Extensions
Extensions are found in the extensions folder of the source tree. SDKTools, Cstrike, and the TF2 extension are engine/MM:S dependent (and the rest are generally not).
Normal extensions are named name.ext.so or name.ext.dll where name is a unique identifier. Dependent extensions will be named like core above.
For example, the SDKTools binary on Counter-Strike: Source for Window would be loaded from extensions/sdktools.ext.2.css.dll, but the GeoIP binary (which is not dependent) would be loaded from extensions/geoip.ext.dll.
Removing SSE
SourceMod binaries are built against SSE by default. SSE is an important set of optimizations, that, according to Valve's hardware survey, are supported on 99.6% percent of respondents' computers. If you are in this 0.4% which does not have SSE support, you should consider buying a newer processor. Only early Pentium 3-grade processors did not have SSE support (for example, the very early Durons), and it is likely your Source server will not perform adequately to support more than few players.
Nonetheless, SourceMod's binaries can all be recompiled to remove its SSE dependence.
Linux
Edit the Makefile of the binary you are trying to compile. Remove all instances of these flags. They can simply be erased, there is no need to replace them with anything.
- -msse
- -mfpmath=sse
Make sure to clean the build after changing the Makefile.
Windows
Load the project file into Visual Studio. Go to Project -> Properties. Expand "Configuration Properties," and then "C/C++" under it. Select "Code Generation." Change the setting "Enable Enhanced Instruction Set" to "Not Set."
Note: You must change this setting for each build configuration that you wish to use.