Difference between revisions of "Building SourceMod"

From AlliedModders Wiki
Jump to: navigation, search
m
m (Adjust linux deps command)
 
(71 intermediate revisions by 16 users not shown)
Line 5: Line 5:
 
=Requirements=
 
=Requirements=
  
No matter what platform you're on, you will need to install some baseline software to get going.
+
==Windows==
  
# Install [http://mercurial.selenic.com/ Mercurial].
+
# Install Visual Studio or Visual C++. VS/VC 2010 or above is required for SourceMod 1.6.x and earlier. VS/VC 2013 Update 2 or above is required for SourceMod 1.7.x and later (Express editions should work fine). VS/VC 2015 is required for SourceMod 1.10.x or later.
# Install AMBuild (You may need to run the install line as administrator):
+
#* If you use 2013 or higher, make sure to get the "Desktop" version: [http://www.visualstudio.com/downloads/download-visual-studio-vs#d-express-windows-desktop Visual Studio Express 2013 for Desktop].
 +
#* With VS/VC 2017, you may use [https://download.visualstudio.microsoft.com/download/pr/b8d403d9-01a4-45a0-9229-db5572fd5e4e/997600ae09705dfc6d069d8ad2cfad1962d8ff6fedd6c9fe5abee36c7c919f34/vs_BuildTools.exe the build tools installer] to install the minimal set of packages.
 +
#** You will want to install the following:  .NET 4.6.1 SDK and corrresponding targeting pack, C++/CLI support, VC++2015.3 v14.00 toolset for desktop, Visual C++ Build Tools core features, Windows 8.1 SDK, and Windows Universal C Runtime.
 +
#** When attempting to configure and build, use the "VS2015 x86 Native Tools Command Prompt" Start Menu option to have the build tools available in the current Command Prompt's PATH.
 +
#* With [https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019 Build Tools for Visual Studio 2019], you can install the following individual components:  MSVC v140 - VS 2015 C++ build tools (v14.00), Windows Universal CRT SDK, and Windows 10 SDK.
 +
# Install [http://git-scm.com/ Git]. Make sure that you select the option that adds Git to PATH.
 +
# Next, you will need to start an environment capable of running Python and interacting with the Visual Studio compiler.
 +
#* Install [http://python.org/ Python].  Versions newer than 3.3 are supported; at the time of writing the latest available version is 3.11.
 +
#* Add Python to your <tt>PATH</tt> variable. Go to Control Panel, System, Advanced, Environment Variables. Add <tt>C:\Python27;C:\Python27\Scripts</tt> to <tt>PATH</tt> (or wherever your Python install is).
 +
#* Under Start, Programs, Microsoft Visual Studio, select the "Visual Studio Tools" folder and run "Visual Studio Command Prompt". Alternately, open a normal command prompt and run <tt>"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars.bat"</tt>. Substitute your Visual Studio version if needed.
 +
 
 +
==Linux==
 +
<ol>
 +
<li>Install Git, via either system packages or from the [http://git-scm.com/ Git] distribution.</li>
 +
<li>Install a C++ compiler and dependencies. SourceMod officially supports clang. For example, on Ubuntu/Debian:
 
<pre>
 
<pre>
hg clone http://hg.alliedmods.net/ambuild
+
sudo dpkg --add-architecture i386; sudo apt update; sudo apt-get install clang lib32stdc++-7-dev lib32z1-dev libc6-dev-i386 linux-libc-dev:i386
cd ambuild
 
python setup.py install
 
 
</pre>
 
</pre>
 +
<li>If building on a 64-bit system, you must install the 32-bit libraries for the compiler; e.g.:
 +
<pre>
 +
sudo apt-get install g++-multilib
 +
</pre>
 +
</ol>
  
==Windows==
+
==Archlinux==
You need one of the following Visual Studio versions:
+
 
 +
# Enable multilib repository as described in the [https://wiki.archlinux.org/index.php/multilib Archlinux wiki page].
 +
# Install the following packages:
 +
#:<pre>pacman -S git python2 gcc-multilib lib32-glibc lib32-libstdc++5 lib32-zlib</pre>
 +
 
 +
==Mac OS X==
 +
Mac OS X 10.7 to 10.14 is required to build, however, SourceMod will work on 10.5. SourceMod will neither build nor run on older PPC Macs.
 +
Newer versions are unsupported due to the removal of 32 bit support from MacOS.
 +
 
 +
<ol>
 +
<li>Install the Xcode Command Line Tools.
 +
  <ul>
 +
    <li>For OS X 10.9 or higher, run the command below in Terminal and click the Install button in the window that appears.
 +
<pre>
 +
xcode-select --install
 +
</pre>
 +
    </li>
 +
    <li>For earlier versions of OS X, download and install Xcode from the App Store. Launch Xcode and then navigate to Preferences -> Downloads -> Components -> Command Line Tools -> Install. If you have recently upgraded Xcode, you will need to perform this step again. SourceMod cannot build without Xcode's command line tools.</li>
 +
  </ul>
 +
</ol>
 +
 
 +
=Downloading Source and Dependencies=
 +
 
 +
First, grab the SourceMod source tree. We recommend placing it inside its own folder, since we'll also need to download its dependencies.
 +
 
 +
'''You should do a recursive checkout of the git repo since the sourcepawn repo is a submodule of sourcemod now, see https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules to do that.'''
 +
<pre>
 +
mkdir -p alliedmodders
 +
cd alliedmodders
 +
git clone --recursive https://github.com/alliedmodders/sourcemod
 +
</pre>
 +
 
 +
Next, run the <tt>checkout-deps.sh</tt> script. This will download all dependencies and attempt to install AMBuild. If you are using Linux or OS X, it may prompt you for your sudo password at the very end. If you want to skip this and install AMBuild manually, just Ctrl+C. (Do not run the checkout script with sudo.)
 +
<pre>
 +
bash sourcemod/tools/checkout-deps.sh
 +
</pre>
  
*Microsoft Visual C++ 2012 (Express or higher) will work for some games; notably, not Dota 2.
+
After it's done, you should see a large number of hl2sdk folders and other assorted dependencies, like MySQL, Metamod:Source, and AMBuild.
*Microsoft Visual C++ 2010 (Express or higher) is supported and used for official builds.
 
  
 +
If you are on Windows, you can use 'checkout-deps' PowerShell script (if it exists), you just may need to swap ExecutionPolicy to a less restrictive one. (See: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies).
  
 +
Otherwise, you can manually download the dependencies with the commands below:
 +
<pre>
 +
git clone --mirror https://github.com/alliedmodders/hl2sdk hl2sdk-proxy-repo
 +
# For each SDK you want to build with:
 +
# git clone hl2sdk-proxy-repo hl2sdk-<SDK> -b <SDK>
 +
# e.g. git clone hl2sdk-proxy-repo hl2sdk-csgo -b csgo
  
 +
git clone https://github.com/alliedmodders/metamod-source mmsource-1.10 -b 1.10-dev
  
==Linux==
+
# If building version 1.10 of SourceMod, use MySQL 5.5
For Linux, SourceMod requires the GNU C/C++ Compiler (from GCC):
+
wget https://cdn.mysql.com/archives/mysql-5.5/mysql-5.5.54-win32.zip mysql-5.5
*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==
+
# If building < version 1.10 of SourceMod, use MySQL 5.0
SourceMod is strictly a 32-bit x86 (IA32) product. You should not try to force a compiler to build 64-bit binaries of SourceMod.
+
wget https://cdn.mysql.com/archives/mysql-5.0/mysql-noinstall-5.0.24a-win32.zip mysql-5.0
  
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 [[Compiling SourceMod#Removing SSE|Removing SSE]] section near the bottom.
+
# Install AMBuild
 +
git clone https://github.com/alliedmodders/ambuild
 +
pip install ./ambuild
 +
</pre>
  
Approximate compiling times for SourceMod's Core are roughly in September 2008:
+
Note that you can skip MySQL and SDK versions you don't plan to build.
*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=
+
=Configuring=
This section describes how to set up your computer for compiling.
 
  
==Getting the Files==
+
The first time you are building a SourceMod tree, you must ''configure'' the build. This step initializes some basic information and allows some customization around how things get compiled.
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 [http://mercurial.selenic.com/ 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.
+
First create a build folder within your sourcemod folder, and then run <tt>configure.py</tt>. For example:
 +
<pre>
 +
cd sourcemod
 +
mkdir build
 +
cd build
 +
python ../configure.py
 +
</pre>
  
*SourceMod. For full download options, see the [http://www.sourcemod.net/downloads.php SourceMod Downloads] page.  Obviously, you must download the source code and not a binary package.
+
'''Note:''' If it complains about <tt>Could not find a source copy of Metamod:Source</tt>, rename the <tt>mmsource-11</tt> folder to <tt>metamod-source</tt>. See https://github.com/alliedmodders/sourcemod/blob/master/AMBuildScript#L186-L193 for the valid folder names it looks for
*Download the appropriate [http://hg.alliedmods.net/hl2sdks/ 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: [http://hg.alliedmods.net/hl2sdks/hl2sdk hl2sdk]
 
**HL2SDK OrangeBox.  As of this writing (Dec 2012) this engine is only used by third-party mods. Repository: [http://hg.alliedmods.net/hl2sdks/hl2sdk-ob 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: [http://hg.alliedmods.net/hl2sdks/hl2sdk-ob-valve 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: [http://hg.alliedmods.net/hl2sdks/hl2sdk-swarm 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: [http://hg.alliedmods.net/hl2sdks/hl2sdk-bgt hl2sdk-bgt]
 
**HL2SDK CS:GO. This engine is used for CS:GO. Repository: [http://hg.alliedmods.net/hl2sdks/hl2sdk-csgo hl2sdk-csgo]
 
**HL2SDK CS:S. This engine is used for CS:S. Repository: [http://hg.alliedmods.net/hl2sdks/hl2sdk-css 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: [http://hg.alliedmods.net/hl2sdks/hl2sdk-darkm 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: [http://hg.alliedmods.net/hl2sdks/hl2sdk-eye hl2sdk-eye]
 
**HL2SDK Gmod12. This engine is used for GMod12. As of this writing (Dec 2012), SourceMod does not support GMod13. Repository: [http://hg.alliedmods.net/hl2sdks/hl2sdk-gmod hl2sdk-gmod]
 
**HL2SDK Left4Dead. This engine is used for L4D. Repository: [http://hg.alliedmods.net/hl2sdks/hl2sdk-l4d hl2sdk-l4d]
 
**HL2SDK Left4Dead2. This engine is used for L4D2. Repository: [http://hg.alliedmods.net/hl2sdks/hl2sdk-l4d2 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: [http://hg.alliedmods.net/hl2sdks/hl2sdk-portal2 hl2sdk-portal2]
 
**HL2SDK Dota 2. Repository: [http://hg.alliedmods.net/hl2sdks/hl2sdk-dota/ hl2sdk-dota]
 
*Metamod:Source Source Code. Visit [http://www.metamodsource.net/?go=downloads 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.
+
You may also need to run Python as <tt>python3</tt> instead of <tt>python</tt>, depending on your operating system's installed Python version(s).
  
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:
+
It is safe to reconfigure over an old build. However, it's probably a bad idea to configure inside a random, non-empty folder.
*Linux: We use the 5.0.45 binary from the "[http://dev.mysql.com/downloads/mysql/5.0.html#linux Linux (non RPM packages)]" for "Linux (x86)."  You can also use [http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.45-linux-i686-glibc23.tar.gz 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 [http://downloads.mysql.com/archives/mysql-5.0/mysql-noinstall-5.0.24a-win32.zip 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.
+
There are a few extra options you can pass to <tt>configure</tt>:
 +
*--enable-debug - Compile with symbols and debug checks/assertions.
 +
*--enable-optimize - Compile with optimizations.
 +
*--no-sse - Disable floating point optimizations (if you have a very, very old CPU).
 +
*--no-mysql - Don't build the MySQL database module.
 +
*--sdks css - Only build css.
  
==Linux==
+
See configure.py for all the options.
As of this writing, SourceMod's Makefiles are hardcoded to use a binary called "gcc"  You can override this, for example:
 
<pre>make CPP=gcc-4.4</pre>
 
  
Note that you must use <tt>gcc</tt> and not <tt>g++</tt>.
+
=Building=
  
SourceMod's Makefiles have strict directory organizational rules.  You must have a top-level folder.  For this document, we'll assume it is called <tt>sourcemod</tt>, though it can be named anything.  The layout of <tt>sourcemod</tt> must be:
+
To build SourceMod, simply type:
*<tt>sourcemod</tt>/
+
<pre>
**<tt>hl2sdk</tt> - symlink or folder containing the HL2SDK for Original/Episode 1
+
ambuild
**<tt>hl2sdk-ob</tt> - symlink or folder containing the HL2SDK for Orange Box
+
</pre>
**<tt>hl2sdk-css</tt> - symlink or folder containing the HL2SDK for CS:S
 
**<tt>hl2sdk-ob-valve</tt> - symlink or folder containing the HL2SDK for Source 2009 (HL2:DM, DoD:S, TF2)
 
**<tt>hl2sdk-l4d</tt> - symlink or folder containing the HL2SDK for Left 4 Dead
 
**<tt>hl2sdk-l4d2</tt> - symlink or folder containing the HL2SDK for Left 4 Dead 2
 
**<tt>hl2sdk-csgo</tt> - symlink or folder containing the HL2SDK for CS:GO
 
**<tt>hl2sdk-dota</tt> - symlink or folder containing the HL2SDK for Dota 2
 
**<tt>mmsource-central</tt> - symlink or folder containing any Metamod:Source version 1.7 or higher (1.9 or newer recommended for CS:S and CS:GO support)
 
**<tt>sourcemod-central</tt> - folder containing SourceMod's source code tree.  This can be named anything, as long as it's a valid SourceMod tree (like [http://hg.alliedmods.net/sourcemod-central sourcemod-central]).  You can also use [http://hg.alliedmods.net/sourcemod-1.1 sourcemod-1.1].
 
**<tt>mysql-5.0</tt> - 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:
+
In your build folder. Alternately, you can specify the path of the build folder:
 
<pre>
 
<pre>
#prerequisites
+
ambuild debug-build
#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
 
 
</pre>
 
</pre>
  
==Windows==
+
The full package layout that would be shipped for release is in the <tt>package</tt> folder of the build.
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).
+
=Deprecated Tools=
*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).
+
==Visual Studio Project Files==
*Click the Advanced tab.
+
In the future, we will use AMBuild to automatically generate project files, and the existing project files will be removed from the SourceMod tree. In the meantime however, it is possible to use these files. Unfortunately, they require a bit of extra work to use.
*Click the Environment Variables button.
+
 
 +
First, make sure you've downloaded all necessary dependencies (SDKs, Metamod:Source source code, and MySQL) via the <tt>checkout-windows-deps.bat</tt> script. Next,
 +
#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 <tt>fixed-width font</tt> and their value descriptions follow.
+
Now, add your environment variables to either your User settings or your System settings. Create a new variable for each item in the list below. You may omit SDKs that you do not plan to build against. The item names are in <tt>fixed-width font</tt> and their value descriptions follow.
*<tt>MMSOURCE19</tt> - Path to Metamod:Source 1.9+
+
*<tt>MMSOURCE19</tt> - Path to Metamod:Source 1.10+
 +
*<tt>MMSOURCE18</tt> - Path to Metamod:Source 1.10+
 
*<tt>HL2SDK</tt> - Path to HL2SDK Ep1/Original
 
*<tt>HL2SDK</tt> - Path to HL2SDK Ep1/Original
 
*<tt>HL2SDKOB</tt> - Path to HL2SDK Ep2/OrangeBox for mods
 
*<tt>HL2SDKOB</tt> - Path to HL2SDK Ep2/OrangeBox for mods
Line 130: Line 162:
 
*<tt>HL2SDKL4D2</tt> - Path to HL2SDK L4D2
 
*<tt>HL2SDKL4D2</tt> - Path to HL2SDK L4D2
 
*<tt>HL2SDK-DOTA</tt> - Path to HL2SDK DOTA 2
 
*<tt>HL2SDK-DOTA</tt> - Path to HL2SDK DOTA 2
 +
*<tt>MYSQL5</tt> - Path to the folder that contains MySQL's <tt>include</tt> and <tt>lib</tt> folders.
  
Note that the Windows project does not have entries for Portal 2 or GMod.
+
==Makefiles==
 
+
Makefiles are deprecated and will be removed from the tree soon.
=Building=
 
Binaries have seven build modes, each paired with either Release or Debug, meaning there are fourteen build options total.  They build modes are:
 
*<tt>original</tt> - Building against HL2SDK_ORIG with MM:S 1.4 API (aka core-legacy)
 
*<tt>orangebox</tt> - Building against HL2SDK_OB with MM:S 1.6 API or higher
 
*<tt>css</tt> - Building against HL2SDK_CSS with MM:S 1.9 API or higher
 
*<tt>orangeboxvalve</tt> - Building against HL2SDK_OB_VALVE with MM:S 1.6 API or higher
 
*<tt>left4dead</tt> - Building against HL2SDK_L4D with MM:S 1.6 API or higher
 
*<tt>left4dead2</tt> - Building against HL2SDK_L4D2 with MM:S 1.6 API or higher
 
*<tt>csgo</tt> - 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 <tt>Release</tt> or <tt>Debug</tt> (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, <tt>ENGINE</tt>.  It must be <tt>original</tt>, <tt>orangebox</tt>, <tt>css</tt>, <tt>orangeboxvalve</tt>, <tt>left4dead</tt>, <tt>left4dead2</tt>, or <tt>csgo</tt>.  For example, to build a TF2-compatible binary in debug mode:
 
 
 
<pre>make ENGINE=orangeboxvalve DEBUG=true</pre>
 
 
 
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 <tt>.sln</tt> and are found in an <tt>msvc10</tt> folder that resides inside each binary's main source folder.  For example, Core is located in <tt>core/msvc10/sourcemod_mm.sln</tt>. 
 
 
 
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 <tt>msvc10</tt> named after the full configuration name.  For example, using "Debug - Old Metamod" with the "sdktools" extension will result in the binary: <tt>extensions/sdktools/msvc10/Debug - Old Metamod/sdktools.ext.dll</tt>
 
 
 
'''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 <tt>sourcemod/bin</tt> for packaging.  The projects files related to Core are:
 
 
 
*<tt>loader</tt> - 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 <tt>sourcemod_mm_i486.so</tt> or <tt>sourcemod_mm.dll</tt>.
 
*<tt>core</tt> - This is Core itself, and is a dependent binary.  It has eleven outputs:
 
**Original/Episode 1: <tt>sourcemod.1.ep1.so</tt>/<tt>sourcemod.1.ep1.dll</tt>
 
**Orange Box: <tt>sourcemod.2.ep2.so</tt>/<tt>sourcemod.2.ep2.dll</tt>
 
**Orange Box Valve: <tt>sourcemod.2.ep2v.so</tt>/<tt>sourcemod.2.ep2v.dll</tt>
 
**Alien Swarm: <tt>sourcemod.2.swarm.so</tt>/<tt>sourcemod.2.swarm.dll</tt>
 
**Bloody Good Time: <tt>sourcemod.2.bgt.so</tt>/<tt>sourcemod.2.bgt.dll</tt>
 
**CS:GO: <tt>sourcemod.2.csgo.so</tt>/<tt>sourcemod.2.csgo.dll</tt>
 
**CS:S: <tt>sourcemod.2.css.so</tt>/<tt>sourcemod.2.css.dll</tt>
 
**Dark Messiah: <tt>sourcemod.2.darkm.so</tt>/<tt>sourcemod.2.darkm.dll</tt>
 
**E.Y.E.: <tt>sourcemod.2.eye.so</tt>/<tt>sourcemod.2.eye.dll</tt>
 
**Left 4 Dead: <tt>sourcemod.2.l4d.so</tt>/<tt>sourcemod.2.l4d.dll</tt>
 
**Left 4 Dead 2: <tt>sourcemod.2.l4d2.so</tt>/<tt>sourcemod.2.l4d2.dll</tt>
 
 
 
*<tt>sourcepawn/jit/x86</tt> - This is the SourcePawn JIT for generating IA32/x86 instructions from <tt>.smx</tt> files.  Currently the source code for this is not made available.  It is built as <tt>sourcepawn.jit.x86.so</tt>/<tt>sourcepawn.jit.x86.dll</tt>.
 
 
 
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 <tt>extensions</tt> 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 <tt>name.ext.so</tt> or <tt>name.ext.dll</tt> where <tt>name</tt> 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 <tt>extensions/sdktools.ext.2.css.dll</tt>, but the GeoIP binary (which is not dependent) would be loaded from <tt>extensions/geoip.ext.dll</tt>.
 
 
 
=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.
 
*<tt>-msse</tt>
 
*<tt>-mfpmath=sse</tt>
 
 
 
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.
 
 
 
  
 
[[Category:SourceMod Documentation]]
 
[[Category:SourceMod Documentation]]
 
[[Category:SourceMod Development]]
 
[[Category:SourceMod Development]]

Latest revision as of 10:06, 21 April 2024

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.

Requirements

Windows

  1. Install Visual Studio or Visual C++. VS/VC 2010 or above is required for SourceMod 1.6.x and earlier. VS/VC 2013 Update 2 or above is required for SourceMod 1.7.x and later (Express editions should work fine). VS/VC 2015 is required for SourceMod 1.10.x or later.
    • If you use 2013 or higher, make sure to get the "Desktop" version: Visual Studio Express 2013 for Desktop.
    • With VS/VC 2017, you may use the build tools installer to install the minimal set of packages.
      • You will want to install the following: .NET 4.6.1 SDK and corrresponding targeting pack, C++/CLI support, VC++2015.3 v14.00 toolset for desktop, Visual C++ Build Tools core features, Windows 8.1 SDK, and Windows Universal C Runtime.
      • When attempting to configure and build, use the "VS2015 x86 Native Tools Command Prompt" Start Menu option to have the build tools available in the current Command Prompt's PATH.
    • With Build Tools for Visual Studio 2019, you can install the following individual components: MSVC v140 - VS 2015 C++ build tools (v14.00), Windows Universal CRT SDK, and Windows 10 SDK.
  2. Install Git. Make sure that you select the option that adds Git to PATH.
  3. Next, you will need to start an environment capable of running Python and interacting with the Visual Studio compiler.
    • Install Python. Versions newer than 3.3 are supported; at the time of writing the latest available version is 3.11.
    • Add Python to your PATH variable. Go to Control Panel, System, Advanced, Environment Variables. Add C:\Python27;C:\Python27\Scripts to PATH (or wherever your Python install is).
    • Under Start, Programs, Microsoft Visual Studio, select the "Visual Studio Tools" folder and run "Visual Studio Command Prompt". Alternately, open a normal command prompt and run "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars.bat". Substitute your Visual Studio version if needed.

Linux

  1. Install Git, via either system packages or from the Git distribution.
  2. Install a C++ compiler and dependencies. SourceMod officially supports clang. For example, on Ubuntu/Debian:
    sudo dpkg --add-architecture i386; sudo apt update; sudo apt-get install clang lib32stdc++-7-dev lib32z1-dev libc6-dev-i386 linux-libc-dev:i386
    
  3. If building on a 64-bit system, you must install the 32-bit libraries for the compiler; e.g.:
    sudo apt-get install g++-multilib
    

Archlinux

  1. Enable multilib repository as described in the Archlinux wiki page.
  2. Install the following packages:
    pacman -S git python2 gcc-multilib lib32-glibc lib32-libstdc++5 lib32-zlib

Mac OS X

Mac OS X 10.7 to 10.14 is required to build, however, SourceMod will work on 10.5. SourceMod will neither build nor run on older PPC Macs. Newer versions are unsupported due to the removal of 32 bit support from MacOS.

  1. Install the Xcode Command Line Tools.
    • For OS X 10.9 or higher, run the command below in Terminal and click the Install button in the window that appears.
      xcode-select --install
      
    • For earlier versions of OS X, download and install Xcode from the App Store. Launch Xcode and then navigate to Preferences -> Downloads -> Components -> Command Line Tools -> Install. If you have recently upgraded Xcode, you will need to perform this step again. SourceMod cannot build without Xcode's command line tools.

Downloading Source and Dependencies

First, grab the SourceMod source tree. We recommend placing it inside its own folder, since we'll also need to download its dependencies.

You should do a recursive checkout of the git repo since the sourcepawn repo is a submodule of sourcemod now, see https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules to do that.

mkdir -p alliedmodders
cd alliedmodders
git clone --recursive https://github.com/alliedmodders/sourcemod

Next, run the checkout-deps.sh script. This will download all dependencies and attempt to install AMBuild. If you are using Linux or OS X, it may prompt you for your sudo password at the very end. If you want to skip this and install AMBuild manually, just Ctrl+C. (Do not run the checkout script with sudo.)

bash sourcemod/tools/checkout-deps.sh

After it's done, you should see a large number of hl2sdk folders and other assorted dependencies, like MySQL, Metamod:Source, and AMBuild.

If you are on Windows, you can use 'checkout-deps' PowerShell script (if it exists), you just may need to swap ExecutionPolicy to a less restrictive one. (See: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies).

Otherwise, you can manually download the dependencies with the commands below:

git clone --mirror https://github.com/alliedmodders/hl2sdk hl2sdk-proxy-repo
# For each SDK you want to build with:
# git clone hl2sdk-proxy-repo hl2sdk-<SDK> -b <SDK>
# e.g. git clone hl2sdk-proxy-repo hl2sdk-csgo -b csgo

git clone https://github.com/alliedmodders/metamod-source mmsource-1.10 -b 1.10-dev

# If building version 1.10 of SourceMod, use MySQL 5.5
wget https://cdn.mysql.com/archives/mysql-5.5/mysql-5.5.54-win32.zip mysql-5.5

# If building < version 1.10 of SourceMod, use MySQL 5.0
wget https://cdn.mysql.com/archives/mysql-5.0/mysql-noinstall-5.0.24a-win32.zip mysql-5.0

# Install AMBuild
git clone https://github.com/alliedmodders/ambuild
pip install ./ambuild

Note that you can skip MySQL and SDK versions you don't plan to build.

Configuring

The first time you are building a SourceMod tree, you must configure the build. This step initializes some basic information and allows some customization around how things get compiled.

First create a build folder within your sourcemod folder, and then run configure.py. For example:

cd sourcemod
mkdir build
cd build
python ../configure.py

Note: If it complains about Could not find a source copy of Metamod:Source, rename the mmsource-11 folder to metamod-source. See https://github.com/alliedmodders/sourcemod/blob/master/AMBuildScript#L186-L193 for the valid folder names it looks for

You may also need to run Python as python3 instead of python, depending on your operating system's installed Python version(s).

It is safe to reconfigure over an old build. However, it's probably a bad idea to configure inside a random, non-empty folder.

There are a few extra options you can pass to configure:

  • --enable-debug - Compile with symbols and debug checks/assertions.
  • --enable-optimize - Compile with optimizations.
  • --no-sse - Disable floating point optimizations (if you have a very, very old CPU).
  • --no-mysql - Don't build the MySQL database module.
  • --sdks css - Only build css.

See configure.py for all the options.

Building

To build SourceMod, simply type:

ambuild

In your build folder. Alternately, you can specify the path of the build folder:

ambuild debug-build

The full package layout that would be shipped for release is in the package folder of the build.

Deprecated Tools

Visual Studio Project Files

In the future, we will use AMBuild to automatically generate project files, and the existing project files will be removed from the SourceMod tree. In the meantime however, it is possible to use these files. Unfortunately, they require a bit of extra work to use.

First, make sure you've downloaded all necessary dependencies (SDKs, Metamod:Source source code, and MySQL) via the checkout-windows-deps.bat script. Next,

  1. Open the Control Panel (for example, via Start -> Settings).
  2. 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).
  3. Click the Advanced tab.
  4. Click the Environment Variables button.

Now, add your environment variables to either your User settings or your System settings. Create a new variable for each item in the list below. You may omit SDKs that you do not plan to build against. The item names are in fixed-width font and their value descriptions follow.

  • MMSOURCE19 - Path to Metamod:Source 1.10+
  • MMSOURCE18 - Path to Metamod:Source 1.10+
  • 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
  • MYSQL5 - Path to the folder that contains MySQL's include and lib folders.

Makefiles

Makefiles are deprecated and will be removed from the tree soon.