Skip to content

Commit

Permalink
Merge branch 'master' into sci
Browse files Browse the repository at this point in the history
  • Loading branch information
nekonomicon committed Jan 15, 2024
2 parents a17ecb4 + b8e143f commit 845cdcd
Show file tree
Hide file tree
Showing 86 changed files with 1,353 additions and 2,012 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ jobs:
- name: Build on Linux
if: startsWith(matrix.os, 'ubuntu')
run: |
schroot --chroot steamrt_scout_i386 -- cmake -B build -S . -DCMAKE_EXE_LINKER_FLAGS="-Wl,--no-undefined" -DCMAKE_INSTALL_PREFIX="$PWD/dist"
schroot --chroot steamrt_scout_i386 -- cmake -DCMAKE_BUILD_TYPE=Release -DPOLLY=ON -B build -S . -DCMAKE_EXE_LINKER_FLAGS="-Wl,--no-undefined" -DCMAKE_INSTALL_PREFIX="$PWD/dist"
schroot --chroot steamrt_scout_i386 -- cmake --build build --target all
schroot --chroot steamrt_scout_i386 -- cmake --build build --target install
- name: Build on Linux with vgui
if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.cc, 'gcc')
run: |
schroot --chroot steamrt_scout_i386 -- cmake -B build-vgui -S . -DCMAKE_EXE_LINKER_FLAGS="-Wl,--no-undefined" -DUSE_VGUI=ON -DCMAKE_INSTALL_PREFIX="$PWD/dist-vgui"
schroot --chroot steamrt_scout_i386 -- cmake -DCMAKE_BUILD_TYPE=Release -DPOLLY=ON -B build-vgui -S . -DCMAKE_EXE_LINKER_FLAGS="-Wl,--no-undefined" -DUSE_VGUI=ON -DCMAKE_INSTALL_PREFIX="$PWD/dist-vgui"
cp vgui_support/vgui-dev/lib/vgui.so build-vgui/cl_dll
schroot --chroot steamrt_scout_i386 -- cmake --build build-vgui --target all
schroot --chroot steamrt_scout_i386 -- cmake --build build-vgui --target install
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ CMakeSettings.json
CMakeFiles
CMakeCache.txt
Makefile

# Android Studio/Gradle
.gradle/
.externalNativeBuild
.cxx/
.idea/
local.properties
.project
.classpath
.settings
152 changes: 65 additions & 87 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# SOFTWARE.
#

cmake_minimum_required(VERSION 2.8.12)
# 3.9 added captures in if(MATCHES)
cmake_minimum_required(VERSION 3.9)

if(NOT ${CMAKE_VERSION} VERSION_LESS "3.15.0")
cmake_policy(SET CMP0091 NEW)
Expand All @@ -32,6 +33,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include(CheckIncludeFile)
include(CheckCSourceCompiles)
include(VSForceXPToolchain) # Force XP toolchain for Visual Studio
include(CheckIPOSupported)

project (HLSDK-PORTABLE)

Expand All @@ -45,41 +47,67 @@ option(USE_NOVGUI_SCOREBOARD "Prefer non-VGUI Scoreboard when USE_VGUI is enable
option(USE_VOICEMGR "Enable VOICE MANAGER." OFF)
option(BUILD_CLIENT "Build client dll" ON)
option(BUILD_SERVER "Build server dll" ON)
option(POLLY "Enable pollyhedral optimization" OFF)

if (CMAKE_SIZEOF_VOID_P EQUAL 4 OR
if(CMAKE_SIZEOF_VOID_P EQUAL 4 OR
((WIN32 OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
AND (CMAKE_SYSTEM_PROCESSOR STREQUAL "x64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "X64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")))
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "X86_64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "EM64T")))
option(64BIT "Disable auto -m32 appending to compiler flags" OFF)
option(GOLDSOURCE_SUPPORT "Build goldsource compatible client library" ON)
else()
option(64BIT "Disable auto -m32 appending to compiler flags" ON)
option(GOLDSOURCE_SUPPORT "Build goldsource compatible client library" OFF)
endif()

option(BARNACLE_FIX_VISIBILITY "Enable barnacle tongue length fix" ON)
option(CLIENT_WEAPONS "Enable client local weapons prediction" ON)
option(CROWBAR_IDLE_ANIM "Enable crowbar idle animation" ON)
option(CROWBAR_DELAY_FIX "Enable crowbar attack delay fix" ON)
option(CROWBAR_FIX_RAPID_CROWBAR "Enable rapid crowbar fix" ON)
option(GAUSS_OVERCHARGE_FIX "Enable gauss overcharge fix" OFF)
option(TRIPMINE_BEAM_DUPLICATION_FIX "Enable fix of tripmine beam duplication on level transition" OFF)
option(HANDGRENADE_DEPLOY_FIX "Enable handgrenade deploy animation fix after finishing a throw" OFF)
option(WEAPONS_ANIMATION_TIMES_FIX "Enable animation times fix for some weapons" OFF)
option(OEM_BUILD "Enable OEM Build" OFF)
option(HLDEMO_BUILD "Enable Demo Build" OFF)

set(GAMEDIR "sci" CACHE STRING "Gamedir path")
set(SERVER_INSTALL_DIR "dlls" CACHE STRING "Where put server dll")
set(CLIENT_INSTALL_DIR "cl_dlls" CACHE STRING "Where put client dll")
set(SERVER_LIBRARY_NAME "game" CACHE STRING "Library name for PC platforms")
message(STATUS "Half-Life: Quest Mode")
# It seems CMAKE_SYSTEM_PROCESSOR parameter completely useless for APPLE platform,
# so may need to set options here manually.
if((WIN32 OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
AND (((CMAKE_SYSTEM_PROCESSOR STREQUAL "x64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "X64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "X86_64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "EM64T") AND NOT 64BIT)
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "X86"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "i386"))
option(GOLDSOURCE_SUPPORT "Build goldsource compatible client library" ON)
else()
option(GOLDSOURCE_SUPPORT "Build goldsource compatible client library" OFF)
endif()

#-----------------
# MAIN BUILD CODE \
###################\

file(STRINGS "mod_options.txt" MOD_OPTIONS_STRINGS REGEX "^([A-Za-z0-9_]+)=([A-Za-z0-9_]+)\ \#\ (.*)$")
foreach(LINE IN LISTS MOD_OPTIONS_STRINGS)
# file() itself doesn't populate CMAKE_MATCH_<n>, so
# reparse the string

if(${LINE} MATCHES "^([A-Za-z0-9_]+)=([A-Za-z0-9_]+)\ \#\ (.*)$")
# detect boolean options
if(${CMAKE_MATCH_2} STREQUAL "ON" OR ${CMAKE_MATCH_2} STREQUAL "OFF")
option(${CMAKE_MATCH_1} "${CMAKE_MATCH_3}" ${CMAKE_MATCH_2})

# let's check it here as well
if(${CMAKE_MATCH_1})
message(STATUS ${CMAKE_MATCH_3} " is enabled")
add_definitions(-D${CMAKE_MATCH_1})
else()
message(STATUS ${CMAKE_MATCH_3} " is disabled")
endif()
else()
set(${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE STRING "${CMAKE_MATCH_3}")
endif()
endif()
endforeach()

if(HLDEMO_BUILD AND OEM_BUILD)
message(FATAL_ERROR "Don't mix Demo and OEM builds!")
endif()
Expand Down Expand Up @@ -109,76 +137,11 @@ else()
message(STATUS "Building for 32 Bit")
endif()

if(CLIENT_WEAPONS)
message(STATUS "Client weapons enabled.")
add_definitions(-DCLIENT_WEAPONS)
endif()

if(BARNACLE_FIX_VISIBILITY)
message(STATUS "Barnacle tongue fix enabled")
add_definitions(-DBARNACLE_FIX_VISIBILITY)
endif()

if(CROWBAR_IDLE_ANIM)
message(STATUS "Crowbar idle animation enabled")
add_definitions(-DCROWBAR_IDLE_ANIM)
endif()

if(CROWBAR_DELAY_FIX)
message(STATUS "Crowbar attack delay fix enabled")
add_definitions(-DCROWBAR_DELAY_FIX)
endif()

if(CROWBAR_FIX_RAPID_CROWBAR)
message(STATUS "Rapid crowbar fix enabled")
add_definitions(-DCROWBAR_FIX_RAPID_CROWBAR)
endif()

if(GAUSS_OVERCHARGE_FIX)
message(STATUS "Gauss overcharge fix enabled")
add_definitions(-DGAUSS_OVERCHARGE_FIX)
endif()

if(TRIPMINE_BEAM_DUPLICATION_FIX)
message(STATUS "Tripmine beam duplication fix enabled")
add_definitions(-DTRIPMINE_BEAM_DUPLICATION_FIX)
endif()

if(HANDGRENADE_DEPLOY_FIX)
message(STATUS "Handgrenade deploy animation fix enabled")
add_definitions(-DHANDGRENADE_DEPLOY_FIX)
endif()

if(WEAPONS_ANIMATION_TIMES_FIX)
message(STATUS "Weapons animation times fix enabled")
add_definitions(-DWEAPONS_ANIMATION_TIMES_FIX)
endif()

if(OEM_BUILD)
message(STATUS "OEM build enabled")
add_definitions(-DOEM_BUILD)
endif()

if(HLDEMO_BUILD)
message(STATUS "Demo build enabled")
add_definitions(-DHLDEMO_BUILD)
endif()

if (MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--add-stdcall-alias")
endif()

# add_compile_options for older cmake versions
if(${CMAKE_VERSION} VERSION_LESS "3.0.2")
macro(add_compile_options)
set(list_var "${ARGV}")
foreach(arg IN LISTS list_var)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${arg}")
endforeach()
endmacro()
endif()

if(NOT MSVC)
#add_compile_options(-Wempty-body) # GCC/Clang flag
add_compile_options(-Wreturn-type) # GCC/Clang flag
Expand All @@ -190,6 +153,13 @@ if(VITA)
add_compile_options(-fno-use-cxa-atexit)
endif()

check_ipo_supported(RESULT HAVE_LTO OUTPUT LTO_ERROR)
if(HAVE_LTO)
message(STATUS "IPO / LTO enabled")
else()
message(STATUS "IPO / LTO not supported: <${LTO_ERROR}>")
endif()

check_include_file("tgmath.h" HAVE_TGMATH_H)
if(HAVE_TGMATH_H)
if(NOT MSVC)
Expand All @@ -216,3 +186,11 @@ endif()
if(NOT BUILD_SERVER AND NOT BUILD_CLIENT)
message(FATAL_ERROR "Nothing to build")
endif()

if(POLLY)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-mllvm -polly)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fgraphite-identity -floop-interchange -floop-block)
endif()
endif()
63 changes: 53 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ git clone --recursive https://github.com/FWGS/hlsdk-portable

### Prerequisites

Install and run [Visual Studio Installer](https://visualstudio.microsoft.com/downloads/). The installer allows you to choose specific components. Select `Desktop development with C++`. You can untick everything you don't need in Installation details, but you must keep `MSVC` ticked. You may also keep `C++ CMake tools for Windows` ticked as you'll need **cmake**. Alternatively you can install **cmake** from the [cmake.org](https://cmake.org/download/) and during installation tick *Add to the PATH...*.
Install and run [Visual Studio Installer](https://visualstudio.microsoft.com/downloads/). The installer allows you to choose specific components. Select `Desktop development with C++`. You can untick everything you don't need in Installation details, but you must keep `MSVC` and corresponding Windows SDK (e.g. Windows 10 SDK or Windows 11 SDK) ticked. You may also keep `C++ CMake tools for Windows` ticked as you'll need **cmake**. Alternatively you can install **cmake** from the [cmake.org](https://cmake.org/download/) and during installation tick *Add to the PATH...*.

### Opening command prompt

Expand Down Expand Up @@ -164,7 +164,7 @@ sudo ./setup_chroot.sh --i386 --tarball ./com.valvesoftware.SteamRuntime.Sdk-i38

Now you can use cmake and make prepending the commands with `schroot --chroot steamrt_scout_i386 --`:
```
schroot --chroot steamrt_scout_i386 -- cmake -B build-in-steamrt -S .
schroot --chroot steamrt_scout_i386 -- cmake -DCMAKE_BUILD_TYPE=Release -B build-in-steamrt -S .
schroot --chroot steamrt_scout_i386 -- cmake --build build-in-steamrt
```

Expand All @@ -180,13 +180,20 @@ sudo apt install cmake build-essential gcc-multilib g++-multilib libsdl2-dev:i38
### Building

```
cmake -B build -S .
cmake -DCMAKE_BUILD_TYPE=Release -B build -S .
cmake --build build
```

Note that the libraries built this way might be not compatible with Steam Half-Life. If you have such issue you can configure it to build statically with c++ and gcc libraries:
```
cmake .. -DCMAKE_C_FLAGS="-static-libstdc++ -static-libgcc"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc" -B build -S .
cmake --build build
```

Alternatively, you can avoid libstdc++/libgcc_s linking using small libsupc++ library and optimization build flags instead(Really just set Release build type and set C compiler as C++ compiler):
```
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=cc -B build -S .
cmake --build build
```
To ensure portability it's still better to build using Steam Runtime or another chroot of some older distro.

Expand Down Expand Up @@ -229,13 +236,36 @@ Insert your actual user name in place of `yourusername`.

Prepend any make or cmake call with `schroot -c jessie --`:
```
schroot --chroot jessie -- cmake -B build-in-chroot -S .
schroot --chroot jessie -- cmake -DCMAKE_BUILD_TYPE=Release -B build-in-chroot -S .
schroot --chroot jessie -- cmake --build build-in-chroot
```

## Android
1. Set up [Android Studio/Android SDK](https://developer.android.com/studio).

### Android Studio
Open the project located in the `android` folder and build.

### Command-line
```
cd android
./gradlew assembleRelease
```

### Customizing the build
settings.gradle:
* **rootProject.name** - project name displayed in Android Studio (optional).

TODO
app/build.gradle:
* **android->namespace** and **android->defaultConfig->applicationId** - set both to desired package name.
* **getBuildNum** function - set **releaseDate** variable as desired.

app/java/su/xash/hlsdk/MainActivity.java:
* **.putExtra("gamedir", ...)** - set desired gamedir.

src/main/AndroidManifest.xml:
* **application->android:label** - set desired application name.
* **su.xash.engine.gamedir** value - set to same as above.

## Nintendo Switch

Expand Down Expand Up @@ -307,7 +337,13 @@ Install C and C++ compilers (like gcc or clang), cmake and make.
### Building

```
cmake -B build -S .
cmake -DCMAKE_BUILD_TYPE=Release -B build -S .
cmake --build build
```

Force 64-bit build:
```
cmake -DCMAKE_BUILD_TYPE=Release -D64BIT=1 -B build -S .
cmake --build build
```

Expand All @@ -316,15 +352,22 @@ cmake --build build
To use waf, you need to install python (2.7 minimum)

```
(./waf configure -T release)
(./waf)
./waf configure -T release
./waf
```

Force 64-bit build:
```
./waf configure -T release -8
./waf
```

## Build options

Some useful build options that can be set during the cmake step.

* **GOLDSOURCE_SUPPORT** - allows to turn off/on the support for GoldSource input. Set to **ON** by default on Windows and Linux, **OFF** on other platforms.
* **GOLDSOURCE_SUPPORT** - allows to turn off/on the support for GoldSource input. Set to **ON** by default on x86 Windows and x86 Linux, **OFF** on other platforms.
* **64BIT** - allows to turn off/on 64-bit build. Set to **OFF** by default on x86_64 Windows, x86_64 Linux and 32-bit platforms, **ON** on other 64-bit platforms.
* **USE_VGUI** - whether to use VGUI library. **OFF** by default. You need to init `vgui_support` submodule in order to build with VGUI.

This list is incomplete. Look at `CMakeLists.txt` to see all available options.
Expand Down
Loading

0 comments on commit 845cdcd

Please sign in to comment.