Difference between revisions of "Building SourceMod"

From AlliedModders Wiki
Jump to: navigation, search
m (Updated for DS's new Makefile setup)
(Configuring: Add note on running Python 3)
(108 intermediate revisions by 22 users not shown)
Line 1: Line 1:
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.  These directions may change any time and may be updated as SourceMod's build process improves.
+
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:''' You cannot use MingW to build working SourceMod Windows binaries.  It is not ABI compatible with Visual C++ which is what Valve uses for the Source engine.  You can only use GCC to build Linux binaries.
+
Note that specific compiler versions are required to maintain ABI compatibility with Source engine binaries.
  
 
=Requirements=
 
=Requirements=
  
 
==Windows==
 
==Windows==
*Microsoft Visual C++ 2005 (Express or higher) is supported and used for official builds.
 
*Microsoft Visual C++ 2008 (Express or higher) is unsupported, but can load and build SourceMod's 2005 project files.
 
*Microsoft Visual C++ 2003 7.1 or higher may not build out-of-box, but can build compatible binaries.
 
*Microsoft Visual C++ 2003 7.0 or lower '''cannot''' be used.
 
  
If you are installing Visual C++ 2005 Express, it may not come with Microsoft's Platform SDK installed. If this is the case, you must manually install the Platform SDK.  You can find directions on how to do this and test your setup [http://www.microsoft.com/express/2005/platformsdk/default.aspx here].  Visual C++ 2008 "streamlines" the Platform SDK installation according to Microsoft.
+
# 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: [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==
 
==Linux==
For Linux, SourceMod requires the GNU C/C++ Compiler (from GCC):
+
<ol>
*Version 4.1 is used for official binaries and is guaranteed to build.
+
<li>Install Git, via either system packages or from the [http://git-scm.com/ Git] distribution.</li>
*Versions 3.4 through 4.2 are guaranteed to be binary (ABI) compatible, although SourceMod may not necessarily build out-of-box against them.
+
<li>Install a C++ compiler and dependencies. SourceMod officially supports clang. For example, on Ubuntu/Debian:
*Any GCC version below 3.4 '''cannot''' be used.
+
<pre>
 +
sudo apt-get install clang lib32stdc++-7-dev lib32z1-dev libc6-dev-i386 linux-libc-dev:i386
 +
</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>
  
==CPU==
+
==Archlinux==
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 [[Compiling SourceMod#Removing SSE|Removing SSE]] section near the bottom.
+
# 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>
  
Approximate compiling times for SourceMod's Core are roughly:
+
==Mac OS X==
*Windows, Core 2 Quad E6600: 30 seconds (using /MP)
+
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.
*Windows, Core 2 Duo E6600: 75 seconds
+
Newer versions are unsupported due to the removal of 32 bit support from MacOS.
*Windows, Centrino 1.8GHz: 5 minutes
 
*Linux, Core 2 Duo E6600: <= 1 minute
 
*Linux, P3 Dual 500MHz: >= 7 minutes
 
  
 +
<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>
  
=Setup=
+
=Downloading Source and Dependencies=
This section describes how to set up your computer for compiling.
 
  
==Getting the Files==
+
First, grab the SourceMod source tree. We recommend placing it inside its own folder, since we'll also need to download its dependencies.
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://subversion.tigris.org/ Subversion].  We have our own [[Subversion Tutorial]] if you prefer that method.  Although you do not need both HL2SDK versions (unless you wish to build binaries against both), you do need both Metamod:Source versions.  Extensions don't necessarily require Metamod:Source (or even the Source Engine) but its template library is used extensively in SourceMod.
+
'''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>
*SourceMod
+
mkdir -p alliedmodders
**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.
+
cd alliedmodders
*HL2SDK Ep1/Original.  As of this writing (Jan 2008) this engine is used for most Source games, except for TF and the newest Garry's Mod.
+
git clone --recursive https://github.com/alliedmodders/sourcemod
**Repository: [http://hg.alliedmods.net/hl2sdk hl2sdk]
+
</pre>
*HL2SDK Ep2/OrangeBox.  As of this writing (Jan 2008) this engine is used for TF and the newest Garry's Mod.
 
**Repository: [http://hg.alliedmods.net/hl2sdk-ob hl2sdk-ob]
 
*Metamod:Source 1.4.2+.  As of this writing (Jan 2008), 1.4.4 is the latest stable.
 
**Subversion: svn://svn.alliedmods.net/sourcemm/tags/sourcemm-1.4.4
 
**Web Tarballs: [http://svn.alliedmods.net/viewvc.cgi/tags/sourcemm-1.4.4/?root=sourcemm 1.4.4]
 
*Metamod:Source 1.6+.  As of this writing (Aug 2008), 1.6.2.
 
**Subversion: svn://svn.alliedmods.net/svnroot/sourcemm/tags/sourcemm-1.6.2
 
**Web Tarballs: [http://svn.alliedmods.net/viewvc.cgi/tags/sourcemm-1.6.2.tar.gz?root=sourcemm&view=tar 1.6.2]
 
 
 
'''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 "[http://dev.mysql.com/downloads/mysql/5.0.html#linux Linux (non RPM packages)]" for "Linux (x86)."  You can also use [http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.45-linux-i686-glibc23.tar.gz/from/pick 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://www.bailopan.net/mysql-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.
 
 
 
==Linux==
 
As of this writing, SourceMod's Makefiles are hardcoded to use a binary called "gcc-4.1"  You can override this, for example:
 
<pre>make CPP=gcc</pre>
 
 
 
Otherwise, you can also just create a symlink:
 
<pre>sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.1</pre>
 
 
 
Note that you must use <tt>gcc</tt> and not <tt>g++</tt>.
 
  
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:
+
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.)
*<tt>sourcemod</tt>/
 
**<tt>hl2sdk</tt> - symlink or folder containing the HL2SDK
 
**<tt>hl2sdk-ob</tt> - symlink or folder containing the HL2SDK for Orange Box/TF
 
**<tt>sourcemm-1.4</tt> - symlink or folder containing any Metamod:Source version 1.4.2 or higher.
 
**<tt>sourcemm-1.6</tt> - symlink or folder containing any Metamod:Source version 1.6 or higher.
 
**<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.0 sourcemod-1.0].
 
**<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:
 
 
<pre>
 
<pre>
#prerequisites
+
bash sourcemod/tools/checkout-deps.sh
#apt-get install g++-4.1 gcc-4.1 make subversion
 
#apt-get instal 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==
+
After it's done, you should see a large number of hl2sdk folders and other assorted dependencies, like MySQL, Metamod:Source, and AMBuild.
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 <tt>fixed-width font</tt> and their value descriptions follow.
+
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).
*<tt>SOURCEMM16</tt> - Path to Metamod:Source 1.6+
 
*<tt>SOURCEMM14</tt> - Path to Metamod:Source 1.4.2+
 
*<tt>HL2SDK</tt> - Path to HL2SDK Ep1/Original
 
*<tt>HL2SDKOB</tt> - Path to HL2SDK Ep2/OrangeBox
 
  
 +
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
  
=Building=
+
git clone https://github.com/alliedmodders/metamod-source mmsource-1.10 -b 1.10-dev
SourceMod has two types of binaries: those with an engine/MM:S dependence, and those without ("normal" binaries). Normal binaries have two modes:
 
*<tt>Release</tt> - Optimized binary for release.
 
*<tt>Debug</tt> - Unoptimized binary with debugging checks.
 
  
Engine/MM:S dependent binaries have three build modes, each paired with either Release or Debug, meaning there are six build options total. They are:
+
# If building version 1.10 of SourceMod, use MySQL 5.5
*<tt>Original</tt> - Building against MM:S 1.4.2+/HL2SDK
+
wget https://cdn.mysql.com/archives/mysql-5.5/mysql-5.5.54-win32.zip mysql-5.5
*<tt>Episode2</tt> - Building against MM:S 1.6+/HL2SDK-OB
 
  
==Linux==
+
# If building < version 1.10 of SourceMod, use MySQL 5.0
For both Normal and Engine/MM:S dependent binaries, 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.
+
wget https://cdn.mysql.com/archives/mysql-5.0/mysql-noinstall-5.0.24a-win32.zip mysql-5.0
  
'''Note:''' Our Makefiles are not set up to detect changes in header files. If you change a header file, you must clean your build.
+
# Install AMBuild
 +
git clone https://github.com/alliedmodders/ambuild
 +
pip install ./ambuild
 +
</pre>
  
===Normal Binaries===
+
Note that you can skip MySQL and SDK versions you don't plan to build.
For normal binaries, you can build simply with:
 
  
<pre>make</pre>
+
=Configuring=
  
You can clean stale object files with:
+
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.
<pre>make clean</pre>
 
  
Or build debug builds with:
+
First create a build folder within your sourcemod folder, and then run <tt>configure.py</tt>. For example:
<pre>make DEBUG=true</pre>
+
<pre>
 +
cd sourcemod
 +
mkdir build
 +
cd build
 +
python ../configure.py
 +
</pre>
  
===Dependent Binaries===
+
'''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
Binaries that have an Engine or MM:S dependency require one extra parameter, <tt>ENGINE</tt>.  It must be either <tt>orangebox</tt> or <tt>original</tt>. For example, to build a TF-compatible binary in debug mode:
 
  
<pre>make ENGINE=orangebox DEBUG=true</pre>
+
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).
  
Dependent binaries are dropped into one of the following folders:
+
It is safe to reconfigure over an old build. However, it's probably a bad idea to configure inside a random, non-empty folder.
*Debug.original
 
*Debug.orangebox
 
*Release.original
 
*Release.orangebox
 
  
==Windows==
+
There are a few extra options you can pass to <tt>configure</tt>:
Windows project files end with <tt>.vcproj</tt> and are found in an <tt>msvc8</tt> folder that resides inside each binary's main source folder. For example, Core is located in <tt>core/msvc8/sourcemod_mm.vcproj</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.
  
Once the file is opened, you can select which build to use by going to Build -> Configuration Manager. Normal binaries have simply "Debug" and "Release."  Dependent binaries have the following builds:
+
See configure.py for all the options.
*Debug - Old Metamod
 
*Debug - Episode 2
 
*Release - Old Metamod
 
*Release - Episode 2
 
  
'''Note''' that dependent binaries will have plain "Debug" and "Release" builds.  These should not be used as they are not configured.
+
=Building=
  
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>msvc8</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/msvc8/Debug - Old Metamod/sdktools.ext.dll</tt>
+
To build SourceMod, simply type:
 +
<pre>
 +
ambuild
 +
</pre>
  
'''Note:''' Visual Studio detects changes to header files intelligently.  It is usually not necessary to rebuild a solution.
+
In your build folder. Alternately, you can specify the path of the build folder:
 +
<pre>
 +
ambuild debug-build
 +
</pre>
  
 +
The full package layout that would be shipped for release is in the <tt>package</tt> folder of the build.
  
=Binary Organization=
+
=Deprecated Tools=
Although SourceMod has a somewhat unified building mechanism, each of the binaries has a different purpose. They can be separated into the following classes:
+
==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.
  
*Core-Related: Binaries which are required or loaded intrinsically by Core.
+
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,
*Extensions: Binaries which are loaded via the extension mechanism.
+
#Open the Control Panel (for example, via Start -> Settings).
*External: Binaries which are standalone or unrelated to SourceMod's live operation (for example, the compiler).
+
#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.
  
This article is only concerned with the first two types.
+
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.10+
==Core-Related Binaries==
+
*<tt>MMSOURCE18</tt> - Path to Metamod:Source 1.10+
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>HL2SDK</tt> - Path to HL2SDK Ep1/Original
 
+
*<tt>HL2SDKOB</tt> - Path to HL2SDK Ep2/OrangeBox for mods
*<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>HL2SDKOBVALVE</tt> - Path to HL2SDK Source 2009 (HL2:DM, DoD:S, TF2)
*<tt>core</tt> - This is Core itself, and is a dependent binary. It has three outputs:
+
*<tt>HL2SDK-SWARM</tt> - Path to HL2SDK Alien Swarm
**Original: <tt>sourcemod.1.ep1.so</tt>/<tt>sourcemod.1.ep1.dll</tt>
+
*<tt>HL2SDK-BGT</tt> - Path to HL2SDK for Bloody Good Time
**Episode 1: <tt>sourcemod.1.ep1.so</tt>/<tt>sourcemod.2.ep1.dll</tt> (unsupported, not packaged)
+
*<tt>HL2SDKCSGO</tt> - Path to HL2SDK CS:GO
**Episode 2: <tt>sourcemod.1.ep1.so</tt>/<tt>sourcemod.2.ep2.dll</tt>
+
*<tt>HL2SDKCSS</tt> - Path to HL2SDK CS:S
*<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>.
+
*<tt>HL2SDK-DARKM</tt> - Path to HL2SDK Dark Messiah
 
+
*<tt>HL2SDK-EYE</tt> - Path to HL2SDK E.Y.E.: Divine Cybermancy
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.
+
*<tt>HL2SDKL4D</tt> - Path to HL2SDK L4D1
 
+
*<tt>HL2SDKL4D2</tt> - Path to HL2SDK L4D2
==Extensions==
+
*<tt>HL2SDK-DOTA</tt> - Path to HL2SDK DOTA 2
Extensions are found in the <tt>extensions</tt> folder of the source tree.  SDKTools, Cstrike, and the upcoming TF extension are engine/MM:S dependent (and the rest are generally not).
+
*<tt>MYSQL5</tt> - Path to the folder that contains MySQL's <tt>include</tt> and <tt>lib</tt> folders.
 
 
Extensions always are named <tt>name.ext.so</tt> or <tt>name.ext.dll</tt> where <tt>name</tt> is a unique identifier. This is true even of dependent binaries.
 
 
 
When loading extensions, SourceMod looks in two separate folders.  First, it checks the ''dependent extension folder'', which is <tt>extensions/auto.x.y</tt> where <tt>x</tt> is the MM:S version (1 for 1.4, 2 for 1.6) and <tt>y</tt> is the Engine version (1 for Original/Ep1, 2 for Ep2/OrangeBox).  If no matching extension is found there, it looks in <tt>extensions</tt>.
 
 
 
For example, the SDKTools binary on Counter-Strike would be loaded from <tt>extensions/auto.1.ep1</tt>, but the GeoIP binary (which is not dependent) would be loaded from <tt>extensions</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.
 
  
 +
==Makefiles==
 +
Makefiles are deprecated and will be removed from the tree soon.
  
 
[[Category:SourceMod Documentation]]
 
[[Category:SourceMod Documentation]]
 
[[Category:SourceMod Development]]
 
[[Category:SourceMod Development]]

Revision as of 21:05, 25 March 2023

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 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.