diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 60d5d98..d9ca97e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,13 @@ name: Build LootCLI on: push: - branches: master + branches: [master] pull_request: types: [opened, synchronize, reopened] + +env: + VCPKG_BINARY_SOURCES: clear;x-azblob,${{ vars.AZ_BLOB_VCPKG_URL }},${{ secrets.AZ_BLOB_SAS }},readwrite + jobs: build: runs-on: windows-2022 @@ -11,5 +15,4 @@ jobs: - name: Build LootCLI uses: ModOrganizer2/build-with-mob-action@master with: - mo2-third-parties: boost libloot mo2-dependencies: cmake_common diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3103a1f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-merge-conflict + - id: check-case-conflict + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v19.1.5 + hooks: + - id: clang-format + 'types_or': [c++, c] + +ci: + autofix_commit_msg: "[pre-commit.ci] Auto fixes from pre-commit.com hooks." + autofix_prs: true + autoupdate_commit_msg: "[pre-commit.ci] Pre-commit autoupdate." + autoupdate_schedule: quarterly + submodules: false diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cffcf2..35e9d98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,32 @@ cmake_minimum_required(VERSION 3.16) -if(DEFINED DEPENDENCIES_DIR) - include(${DEPENDENCIES_DIR}/modorganizer_super/cmake_common/mo2.cmake) -else() - include(${CMAKE_CURRENT_LIST_DIR}/../cmake_common/mo2.cmake) -endif() +include(CMakePackageConfigHelpers) project(lootcli) + add_subdirectory(src) + +# install the header helper +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/mo2-lootcli-header-config.cmake" + INSTALL_DESTINATION "lib/cmake/mo2-lootcli-header" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/version.h" lootcli_version) +string(REGEX MATCH "#define LOOTCLI_VERSION_STRING[ \t]*\"([0-9.]+)\"" _ ${lootcli_version}) +set(lootcli_version ${CMAKE_MATCH_1}) + +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/mo2-lootcli-header-config-version.cmake" + VERSION "${lootcli_version}" + COMPATIBILITY AnyNewerVersion + ARCH_INDEPENDENT +) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/mo2-lootcli-header-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/mo2-lootcli-header-config-version.cmake + DESTINATION lib/cmake/mo2-lootcli-header +) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..023baf5 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,52 @@ +{ + "configurePresets": [ + { + "errors": { + "deprecated": true + }, + "hidden": true, + "name": "cmake-dev", + "warnings": { + "deprecated": true, + "dev": true + } + }, + { + "cacheVariables": { + "VCPKG_MANIFEST_NO_DEFAULT_FEATURES": { + "type": "BOOL", + "value": "ON" + } + }, + "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "hidden": true, + "name": "vcpkg" + }, + { + "binaryDir": "${sourceDir}/vsbuild", + "architecture": { + "strategy": "set", + "value": "x64" + }, + "cacheVariables": { + "CMAKE_CXX_FLAGS": "/EHsc /MP /W4", + "VCPKG_TARGET_TRIPLET": { + "type": "STRING", + "value": "x64-windows-static-md" + } + }, + "generator": "Visual Studio 17 2022", + "inherits": ["cmake-dev", "vcpkg"], + "name": "vs2022-windows", + "toolset": "v143" + } + ], + "buildPresets": [ + { + "name": "vs2022-windows", + "resolvePackageReferences": "on", + "configurePreset": "vs2022-windows" + } + ], + "version": 4 +} diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in new file mode 100644 index 0000000..4c845a2 --- /dev/null +++ b/cmake/config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include ( "${CMAKE_CURRENT_LIST_DIR}/mo2-lootcli-header-targets.cmake" ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ceacdc..0bda942 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,85 @@ cmake_minimum_required(VERSION 3.16) +# Qt is not required, this allows us to skip building the executable and only create +# the single-header interface when using this as a VCPKG dependency + +find_package(Qt6 CONFIG COMPONENTS Core) + +if (Qt6_FOUND) + +message(STATUS "Qt6 found, building lootcli executable") + +find_package(tomlplusplus CONFIG REQUIRED) +find_package(libloot CONFIG REQUIRED) +find_package(Boost REQUIRED CONFIG COMPONENTS locale) + +# avoid CMake error/warning +set_target_properties(libloot::loot PROPERTIES + MAP_IMPORTED_CONFIG_RELEASE RelWithDebInfo + MAP_IMPORTED_CONFIG_MINSIZEREL RelWithDebInfo +) + add_executable(lootcli WIN32) +set_target_properties(lootcli PROPERTIES + CXX_STANDARD 20 + WIN32_EXECUTABLE TRUE) +target_sources(lootcli + PRIVATE + game_settings.cpp + game_settings.h + lootthread.cpp + lootthread.h + main.cpp + pch.h + version.h + version.rc + ${CMAKE_CURRENT_SOURCE_DIR}/../include/lootcli/lootcli.h +) +target_compile_definitions(lootcli + PRIVATE + _UNICODE UNICODE + _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) +target_include_directories(lootcli PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) +target_precompile_headers(lootcli PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/pch.h) +target_link_libraries(lootcli + PRIVATE libloot::loot Boost::headers Boost::locale + tomlplusplus::tomlplusplus Qt6::Core) + +if (MSVC) + target_compile_options(lootcli + PRIVATE + "/MP" + "/W4" + "/external:anglebrackets" + "/external:W0" + ) + target_link_options(lootcli + PRIVATE + $<$:/LTCG /INCREMENTAL:NO /OPT:REF /OPT:ICF> + ) + target_compile_definitions(lootcli PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) + + set_target_properties(lootcli PROPERTIES VS_STARTUP_PROJECT lootcli) +endif() + +install(FILES + $ + $ +DESTINATION bin/loot) + +endif() -mo2_configure_executable(lootcli - WARNINGS OFF - TRANSLATIONS OFF - PRIVATE_DEPENDS boost Qt::Core loot tomlplusplus) -target_include_directories(lootcli - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) +# library to make the header available +add_library(lootcli-header INTERFACE) +target_sources(lootcli-header INTERFACE + FILE_SET HEADERS + BASE_DIRS ${CMAKE_CURRENT_LIST_DIR}/../include + FILES ${CMAKE_CURRENT_LIST_DIR}/../include/lootcli/lootcli.h) +add_library(mo2::lootcli-header ALIAS lootcli-header) -mo2_install_target(lootcli INSTALLDIR bin/loot) +install(TARGETS lootcli-header EXPORT lootcliHeaderTargets FILE_SET HEADERS) +install(EXPORT lootcliHeaderTargets + FILE mo2-lootcli-header-targets.cmake + NAMESPACE mo2:: + DESTINATION lib/cmake/mo2-lootcli-header +) diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..d890106 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,30 @@ +{ + "dependencies": ["boost-locale", "tomlplusplus", "libloot"], + "overrides": [ + { + "name": "tomlplusplus", + "version": "3.1.0" + } + ], + "vcpkg-configuration": { + "default-registry": { + "kind": "git", + "repository": "https://github.com/Microsoft/vcpkg", + "baseline": "294f76666c3000630d828703e675814c05a4fd43" + }, + "registries": [ + { + "kind": "git", + "repository": "https://github.com/Microsoft/vcpkg", + "baseline": "294f76666c3000630d828703e675814c05a4fd43", + "packages": ["boost*", "boost-*"] + }, + { + "kind": "git", + "repository": "https://github.com/ModOrganizer2/vcpkg-registry", + "baseline": "8beb2e0efa9c17dd6d17bb05288dd1e40727f673", + "packages": ["libloot"] + } + ] + } +}