From bddbcce8ffc53cf3b43f6d4aa70b7f8efc01ff7b Mon Sep 17 00:00:00 2001 From: Angad <66992519+ThirdEyeSqueegee@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:43:25 -0700 Subject: [PATCH] chore: maintenance (#280) --- .clang-tidy | 2 + .clangd | 19 +++ .github/update_vcpkg_baselines.py | 44 +++++ .../{lint_pr_title.yaml => lint_pr_title.yml} | 0 .github/workflows/main_ci.yml | 12 +- .github/workflows/maintenance.yml | 12 +- .github/workflows/update_vcpkg_baselines.yml | 37 ++++ CMakeLists.txt | 160 +++++++----------- CMakePresets.json | 40 ++--- README.md | 4 +- cmake/CommonLibSF.cmake | 76 ++++++--- cmake/config.cmake.in | 1 - cmake/make-sourcelist.ps1 | 63 ------- scripts/add-file.ps1 | 98 ----------- vcpkg.json | 9 +- 15 files changed, 256 insertions(+), 321 deletions(-) create mode 100644 .clang-tidy create mode 100644 .clangd create mode 100644 .github/update_vcpkg_baselines.py rename .github/workflows/{lint_pr_title.yaml => lint_pr_title.yml} (100%) create mode 100644 .github/workflows/update_vcpkg_baselines.yml delete mode 100644 cmake/make-sourcelist.ps1 delete mode 100644 scripts/add-file.ps1 diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..afefd53d --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,2 @@ +--- +Checks: "-*,clang-analyzer-*,concurrency-*,misc-*,performance-*,bugprone-*,-bugprone-narrowing-conversions,-bugprone-easily-swappable-parameters,cert-err52-cpp,cert-err60-cpp,cert-err34-c,cert-mem57-cpp,cert-msc50-cpp,cert-env33-c,cert-oop58-cpp,cert-oop57-cpp,cert-msc51-cpp,cert-dcl58-cpp,cert-flp30-c,cppcoreguidelines-*,-cppcoreguidelines-macro-to-enum,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-use-default-member-init,-cppcoreguidelines-explicit-virtual-functions,-cppcoreguidelines-noexcept-swap,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-noexcept-destructor,-cppcoreguidelines-c-copy-assignment-signature,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-noexcept-move-operations,google-build-namespaces,google-default-arguments,google-build-explicit-make-pair,google-runtime-int,google-runtime-operator,google-explicit-constructor,hicpp-multiway-paths-covered,hicpp-no-assembler,hicpp-exception-baseclass,hicpp-signed-bitwise,-misc-non-private-member-variables-in-classes,modernize-*,-modernize-use-trailing-return-type,readability-*,-readability-function-size,-readability-avoid-const-params-in-decls,-readability-identifier-length,-readability-implicit-bool-conversion,-readability-magic-numbers,-readability-qualified-auto,-readability-redundant-member-init,-readability-function-cognitive-complexity,-readability-identifier-naming,-*-include-cleaner" diff --git a/.clangd b/.clangd new file mode 100644 index 00000000..d403f7f4 --- /dev/null +++ b/.clangd @@ -0,0 +1,19 @@ +CompileFlags: + Compiler: clang-cl + +Index: + StandardLibrary: Yes + +Diagnostics: + ClangTidy: + FastCheckFilter: Loose + +Hover: + ShowAKA: Yes + +--- +If: + PathMatch: ../CommonLibSSE-NG + +Index: + Background: Skip diff --git a/.github/update_vcpkg_baselines.py b/.github/update_vcpkg_baselines.py new file mode 100644 index 00000000..59c1b2fc --- /dev/null +++ b/.github/update_vcpkg_baselines.py @@ -0,0 +1,44 @@ +from json import dumps, load +from re import sub +from subprocess import run + +vcpkg_repo = "https://github.com/microsoft/vcpkg" +custom_vcpkg_registry_repo = "https://github.com/ThirdEyeSqueegee/vcpkg-ports" + +vcpkg_ref = ( + run(["git", "ls-remote", vcpkg_repo, "refs/heads/master"], capture_output=True) + .stdout.decode() + .splitlines()[0] + .split()[0] +) + +custom_vcpkg_registry_ref = ( + run(["git", "ls-remote", custom_vcpkg_registry_repo], capture_output=True) + .stdout.decode() + .splitlines()[0] + .split()[0] +) + +with open("./vcpkg.json") as f: + vcpkg_json = load(f) + +vcpkg_json["builtin-baseline"] = vcpkg_ref +vcpkg_json["vcpkg-configuration"]["registries"][0]["baseline"] = ( + custom_vcpkg_registry_ref +) + +vcpkg_json_str = dumps(vcpkg_json, indent=2) +vcpkg_json_str += "\n" + +with open("./vcpkg.json", "w", newline="\r\n") as f: + f.write(vcpkg_json_str) + +with open("./.github/workflows/main_ci.yml") as f: + main_ci_yml = f.read() + +main_ci_yml = sub( + r"(VCPKG_COMMIT_ID: ).*", f"VCPKG_COMMIT_ID: {vcpkg_ref}", main_ci_yml +) + +with open("./.github/workflows/main_ci.yml", "w") as f: + f.write(main_ci_yml) diff --git a/.github/workflows/lint_pr_title.yaml b/.github/workflows/lint_pr_title.yml similarity index 100% rename from .github/workflows/lint_pr_title.yaml rename to .github/workflows/lint_pr_title.yml diff --git a/.github/workflows/main_ci.yml b/.github/workflows/main_ci.yml index c866e2d0..678caa66 100644 --- a/.github/workflows/main_ci.yml +++ b/.github/workflows/main_ci.yml @@ -3,24 +3,32 @@ name: Main CI [CMake] on: pull_request: branches: main + types: [opened, synchronize, ready_for_review] paths: - - "src/**" - - "include/**" - ".github/workflows/main_ci.yml" + - "cmake/**" + - "include/**" + - "src/**" - "CMakeLists.txt" - "CMakePresets.json" - "vcpkg.json" workflow_dispatch: +concurrency: + group: main-ci + cancel-in-progress: true + jobs: build-cmake: runs-on: windows-latest + strategy: fail-fast: false matrix: compiler: - msvc - clang-cl + steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/maintenance.yml b/.github/workflows/maintenance.yml index d5aea5a1..8cc0f13b 100644 --- a/.github/workflows/maintenance.yml +++ b/.github/workflows/maintenance.yml @@ -4,8 +4,8 @@ on: push: branches: main paths: - - "src/**" - "include/**" + - "src/**" workflow_dispatch: concurrency: @@ -15,7 +15,9 @@ concurrency: jobs: maintenance: runs-on: ubuntu-latest + if: github.repository_owner == 'Starfield-Reverse-Engineering' + steps: - name: Checkout uses: actions/checkout@v4 @@ -25,13 +27,7 @@ jobs: run: "& ${{ github.workspace }}/.github/make-directives.ps1 ${{ github.workspace }}" - name: Run clang-format - uses: DoozyX/clang-format-lint-action@v0.17 - with: - source: "." - exclude: "./docs" - extensions: "c,cc,cpp,cppm,cxx,h,hpp,hxx,inl,inc,ixx,mxx" - clangFormatVersion: 17 - inplace: True + uses: jayllyz/clang-format-action@v1 - name: Add & Commit id: registry diff --git a/.github/workflows/update_vcpkg_baselines.yml b/.github/workflows/update_vcpkg_baselines.yml new file mode 100644 index 00000000..aa12e583 --- /dev/null +++ b/.github/workflows/update_vcpkg_baselines.yml @@ -0,0 +1,37 @@ +name: Update vcpkg baselines + +on: + schedule: + - cron: 0 */6 * * * + repository_dispatch: + types: [update-baselines-event] + workflow_dispatch: + +permissions: write-all + +concurrency: + group: update-vcpkg-baselines + cancel-in-progress: true + +jobs: + update-vcpkg-baselines: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + token: ${{ secrets.EDIT_WORKFLOW_TOKEN }} + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.12 + + - run: python .github/update_vcpkg_baselines.py + + - name: Add & Commit + uses: EndBug/add-and-commit@v9 + with: + default_author: github_actions + message: "ci: update vcpkg baselines" diff --git a/CMakeLists.txt b/CMakeLists.txt index da40378d..ed7c50dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.26) +cmake_minimum_required(VERSION 3.30) message("Using toolchain file ${CMAKE_TOOLCHAIN_FILE}.") # singleton target across multiple projects @@ -7,7 +7,7 @@ if(TARGET CommonLibSF) endif() # options if not defined -option(SFSE_SUPPORT_XBYAK "Enables trampoline support for Xbyak." OFF) +option(SFSE_SUPPORT_XBYAK "Enables trampoline support for xbyak." OFF) option(SFSE_BUILD_TESTS "Builds the tests." OFF) # info @@ -19,12 +19,8 @@ project( # standards & flags set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF) set(CMAKE_OPTIMIZE_DEPENDENCIES ON) -set_property(GLOBAL PROPERTY USE_FOLDERS ON) - include(GNUInstallDirs) # out-of-source builds only @@ -35,10 +31,14 @@ endif() # dependencies find_package(spdlog CONFIG REQUIRED) -file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/include/*" - "${CMAKE_CURRENT_SOURCE_DIR}/src/*" +file( + GLOB_RECURSE + SOURCES + CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/include/* + ${CMAKE_CURRENT_SOURCE_DIR}/src/* ) +list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/include/SFSE/Impl/PCH.h) source_group( TREE ${CMAKE_CURRENT_SOURCE_DIR} @@ -46,144 +46,110 @@ source_group( ) function(configure_target TARGET_NAME) + if(SFSE_SUPPORT_XBYAK) + find_package(xbyak CONFIG REQUIRED) + endif() + target_compile_definitions( ${TARGET_NAME} PUBLIC WINVER=0x0A00 # windows 10, minimum supported version by starfield _WIN32_WINNT=0x0A00 - "$<$:SFSE_SUPPORT_XBYAK=1>" + $<$:SFSE_SUPPORT_XBYAK=1> + WIN32_LEAN_AND_MEAN + NOMINMAX + _ITERATOR_DEBUG_LEVEL=0 ) # FIXME: https://gitlab.kitware.com/cmake/cmake/-/issues/24922 set_property( TARGET ${TARGET_NAME} PROPERTY VS_USER_PROPS - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/build_stl_modules.props" + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/build_stl_modules.props ) - if(MSVC) - target_compile_options( - ${TARGET_NAME} - PUBLIC - /bigobj # support large object file format - /utf-8 # assume UTF-8 sources even without a BOM - - # warnings -> errors - /we4715 # 'function' : not all control paths return a value - - # disable warnings - /wd4005 # macro redefinition - /wd4061 # enumerator 'identifier' in switch of enum 'enumeration' is not explicitly handled by a case label - /wd4068 # unknown pragma - /wd4200 # nonstandard extension used : zero-sized array in struct/union - /wd4201 # nonstandard extension used : nameless struct/union - /wd4265 # 'type': class has virtual functions, but its non-trivial destructor is not virtual; instances of this class may not be destructed correctly - /wd4266 # 'function' : no override available for virtual member function from base 'type'; function is hidden - /wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data - /wd4371 # 'classname': layout of class may have changed from a previous version of the compiler due to better packing of member 'member' - /wd4514 # 'function' : unreferenced inline function has been removed - /wd4582 # 'type': constructor is not implicitly called - /wd4583 # 'type': destructor is not implicitly called - /wd4623 # 'derived class' : default constructor was implicitly defined as deleted because a base class default constructor is inaccessible or deleted - /wd4625 # 'derived class' : copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted - /wd4626 # 'derived class' : assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted - /wd4710 # 'function' : function not inlined - /wd4711 # function 'function' selected for inline expansion - /wd4820 # 'bytes' bytes padding added after construct 'member_name' - /wd4996 - /wd5026 # 'type': move constructor was implicitly defined as deleted - /wd5027 # 'type': move assignment operator was implicitly defined as deleted - /wd5045 # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified - /wd5053 # support for 'explicit()' in C++17 and earlier is a vendor extension - /wd5204 # 'type-name': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly - /wd5220 # 'member': a non-static data member with a volatile qualified type no longer implies that compiler generated copy / move constructors and copy / move assignment operators are not trivial - ) - endif() + target_compile_options( + ${TARGET_NAME} + PUBLIC + /bigobj # support large object file format + /wd4005 # macro redefinition + /wd4068 # unknown pragma + /wd4200 # nonstandard extension used: zero-sized array in struct/union + /wd4201 # nonstandard extension used: nameless struct/union + ) - if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CLIBSF_COMPILEFLAGS_RELEASE /fp:fast /GR- /Gw /O2) + if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL Clang) + set(CLIBSF_COMPILEFLAGS_RELEASE /Ob3 /GR- /Gw /Qvec -flto -fsplit-lto-unit -fvirtual-function-elimination -fwhole-program-vtables) target_compile_options( ${TARGET_NAME} PRIVATE - /D_ITERATOR_DEBUG_LEVEL=0 - /cgthreads8 - /diagnostics:caret - /EHsc - /fp:contract - /fp:except- - /guard:cf- - /permissive- - /Zc:__cplusplus - /Zc:rvalueCast - /Zc:ternary - /external:W0 + /Zc:alignedNew + /Zc:char8_t + /Zc:sizedDealloc + /Zc:strictStrings + /Zc:threadSafeInit + -fansi-escape-codes + -fcolor-diagnostics + -fcomplete-member-pointers + -fexperimental-library + -fforce-emit-vtables + -fms-compatibility + -fms-extensions + -fstrict-aliasing -Wno-overloaded-virtual -Wno-delete-non-abstract-non-virtual-dtor -Wno-inconsistent-missing-override -Wno-reinterpret-base-class -Wno-return-type -Wno-invalid-offsetof - -Wno-switch) - - target_compile_options(${TARGET_NAME} PRIVATE $<$:${CLIBSF_COMPILEFLAGS_RELEASE}>) - elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(CLIBSF_COMPILEFLAGS_RELEASE /fp:fast /GR- /Gw /O2 /Ob3 /Qpar) + -Wno-switch + -Wno-unused-command-line-argument + $<$:${CLIBSF_COMPILEFLAGS_RELEASE}> + ) + elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL MSVC) + set(CLIBSF_COMPILEFLAGS_RELEASE /fp:fast /Ob3 /GL /GR- /Gw /Qpar) target_compile_options( - ${TARGET_NAME} PRIVATE - /D_ITERATOR_DEBUG_LEVEL=0 + ${TARGET_NAME} + PRIVATE /cgthreads8 /diagnostics:caret - /EHsc - /fp:contract - /fp:except- - /guard:cf- + /jumptablerdata /MP - /permissive- /W4 /Zc:__cplusplus /Zc:enumTypes - /Zc:lambda - /Zc:preprocessor - /Zc:referenceBinding - /Zc:rvalueCast + /Zc:inline /Zc:templateScope - /Zc:ternary - /external:anglebrackets - /external:W0) - - target_compile_options(${TARGET_NAME} PRIVATE $<$:${CLIBSF_COMPILEFLAGS_RELEASE}>) + $<$:${CLIBSF_COMPILEFLAGS_RELEASE}> + ) endif() target_include_directories( ${TARGET_NAME} PUBLIC - "$" - "$" + $ + $ + ) + + target_precompile_headers( + ${TARGET_NAME} + PRIVATE + include/SFSE/Impl/PCH.h ) target_link_libraries( ${TARGET_NAME} PUBLIC + spdlog::spdlog advapi32.lib bcrypt.lib dbghelp.lib dxgi.lib ole32.lib - spdlog::spdlog version.lib ws2_32.lib ) - - if(SFSE_SUPPORT_XBYAK) - find_package(xbyak CONFIG REQUIRED) - endif() - - target_precompile_headers( - ${TARGET_NAME} - PRIVATE - include/SFSE/Impl/PCH.h - ) endfunction() if(SFSE_BUILD_TESTS) diff --git a/CMakePresets.json b/CMakePresets.json index ba1bf801..b5d3a96c 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,32 +2,22 @@ "version": 6, "cmakeMinimumRequired": { "major": 3, - "minor": 26, - "patch": 0 + "minor": 30 }, "configurePresets": [ - { - "name": "common", - "hidden": true, - "cacheVariables": { - "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$:Debug>DLL" - } - }, { "name": "packaging-vcpkg", "hidden": true, - "cacheVariables": { - "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", - "VCPKG_TARGET_TRIPLET": "x64-windows-static-md", - "VCPKG_HOST_TRIPLET": "x64-windows-static-md" - } + "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" }, { "name": "buildtype-debug-msvc", "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_CONFIGURATION_TYPES": "Debug" + "CMAKE_CONFIGURATION_TYPES": "Debug", + "VCPKG_TARGET_TRIPLET": "x64-windows-static-md", + "VCPKG_HOST_TRIPLET": "x64-windows-static-md" } }, { @@ -35,7 +25,9 @@ "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", - "CMAKE_CONFIGURATION_TYPES": "Release" + "CMAKE_CONFIGURATION_TYPES": "Release", + "VCPKG_TARGET_TRIPLET": "x64-windows-static-md-release", + "VCPKG_HOST_TRIPLET": "x64-windows-static-md-release" } }, { @@ -43,7 +35,9 @@ "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_CONFIGURATION_TYPES": "Debug" + "CMAKE_CONFIGURATION_TYPES": "Debug", + "VCPKG_TARGET_TRIPLET": "x64-windows-static-md", + "VCPKG_HOST_TRIPLET": "x64-windows-static-md" } }, { @@ -51,7 +45,9 @@ "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", - "CMAKE_CONFIGURATION_TYPES": "Release" + "CMAKE_CONFIGURATION_TYPES": "Release", + "VCPKG_TARGET_TRIPLET": "x64-windows-static-md-release", + "VCPKG_HOST_TRIPLET": "x64-windows-static-md-release" } }, { @@ -100,7 +96,6 @@ { "name": "build-debug-msvc-msvc", "inherits": [ - "common", "packaging-vcpkg", "buildtype-debug-msvc", "generator-msvc", @@ -111,7 +106,6 @@ { "name": "build-debug-msvc-ninja", "inherits": [ - "common", "packaging-vcpkg", "buildtype-debug-msvc", "generator-ninja", @@ -123,7 +117,6 @@ "name": "build-debug-clang-cl-msvc", "toolset": "ClangCL", "inherits": [ - "common", "packaging-vcpkg", "buildtype-debug-clang-cl", "generator-msvc", @@ -134,7 +127,6 @@ { "name": "build-debug-clang-cl-ninja", "inherits": [ - "common", "packaging-vcpkg", "buildtype-debug-clang-cl", "generator-ninja", @@ -145,7 +137,6 @@ { "name": "build-release-msvc-msvc", "inherits": [ - "common", "packaging-vcpkg", "buildtype-release-msvc", "generator-msvc", @@ -156,7 +147,6 @@ { "name": "build-release-msvc-ninja", "inherits": [ - "common", "packaging-vcpkg", "buildtype-release-msvc", "generator-ninja", @@ -168,7 +158,6 @@ "name": "build-release-clang-cl-msvc", "toolset": "ClangCL", "inherits": [ - "common", "packaging-vcpkg", "buildtype-release-clang-cl", "generator-msvc", @@ -179,7 +168,6 @@ { "name": "build-release-clang-cl-ninja", "inherits": [ - "common", "packaging-vcpkg", "buildtype-release-clang-cl", "generator-ninja", diff --git a/README.md b/README.md index 8de7577c..331e7706 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ [![C++23](https://img.shields.io/static/v1?label=standard&message=c%2B%2B23&color=blue&logo=c%2B%2B&&logoColor=red&style=flat)](https://en.cppreference.com/w/cpp/compiler_support) ![Platform](https://img.shields.io/static/v1?label=platform&message=windows&color=dimgray&style=flat&logo=windows) -[![Game version](https://img.shields.io/badge/game%20version-1.13.61-orange)](#Developing-with-CommonLibSF) +[![Game version](https://img.shields.io/badge/game%20version-1.14.70-orange)](#Developing-with-CommonLibSF) [![Main CI](https://img.shields.io/github/actions/workflow/status/Starfield-Reverse-Engineering/CommonLibSF/main_ci.yml)](https://github.com/Starfield-Reverse-Engineering/CommonLibSF/actions/workflows/main_ci.yml) ## Requirements -- [CMake v3.26+](https://cmake.org/) or [XMake v2.8.2+](https://github.com/xmake-io/xmake/releases) +- [CMake v3.30+](https://cmake.org/) or [XMake v2.8.2+](https://github.com/xmake-io/xmake/releases) - Add this to your `PATH` - [vcpkg](https://github.com/microsoft/vcpkg) - Create a Windows environment variable called `VCPKG_ROOT` with the value as the path to your vcpkg install directory diff --git a/cmake/CommonLibSF.cmake b/cmake/CommonLibSF.cmake index cff6a0f6..ff9e1ab5 100644 --- a/cmake/CommonLibSF.cmake +++ b/cmake/CommonLibSF.cmake @@ -1,6 +1,5 @@ function(commonlibsf_parse_version VERSION) - message("${version_match_count}") - string(REGEX MATCHALL "^([0-9]+)(\\.([0-9]+)(\\.([0-9]+)(\\.([0-9]+))?)?)?$" version_match "${VERSION}") + string(REGEX MATCHALL "^([0-9]+)(\.([0-9]+)(\.([0-9]+)(\.([0-9]+))?)?)?$" version_match "${VERSION}") unset(COMMONLIBSF_VERSION_MAJOR PARENT_SCOPE) unset(COMMONLIBSF_VERSION_MINOR PARENT_SCOPE) unset(COMMONLIBSF_VERSION_PATCH PARENT_SCOPE) @@ -11,20 +10,46 @@ function(commonlibsf_parse_version VERSION) return() endif() + if(CMAKE_MATCH_1) + string(STRIP ${CMAKE_MATCH_1} CMAKE_MATCH1) # save stripped version since we're doing a regex check later + endif() + + if(CMAKE_MATCH_3) + string(STRIP ${CMAKE_MATCH_3} CMAKE_MATCH3) + endif() + + if(CMAKE_MATCH_5) + string(STRIP ${CMAKE_MATCH_5} CMAKE_MATCH5) + endif() + + if(CMAKE_MATCH_7) + string(STRIP ${CMAKE_MATCH_7} CMAKE_MATCH7) + endif() + set(COMMONLIBSF_VERSION_MATCH TRUE PARENT_SCOPE) - set(COMMONLIBSF_VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE) + set(COMMONLIBSF_VERSION_MAJOR "0" PARENT_SCOPE) set(COMMONLIBSF_VERSION_MINOR "0" PARENT_SCOPE) set(COMMONLIBSF_VERSION_PATCH "0" PARENT_SCOPE) set(COMMONLIBSF_VERSION_TWEAK "0" PARENT_SCOPE) - if(DEFINED CMAKE_MATCH_3) - set(COMMONLIBSF_VERSION_MINOR "${CMAKE_MATCH_3}" PARENT_SCOPE) + if(DEFINED CMAKE_MATCH1 AND CMAKE_MATCH1 MATCHES "^[0-9]+$") + message("Setting major version to ${CMAKE_MATCH_0}") + set(COMMONLIBSF_VERSION_MAJOR "${CMAKE_MATCH_0}" PARENT_SCOPE) + endif() + + if(DEFINED CMAKE_MATCH3 AND CMAKE_MATCH3 MATCHES "^[0-9]+$") + message("Setting minor version to ${CMAKE_MATCH_0}") + set(COMMONLIBSF_VERSION_MINOR "${CMAKE_MATCH_0}" PARENT_SCOPE) endif() - if(DEFINED CMAKE_MATCH_5) - set(COMMONLIBSF_VERSION_PATCH "${CMAKE_MATCH_5}" PARENT_SCOPE) + + if(DEFINED CMAKE_MATCH5 AND CMAKE_MATCH5 MATCHES "^[0-9]+$") + message("Setting patch version to ${CMAKE_MATCH_0}") + set(COMMONLIBSF_VERSION_PATCH "${CMAKE_MATCH_0}" PARENT_SCOPE) endif() - if(DEFINED CMAKE_MATCH_7) - set(COMMONLIBSF_VERSION_TWEAK "${CMAKE_MATCH_7}" PARENT_SCOPE) + + if(DEFINED CMAKE_MATCH7 AND CMAKE_MATCH7 MATCHES "^[0-9]+$") + message("Setting tweak version to ${CMAKE_MATCH_0}") + set(COMMONLIBSF_VERSION_TWEAK "${CMAKE_MATCH_0}" PARENT_SCOPE) endif() endfunction() @@ -33,45 +58,48 @@ function(target_commonlibsf_properties TARGET) set(options OPTIONAL USE_ADDRESS_LIBRARY USE_SIGNATURE_SCANNING STRUCT_DEPENDENT EXCLUDE_FROM_ALL) set(oneValueArgs NAME AUTHOR EMAIL VERSION MINIMUM_SFSE_VERSION) set(multiValueArgs COMPATIBLE_RUNTIMES SOURCES) - cmake_parse_arguments(PARSE_ARGV 1 ADD_COMMONLIBSF_PLUGIN "${options}" "${oneValueArgs}" - "${multiValueArgs}") + "${multiValueArgs}") set(commonlibsf_plugin_file "${CMAKE_CURRENT_BINARY_DIR}/Plugin.h") # Set the plugin name. set(commonlibsf_plugin_name "${TARGET}") + if(DEFINED ADD_COMMONLIBSF_PLUGIN_NAME) set(commonlibsf_plugin_name "${ADD_COMMONLIBSF_PLUGIN_NAME}") endif() # Setup version number of the plugin. set(commonlibsf_plugin_version "${PROJECT_VERSION}") + if(DEFINED ADD_COMMONLIBSF_PLUGIN_VERSION) set(commonlibsf_plugin_version "${ADD_COMMONLIBSF_PLUGIN_VERSION}") endif() + message("Parsing commonlibsf_plugin_version ${commonlibsf_plugin_version}") commonlibsf_parse_version("${commonlibsf_plugin_version}") if(NOT DEFINED COMMONLIBSF_VERSION_MAJOR) message(FATAL_ERROR "Unable to parse plugin version number ${commonlibsf_plugin_version}.") endif() - set(commonlibsf_plugin_version "REL::Version{${COMMONLIBSF_VERSION_MAJOR}, ${COMMONLIBSF_VERSION_MINOR}, ${COMMONLIBSF_VERSION_PATCH}, ${COMMONLIBSF_VERSION_TWEAK}}") + set(commonlibsf_plugin_version "REL::Version{ ${COMMONLIBSF_VERSION_MAJOR}, ${COMMONLIBSF_VERSION_MINOR}, ${COMMONLIBSF_VERSION_PATCH}, ${COMMONLIBSF_VERSION_TWEAK} }") # Handle minimum SFSE version constraints. if(NOT DEFINED ADD_COMMONLIBSF_PLUGIN_MINIMUM_SFSE_VERSION) set(ADD_COMMONLIBSF_PLUGIN_MINIMUM_SFSE_VERSION 0) endif() + message("Parsing ADD_COMMONLIBSF_PLUGIN_MINIMUM_SFSE_VERSION ${ADD_COMMONLIBSF_PLUGIN_MINIMUM_SFSE_VERSION}") commonlibsf_parse_version("${ADD_COMMONLIBSF_PLUGIN_MINIMUM_SFSE_VERSION}") if(NOT COMMONLIBSF_VERSION_MATCH) message(FATAL_ERROR "Unable to parse SFSE minimum SFSE version number " - "${ADD_COMMONLIBSF_PLUGIN_MINIMUM_SFSE_VERSION}.") + "${ADD_COMMONLIBSF_PLUGIN_MINIMUM_SFSE_VERSION}.") endif() - set(commonlibsf_min_sfse_version "REL::Version{${COMMONLIBSF_VERSION_MAJOR}, ${COMMONLIBSF_VERSION_MINOR}, ${COMMONLIBSF_VERSION_PATCH}, ${COMMONLIBSF_VERSION_TWEAK}}") + set(commonlibsf_min_sfse_version "REL::Version{ ${COMMONLIBSF_VERSION_MAJOR}, ${COMMONLIBSF_VERSION_MINOR}, ${COMMONLIBSF_VERSION_PATCH}, ${COMMONLIBSF_VERSION_TWEAK} }") # Setup compatibility configuration. if(NOT ADD_COMMONLIBSF_PLUGIN_STRUCT_DEPENDENT) @@ -80,11 +108,16 @@ function(target_commonlibsf_properties TARGET) set(commonlibsf_is_layout_dependent "false") endif() - if(NOT ADD_COMMONLIBSF_PLUGIN_USE_SIGNATURE_SCANNING) + if(NOT ADD_COMMONLIBSF_PLUGIN_USE_SIGNATURE_SCANNING AND NOT DEFINED ADD_COMMONLIBSF_PLUGIN_COMPATIBLE_RUNTIMES) set(ADD_COMMONLIBSF_PLUGIN_USE_ADDRESS_LIBRARY TRUE) endif() if(ADD_COMMONLIBSF_PLUGIN_USE_ADDRESS_LIBRARY OR ADD_COMMONLIBSF_PLUGIN_USE_SIGNATURE_SCANNING) + if(DEFINED ADD_COMMONLIBSF_PLUGIN_COMPATIBLE_RUNTIMES) + message(FATAL_ERROR "COMPATIBLE_RUNTIMES option should not be used with USE_ADDRESS_LIBRARY or " + "USE_SIGNATURE_SCANNING") + endif() + if(NOT ADD_COMMONLIBSF_PLUGIN_USE_ADDRESS_LIBRARY) set(commonlibsf_uses_address_library "false") else() @@ -96,19 +129,25 @@ function(target_commonlibsf_properties TARGET) set(commonlibsf_plugin_compatibility "{ SFSE::RUNTIME_LATEST }") else() list(LENGTH ${ADD_COMMONLIBSF_PLUGIN_COMPATIBLE_RUNTIMES} commonlibsf_plugin_compatibility_count) + if(commonlibsf_plugin_compatibility_count GREATER 16) message(FATAL_ERROR "No more than 16 version numbers can be provided for COMPATIBLE_RUNTIMES.") endif() + foreach(STARFIELD_VERSION ${ADD_COMMONLIBSF_PLUGIN_COMPATIBLE_RUNTIMES}) if(DEFINED commonlibsf_plugin_compatibility) set(commonlibsf_plugin_compatibility "${commonlibsf_plugin_compatibility}, ") endif() + commonlibsf_parse_version("${STARFIELD_VERSION}") + if(NOT COMMONLIBSF_VERSION_MATCH) message(FATAL_ERROR "Unable to parse Starfield runtime version number ${STARFIELD_VERSION}.") endif() - set(commonlibsf_plugin_compatibility "${commonlibsf_plugin_compatibility}REL::Version{${COMMONLIBSF_VERSION_MAJOR}, ${COMMONLIBSF_VERSION_MINOR}, ${COMMONLIBSF_VERSION_PATCH}, ${COMMONLIBSF_VERSION_TWEAK}}") + + set(commonlibsf_plugin_compatibility "${commonlibsf_plugin_compatibility}REL::Version{ ${COMMONLIBSF_VERSION_MAJOR}, ${COMMONLIBSF_VERSION_MINOR}, ${COMMONLIBSF_VERSION_PATCH}, ${COMMONLIBSF_VERSION_TWEAK} }") endforeach() + set(commonlibsf_plugin_compatibility "{ ${commonlibsf_plugin_compatibility} }") endif() @@ -144,11 +183,10 @@ endfunction() function(add_commonlibsf_plugin TARGET) set(options OPTIONAL USE_ADDRESS_LIBRARY USE_SIGNATURE_SCANNING STRUCT_DEPENDENT EXCLUDE_FROM_ALL) - set(oneValueArgs NAME AUTHOR VERSION MINIMUM_SFSE_VERSION) + set(oneValueArgs NAME AUTHOR EMAIL VERSION MINIMUM_SFSE_VERSION) set(multiValueArgs COMPATIBLE_RUNTIMES SOURCES) - cmake_parse_arguments(PARSE_ARGV 1 ADD_COMMONLIBSF_PLUGIN "${options}" "${oneValueArgs}" - "${multiValueArgs}") + "${multiValueArgs}") add_library("${TARGET}" SHARED $<$:EXCLUDE_FROM_ALL> ${ADD_COMMONLIBSF_PLUGIN_SOURCES}) diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 0595a7f1..95aea02c 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -3,4 +3,3 @@ include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@.cmake") include(CMakeFindDependencyMacro) find_dependency(spdlog CONFIG) -find_dependency(xbyak CONFIG) diff --git a/cmake/make-sourcelist.ps1 b/cmake/make-sourcelist.ps1 deleted file mode 100644 index 0c042e98..00000000 --- a/cmake/make-sourcelist.ps1 +++ /dev/null @@ -1,63 +0,0 @@ -#Requires -Version 5 - -# args -param ( - [string]$PathIn, - [string]$PathOut -) - -$ErrorActionPreference = "Stop" - -$SourceExt = @('.asm', '.c', '.cc', '.cpp', 'cppm', '.cxx', '.h', '.hpp', '.hxx', 'inc', '.inl', '.ixx', '.mxx') -$ConfigExt = @('.ini', '.json', '.toml', '.xml') -$DocsExt = @('.md') - -function Normalize-Path { - param ( - [string]$in - ) - - $out = $in -replace '\\', '/' - while ($out.Contains('//')) { - $out = $out -replace '//', '/' - } - return $out -} - -function Resolve-Files { - param ( - [string[]]$range = @('include', 'src') - ) - - process { - Push-Location $PathIn - $_generated = [System.Collections.ArrayList]::new(2048) - - try { - foreach ($directory in $range) { - Write-Host "[$PathIn/$directory]" - - Get-ChildItem "$PathIn/$directory" -Recurse -File -ErrorAction SilentlyContinue | Where-Object { - ($_.Extension -in ($SourceExt + $DocsExt)) - } | Resolve-Path -Relative | ForEach-Object { - Write-Host "`t<$_>" - $_generated.Add("`n`t`"$(Normalize-Path $_.Substring(2))`"") | Out-Null - } - } - } - finally { - Pop-Location - } - - return $_generated - } -} - -# @@SOURCEGEN -Write-Host "`tGenerating CMake sourcelist..." -Remove-Item "$PathOut/sourcelist.cmake" -Force -Confirm:$false -ErrorAction Ignore - -$generated = 'set(SOURCES' -$generated += Resolve-Files -$generated += "`n)" -[IO.File]::WriteAllText("$PathOut/sourcelist.cmake", $generated) diff --git a/scripts/add-file.ps1 b/scripts/add-file.ps1 deleted file mode 100644 index 1e9a0fa2..00000000 --- a/scripts/add-file.ps1 +++ /dev/null @@ -1,98 +0,0 @@ -<# -.SYNOPSIS -this script is for adding/modifying/commiting RE files alongside the CLib development. - -.EXAMPLE -to add new RE file (.h and .cpp), just input the file name, multiple files are separated by space -: TESNewUndefinedClass BGSInferiorStructure NiPoint200 - -to del RE file, prepend -d -: -d TESNewUndefinedClass BGSInferiorStructure NiPoint200 - -to undo last action, use -u -: -u -*can only revert last commit, cannot undo-revert last commit - -to bring RE file changes into a current ongoing visual studio project, use -r and do a build inside visual studio -: -r - -use ctrl ^ c to exit -#> - - -$workspace = Resolve-Path "$PSScriptRoot/../" -Push-Location $workspace -$include = "$workspace/include/RE" -$src = "$workspace/src/RE" - - -function Modify-File { - param ( - [string]$file, - [bool]$add = $true - ) - - $abbr = "$($file[0])" - if ($add) { - "#pragma once`n`nnamespace RE`n{`n}`n" | Out-File "$include/$abbr/$file.h" utf8 - "#include `"RE/$($abbr.ToUpper())/$file.h`"`nnamespace RE`n{`n}`n" | Out-File "$src/$abbr/$file.cpp" utf8 - - Write-Host "add [$file]" - } - else { - Remove-Item "$include/$abbr/$file.h" -Force -Confirm:$false -ErrorAction:SilentlyContinue | Out-Null - Remove-Item "$src/$abbr/$file.cpp" -Force -Confirm:$false -ErrorAction:SilentlyContinue | Out-Null - Write-Host "del [$file]" - } -} - - -$lastFile = "" -# 0 del -# 1 add -# 2 revert -# 3 commit -$lastAction = 0 - -while ($true) { - $cmd = Read-Host " " - - switch ($cmd[0]) { - '-' { - # actions - switch ($cmd[1]) { - 'd' { - # del - $files = $cmd.Split(' ') - $files = $files[1..$($files.Length - 1)] - $files | % { Modify-File $_ $false } - $script:lastFile = $files - $script:lastAction = $false - break - } - 'r' { - # refresh - & "$workspace/.github/make-directives.ps1" "$workspace" - - $cmake = "$workspace/CMakeLists.txt" - [IO.File]::WriteAllText($cmake, [IO.File]::ReadAllText($cmake)) - break - } - 'u' { - # undo - $script:lastAction = !$script:lastAction - $script:lastFile | % { Modify-File $_ $script:lastAction } - break - } - } - break - } - default { - $files = $cmd.Split(' ') - $files | % { Modify-File $_ $true } - $script:lastFile = $files - $script:lastAction = $true - break - } - } -} diff --git a/vcpkg.json b/vcpkg.json index ffe82752..3e189420 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,19 +1,18 @@ { "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "commonlibsf", - "version-date": "2024-07-13", + "version-string": "latest", "description": "A collaborative reverse-engineered library for Starfield.", "homepage": "https://github.com/Starfield-Reverse-Engineering/CommonLibSF", "license": "GPL-3.0-or-later", - "supports": "windows & x64", - "builtin-baseline": "7a57b42f959ad138a5283477fe2e6c97a7cb852f", - "dependencies": ["spdlog", "xbyak"], + "builtin-baseline": "f0f811770e0538fcb295a1750c0a5e0de5131d29", + "dependencies": ["spdlog"], "vcpkg-configuration": { "registries": [ { "kind": "git", + "baseline": "e376718dc96bd2a6431cc8f7b05eca555d51a123", "repository": "https://github.com/ThirdEyeSqueegee/vcpkg-ports", - "baseline": "4464251a08810053868f982a09db1f8cec4d9ee0", "packages": ["spdlog"] } ]