Skip to content

Commit

Permalink
Merge remote-tracking branch 'hagb/cmake' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Hagb committed Nov 15, 2024
2 parents fbeb48b + ce077ea commit 9a14e22
Show file tree
Hide file tree
Showing 25 changed files with 200 additions and 111 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/tools/*.run
.vs*
out/
*.lib
*.lib
/th155r/Netcode/embedded_h/
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"ms-vscode.cmake-tools",
"llvm-vs-code-extensions.vscode-clangd"
]
}
72 changes: 0 additions & 72 deletions .vscode/settings.json

This file was deleted.

114 changes: 114 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
cmake_minimum_required(VERSION 3.15)
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/toolchain-clang.cmake)
endif()
project(squiroll)

set (CMAKE_CXX_STANDARD 20)
set (REPLACEMENT_FILES_DIR "replacement_files")
set (NEW_FILES_DIR "new_files")

# Generate PDB files
add_compile_options(-gcodeview-command-line -gcolumn-info -gcodeview -gcodeview-ghash -g)
add_link_options(/DEBUG)
add_link_options("$<$<NOT:$<CONFIG:Debug>>:SHELL:/OPT:REF /OPT:ICF /PDBALTPATH:%_PDB%>")
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:SHELL:-Xclang -O3>")

add_compile_options(
-Wno-cpp
-Wno-narrowing
-Wno-nonportable-include-path
-Wno-pragma-pack
-Wno-c++11-narrowing
-Wno-c++17-extensions
-Wno-c++2b-extensions
-Wno-unused-function
-Wno-unused-const-variable
-Wno-unused-variable
-Wno-unused-but-set-variable
-Wno-unused-label
-Wno-missing-braces
-Wno-logical-op-parentheses
-Wno-bitwise-op-parentheses
-Wno-shift-op-parentheses
-Wno-pointer-to-int-cast
-Wno-int-to-pointer-cast
-Wno-format-security
-Wno-gnu-alignof-expression
-Wno-missing-declarations
-Wno-initializer-overrides
-Wno-microsoft-goto
-Wno-microsoft-template
-Wno-microsoft-extra-qualification
-Wno-deprecated-this-capture
-Wno-inline-namespace-reopened-noninline
/clang:-mstack-probe-size=1024
/GS-
/Gs-
/EHsc
/Zc:threadSafeInit-
)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE _CRT_DECLARE_NONSTDC_NAMES _WINSOCK_DEPRECATED_NO_WARNINGS DOSWIN32=1 NOMINMAX _WINSOCKAPI_)

add_executable(
th155r
th155r/main.cpp
)
target_include_directories(th155r PRIVATE th155r/shared)
set_property(TARGET th155r PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded")
install(TARGETS th155r DESTINATION .)
install(FILES $<TARGET_PDB_FILE:th155r> DESTINATION .)

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "X86" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64"))
add_executable(make_embed tools/make_embed.cpp)
set(MAKE_EMBED make_embed)
else()
include(ExternalProject)
set(MAKE_EMBED_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/tools_prefix)
ExternalProject_Add(make_embed_ BUILD_ALWAYS true SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools/
BUILD_BYPRODUCTS ${MAKE_EMBED_PREFIX}/bin/make_embed${CMAKE_HOST_EXECUTABLE_SUFFIX}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MAKE_EMBED_PREFIX}/)
add_executable(make_embed IMPORTED)
set_property(TARGET make_embed PROPERTY IMPORTED_LOCATION ${MAKE_EMBED_PREFIX}/bin/make_embed${CMAKE_HOST_EXECUTABLE_SUFFIX})
add_dependencies(make_embed make_embed_)
endif()

set(EMBEDDED_H ${CMAKE_CURRENT_BINARY_DIR}/embedded_h)
function(target_embed_dir target dir)
make_directory(${EMBEDDED_H}/${dir})
file(GLOB FILES CONFIGURE_DEPENDS ${dir}/*)
file(REAL_PATH ${dir}/../ dir)
foreach(file_full_path ${FILES})
file(RELATIVE_PATH file_path ${dir} ${file_full_path})
add_custom_command(
OUTPUT ${EMBEDDED_H}/${file_path}.h
COMMAND $<TARGET_FILE:make_embed> ${file_full_path} ${EMBEDDED_H}/${file_path}.h
DEPENDS make_embed
MAIN_DEPENDENCY ${file_path}
)
target_sources(${target} PRIVATE ${EMBEDDED_H}/${file_path}.h)
# message(${file_full_path} ${file_path})
endforeach()
endfunction()
file(GLOB NETCODE_CPPS CONFIGURE_DEPENDS th155r/Netcode/*.cpp)
add_library(
Netcode
SHARED
${NETCODE_CPPS}
)
target_embed_dir(Netcode ${REPLACEMENT_FILES_DIR})
target_embed_dir(Netcode ${NEW_FILES_DIR})
target_include_directories(Netcode PRIVATE ${EMBEDDED_H})
target_link_libraries(
Netcode
user32
ws2_32
dbghelp
)
target_include_directories(Netcode PRIVATE th155r/shared th155r/Netcode/include)
target_link_options(Netcode PRIVATE "-exclude-all-symbols" "-kill-at" "/DEF:${CMAKE_SOURCE_DIR}/Netcode.def")
target_sources(Netcode PRIVATE "Netcode.def")
# Avoid using different ABI on STL on debug builds
set_property(TARGET Netcode PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded")
install(TARGETS Netcode DESTINATION .)
install(FILES $<TARGET_PDB_FILE:Netcode> DESTINATION .)
6 changes: 3 additions & 3 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

set TOOLS_PATH=.\tools\make_embed_windows.exe
set REPLACEMENT_FILES_DIR=replacement_files
set REPLACEMENT_DESTINATION_DIR=th155r\Netcode\replacement_files
set REPLACEMENT_DESTINATION_DIR=th155r\Netcode\embedded_h\replacement_files

set NEW_FILES_DIR=new_files
set NEW_DESTINATION_DIR=th155r\Netcode\new_files
set NEW_DESTINATION_DIR=th155r\Netcode\embedded_h\new_files

mkdir "%REPLACEMENT_DESTINATION_DIR%"
mkdir "%NEW_DESTINATION_DIR%"
Expand All @@ -26,4 +26,4 @@ set DEFINES=-D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -DNOMINM
set WARNINGS=-Wno-cpp -Wno-narrowing

clang++ -m32 -std=c++20 %WARNINGS% %DEFINES% /Ith155r/shared th155r/main.cpp -O2 /link $LIBPATHS /OUT:th155r.exe
clang++ -m32 -std=c++20 %WARNINGS% %DEFINES% /Ith155r/shared /Ith155r/Netcode/include th155r/Netcode/*.cpp /std:c++20 -static -O2 /link /DLL $LIBPATHS user32.lib WS2_32.lib dbghelp.lib -exclude-all-symbols -kill-at /DEF:Netcode.def /OUT:Netcode.dll
clang++ -m32 -std=c++20 %WARNINGS% %DEFINES% /Ith155r/shared /Ith155r/Netcode/embedded_h /Ith155r/Netcode/include th155r/Netcode/*.cpp /std:c++20 -static -O2 /link /DLL $LIBPATHS user32.lib WS2_32.lib dbghelp.lib -exclude-all-symbols -kill-at /DEF:Netcode.def /OUT:Netcode.dll
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
TOOLS_PATH="./tools/make_embed_linux.run"
REPLACEMENT_FILES_DIR="replacement_files"
REPLACEMENT_DESTINATION_DIR="th155r/Netcode/replacement_files"
REPLACEMENT_DESTINATION_DIR="th155r/Netcode/embedded_h/replacement_files"

NEW_FILES_DIR="new_files"
NEW_DESTINATION_DIR="th155r/Netcode/new_files"
NEW_DESTINATION_DIR="th155r/Netcode/embedded_h/new_files"

mkdir -p "$REPLACEMENT_DESTINATION_DIR"
mkdir -p "$NEW_DESTINATION_DIR"
Expand All @@ -29,4 +29,4 @@ DEFINES="-D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -DNOMINMAX
WARNINGS="-Wno-cpp -Wno-narrowing"

clang-cl-18 -m32 -fuse-ld=lld /EHsc $WARNINGS $DEFINES $INCLUDES /Ith155r/shared th155r/main.cpp -O2 /link $LIBPATHS /OUT:th155r.exe
clang-cl-18 -m32 -fuse-ld=lld /EHsc $WARNINGS $DEFINES $INCLUDES /Ith155r/shared /Ith155r/Netcode/include th155r/Netcode/*.cpp /std:c++20 -static -O2 /link /DLL $LIBPATHS user32.lib WS2_32.lib dbghelp.lib -exclude-all-symbols -kill-at /DEF:Netcode.def /OUT:Netcode.dll
clang-cl-18 -m32 -fuse-ld=lld /EHsc $WARNINGS $DEFINES $INCLUDES /Ith155r/Netcode/embedded_h /Ith155r/shared /Ith155r/Netcode/include th155r/Netcode/*.cpp /std:c++20 -static -O2 /link /DLL $LIBPATHS user32.lib WS2_32.lib dbghelp.lib -exclude-all-symbols -kill-at /DEF:Netcode.def /OUT:Netcode.dll
4 changes: 4 additions & 0 deletions get-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
set -e
cargo install xwin
~/.cargo/bin/xwin --arch x86 splat --include-debug-libs --output ~/.xwin-cache/splat
34 changes: 17 additions & 17 deletions th155r/Netcode/file_replacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,83 +47,83 @@ struct PackageReader : FileReader {

static constexpr uint8_t network_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_BASIC_THCRAP
#include "replacement_files/network_encrypted.nut.h"
#include <replacement_files/network_encrypted.nut.h>
#elif FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/network.nut.h"
#include <replacement_files/network.nut.h>
#endif
};

static constexpr uint8_t network_component_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/network_component.nut.h"
#include <replacement_files/network_component.nut.h>
#endif
};

static constexpr uint8_t network_animation_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/network_animation.nut.h"
#include <replacement_files/network_animation.nut.h>
#endif
};

static constexpr uint8_t version_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/version.nut.h"
#include <replacement_files/version.nut.h>
#endif
};

/*
static constexpr uint8_t menu_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/menu.nut.h"
#include <replacement_files/menu.nut.h>
#endif
};
*/

static constexpr uint8_t title_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/title.nut.h"
#include <replacement_files/title.nut.h>
#endif
};

static constexpr uint8_t config_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/config.nut.h"
#include <replacement_files/config.nut.h>
#endif
};

static constexpr uint8_t config_animation_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/config_animation.nut.h"
#include <replacement_files/config_animation.nut.h>
#endif
};

static constexpr uint8_t battle_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/battle.nut.h"
#include <replacement_files/battle.nut.h>
#endif
};

static constexpr uint8_t battle_practice_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/battle_practice.nut.h"
#include <replacement_files/battle_practice.nut.h>
#endif
};

static constexpr uint8_t vs_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/vs.nut.h"
#include <replacement_files/vs.nut.h>
#endif
};

static constexpr uint8_t item_csv[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/item.csv.h"
#include <replacement_files/item.csv.h>
#endif
};

static constexpr uint8_t dialog_wait_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/dialog_wait.nut.h"
#include <replacement_files/dialog_wait.nut.h>
#endif
};

Expand Down Expand Up @@ -219,11 +219,11 @@ naked void file_replacement_hook() {


static constexpr uint8_t misc_nut[] = {
#include "new_files/misc_config.nut.h"
#include <new_files/misc_config.nut.h>
};

static constexpr uint8_t debug_nut[] = {
#include "new_files/debug.nut.h"
#include <new_files/debug.nut.h>
};

static const std::unordered_map<std::string_view, const EmbedData> new_files = {
Expand All @@ -237,4 +237,4 @@ EmbedData get_new_file_data(const char* name) {
return new_file->second;
}
return {};
}
}
1 change: 0 additions & 1 deletion th155r/Netcode/new_files/debug.nut.h

This file was deleted.

Loading

0 comments on commit 9a14e22

Please sign in to comment.