garrysmod_common

repository·master·Indexed 41 days ago

https://github.com/danielga/garrysmod_common

A collection of common build tools, headers, and Premake scripts for developing Garry's Mod C++ modules and Source SDK-based projects. It provides helper functions for workspace and project creation, SDK header inclusion, and tools for remote Linux debugging in Visual Studio.

Tokens
1.6K
Snippets
3
Records
7
Agent score
50%

What's inside garrysmod_common

  1. Customise Linux debugging project settings

    master

    You can modify the .vcxproj file to adapt the remote debugging environment to your specific setup.

    Required Customisations

    • GCC Version Suffix: Modify <RemoteCompileToolExeSuffix> to specify the gcc version suffix. Leave it empty to use the system's default gcc.
    • SRCDS Location: Update <RemoteSRCDSDir> to point to the directory where your Source Dedicated Server (SRCDS) is installed on the remote Linux machine.

    Optional Customisations

    • Files to Copy: Use the <FilesToCopy> tag to define which local files should be synchronized to the remote system. This is useful for including headers or configuration files. You can append new paths using a semicolon (;) separator.
    <!-- Example of modifying the FilesToCopy tag to include an includes directory -->
    <FilesToCopy Include="../../../source/**/*;../../../license.txt;../../../premake5.lua;../../../readme.md;../../../includes/**/*" />
  2. Integrate garrysmod_common into your Premake project

    master

    To use garrysmod_common in your own C++ compilation project, include it in your premake5.lua file. You can specify the path via a custom premake option gmcommon or by setting the GARRYSMOD_COMMON environment variable.

    Note: To enable x86-64 binary compilation, you must set PROJECT_GENERATOR_VERSION = 3 before including the repository.

    PROJECT_GENERATOR_VERSION = 2
    
    newoption({
        trigger = "gmcommon",
        description = "Sets the path to the garrysmod_common (https://github.com/danielga/garrysmod_common) directory",
        value = "path to garrysmod_common directory"
    })
    
    local gmcommon = assert(_OPTIONS.gmcommon or os.getenv("GARRYSMOD_COMMON"),
        "you didn't provide a path to your garrysmod_common (https://github.com/danielga/garrysmod_common) directory")
    include(gmcommon)
  3. Enable auto-installation of compiled files

    master

    You can instruct the project to automatically install compiled files to a specific directory using the following methods:

    1. Automatic/Environment-based: Append the --autoinstall flag to your command. It will use the GARRYSMOD_LUA_BIN environment variable, an automatic path finder, or the DEFAULT_GARRYSMOD_LUA_BIN_DIRECTORY defined in your config.lua.
    2. Explicit Path: Append --autoinstall=path to your command to specify a custom directory.
  4. Set up Visual Studio templates for remote Linux debugging

    master

    To debug Linux Garry's Mod modules remotely using Visual Studio, you must use the provided template project files. Choose the pair that matches your module's target branch:

    • Main branch: debugging_linux.vcxproj and debugging_linux.vcxproj.user
    • x86-64 branch: debugging_linux_x86_64.vcxproj and debugging_linux_x86_64.vcxproj.user

    Setup Steps:

    1. Copy the chosen pair of files into the directory containing your Premake5-generated Visual Studio project files.
    2. Rename both files to gmsv_[MODULE_NAME]_linux (preserving their original extensions, e.g., .vcxproj and .vcxproj.user). Replace [MODULE_NAME] with your actual module name.
    3. Manually add these renamed files to your existing Visual Studio solution.
  5. Compilation requirements and ABI compatibility warnings

    master

    To maintain ABI compatibility with Garry's Mod, follow these platform-specific rules:

    Windows

    • Use Visual Studio 2015, 2017, or 2019.

    Linux

    • Use GCC (tested up to GCC 9; older versions like GCC 4 or 5 may cause C++ compilation errors).

    macOS

    • Any Xcode (using the GCC compiler) version might work.
    • Requirement: Use the Mac OSX 10.7 SDK and compile in release mode.

    Important Restrictions

    Do not use internal classes/structures (e.g., GameDepot::System or IGamemodeSystem::Information) unless you are compiling in release mode on Windows/Linux, or using the Mac OSX 10.7 SDK in release mode on macOS.

    If you encounter errors, ensure your files use the correct line endings (\n) for your target OS.

  6. Configure the workspace and projects using garrysmod_common

    master

    Once garrysmod_common is included, use its helper functions to set up your build environment.

    CreateWorkspace

    Creates the workspace. Must be called at least once before other functions.

    • name: The workspace name.
    • allow_debug: (Optional) Whether to include a debug compilation mode (defaults to true).
    • path: (Optional) The workspace path.

    CreateProject

    Creates a project for the specified state.

    • serverside: (Boolean) Whether the project is server-side.
    • manual_files: (Optional) If true, allows adding source/header files manually via the files function. Defaults to false.
    • source_path: (Optional) Path for source files. Can also be set via --source=path premake option.
    CreateWorkspace({
        name = workspace_name,
        allow_debug = workspace_add_debug, -- optional
        path = workspace_path -- optional
    })
    
    CreateProject({
        serverside = project_serverside,
        manual_files = project_manual_files, -- optional
        source_path = project_source_path -- optional
    })
  7. Include headers and submodules

    master

    Use these functions to include the necessary Garry's Mod headers, LuaJIT headers, and submodules (like detouring and scanning) into your project. Source SDK-based projects do not require a separate SDK path as it is provided via this repository.

    Extended/Submodule Helpers:

    • IncludeHelpersExtended(): Uses this repository path.
    • IncludeLuaShared(): Uses this repository path.
    • IncludeDetouring(): Uses the detouring submodule.
    • IncludeScanning(): Uses the scanning submodule.

    SDK Helpers:

    • IncludeSDKCommon()
    • IncludeSDKTier0()
    • IncludeSDKTier1()
    • IncludeSDKTier2()
    • IncludeSDKTier3()
    • IncludeSDKMathlib()
    • IncludeSDKRaytrace()
    • IncludeSteamAPI()