Skip to content

Commit 46bbf8d

Browse files
Add OpenSSL submodule and build integration
Add OpenSSL as a git submodule and integrate it into the build system. GetOpenSSL.cmake now uses ExternalProject to build OpenSSL for the nxdk toolchain and creates imported OpenSSL::Crypto/OpenSSL::SSL targets; moonlight-common-c is made to depend on the openssl_external target when available. Update CMakeLists and find modules: fix CMakePresets binary dir path, add NXDK ws2_32 linking for enet and moonlight-common-c, convert SDL2 to an imported NXDK::SDL2 target, and adjust NXDK include paths. Improve build scripts and wrappers: add build-mingw64.bat and build-mingw64.sh to launch MSYS2/mingw64 builds, and rewrite build.sh to be more robust (set -euo pipefail), support --build-dir and --clean, honor NXDK_DIR env, and use cmake -B for out-of-tree builds. Update README with submodule instructions, build directory options, and wrapper usage. Minor tests CMakeLists fixes and update third-party submodule commits.
1 parent e5fd376 commit 46bbf8d

File tree

14 files changed

+282
-63
lines changed

14 files changed

+282
-63
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,8 @@ jobs:
131131
132132
- name: Build
133133
run: |
134-
export NXDK_DIR="$(pwd)/third-party/nxdk"
135-
eval "$(${NXDK_DIR}/bin/activate -s)"
136-
cd "${NXDK_DIR}"
137-
make NXDK_ONLY=y
138-
make tools
139-
140-
cd "${GITHUB_WORKSPACE}"
141-
mkdir -p build
142-
143-
# the main target needs to be cross compiled
144-
echo "--- Building ALL ---"
145-
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE="${NXDK_DIR}/share/toolchain-nxdk.cmake"
146-
cmake --build build
134+
chmod +x build.sh
135+
./build.sh
147136
148137
# TODO: Tests are not building properly...
149138
# the tests target should not be cross compiled, so we can run it on the runner

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
path = third-party/nxdk
1111
url = https://github.com/XboxDev/nxdk.git
1212
branch = master
13+
[submodule "third-party/openssl"]
14+
path = third-party/openssl
15+
url = https://github.com/openssl/openssl.git
16+
branch = master

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ include(GetOpenSSL REQUIRED)
7676
set(ENET_NO_INSTALL ON CACHE BOOL "Don't install any libraries built for enet")
7777
set(BUILD_SHARED_LIBS OFF)
7878
add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c")
79-
target_link_libraries(enet PUBLIC NXDK::NXDK NXDK::Net)
79+
if(TARGET moonlight-common-c AND TARGET openssl_external)
80+
add_dependencies(moonlight-common-c openssl_external)
81+
endif()
82+
target_link_libraries(enet PUBLIC NXDK::NXDK NXDK::Net NXDK::ws2_32)
83+
if(TARGET moonlight-common-c)
84+
target_link_libraries(moonlight-common-c PRIVATE NXDK::ws2_32)
85+
endif()
8086

8187
add_executable(${CMAKE_PROJECT_NAME}
8288
${MOONLIGHT_SOURCES}

CMakePresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"generator": "MSYS Makefiles",
1414
"cmakeExecutable": "C:/msys64/usr/bin/cmake",
1515
"toolchainFile": "${sourceDir}/third-party/nxdk/share/toolchain-nxdk.cmake",
16-
"binaryDir": "${sourceDir}/cmake-build-nxdx-release",
16+
"binaryDir": "${sourceDir}/cmake-build-nxdk-release",
1717
"environment": {
1818
"NXDK_DIR": "${sourceDir}/third-party/nxdk",
1919
"PATH": "C:/msys64/mingw64/bin;C:/msys64/usr/bin;$penv{PATH}"

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ Nothing works, except the splash screen.
1313

1414
## Build
1515

16-
### Pre Build
16+
### Pre-Build
1717

18-
1. Install nxdk prerequisites. Then run the following from mingw64 or bash shell:
18+
1. Clone the repository with submodules, or update them after cloning.
19+
20+
```bash
21+
git submodule update --init --recursive
22+
```
23+
24+
2. Install nxdk prerequisites. Then run the following from mingw64 or bash shell:
1925

2026
```bash
2127
export NXDK_DIR="$(pwd)/third-party/nxdk"
@@ -53,6 +59,24 @@ This script takes care of everything, except installing the prerequisites.
5359
./build.sh
5460
```
5561

62+
The default build directory is `build`. You can override it or force a clean build:
63+
64+
```bash
65+
./build.sh --build-dir cmake-build-nxdk-release
66+
./build.sh --clean
67+
./build.sh build clean
68+
```
69+
70+
To launch the same build from shells outside MSYS2 on Windows, use one of these wrappers:
71+
72+
```bat
73+
build-mingw64.bat
74+
```
75+
76+
```bash
77+
./build-mingw64.sh
78+
```
79+
5680
## Todo:
5781

5882
- Build

build-mingw64.bat

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@echo off
2+
setlocal
3+
4+
set "SCRIPT_DIR=%~dp0"
5+
set "MSYS2_SHELL=C:\msys64\msys2_shell.cmd"
6+
7+
if not exist "%MSYS2_SHELL%" (
8+
echo MSYS2 shell not found at %MSYS2_SHELL%
9+
exit /b 1
10+
)
11+
12+
pushd "%SCRIPT_DIR%" >nul
13+
call "%MSYS2_SHELL%" -defterm -here -no-start -mingw64 -c "./build.sh %*"
14+
set "EXIT_CODE=%ERRORLEVEL%"
15+
popd >nul
16+
17+
exit /b %EXIT_CODE%

build-mingw64.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
6+
MSYS2_SHELL="/c/msys64/msys2_shell.cmd"
7+
8+
if [ ! -f "${MSYS2_SHELL}" ]; then
9+
echo "MSYS2 shell not found at ${MSYS2_SHELL}"
10+
exit 1
11+
fi
12+
13+
BUILD_ARGS=""
14+
for ARG in "$@"; do
15+
ESCAPED_ARG=$(printf "%s" "${ARG}" | sed "s/'/'\\''/g")
16+
BUILD_ARGS="${BUILD_ARGS} '${ESCAPED_ARG}'"
17+
done
18+
19+
cd "${SCRIPT_DIR}"
20+
exec "${MSYS2_SHELL}" -defterm -here -no-start -mingw64 -c "./build.sh${BUILD_ARGS}"

build.sh

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,101 @@
11
#!/bin/bash
22

33
# Exit immediately if a command exits with a non-zero status
4-
set -e
4+
set -euo pipefail
5+
6+
usage() {
7+
echo "Usage: $0 [--build-dir <dir> | <dir>] [--clean|clean] [--distclean|distclean]"
8+
}
9+
10+
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
BUILD_DIR="build"
12+
CLEAN_BUILD=0
13+
DISTCLEAN_BUILD=0
14+
POSITIONAL_BUILD_DIR_SET=0
15+
16+
while [ "$#" -gt 0 ]; do
17+
case "$1" in
18+
--build-dir|-B)
19+
if [ "$#" -lt 2 ]; then
20+
usage
21+
exit 1
22+
fi
23+
BUILD_DIR="$2"
24+
POSITIONAL_BUILD_DIR_SET=1
25+
shift 2
26+
;;
27+
--clean|clean)
28+
CLEAN_BUILD=1
29+
shift
30+
;;
31+
--distclean|distclean)
32+
DISTCLEAN_BUILD=1
33+
CLEAN_BUILD=1
34+
shift
35+
;;
36+
-h|--help)
37+
usage
38+
exit 0
39+
;;
40+
*)
41+
if [ "${POSITIONAL_BUILD_DIR_SET}" -eq 0 ]; then
42+
BUILD_DIR="$1"
43+
POSITIONAL_BUILD_DIR_SET=1
44+
shift
45+
else
46+
echo "Unknown argument: $1"
47+
usage
48+
exit 1
49+
fi
50+
;;
51+
esac
52+
done
53+
54+
case "${BUILD_DIR}" in
55+
/*)
56+
BUILD_DIR_PATH="${BUILD_DIR}"
57+
;;
58+
*)
59+
BUILD_DIR_PATH="${PROJECT_ROOT}/${BUILD_DIR}"
60+
;;
61+
esac
562

663
# Set the NXDK_DIR environment variable
7-
NXDK_DIR="$(pwd)/third-party/nxdk"
8-
export NXDK_DIR
64+
export NXDK_DIR="${NXDK_DIR:-${PROJECT_ROOT}/third-party/nxdk}"
65+
66+
if [ ! -d "${NXDK_DIR}" ]; then
67+
echo "NXDK directory not found: ${NXDK_DIR}"
68+
echo "Run: git submodule update --init --recursive"
69+
exit 1
70+
fi
971

1072
# Activate the nxdk environment
1173
eval "$("${NXDK_DIR}/bin/activate" -s)"
1274

1375
# Navigate to the nxdk directory
1476
cd "${NXDK_DIR}"
1577

78+
if [ "${DISTCLEAN_BUILD}" -eq 1 ]; then
79+
make distclean
80+
fi
81+
1682
# Build nxdk with the specified options
1783
make NXDK_ONLY=y
1884
make tools
1985

20-
# Navigate back to the project root directory
21-
cd -
86+
cd "${PROJECT_ROOT}"
2287

23-
# Create the build directory
24-
mkdir -p build
88+
if [ "${CLEAN_BUILD}" -eq 1 ]; then
89+
rm -rf "${BUILD_DIR_PATH}"
90+
fi
2591

2692
# Configure the project
27-
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE="${NXDK_DIR}/share/toolchain-nxdk.cmake"
93+
cmake \
94+
-G "Unix Makefiles" \
95+
-B "${BUILD_DIR_PATH}" \
96+
-S . \
97+
-DCMAKE_TOOLCHAIN_FILE="${NXDK_DIR}/share/toolchain-nxdk.cmake" \
98+
-DCMAKE_DEPENDS_USE_COMPILER=FALSE
2899

29100
# Build the project
30-
cmake --build build
101+
cmake --build "${BUILD_DIR_PATH}"

cmake/modules/FindNXDK.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ if(NOT TARGET NXDK::NXDK)
9696
pdclib
9797
winapi
9898
winmm
99-
ws2_32
10099
xboxrt
101100
zlib
102101
)
@@ -125,10 +124,10 @@ if (NOT TARGET NXDK::Net)
125124
target_include_directories(
126125
NXDK::Net
127126
SYSTEM INTERFACE
127+
"${NXDK_DIR}/lib"
128128
"${NXDK_DIR}/lib/net/lwip/src/include"
129129
"${NXDK_DIR}/lib/net/nforceif/include"
130130
"${NXDK_DIR}/lib/net/nvnetdrv"
131-
"${NXDK_DIR}/lib/net/pktdrv"
132131
)
133132
endif ()
134133

cmake/modules/FindNXDK_SDL2.cmake

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
if(NOT TARGET NXDK::SDL2)
2-
find_package(PkgConfig REQUIRED)
3-
pkg_check_modules(SDL2 REQUIRED IMPORTED_TARGET sdl2)
2+
add_library(nxdk_sdl2 STATIC IMPORTED)
3+
set_target_properties(
4+
nxdk_sdl2
5+
PROPERTIES
6+
IMPORTED_LOCATION "${NXDK_DIR}/lib/libSDL2.lib"
7+
)
48

5-
add_library(NXDK::SDL2 ALIAS PkgConfig::SDL2)
9+
add_library(NXDK::SDL2 INTERFACE IMPORTED)
10+
target_link_libraries(
11+
NXDK::SDL2
12+
INTERFACE
13+
nxdk_sdl2
14+
)
15+
target_include_directories(
16+
NXDK::SDL2
17+
SYSTEM INTERFACE
18+
"${NXDK_DIR}/lib/sdl/SDL2/include"
19+
)
620
endif()

0 commit comments

Comments
 (0)