Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add REX and upgrade to c++23 #11

Merged
merged 7 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions .github/workflows/main_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,39 @@ on:
workflow_dispatch:

env:
BUILD_TYPE: Debug
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg-cache

jobs:
windows:
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
build-type:
- debug
- release
compiler:
- msvc
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2
with:
path: main

- name: Setup cmake
uses: lukka/get-cmake@latest

- name: Setup vcpkg
run: |
mkdir -p ${{ env.VCPKG_DEFAULT_BINARY_CACHE }}
cd $env:VCPKG_INSTALLATION_ROOT
./bootstrap-vcpkg.bat
./vcpkg --version > ${{ github.workspace }}/vcpkg-version.txt
- name: Setup msvc
uses: ilammy/[email protected]

- name: Cache vcpkg
uses: actions/cache@v2
id: vcpkg-cache
env:
cache-name: vcpkg-cache
- name: Setup vcpkg
uses: friendlyanon/setup-vcpkg@v1
with:
path: ${{ env.VCPKG_DEFAULT_BINARY_CACHE }}/*
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('main/**/vcpkg.json', 'vcpkg-version.txt') }}

- name: Configure CMake
working-directory: ${{ github.workspace }}/main
run: cmake --preset vs2022-windows-vcpkg
committish: 943c5ef1c8f6b5e6ced092b242c8299caae2ff01

- name: Build
working-directory: ${{ github.workspace }}/main
run: cmake --build build --config ${{ env.BUILD_TYPE }}
uses: lukka/[email protected]
with:
cmakeListsTxtPath: ${{ github.workspace }}/main/CMakeLists.txt
configurePreset: build-${{ matrix.build-type }}-${{ matrix.compiler }}-vcpkg
buildPreset: ${{ matrix.build-type }}-${{ matrix.compiler }}-vcpkg
116 changes: 71 additions & 45 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,76 +1,102 @@
{
"configurePresets": [
{
"binaryDir": "${sourceDir}/build",
"name": "common",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": {
"type": "STRING",
"value": "Debug"
}
"CMAKE_CXX_FLAGS": "$env{PROJECT_PLATFORM_FLAGS} $env{PROJECT_TEXT_FLAGS} $env{PROJECT_COMPILER_FLAGS} $penv{CXX_FLAGS}",
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
},
"environment": {
"PROJECT_ARCHITECTURE": "x64",
"PROJECT_PLATFORM": "windows",
"PROJECT_TEXT_FLAGS": "-DUNICODE -D_UNICODE"
},
"errors": {
"deprecated": true
},
"hidden": true,
"name": "cmake-dev",
"warnings": {
"deprecated": true,
"dev": true
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"intelliSenseMode": "$env{PROJECT_PLATFORM}-$env{PROJECT_COMPILER}-$env{PROJECT_ARCHITECTURE}",
"enableMicrosoftCodeAnalysis": true,
"enableClangTidyCodeAnalysis": true
}
}
},
{
"name": "buildtype-debug",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "STRING",
"value": "$env{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "buildtype-release",
"hidden": true,
"name": "vcpkg"
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "packaging-vcpkg",
"hidden": true,
"toolchainFile": "$env{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"CMAKE_EXE_LINKER_FLAGS_RELEASE": {
"type": "STRING",
"value": "/DEBUG:FASTLINK"
},
"CMAKE_MSVC_RUNTIME_LIBRARY": {
"type": "STRING",
"value": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
},
"VCPKG_TARGET_TRIPLET": {
"type": "STRING",
"value": "x64-windows-static-md"
}
},
"VCPKG_HOST_TRIPLET": "$env{PROJECT_ARCHITECTURE}-$env{PROJECT_PLATFORM}-static-md",
"VCPKG_TARGET_TRIPLET": "$env{PROJECT_ARCHITECTURE}-$env{PROJECT_PLATFORM}-static-md"
}
},
{
"name": "generator-ninja",
"hidden": true,
"name": "windows"
"generator": "Ninja"
},
{
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4 /WX /external:anglebrackets /external:W0"
},
"generator": "Visual Studio 16 2019",
"name": "compiler-msvc",
"hidden": true,
"environment": {
"PROJECT_COMPILER_FLAGS": "/EHsc /MP /W4 /WX /external:W0 /bigobj",
"PROJECT_COMPILER": "msvc"
}
},
{
"name": "build-debug-msvc-vcpkg",
"inherits": [
"cmake-dev",
"vcpkg",
"windows"
"common",
"buildtype-debug",
"packaging-vcpkg",
"generator-ninja",
"compiler-msvc"
],
"name": "vs2019-windows-vcpkg"
"binaryDir": "${sourceDir}/build/debug-msvc-vcpkg"
},
{
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4 /WX /external:W0"
},
"generator": "Visual Studio 17 2022",
"name": "build-release-msvc-vcpkg",
"inherits": [
"cmake-dev",
"vcpkg",
"windows"
"common",
"buildtype-release",
"packaging-vcpkg",
"generator-ninja",
"compiler-msvc"
],
"name": "vs2022-windows-vcpkg",
"toolset": "v143"
"binaryDir": "${sourceDir}/build/release-msvc-vcpkg"
}
],
"buildPresets": [
{
"name": "debug-msvc-vcpkg",
"configurePreset": "build-debug-msvc-vcpkg",
"displayName": "Debug (MSVC, Vcpkg)"
},
{
"name": "release-msvc-vcpkg",
"configurePreset": "build-release-msvc-vcpkg",
"displayName": "Release (MSVC, Vcpkg)"
}
],
"version": 2
"version": 3
}
11 changes: 9 additions & 2 deletions CommonLibF4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ target_compile_definitions(
target_compile_features(
"${PROJECT_NAME}"
PUBLIC
cxx_std_20
cxx_std_23
)

if (MSVC)
Expand Down Expand Up @@ -93,10 +93,16 @@ target_include_directories(
target_link_libraries(
"${PROJECT_NAME}"
PUBLIC
advapi32.lib
bcrypt.lib
d3d11.lib
d3dcompiler.lib
dbghelp.lib
dxgi.lib
mmio::mmio
ole32.lib
spdlog::spdlog
Version.lib
version.lib
)

target_precompile_headers(
Expand Down Expand Up @@ -132,5 +138,6 @@ install(
"include/F4SE"
"include/RE"
"include/REL"
"include/REX"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
40 changes: 38 additions & 2 deletions CommonLibF4/cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(SOURCES
include/F4SE/API.h
include/F4SE/F4SE.h
include/F4SE/Impl/PCH.h
include/F4SE/Impl/WinAPI.h
include/F4SE/Interfaces.h
include/F4SE/Logger.h
include/F4SE/Trampoline.h
Expand Down Expand Up @@ -344,9 +343,35 @@ set(SOURCES
include/RE/msvc/memory.h
include/RE/msvc/typeinfo.h
include/REL/Relocation.h
include/REX/W32.h
include/REX/W32/ADVAPI32.h
include/REX/W32/BASE.h
include/REX/W32/BCRYPT.h
include/REX/W32/COM.h
include/REX/W32/COMPTR.h
include/REX/W32/D3D.h
include/REX/W32/D3D11.h
include/REX/W32/D3D11_1.h
include/REX/W32/D3D11_2.h
include/REX/W32/D3D11_3.h
include/REX/W32/D3D11_4.h
include/REX/W32/D3DCOMPILER.h
include/REX/W32/DBGHELP.h
include/REX/W32/DINPUT.h
include/REX/W32/DXGI.h
include/REX/W32/DXGI_2.h
include/REX/W32/DXGI_3.h
include/REX/W32/DXGI_4.h
include/REX/W32/DXGI_5.h
include/REX/W32/DXGI_6.h
include/REX/W32/KERNEL32.h
include/REX/W32/OLE32.h
include/REX/W32/SHELL32.h
include/REX/W32/USER32.h
include/REX/W32/VERSION.h
include/REX/W32/XINPUT.h
src/F4SE/API.cpp
src/F4SE/Impl/PCH.cpp
src/F4SE/Impl/WinAPI.cpp
src/F4SE/Interfaces.cpp
src/F4SE/Logger.cpp
src/F4SE/Trampoline.cpp
Expand Down Expand Up @@ -387,4 +412,15 @@ set(SOURCES
src/RE/NetImmerse/NiRect.cpp
src/RE/Scaleform/GFx/GFx_Player.cpp
src/REL/Relocation.cpp
src/REX/W32/ADVAPI32.cpp
src/REX/W32/BCRYPT.cpp
src/REX/W32/D3D11.cpp
src/REX/W32/D3DCOMPILER.cpp
src/REX/W32/DBGHELP.cpp
src/REX/W32/DXGI.cpp
src/REX/W32/KERNEL32.cpp
src/REX/W32/OLE32.cpp
src/REX/W32/SHELL32.cpp
src/REX/W32/USER32.cpp
src/REX/W32/VERSION.cpp
)
33 changes: 12 additions & 21 deletions CommonLibF4/include/F4SE/Impl/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ static_assert(
#include <spdlog/spdlog.h>
#pragma warning(pop)

#include "F4SE/Impl/WinAPI.h"
#include "REX/W32/KERNEL32.h"
#include "REX/W32/USER32.h"

namespace F4SE
{
Expand Down Expand Up @@ -578,15 +579,14 @@ namespace F4SE
}();

const auto caption = []() -> std::string {
const auto maxPath = WinAPI::GetMaxPath();
std::vector<char> buf;
buf.reserve(maxPath);
buf.resize(maxPath / 2);
buf.reserve(REX::W32::MAX_PATH);
buf.resize(REX::W32::MAX_PATH / 2);
std::uint32_t result = 0;
do {
buf.resize(buf.size() * 2);
result = WinAPI::GetModuleFileName(
WinAPI::GetCurrentModule(),
result = REX::W32::GetModuleFileNameA(
REX::W32::GetCurrentModule(),
buf.data(),
static_cast<std::uint32_t>(buf.size()));
} while (result && result == buf.size() && buf.size() <= std::numeric_limits<std::uint32_t>::max());
Expand All @@ -606,15 +606,8 @@ namespace F4SE
a_loc.function_name() },
spdlog::level::critical,
a_msg);
WinAPI::MessageBox(nullptr, body.c_str(), (caption.empty() ? nullptr : caption.c_str()), 0);
WinAPI::TerminateProcess(WinAPI::GetCurrentProcess(), EXIT_FAILURE);
}

template <class Enum>
[[nodiscard]] constexpr auto to_underlying(Enum a_val) noexcept //
requires(std::is_enum_v<Enum>)
{
return static_cast<std::underlying_type_t<Enum>>(a_val);
REX::W32::MessageBoxA(nullptr, body.c_str(), (caption.empty() ? nullptr : caption.c_str()), 0);
REX::W32::TerminateProcess(REX::W32::GetCurrentProcess(), EXIT_FAILURE);
}

template <class To, class From>
Expand Down Expand Up @@ -660,8 +653,8 @@ namespace F4SE
-> std::optional<std::wstring>
{
const auto cvt = [&](wchar_t* a_dst, std::size_t a_length) {
return WinAPI::MultiByteToWideChar(
WinAPI::CP_UTF8,
return REX::W32::MultiByteToWideChar(
REX::W32::CP_UTF8,
0,
a_in.data(),
static_cast<int>(a_in.length()),
Expand All @@ -686,8 +679,8 @@ namespace F4SE
-> std::optional<std::string>
{
const auto cvt = [&](char* a_dst, std::size_t a_length) {
return WinAPI::WideCharToMultiByte(
WinAPI::CP_UTF8,
return REX::W32::WideCharToMultiByte(
REX::W32::CP_UTF8,
0,
a_in.data(),
static_cast<int>(a_in.length()),
Expand Down Expand Up @@ -721,14 +714,12 @@ namespace RE
{
using namespace std::literals;
namespace stl = F4SE::stl;
namespace WinAPI = F4SE::WinAPI;
}

namespace REL
{
using namespace std::literals;
namespace stl = F4SE::stl;
namespace WinAPI = F4SE::WinAPI;
}

#include "REL/Relocation.h"
Expand Down
Loading
Loading