diff --git a/.copier-answers.yml b/.copier-answers.yml index e69ac83..0d2750a 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,4 +1,4 @@ -_commit: v1.6.21 +_commit: v1.7.3 _src_path: https://github.com/serious-scaffold/ss-cpp author_email: msclock@126.com author_name: l.feng @@ -19,6 +19,7 @@ repo_host: github.com repo_name: cppfront-practice repo_namespace: msclock repo_platform: github +unit_test: catch2 use_cdash: false use_codecov: true use_codeql: true diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index c12eb6a..db85aee 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -27,13 +27,13 @@ jobs: timeout-minutes: 15 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} ref: ${{ github.head_ref }} - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -50,7 +50,7 @@ jobs: ccache: true doxygen: true - - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 + - uses: actions/setup-python@v5 with: python-version: 3.x @@ -67,7 +67,7 @@ jobs: run: make docs - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./docs/_build/html diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bfa55a8..6f795ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,15 +20,15 @@ jobs: pre-commit: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 + - uses: actions/setup-python@v5 with: python-version: 3.11 - - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + - uses: pre-commit/action@v3.0.1 with: extra_args: --hook-stage manual --all-files @@ -47,12 +47,12 @@ jobs: name: check • ${{ matrix.triplet }} • ${{ matrix.compiler }} • c++${{ matrix.std }} • ${{ matrix.build_type }} steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -124,12 +124,12 @@ jobs: name: check • ${{ matrix.triplet }} • ${{ matrix.compiler }} • c++${{ matrix.std }} • ${{ matrix.build_type }} steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -189,7 +189,7 @@ jobs: check-on-windows: - runs-on: windows-2022 + runs-on: windows-2025 needs: [pre-commit] strategy: @@ -202,12 +202,12 @@ jobs: name: check • ${{ matrix.triplet }} • ${{ matrix.compiler }} • c++${{ matrix.std }} • ${{ matrix.build_type }} steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -254,7 +254,7 @@ jobs: check-mingw: - runs-on: windows-2022 + runs-on: windows-2025 needs: [pre-commit] strategy: @@ -267,12 +267,12 @@ jobs: name: check • ${{ matrix.triplet }} • ${{ matrix.compiler }} • c++${{ matrix.std }} • ${{ matrix.build_type }} steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -289,7 +289,7 @@ jobs: ninja: true ccache: true - - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 + - uses: actions/setup-python@v5 with: python-version: 3.x @@ -335,12 +335,12 @@ jobs: name: check • sanitizers • ${{ matrix.sanitizer }} • ${{ matrix.build_type }} steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -382,12 +382,12 @@ jobs: name: check • valgrind • ${{ matrix.build_type }} steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -433,7 +433,7 @@ jobs: - name: Upload test results if: failure() - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + uses: actions/upload-artifact@v4 with: name: valgrind-results path: out/valgrind-results.tar.gz @@ -443,12 +443,12 @@ jobs: needs: [pre-commit] steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -463,7 +463,7 @@ jobs: ninja: true ccache: true - - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 + - uses: actions/setup-python@v5 with: python-version: 3.x @@ -491,12 +491,12 @@ jobs: needs: [pre-commit] steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -511,7 +511,7 @@ jobs: ninja: true ccache: true - - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 + - uses: actions/setup-python@v5 with: python-version: 3.x @@ -539,12 +539,12 @@ jobs: needs: [pre-commit] steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -562,7 +562,7 @@ jobs: doxygen: true graphviz: true - - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 + - uses: actions/setup-python@v5 with: python-version: 3.x @@ -584,12 +584,12 @@ jobs: needs: [pre-commit] steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -628,7 +628,7 @@ jobs: run: cmake --build --preset=default --target ccov-all - name: Upload coverage report - uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3 + uses: codecov/codecov-action@v5.4.2 with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index c3d7afe..8809787 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -45,18 +45,18 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Initialize CodeQL - uses: github/codeql-action/init@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} config-file: ./.github/codeql-config.yml - name: Cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 + uses: actions/cache@v4 with: path: | ~/vcpkg @@ -87,4 +87,4 @@ jobs: run: cmake --build --preset=default --target all - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/renovate.yml b/.github/workflows/renovate.yml index 79b6dee..ee882b8 100644 --- a/.github/workflows/renovate.yml +++ b/.github/workflows/renovate.yml @@ -28,7 +28,7 @@ jobs: - name: Generate a token with GitHub App if App ID exists id: generate-token if: vars.BOT_APP_ID - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2 + uses: actions/create-github-app-token@v2 with: app-id: ${{ vars.BOT_APP_ID }} private-key: ${{ secrets.BOT_PRIVATE_KEY }} diff --git a/.github/workflows/semantic-release.yml b/.github/workflows/semantic-release.yml index 8035ac8..b5898cc 100644 --- a/.github/workflows/semantic-release.yml +++ b/.github/workflows/semantic-release.yml @@ -24,7 +24,7 @@ jobs: - name: Generate a bot token with BOT_APP_ID id: bot_token if: vars.BOT_APP_ID && env.BOT_PRIVATE_KEY != null - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2 + uses: actions/create-github-app-token@v2 env: BOT_PRIVATE_KEY: ${{ secrets.BOT_PRIVATE_KEY }} with: @@ -40,13 +40,13 @@ jobs: echo "# :warning: GITHUB_TOKEN is used" >> $GITHUB_STEP_SUMMARY echo "The GITHUB_TOKEN is used instead of a bot token or PAT that will not emit the released publish event for triggering a released workflow." >> $GITHUB_STEP_SUMMARY - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ steps.bot_token.outputs.token || secrets.PAT || secrets.GITHUB_TOKEN }} - name: Setup Node.js - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 + uses: actions/setup-node@v4 with: node-version: lts/* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index adea7ec..d570423 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -63,6 +63,12 @@ repos: additional_dependencies: [pyyaml] types: [file] files: (\.cmake|CMakeLists.txt)(.in)?$ + exclude: | + (?x)( + ^(cmake/vcpkg/ports/.*) | + ^(cmake/vcpkg/triplets/.*) | + ^(cmake/vcpkg/scripts/toolchains/.*) + ) # Check for spelling - repo: https://github.com/codespell-project/codespell diff --git a/.renovaterc.json b/.renovaterc.json index d508bf5..10cf532 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -2,11 +2,10 @@ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:recommended", - "helpers:pinGitHubActionDigests", ":enablePreCommit" ], "automergeType": "pr", - "automergeStrategy": "merge-commit", + "automergeStrategy": "squash", "ignoreScripts": false, "platformAutomerge": false, "packageRules": [ diff --git a/cmake/presets/triplets/x64-mingw-dynamic.json b/cmake/presets/triplets/x64-mingw-dynamic.json index 672dde6..849b15f 100644 --- a/cmake/presets/triplets/x64-mingw-dynamic.json +++ b/cmake/presets/triplets/x64-mingw-dynamic.json @@ -11,7 +11,8 @@ "x64" ], "cacheVariables": { - "VCPKG_TARGET_TRIPLET": "x64-mingw-dynamic" + "VCPKG_TARGET_TRIPLET": "x64-mingw-dynamic", + "VCPKG_HOST_TRIPLET": "x64-mingw-dynamic" } } ] diff --git a/cmake/presets/triplets/x64-mingw-static.json b/cmake/presets/triplets/x64-mingw-static.json index 49fb429..1caf05b 100644 --- a/cmake/presets/triplets/x64-mingw-static.json +++ b/cmake/presets/triplets/x64-mingw-static.json @@ -11,7 +11,8 @@ "x64" ], "cacheVariables": { - "VCPKG_TARGET_TRIPLET": "x64-mingw-static" + "VCPKG_TARGET_TRIPLET": "x64-mingw-static", + "VCPKG_HOST_TRIPLET": "x64-mingw-static" } } ] diff --git a/cmake/presets/x64-mingw-dynamic-windows-mingw.json b/cmake/presets/x64-mingw-dynamic-windows-mingw.json index 1300509..e917922 100644 --- a/cmake/presets/x64-mingw-dynamic-windows-mingw.json +++ b/cmake/presets/x64-mingw-dynamic-windows-mingw.json @@ -15,7 +15,6 @@ "mingw", "x64-mingw-dynamic" ] - } ], "buildPresets": [ diff --git a/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake b/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake index 5546f78..653b4d5 100644 --- a/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake +++ b/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake @@ -111,6 +111,31 @@ function(_vcpkg_upgrade vcpkg_root vcpkg_repo vcpkg_ref) return() endif() + # Check .gitconfig on linux or windows + if(EXISTS "$ENV{HOME}/.gitconfig" OR EXISTS "$ENV{USERPROFILE}/.gitconfig") + execute_process( + COMMAND ${GIT_EXECUTABLE} config --get-all safe.directory + WORKING_DIRECTORY ${vcpkg_root} + OUTPUT_VARIABLE safe_directory + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE result) + endif() + + if(NOT DEFINED safe_directory + OR (DEFINED safe_directory AND NOT safe_directory MATCHES "${vcpkg_root}")) + message(STATUS "vcpkg root is not in the git safe directory, adding...") + + execute_process( + COMMAND ${GIT_EXECUTABLE} config --global safe.directory ${vcpkg_root} + --append + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${GIT_EXECUTABLE} config failed with ${result}") + endif() + endif() + execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY ${vcpkg_root} @@ -210,4 +235,16 @@ function(_vcpkg_bootstrap) endif() _vcpkg_set_cache_variables("${vcpkg_root}") + + # Make sure downloads folder is 755 on linux + if(CMAKE_HOST_UNIX) + execute_process( + COMMAND chmod 755 ${vcpkg_root}/downloads + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(STATUS "failed to chmod 755 ${vcpkg_root}/downloads") + endif() + endif() endfunction() diff --git a/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake b/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake index 2cff74e..2c0d034 100644 --- a/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake +++ b/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake @@ -5,41 +5,51 @@ SPDX-FileCopyrightText: Copyright 2024 msclock # configure VCPKG_CHAINLOAD_TOOLCHAIN_FILE based on VCPKG_TARGET_TRIPLET and # VCPKG_TARGET_ARCHITECTURE -function(_vcpkg_chainload_toolchain) - if(DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) - return() - endif() +macro(_vcpkg_chainload_toolchain) + if(NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + if(NOT DEFINED VCPKG_TARGET_TRIPLET OR NOT DEFINED + VCPKG_TARGET_ARCHITECTURE) + message( + FATAL_ERROR + "VCPKG_TARGET_TRIPLET and VCPKG_TARGET_ARCHITECTURE must be set before calling _vcpkg_chainload_toolchain()" + ) + endif() - if(NOT DEFINED VCPKG_TARGET_TRIPLET OR NOT DEFINED VCPKG_TARGET_ARCHITECTURE) - message( - FATAL_ERROR - "VCPKG_TARGET_TRIPLET and VCPKG_TARGET_ARCHITECTURE must be set before calling _vcpkg_chainload_toolchain()" - ) - endif() + # Load toolchain variables from triplet and architecture + + string(LENGTH "${VCPKG_TARGET_ARCHITECTURE}-" _prefix_len) + string(SUBSTRING ${VCPKG_TARGET_TRIPLET} ${_prefix_len} -1 _stripped_string) + string(REPLACE "-" ";" _triplet_parts "${_stripped_string}") + list(GET _triplet_parts 0 _chainload_toolchain_name) - # Load toolchain variables from triplet and architecture + set(_toolchain "scripts/toolchains/${_chainload_toolchain_name}.cmake") - string(LENGTH "${VCPKG_TARGET_ARCHITECTURE}-" _prefix_len) - string(SUBSTRING ${VCPKG_TARGET_TRIPLET} ${_prefix_len} -1 _stripped_string) - string(REPLACE "-" ";" _triplet_parts "${_stripped_string}") - list(GET _triplet_parts 0 _chainload_toolchain_name) + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${_toolchain}") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE + "${CMAKE_CURRENT_LIST_DIR}/${_toolchain}" + CACHE INTERNAL "vcpkg chainload") + elseif(EXISTS "${_VCPKG_ROOT}/${_toolchain}") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE + "${_VCPKG_ROOT}/${_toolchain}" + CACHE INTERNAL "vcpkg chainload") - set(_toolchain "scripts/toolchains/${_chainload_toolchain_name}.cmake") + else() + message( + WARNING + "Could not find toolchain file for ${_chainload_toolchain_name}, skipping chainload" + ) + endif() + endif() - if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${_toolchain}") - set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE - "${CMAKE_CURRENT_LIST_DIR}/${_toolchain}" - CACHE INTERNAL "vcpkg chainload") - elseif(EXISTS "${_VCPKG_ROOT}/${_toolchain}") - set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE - "${_VCPKG_ROOT}/${_toolchain}" - CACHE INTERNAL "vcpkg chainload") - else() + if(EXISTS "${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") message( - WARNING - "Could not find toolchain file for ${_chainload_toolchain_name}, skipping chainload" + STATUS "vcpkg_chainload_toolchain_file: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}" ) + include(${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}) endif() - message( - STATUS "vcpkg_chainload_toolchain_file: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") -endfunction() + unset(_chainload_toolchain_name) + unset(_triplet_parts) + unset(_toolchain) + unset(_prefix_len) + unset(_stripped_string) +endmacro() diff --git a/cmake/vcpkg/ports/README.md b/cmake/vcpkg/ports/README.md index a129778..5f8f853 100644 --- a/cmake/vcpkg/ports/README.md +++ b/cmake/vcpkg/ports/README.md @@ -1,3 +1,19 @@ # Customize vcpkg ports This folder applies to the custom vcpkg ports. These ports are loaded automatically which can be patched from the `ports` folder of the vcpkg repository or created from scratch. + +## Customize linkage + +Prepare the port from the vcpkg repository + +```bash +cp /path/to/vcpkg/repository/ports/7zip . -r +``` + +Edit the port to only accept the dynamic linkage by [vcpkg_check_linkage](https://learn.microsoft.com/en-us/vcpkg/maintainers/functions/vcpkg_check_linkage) to the head of the port file + +```bash +sed -i '1s/^/vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)\n/' 7zip/portfile.cmake +``` + +And re-cmake the project to re-build the port with dynamic linkage. diff --git a/cmake/vcpkg/ports/fmt/fix-write-batch.patch b/cmake/vcpkg/ports/fmt/fix-write-batch.patch new file mode 100644 index 0000000..6bec3b8 --- /dev/null +++ b/cmake/vcpkg/ports/fmt/fix-write-batch.patch @@ -0,0 +1,13 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 88c12148..967b53dd 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -260,7 +260,7 @@ if (FMT_MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio") + join(netfxpath + "C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\" + ".NETFramework\\v4.0") +- file(WRITE run-msbuild.bat " ++ file(WRITE "${CMAKE_BINARY_DIR}/run-msbuild.bat" " + ${MSBUILD_SETUP} + ${CMAKE_MAKE_PROGRAM} -p:FrameworkPathOverride=\"${netfxpath}\" %*") + endif () diff --git a/cmake/vcpkg/ports/fmt/portfile.cmake b/cmake/vcpkg/ports/fmt/portfile.cmake new file mode 100644 index 0000000..3058d1c --- /dev/null +++ b/cmake/vcpkg/ports/fmt/portfile.cmake @@ -0,0 +1,37 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO fmtlib/fmt + REF "${VERSION}" + SHA512 46974efd36e613477351aa357c451cee434da797c2a505f9f86d73e394dcb35dc2dc0cda66abb98c023e8f24deac9d8e3ee6f9f6c0971cc4c00e37c34aa7f15f + HEAD_REF master + PATCHES + fix-write-batch.patch +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + -DFMT_CMAKE_DIR=share/fmt + -DFMT_TEST=OFF + -DFMT_DOC=OFF +) + +vcpkg_cmake_install() +vcpkg_cmake_config_fixup() +vcpkg_fixup_pkgconfig() +vcpkg_copy_pdbs() + +if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/fmt/base.h" + "defined(FMT_SHARED)" + "1" + ) +endif() + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" +) + +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/cmake/vcpkg/ports/fmt/usage b/cmake/vcpkg/ports/fmt/usage new file mode 100644 index 0000000..e5a9d70 --- /dev/null +++ b/cmake/vcpkg/ports/fmt/usage @@ -0,0 +1,8 @@ +The package fmt provides CMake targets: + + find_package(fmt CONFIG REQUIRED) + target_link_libraries(main PRIVATE fmt::fmt) + + # Or use the header-only version + find_package(fmt CONFIG REQUIRED) + target_link_libraries(main PRIVATE fmt::fmt-header-only) diff --git a/cmake/vcpkg/ports/fmt/vcpkg.json b/cmake/vcpkg/ports/fmt/vcpkg.json new file mode 100644 index 0000000..4d59119 --- /dev/null +++ b/cmake/vcpkg/ports/fmt/vcpkg.json @@ -0,0 +1,18 @@ +{ + "name": "fmt", + "version": "11.2.0", + "port-version": 1, + "description": "{fmt} is an open-source formatting library providing a fast and safe alternative to C stdio and C++ iostreams.", + "homepage": "https://github.com/fmtlib/fmt", + "license": "MIT", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/cmake/vcpkg/scripts/build_type.cmake b/cmake/vcpkg/scripts/build_type.cmake index a49dad6..95342bf 100644 --- a/cmake/vcpkg/scripts/build_type.cmake +++ b/cmake/vcpkg/scripts/build_type.cmake @@ -5,22 +5,30 @@ SPDX-FileCopyrightText: Copyright 2024 msclock This module initializes the build type. ]] -if(NOT CMAKE_BUILD_TYPE) - message(STATUS "Setting CMAKE_BUILD_TYPE to 'Debug' as none was specified.") -endif() -set(CMAKE_BUILD_TYPE - Debug - CACHE STRING "Choose the type of build.") - -# Set the possible values of build type for cmake-gui, ccmake -get_property(_builtin_build_types GLOBAL PROPERTY CMAKE_BUILD_TYPE) +get_property(_is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -foreach(_type "Debug" "Release" "MinSizeRel" "RelWithDebInfo") - if(NOT _type IN_LIST _builtin_build_types) - list(APPEND _builtin_build_types ${_type}) +if(_is_multi_config) + message(STATUS "Multi-config generator detected") + message(STATUS "Available configuration types: ${CMAKE_CONFIGURATION_TYPES}") +else() + message(STATUS "Single-config generator detected") + if(NOT CMAKE_BUILD_TYPE) + message(STATUS "Setting CMAKE_BUILD_TYPE to 'Debug' as none was specified.") + set(CMAKE_BUILD_TYPE + Debug + CACHE STRING "Choose the type of build.") endif() -endforeach() -set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_builtin_build_types}) + # Set the possible values of build type for cmake-gui, ccmake + get_property(_builtin_build_types GLOBAL PROPERTY CMAKE_BUILD_TYPE) + + foreach(_type "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + if(NOT _type IN_LIST _builtin_build_types) + list(APPEND _builtin_build_types ${_type}) + endif() + endforeach() -unset(_builtin_build_types) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_builtin_build_types}) + + unset(_builtin_build_types) +endif() diff --git a/cmake/vcpkg/triplets/README.md b/cmake/vcpkg/triplets/README.md index 74db63a..1c110d3 100644 --- a/cmake/vcpkg/triplets/README.md +++ b/cmake/vcpkg/triplets/README.md @@ -2,21 +2,31 @@ This folder applies to the custom vcpkg triplets. These triplets are loaded automatically which can be copied from the `triplets` folder of the vcpkg repository or created from scratch. -For example, to create a custom triplet for Linux x64 with dynamic library linkage: +## Customize linkage + +Prepare the triplet from the vcpkg repository ```bash -# Copy the triplet from the vcpkg repository cp /path/to/vcpkg/repository/triplets/x64-linux.cmake ./x64-linux.cmake -# Edit the triplet to change the library linkage to dynamic +``` + +Edit the triplet to change the [VCPKG_LIBRARY_LINKAGE](https://learn.microsoft.com/en-us/vcpkg/users/triplets) to dynamic + +```bash +# Apply for all ports to link dynamically sed -i ./x64-linux.cmake -e's/set(VCPKG_LIBRARY_LINKAGE static)/set(VCPKG_LIBRARY_LINKAGE dynamic)/g' -# Show the contents of the triplet -cat ./x64-linux.cmake -# set(VCPKG_TARGET_ARCHITECTURE x64) -# set(VCPKG_CRT_LINKAGE dynamic) -# set(VCPKG_LIBRARY_LINKAGE dynamic) -# set(VCPKG_CMAKE_SYSTEM_NAME Linux) +# Or apply for specific ports to link dynamically +cat << EOF >> ./x64-linux.cmake +if(PORT MATCHES "qt5-") + set(VCPKG_LIBRARY_LINKAGE dynamic) +endif() +EOF +``` + +Use it when configure the project +```bash # Use it when configure the project -cmake --preset=default -DVCPKG_TARGET_TRIPLET=x64-linux +cmake ... -DVCPKG_TARGET_TRIPLET=x64-linux ``` diff --git a/cmake/vcpkg/vcpkg.toolchain.cmake b/cmake/vcpkg/vcpkg.toolchain.cmake index e268ec0..997264d 100644 --- a/cmake/vcpkg/vcpkg.toolchain.cmake +++ b/cmake/vcpkg/vcpkg.toolchain.cmake @@ -28,3 +28,6 @@ set(VCPKG_VERBOSE file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json) string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline) vcpkg_configure(CACHE_DIR_NAME cppfront-practice REF ${_builtin_baseline}) + +message(STATUS "CMAKE_CXX_COMPILER_TARGET: ${CMAKE_CXX_COMPILER_TARGET}") +message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}") diff --git a/vcpkg.json b/vcpkg.json index 774a99b..1e2c260 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -2,7 +2,7 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "cppfront-practice", "description": "Practice based on cppfront", - "builtin-baseline": "984f9232b2fe0eb94f5e9f161d6c632c581fff0c", + "builtin-baseline": "41c447cc210dc39aa85d4a5f58b4a1b9e573b3dc", "homepage": "https://github.com/msclock/cppfront-practice", "dependencies": [ "cppfront", @@ -14,12 +14,11 @@ "overrides": [ { "name": "fmt", - "version": "10.2.1", - "port-version": 2 + "version": "11.2.0" }, { "name": "spdlog", - "version": "1.13.0" + "version": "1.15.2" }, { "name": "cmake-modules", @@ -35,8 +34,8 @@ "description": "Dependencies for testing", "dependencies": [ { - "name": "gtest", - "version>=": "1.14.0" + "name": "catch2", + "version>=": "3.7.1" } ] } @@ -45,7 +44,7 @@ "registries": [ { "kind": "git", - "baseline": "5909aec4d2a472ab4c734832c7391926bce7ce18", + "baseline": "72847990e168d014e2918e26218e4ae492f5b569", "repository": "https://github.com/msclock/cmake-registry", "packages": [ "cmake-modules",