Difference between revisions of "Building SourceMod"

From AlliedModders Wiki
Jump to: navigation, search
(New page: 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 dir...)
 
m (Adjust linux deps command)
 
(121 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 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 dpkg --add-architecture i386; sudo apt update; 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.  That means if you try to build it on a 64-bit compiler, it will fail to build or load.  On Windows this should not be a problem, but a 64-bit Linux machine may build 64-bit binaries by default.  If this is the case, you may need to edit the CFLAGS line of the Makefile(s) to have -m32 (which tells GCC to build 32-bit libraries).
 
  
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>
 +
mkdir -p alliedmodders
 +
cd alliedmodders
 +
git clone --recursive https://github.com/alliedmodders/sourcemod
 +
</pre>
  
*SourceMod (here we're using trunk since there are no tagged releases yet)
+
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.)
**For full download options, see the [http://www.sourcemod.net/builds.php SourceMod Builds] page.  Obviously, you must download the source code and not a binary package.
+
<pre>
*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.
+
bash sourcemod/tools/checkout-deps.sh
**Subversion: [svn://svn.alliedmods.net/svnroot/sourcemm/hl2sdk svn://svn.alliedmods.net/svnroot/sourcemm/hl2sdk]
+
</pre>
**Web Tarball: [http://svn.alliedmods.net/viewvc.cgi/hl2sdk.tar.gz?root=sourcemm&view=tar click here]
 
*HL2SDK Ep2/OrangeBox.  As of this writing (Jan 2008) this engine is used for TF and the newest Garry's Mod.
 
**Subversion: [svn://svn.alliedmods.net/svnroot/sourcemm/hl2sdk-ob svn://svn.alliedmods.net/svnroot/sourcemm/hl2sdk-ob]
 
**Web Tarball: [http://svn.alliedmods.net/viewvc.cgi/hl2sdk-ob/?root=sourcemm click here]
 
*Metamod:Source 1.4.2+. As of this writing (Jan 2008), 1.4.2 is the latest stable and 1.4.3 is the development version.  You should check to see if there is a newer version and use it as appropriate.
 
**Subversion: svn://svn.alliedmods.net/sourcemm/tags/sourcemm-1.4.2 (Change the version number for later releases)
 
**Subversion: svn://svn.alliedmods.net/sourcemm/branches/sourcemm-1.4.3 (Latest development version)
 
**Web Tarballs: [http://svn.alliedmods.net/viewvc.cgi/tags/sourcemm-1.4.2/?root=sourcemm 1.4.2] or [http://svn.alliedmods.net/viewvc.cgi/branches/sourcemm-1.4.3.tar.gz?root=sourcemm&view=tar 1.4.3-devel]
 
*Metamod:Source 1.6+.  As of this writing (Jan 2008), 1.6.0 is still the trunk version and has not had a stable release.  When a stable release does come out, it will be tagged similarly to 1.4.2 as above and should be retrieved using that method instead, as trunk is always development.
 
**Subversion: svn://svn.alliedmods.net/sourcemm/trunk (Currently 1.6.0-devel)
 
**Web Tarballs: [http://svn.alliedmods.net/viewvc.cgi/trunk.tar.gz?root=sourcemm&view=tar 1.6.0-devel]
 
  
'''Note''' that when we refer to "Metamod:Source" in this article, we are referring to its source code tree, not a binary package.
+
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 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:
+
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).
*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.
+
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
  
==Linux==
+
git clone https://github.com/alliedmodders/metamod-source mmsource-1.10 -b 1.10-dev
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:
 
*<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.2</tt> - symlink or folder containing any Metamod:Source version 1.4.2 or higher.
 
**<tt>sourcemm</tt> - symlink or folder containing any Metamod:Source version 1.6 or higher.
 
**<tt>trunk</tt> - folder containing SourceMod's source code tree.  This can be named anything; we have called it trunk to represent that it came from /svnroot/sourcemod/trunk.
 
**<tt>mysql-5.0</tt> - symlink or folder containing a MySQL 5.0 distribution
 
  
==Windows==
+
# If building version 1.10 of SourceMod, use MySQL 5.5
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.
+
wget https://cdn.mysql.com/archives/mysql-5.5/mysql-5.5.54-win32.zip mysql-5.5
*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 building < version 1.10 of SourceMod, use MySQL 5.0
*<tt>SOURCEMM</tt> - Path to Metamod:Source 1.6+
+
wget https://cdn.mysql.com/archives/mysql-5.0/mysql-noinstall-5.0.24a-win32.zip mysql-5.0
*<tt>SOURCEMM142</tt> - Path to Metamod:Source 1.4.2+
 
*<tt>HL2SDK</tt> - Path to HL2SDK Ep1/Original
 
*<tt>HL2SDKOB</tt> - Path to HL2SDK Ep2/OrangeBox
 
  
 +
# Install AMBuild
 +
git clone https://github.com/alliedmodders/ambuild
 +
pip install ./ambuild
 +
</pre>
  
=Building=
+
Note that you can skip MySQL and SDK versions you don't plan to build.
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:
+
=Configuring=
*<tt>Original</tt> - Building against MM:S 1.4.2+/HL2SDK
 
*<tt>Episode1</tt> - Building against MM:S 1.6+/HL2SDK (Unsupported)
 
*<tt>Episode2</tt> - Building against MM:S 1.6+/HL2SDK-OB
 
  
==Linux==
+
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.
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.
 
  
'''Note:''' Our Makefiles are not set up to detect changes in header files.  If you change a header file, you must clean your build.
+
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>
  
===Normal 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
For normal binaries, you can build simply with:
 
  
<pre>make</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).
  
You can clean stale object files with:
+
It is safe to reconfigure over an old build. However, it's probably a bad idea to configure inside a random, non-empty folder.
<pre>make clean</pre>
 
  
Or build debug builds with:
+
There are a few extra options you can pass to <tt>configure</tt>:
<pre>make debug</pre>
+
*--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.
  
===Dependent Binaries===
+
See configure.py for all the options.
Binaries that have an Engine or MM:S dependency will have one or more of the following Makefiles. Note that these refer to the build types mentioned earlier.
 
*<tt>Makefile.orig</tt> - Original build.
 
*<tt>Makefile.ep1</tt> - Episode1 build (unsupported).
 
*<tt>Makefile.ep2</tt> - Episode2 build.
 
  
The only difference with using these Makefiles is that you must specify <tt>-f &lt;file></tt>.  For example, to build a TF-compatible binary in debug mode:
+
=Building=
  
<pre>make -f Makefile.ep2 debug</pre>
+
To build SourceMod, simply type:
 +
<pre>
 +
ambuild
 +
</pre>
  
'''Note:''' The <tt>Release</tt> and <tt>Debug</tt> outputs folders are used for each Makefile, and thus it is imperative you clean the object cache before proceeding to build another.
+
In your build folder. Alternately, you can specify the path of the build folder:
 +
<pre>
 +
ambuild debug-build
 +
</pre>
  
==Windows==
+
The full package layout that would be shipped for release is in the <tt>package</tt> folder of the build.
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>.
 
  
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:
+
=Deprecated Tools=
*Debug - Old Metamod
+
==Visual Studio Project Files==
*Debug - Episode 1 (unsupported)
+
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.
*Debug - Episode 2
 
*Release - Old Metamod
 
*Release - Episode 1 (unsupported)
 
*Release - Episode 2
 
  
'''Note''' that dependent binaries will have plain "Debug" and "Release" builds. These should not be used as they are not configured.
+
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.
  
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>
+
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+
'''Note:''' Visual Studio detects changes to header files intelligently.  It is usually not necessary to rebuild a solution.
+
*<tt>MMSOURCE18</tt> - Path to Metamod:Source 1.10+
 
+
*<tt>HL2SDK</tt> - Path to HL2SDK Ep1/Original
 
+
*<tt>HL2SDKOB</tt> - Path to HL2SDK Ep2/OrangeBox for mods
=Binary Organization=
+
*<tt>HL2SDKOBVALVE</tt> - Path to HL2SDK Source 2009 (HL2:DM, DoD:S, TF2)
Although SourceMod has a somewhat unified building mechanism, each of the binaries has a different purpose.  They can be separated into the following classes:
+
*<tt>HL2SDK-SWARM</tt> - Path to HL2SDK Alien Swarm
 
+
*<tt>HL2SDK-BGT</tt> - Path to HL2SDK for Bloody Good Time
*Core-Related: Binaries which are required or loaded intrinsically by Core.
+
*<tt>HL2SDKCSGO</tt> - Path to HL2SDK CS:GO
*Extensions: Binaries which are loaded via the extension mechanism.
+
*<tt>HL2SDKCSS</tt> - Path to HL2SDK CS:S
*External: Binaries which are standalone or unrelated to SourceMod's live operation (for example, the compiler).
+
*<tt>HL2SDK-DARKM</tt> - Path to HL2SDK Dark Messiah
 
+
*<tt>HL2SDK-EYE</tt> - Path to HL2SDK E.Y.E.: Divine Cybermancy
This article is only concerned with the first two types. 
+
*<tt>HL2SDKL4D</tt> - Path to HL2SDK L4D1
 
+
*<tt>HL2SDKL4D2</tt> - Path to HL2SDK L4D2
==Core-Related Binaries==
+
*<tt>HL2SDK-DOTA</tt> - Path to HL2SDK DOTA 2
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>MYSQL5</tt> - Path to the folder that contains MySQL's <tt>include</tt> and <tt>lib</tt> folders.
 
 
*<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 three outputs:
 
**Original: <tt>sourcemod.1.ep1.so</tt>/<tt>sourcemod.1.ep1.dll</tt>
 
**Episode 1: <tt>sourcemod.1.ep1.so</tt>/<tt>sourcemod.2.ep1.dll</tt> (unsupported, not packaged)
 
**Episode 2: <tt>sourcemod.1.ep1.so</tt>/<tt>sourcemod.2.ep2.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 upcoming TF extension are engine/MM:S dependent (and the rest are generally not).
 
 
 
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.  The closed-source binary, <tt>sourcepawn.jit.x86</tt>, is not compiled with SSE, and thus you do not have to worry about it.
 
 
 
==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.
 
 
 
 
 
=Future Changes=
 
It is likely in the future that the environment vars will change:
 
*<tt>SOURCEMM142</tt> -> <tt>SOURCEMM14</tt>
 
*<tt>SOURCEMM</tt> -> <tt>SOURCEMM16</tt>
 
 
 
The Linux Makefiles may change to use different output folders for dependent binaries.  Similarly, the separate file idea may be scrapped to combine different builds into one file.
 
  
If such changes are made, this document will be updated.
+
==Makefiles==
 +
Makefiles are deprecated and will be removed from the tree soon.
  
 
[[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.