Skip to content

Commit

Permalink
Merge branch 'opfor' into opforfixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nekonomicon committed Jan 15, 2024
2 parents c70bf28 + f2ab36c commit f83bf47
Show file tree
Hide file tree
Showing 27 changed files with 610 additions and 2,271 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
43 changes: 40 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,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 @@ -46,16 +47,37 @@ 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)
endif()

# 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()

Expand Down Expand Up @@ -131,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 @@ -157,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()
61 changes: 52 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
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
73 changes: 73 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import java.time.LocalDateTime
import java.time.Month
import java.time.temporal.ChronoUnit

apply plugin: 'com.android.application'

android {
ndkVersion '26.1.10909125'
namespace 'com.example.hlsdk'

defaultConfig {
applicationId 'com.example.hlsdk'
versionName '1.0'
versionCode getBuildNum()
minSdkVersion 3
targetSdk 34
compileSdk 34

externalNativeBuild {
cmake {
arguments '-DPOLLY=ON'
}
}
}

externalNativeBuild {
cmake {
version '3.22.1'
path file('../../CMakeLists.txt')
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
debug {
minifyEnabled false
shrinkResources false
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

lint {
abortOnError false
}

androidResources {
noCompress += ''
}

packagingOptions {
jniLibs {
useLegacyPackaging = true
}
}
}

static def getBuildNum() {
LocalDateTime now = LocalDateTime.now()
LocalDateTime releaseDate = LocalDateTime.of(2023, Month.DECEMBER, 28, 0, 0, 0)
int qBuildNum = releaseDate.until(now, ChronoUnit.DAYS)
int minuteOfDay = now.getHour() * 60 + now.getMinute()
return qBuildNum * 10000 + minuteOfDay
}
34 changes: 34 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:forceQueryable="true"
android:icon="@android:mipmap/sym_def_app_icon"
android:label="hlsdk-portable"
tools:targetApi="r">

<meta-data
android:name="su.xash.engine.gamedir"
android:value="valve" />

<activity
android:name="su.xash.hlsdk.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="su.xash.engine.MOD" />
</intent-filter>
</activity>
</application>

<queries>
<package android:name="su.xash.engine" />
<package android:name="su.xash.engine.test" />
</queries>
</manifest>
37 changes: 37 additions & 0 deletions android/app/src/main/java/su/xash/hlsdk/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package su.xash.hlsdk;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

String pkg = "su.xash.engine.test";

try {
getPackageManager().getPackageInfo(pkg, 0);
} catch (PackageManager.NameNotFoundException e) {
try {
pkg = "su.xash.engine";
getPackageManager().getPackageInfo(pkg, 0);
} catch (PackageManager.NameNotFoundException ex) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=su.xash.engine")).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
finish();
return;
}
}

startActivity(new Intent().setComponent(new ComponentName(pkg, "su.xash.engine.XashActivity"))
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
.putExtra("gamedir", "valve")
.putExtra("gamelibdir", getApplicationInfo().nativeLibraryDir)
.putExtra("package", getPackageName()));
finish();
}
}
17 changes: 17 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
buildscript {
repositories {
mavenCentral()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:8.2.0'
}
}

allprojects {
repositories {
mavenCentral()
google()
}
}
Loading

0 comments on commit f83bf47

Please sign in to comment.