├── .git-blame-ignore-revs ├── cmake ├── vcpkg │ ├── triplets │ │ ├── x64-windows-dynamic.cmake │ │ ├── x86-linux-dynamic.cmake │ │ ├── x64-linux-clang-dynamic.cmake │ │ └── x86-linux-clang-dynamic.cmake │ ├── vcpkg.toolchain.cmake │ └── bootstrap │ │ ├── vcpkg_configure.cmake │ │ ├── vcpkg-config.cmake │ │ ├── vcpkg_autodetect_host_triplet.cmake │ │ ├── vcpkg_autodetect_target_triplet.cmake │ │ ├── vcpkg_skip_install_on_reconfigure.cmake │ │ └── vcpkg_bootstrap.cmake └── presets │ ├── compilers │ ├── msvc.json │ ├── gcc.json │ └── clang.json │ ├── toolchains │ └── vcpkg.json │ ├── os │ ├── linux.json │ ├── windows.json │ └── darwin.json │ ├── generators │ └── ninja.json │ ├── base.json │ ├── x64-linux-gcc.json │ ├── x86-linux-gcc.json │ ├── x64-darwin-gcc.json │ ├── arm64-darwin-gcc.json │ ├── x64-darwin-clang.json │ ├── x64-windows-msvc.json │ ├── x64-windows-clang.json │ ├── arm64-darwin-clang.json │ ├── x64-linux-clang.json │ └── x86-linux-clang.json ├── tests ├── module-1 │ ├── CMakeLists.txt │ └── header-1_test.cpp ├── CMakeLists.txt └── cmake │ └── add_cpp_pt_test.cmake ├── .github ├── actions │ ├── windows │ │ ├── msvc │ │ │ └── action.yaml │ │ ├── clang │ │ │ └── action.yaml │ │ └── base │ │ │ └── action.yaml │ ├── darwin │ │ ├── gcc │ │ │ └── action.yaml │ │ ├── base │ │ │ └── action.yaml │ │ └── x86 │ │ │ └── action.yaml │ ├── linux │ │ ├── gcc │ │ │ └── action.yaml │ │ ├── clang │ │ │ └── action.yaml │ │ ├── base │ │ │ └── action.yaml │ │ └── x86 │ │ │ └── action.yaml │ ├── vcpkg-cache │ │ └── action.yaml │ └── install-dependencies │ │ └── action.yaml ├── ci.yaml └── workflows │ └── ci.yaml ├── .gitignore ├── vcpkg.json ├── src ├── cmake │ ├── cpp-pt-config.cmake │ ├── add_cpp_pt_executable.cmake │ ├── cpp-pt-install-targets.cmake │ ├── set_cpp_pt_target_properties.cmake │ └── add_cpp_pt_module.cmake ├── module-1 │ ├── CMakeLists.txt │ ├── src │ │ └── header-1.cpp │ └── include │ │ └── cpp-pt │ │ └── module-1 │ │ └── header-1.hpp ├── cli │ ├── CMakeLists.txt │ └── src │ │ └── main.cpp └── CMakeLists.txt ├── CMakeLists.txt ├── CMakePresets.json ├── .cmake-format ├── .pre-commit-config.yaml ├── .clang-format ├── README.md └── init.cmake /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /cmake/vcpkg/triplets/x64-windows-dynamic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE dynamic) 4 | -------------------------------------------------------------------------------- /tests/module-1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | add_@cpp_pt_cmake@_test(@cpp_pt_module_header@) 5 | -------------------------------------------------------------------------------- /.github/actions/windows/msvc/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Windows activate msvc" 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - uses: ilammy/msvc-dev-cmd@v1 7 | with: 8 | arch: x64 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # cmake 2 | build 3 | CMakeUserPresets.json 4 | Testing 5 | 6 | #clangd 7 | .cache/clangd 8 | compile_commands.json 9 | 10 | # CLion 11 | .idea 12 | 13 | # other 14 | _build 15 | tmp 16 | -------------------------------------------------------------------------------- /.github/actions/darwin/gcc/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Ubuntu latest gcc" 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Install g++ 7 | shell: bash 8 | run: | 9 | brew install gcc 10 | -------------------------------------------------------------------------------- /.github/actions/linux/gcc/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Ubuntu latest gcc" 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Install g++ 7 | shell: bash 8 | run: | 9 | sudo apt-get install -y g++ 10 | -------------------------------------------------------------------------------- /cmake/vcpkg/triplets/x86-linux-dynamic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x86) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE dynamic) 4 | 5 | set(VCPKG_CMAKE_SYSTEM_NAME Linux) 6 | 7 | set(VCPKG_FIXUP_ELF_RPATH ON) 8 | -------------------------------------------------------------------------------- /.github/actions/linux/clang/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Ubuntu latest clang" 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Install clang 7 | shell: bash 8 | run: | 9 | sudo apt-get install -y clang 10 | -------------------------------------------------------------------------------- /.github/actions/windows/clang/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Windows activate clang" 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - uses: egor-tensin/setup-clang@v1 7 | with: 8 | version: 16 9 | platform: x64 10 | -------------------------------------------------------------------------------- /.github/actions/windows/base/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Ubuntu base dependencies" 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Install system dependencies 7 | shell: bash 8 | run: | 9 | choco install ninja 10 | -------------------------------------------------------------------------------- /.github/actions/darwin/base/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Ubuntu base dependencies" 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Install system dependencies 7 | shell: bash 8 | run: | 9 | brew install ninja cmake 10 | -------------------------------------------------------------------------------- /.github/actions/darwin/x86/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Ubuntu x86 dependencies" 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Install x86 dependencies 7 | shell: bash 8 | run: | 9 | sudo apt-get install -y lib32stdc++6 g++-multilib 10 | -------------------------------------------------------------------------------- /cmake/presets/compilers/msvc.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "configurePresets": [ 4 | { 5 | "name": "msvc", 6 | "hidden": true, 7 | "environment": { 8 | "CC": "cl.exe", 9 | "CXX": "cl.exe" 10 | } 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /.github/actions/linux/base/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Ubuntu base dependencies" 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Install system dependencies 7 | shell: bash 8 | run: | 9 | sudo apt-get update 10 | sudo apt-get install -y ninja-build 11 | -------------------------------------------------------------------------------- /vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", 3 | "name": "@cpp_pt_name@", 4 | "version-string": "0.0.1", 5 | "dependencies": [ 6 | "fmt", 7 | "range-v3", 8 | "ms-gsl", 9 | "catch2" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /.github/actions/linux/x86/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Ubuntu x86 dependencies" 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Install x86 dependencies 7 | shell: bash 8 | run: | 9 | sudo apt-get install -y lib32stdc++6 g++-multilib libc++abi-14-dev libc++abi-14-dev 10 | -------------------------------------------------------------------------------- /tests/module-1/header-1_test.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | // SPDX-License-Identifier: MIT 3 | 4 | #include "@cpp_pt_name@/@cpp_pt_module@/@cpp_pt_module_header@.hpp" 5 | 6 | #include 7 | 8 | TEST_CASE("header sanity check") { 9 | } 10 | -------------------------------------------------------------------------------- /src/cmake/cpp-pt-config.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | include(CMakeFindDependencyMacro) 5 | 6 | find_dependency(fmt) 7 | find_dependency(Microsoft.GSL) 8 | find_dependency(range-v3) 9 | 10 | include("${CMAKE_CURRENT_LIST_DIR}/@cpp_pt_name@-targets.cmake") 11 | -------------------------------------------------------------------------------- /src/module-1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | add_@cpp_pt_cmake@_module(@cpp_pt_module@) 5 | 6 | target_sources(${@cpp_pt_cmake@_module_target} PRIVATE 7 | include/@cpp_pt_name@/@cpp_pt_module@/@cpp_pt_module_header@.hpp 8 | src/@cpp_pt_module_header@.cpp) 9 | -------------------------------------------------------------------------------- /cmake/vcpkg/triplets/x64-linux-clang-dynamic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE dynamic) 4 | 5 | set(VCPKG_CMAKE_SYSTEM_NAME Linux) 6 | 7 | set(VCPKG_CXX_FLAGS -stdlib=libc++) 8 | set(VCPKG_C_FLAGS -stdlib=libc++) 9 | set(VCPKG_LINKER_FLAGS "-stdlib=libc++ -lc++abi") 10 | -------------------------------------------------------------------------------- /cmake/vcpkg/triplets/x86-linux-clang-dynamic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x86) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE dynamic) 4 | 5 | set(VCPKG_CMAKE_SYSTEM_NAME Linux) 6 | 7 | set(VCPKG_CXX_FLAGS -stdlib=libc++) 8 | set(VCPKG_C_FLAGS -stdlib=libc++) 9 | set(VCPKG_LINKER_FLAGS "-stdlib=libc++ -lc++abi") 10 | -------------------------------------------------------------------------------- /src/cli/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | add_@cpp_pt_cmake@_executable(cli) 5 | 6 | target_sources(${@cpp_pt_cmake@_executable_target} PRIVATE src/main.cpp) 7 | 8 | target_link_libraries(${@cpp_pt_cmake@_executable_target} 9 | PRIVATE 10 | @cpp_pt_name@::@cpp_pt_module@ 11 | ) 12 | -------------------------------------------------------------------------------- /src/module-1/src/header-1.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | // SPDX-License-Identifier: MIT 3 | 4 | #include "@cpp_pt_name@/@cpp_pt_module@/@cpp_pt_module_header@.hpp" 5 | 6 | namespace @cpp_pt_name@::@cpp_pt_module@ { 7 | 8 | std::string version() noexcept { 9 | return "0.0.1"; 10 | } 11 | 12 | } // namespace @cpp_pt_name@::@cpp_pt_module@ 13 | -------------------------------------------------------------------------------- /src/cli/src/main.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | // SPDX-License-Identifier: MIT 3 | 4 | #include "@cpp_pt_name@/@cpp_pt_module@/@cpp_pt_module_header@.hpp" 5 | 6 | #include 7 | 8 | int main(int /*argc*/, char * /*argv*/ []) { 9 | fmt::print("@cpp_pt_name@ version: {}\n", @cpp_pt_name@::@cpp_pt_module@::version()); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | @CPP_PT_HAS_NOT_BEEN_INIT_PLEASE_READ_README@ 4 | cmake_minimum_required(VERSION 3.25) 5 | 6 | project(@cpp_pt_name@-dev LANGUAGES CXX) 7 | 8 | list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") 9 | 10 | add_subdirectory(src) 11 | 12 | enable_testing() 13 | add_subdirectory(tests) 14 | -------------------------------------------------------------------------------- /src/module-1/include/cpp-pt/module-1/header-1.hpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | // SPDX-License-Identifier: MIT 3 | 4 | #pragma once 5 | 6 | #include "@cpp_pt_name@/@cpp_pt_module@/export.hpp" 7 | 8 | #include 9 | 10 | namespace @cpp_pt_name@::@cpp_pt_module@ { 11 | 12 | [[nodiscard]] @cpp_pt_module_export@ std::string version() noexcept; 13 | 14 | } // namespace @cpp_pt_name@::@cpp_pt_module@ 15 | -------------------------------------------------------------------------------- /cmake/presets/toolchains/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "configurePresets": [ 4 | { 5 | "name": "vcpkg", 6 | "hidden": true, 7 | "toolchainFile": "${sourceDir}/cmake/vcpkg/vcpkg.toolchain.cmake", 8 | "cacheVariables": { 9 | "VCPKG_INSTALL_OPTIONS": "--no-print-usage", 10 | "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake/vcpkg/triplets", 11 | "VCPKG_PRESET_NAME": "${presetName}" 12 | } 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /cmake/presets/compilers/gcc.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "configurePresets": [ 4 | { 5 | "name": "gcc", 6 | "hidden": true, 7 | "environment": { 8 | "CC": "gcc", 9 | "CXX": "g++" 10 | } 11 | }, 12 | { 13 | "name": "x86-gcc", 14 | "hidden": true, 15 | "inherits": "gcc", 16 | "cacheVariables": { 17 | "CMAKE_C_FLAGS": "-m32", 18 | "CMAKE_CXX_FLAGS": "-m32" 19 | } 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /cmake/presets/compilers/clang.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "configurePresets": [ 4 | { 5 | "name": "clang", 6 | "hidden": true, 7 | "environment": { 8 | "CC": "clang", 9 | "CXX": "clang++" 10 | } 11 | }, 12 | { 13 | "name": "x86-clang", 14 | "hidden": true, 15 | "inherits": "clang", 16 | "cacheVariables": { 17 | "CMAKE_C_FLAGS": "-m32", 18 | "CMAKE_CXX_FLAGS": "-m32" 19 | } 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | @CPP_PT_HAS_NOT_BEEN_INIT_PLEASE_READ_README@ 4 | cmake_minimum_required(VERSION 3.25) 5 | 6 | project( 7 | @cpp_pt_name@ 8 | VERSION 0.0.1 9 | LANGUAGES CXX 10 | ) 11 | 12 | list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") 13 | 14 | include(@cpp_pt_name@-install-targets) 15 | include(add_@cpp_pt_cmake@_module) 16 | include(add_@cpp_pt_cmake@_executable) 17 | 18 | add_subdirectory(@cpp_pt_module@) 19 | add_subdirectory(cli) 20 | -------------------------------------------------------------------------------- /.github/actions/vcpkg-cache/action.yaml: -------------------------------------------------------------------------------- 1 | name: "Vcpkg binary cache + GitHub Actions cache" 2 | 3 | 4 | runs: 5 | using: "composite" 6 | steps: 7 | - uses: actions/github-script@v6 8 | with: 9 | script: | 10 | core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); 11 | core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); 12 | 13 | - name: Set vcpkg binary source 14 | shell: bash 15 | run: | 16 | echo "VCPKG_BINARY_SOURCES=clear;x-gha,readwrite" >> ${GITHUB_ENV} 17 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "cmakeMinimumRequired": { 4 | "major": 3, 5 | "minor": 25, 6 | "patch": 0 7 | }, 8 | "include": [ 9 | "cmake/presets/arm64-darwin-gcc.json", 10 | "cmake/presets/arm64-darwin-clang.json", 11 | "cmake/presets/x64-darwin-gcc.json", 12 | "cmake/presets/x64-darwin-clang.json", 13 | "cmake/presets/x64-linux-gcc.json", 14 | "cmake/presets/x64-windows-clang.json", 15 | "cmake/presets/x64-windows-msvc.json", 16 | "cmake/presets/x86-linux-gcc.json", 17 | "cmake/presets/x64-linux-clang.json" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /cmake/presets/os/linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "configurePresets": [ 4 | { 5 | "name": "linux", 6 | "hidden": true, 7 | "condition": { 8 | "type": "equals", 9 | "lhs": "${hostSystemName}", 10 | "rhs": "Linux" 11 | } 12 | } 13 | ], 14 | "buildPresets": [ 15 | { 16 | "name": "linux", 17 | "hidden": true, 18 | "configurePreset": "linux" 19 | } 20 | ], 21 | "testPresets": [ 22 | { 23 | "name": "linux", 24 | "hidden": true, 25 | "configurePreset": "linux" 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /cmake/presets/os/windows.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "configurePresets": [ 4 | { 5 | "name": "windows", 6 | "hidden": true, 7 | "condition": { 8 | "type": "equals", 9 | "lhs": "${hostSystemName}", 10 | "rhs": "Windows" 11 | } 12 | } 13 | ], 14 | "buildPresets": [ 15 | { 16 | "name": "windows", 17 | "hidden": true, 18 | "configurePreset": "windows" 19 | } 20 | ], 21 | "testPresets": [ 22 | { 23 | "name": "windows", 24 | "hidden": true, 25 | "configurePreset": "windows" 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | @CPP_PT_HAS_NOT_BEEN_INIT_PLEASE_READ_README@ 4 | cmake_minimum_required(VERSION 3.25) 5 | 6 | project(@cpp_pt_name@-tests LANGUAGES CXX) 7 | 8 | list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") 9 | 10 | include(add_@cpp_pt_cmake@_test) 11 | 12 | add_subdirectory(@cpp_pt_module@) 13 | 14 | add_test( 15 | NAME cmake-install 16 | COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --config $ 17 | --prefix "${CMAKE_CURRENT_BINARY_DIR}/cmake/$/install/" 18 | ) 19 | -------------------------------------------------------------------------------- /.cmake-format: -------------------------------------------------------------------------------- 1 | # ----------------------------- 2 | # Options affecting formatting. 3 | # ----------------------------- 4 | with section("format"): 5 | # If a statement is wrapped to more than one line, than dangle the closing 6 | # parenthesis on its own line. 7 | dangle_parens = True 8 | 9 | # ------------------------------------------------ 10 | # Options affecting comment reflow and formatting. 11 | # ------------------------------------------------ 12 | with section("markup"): 13 | # If comment markup is enabled, don't reflow any comment block which matches 14 | # this (regex) pattern. Default is `None` (disabled). 15 | literal_comment_pattern = " Copyright.*" 16 | -------------------------------------------------------------------------------- /cmake/vcpkg/vcpkg.toolchain.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | include_guard(GLOBAL) 5 | 6 | cmake_minimum_required(VERSION 3.25) 7 | 8 | get_property(IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) 9 | 10 | if(IN_TRY_COMPILE) 11 | return() 12 | endif() 13 | 14 | unset(IN_TRY_COMPILE) 15 | 16 | include(${CMAKE_CURRENT_LIST_DIR}/bootstrap/vcpkg-config.cmake) 17 | 18 | vcpkg_configure( 19 | CACHE_DIR_NAME @cpp_pt_name@ 20 | REPO https://github.com/microsoft/vcpkg.git 21 | REF 9edb1b8e590cc086563301d735cae4b6e732d2d2 # release 2023.08.09 22 | ) 23 | 24 | include($CACHE{_VCPKG_TOOLCHAIN_FILE}) 25 | -------------------------------------------------------------------------------- /cmake/vcpkg/bootstrap/vcpkg_configure.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | # bootstrap and configure vcpkg 5 | function(vcpkg_configure) 6 | _vcpkg_bootstrap(${ARGN}) 7 | _vcpkg_autodetect_target_triplet() 8 | _vcpkg_autodetect_host_triplet() 9 | _vcpkg_skip_install_on_reconfigure() 10 | 11 | if ("${__vcpkg_bootstrap_host}" STREQUAL "Linux" 12 | AND "${__vcpkg_bootstrap_arch}" MATCHES "arm|aarch") 13 | # VCPKG_FORCE_SYSTEM_BINARIES must be set on "weird platforms", see 14 | # https://github.com/microsoft/vcpkg-tool/blob/1c9ec1978a6b0c2b39c9e9554a96e3e275f7556e/src/vcpkg.cpp#L277 15 | set(ENV{VCPKG_FORCE_SYSTEM_BINARIES} 1) 16 | endif() 17 | endfunction() 18 | -------------------------------------------------------------------------------- /src/cmake/add_cpp_pt_executable.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | include_guard(GLOBAL) 5 | 6 | include(set_@cpp_pt_cmake@_target_properties) 7 | 8 | # sets all nessary default things 9 | function(add_@cpp_pt_cmake@_executable executable_name) 10 | set(executable_target @cpp_pt_cmake@-${executable_name}) 11 | 12 | add_executable(${executable_target} ${ARGN}) 13 | set_@cpp_pt_cmake@_target_properties(${executable_target} PRIVATE) 14 | 15 | if (TARGET @cpp_pt_name@) 16 | install(TARGETS ${executable_target} EXPORT @cpp_pt_name@-targets) 17 | endif() 18 | 19 | set(@cpp_pt_cmake@_executable_target 20 | ${executable_target} 21 | PARENT_SCOPE 22 | ) 23 | endfunction() 24 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | default_install_hook_types: [pre-commit, commit-msg] 3 | repos: 4 | - repo: https://github.com/pre-commit/pre-commit-hooks 5 | rev: v4.4.0 6 | hooks: 7 | - id: trailing-whitespace 8 | - id: end-of-file-fixer 9 | - repo: https://github.com/pre-commit/mirrors-clang-format 10 | rev: v16.0.6 11 | hooks: 12 | - id: clang-format 13 | types_or: [c++, c] 14 | - repo: https://github.com/python-jsonschema/check-jsonschema 15 | rev: 0.26.1 16 | hooks: 17 | - id: check-github-workflows 18 | - repo: https://github.com/compilerla/conventional-pre-commit 19 | rev: v2.4.0 20 | hooks: 21 | - id: conventional-pre-commit 22 | stages: [commit-msg] 23 | args: [feat, fix, doc, perf, refactor, style, test, chore, u, security, revert] 24 | -------------------------------------------------------------------------------- /cmake/vcpkg/bootstrap/vcpkg-config.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | include_guard(GLOBAL) 5 | 6 | # CMAKE_HOST_* variables are not available during first configure on windows. 7 | cmake_host_system_information(RESULT __vcpkg_bootstrap_host QUERY OS_NAME) 8 | cmake_host_system_information(RESULT __vcpkg_bootstrap_arch QUERY OS_PLATFORM) 9 | 10 | set(__vcpkg_bootstrap_list_dir "${CMAKE_CURRENT_LIST_DIR}") 11 | 12 | include(${__vcpkg_bootstrap_list_dir}/vcpkg_autodetect_target_triplet.cmake) 13 | include(${__vcpkg_bootstrap_list_dir}/vcpkg_autodetect_host_triplet.cmake) 14 | include(${__vcpkg_bootstrap_list_dir}/vcpkg_skip_install_on_reconfigure.cmake) 15 | include(${__vcpkg_bootstrap_list_dir}/vcpkg_bootstrap.cmake) 16 | include(${__vcpkg_bootstrap_list_dir}/vcpkg_configure.cmake) 17 | -------------------------------------------------------------------------------- /tests/cmake/add_cpp_pt_test.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | include_guard(GLOBAL) 5 | 6 | find_package(Catch2 CONFIG REQUIRED) 7 | 8 | if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) 9 | find_package(@cpp_pt_name@ CONFIG REQUIRED) 10 | endif() 11 | 12 | include(CTest) 13 | include(Catch) 14 | 15 | # sets all nessary default things 16 | function(add_@cpp_pt_cmake@_test test_name) 17 | cmake_path(GET CMAKE_CURRENT_LIST_DIR FILENAME module_name) 18 | 19 | set(test_file "${test_name}_test.cpp") 20 | set(test_target "${module_name}-${test_name}") 21 | 22 | add_executable(${test_target} "${test_file}") 23 | 24 | target_link_libraries( 25 | ${test_target} PRIVATE @cpp_pt_name@::${module_name} Catch2::Catch2WithMain 26 | ) 27 | 28 | catch_discover_tests(${test_target} TEST_PREFIX "${test_target}:" ${ARGN}) 29 | endfunction() 30 | -------------------------------------------------------------------------------- /cmake/presets/generators/ninja.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "configurePresets": [ 4 | { 5 | "name": "ninja", 6 | "hidden": true, 7 | "generator": "Ninja" 8 | }, 9 | { 10 | "name": "ninja-multi-config", 11 | "hidden": true, 12 | "generator": "Ninja Multi-Config" 13 | } 14 | ], 15 | "buildPresets": [ 16 | { 17 | "name": "ninja", 18 | "hidden": true 19 | }, 20 | { 21 | "name": "ninja-multi-config", 22 | "hidden": true, 23 | "configurePreset": "ninja-multi-config", 24 | "configuration": "Debug" 25 | } 26 | ], 27 | "testPresets": [ 28 | { 29 | "name": "ninja", 30 | "hidden": true, 31 | "configurePreset": "ninja" 32 | }, 33 | { 34 | "name": "ninja-multi-config", 35 | "hidden": true, 36 | "configurePreset": "ninja-multi-config", 37 | "configuration": "Debug" 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | --- 4 | Language: Cpp 5 | BasedOnStyle: Google 6 | 7 | AlignConsecutiveBitFields: Consecutive 8 | 9 | AllowShortEnumsOnASingleLine: false 10 | AllowShortFunctionsOnASingleLine: None 11 | AllowShortLambdasOnASingleLine: None 12 | AllowShortIfStatementsOnASingleLine: Never 13 | AllowShortLoopsOnASingleLine: false 14 | 15 | DerivePointerAlignment: true 16 | 17 | IncludeBlocks: Regroup 18 | IncludeCategories: 19 | - Regex: '^"(cxx)/' 20 | Priority: 1 21 | - Regex: '^".*\.(h|hpp)"' 22 | Priority: 2 23 | - Regex: '^' 24 | Priority: 3 25 | - Regex: '^' 26 | Priority: 4 27 | - Regex: '^<.*\.h>' 28 | Priority: 6 29 | - Regex: '^<.*>' 30 | Priority: 5 31 | 32 | PackConstructorInitializers: Never 33 | PointerAlignment: Right 34 | 35 | ShortNamespaceLines: 0 36 | -------------------------------------------------------------------------------- /cmake/presets/os/darwin.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "configurePresets": [ 4 | { 5 | "name": "darwin", 6 | "hidden": true, 7 | "condition": { 8 | "type": "equals", 9 | "lhs": "${hostSystemName}", 10 | "rhs": "Darwin" 11 | } 12 | }, 13 | { 14 | "name": "x64-darwin", 15 | "hidden": true, 16 | "inherits": "darwin", 17 | "cacheVariables": { 18 | "CMAKE_APPLE_SILICON_PROCESSOR": "x86_64" 19 | } 20 | }, 21 | { 22 | "name": "arm64-darwin", 23 | "hidden": true, 24 | "inherits": "darwin", 25 | "cacheVariables": { 26 | "CMAKE_APPLE_SILICON_PROCESSOR": "arm64" 27 | } 28 | } 29 | ], 30 | "buildPresets": [ 31 | { 32 | "name": "darwin", 33 | "hidden": true, 34 | "configurePreset": "darwin" 35 | } 36 | ], 37 | "testPresets": [ 38 | { 39 | "name": "darwin", 40 | "hidden": true, 41 | "configurePreset": "darwin" 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /src/cmake/cpp-pt-install-targets.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | include_guard(GLOBAL) 5 | 6 | include(GNUInstallDirs) 7 | 8 | add_library(@cpp_pt_name@ INTERFACE) 9 | add_library(@cpp_pt_name@::@cpp_pt_name@ ALIAS @cpp_pt_name@) 10 | install(TARGETS @cpp_pt_name@ EXPORT @cpp_pt_name@-targets) 11 | 12 | export(EXPORT @cpp_pt_name@-targets NAMESPACE @cpp_pt_name@::) 13 | configure_file("cmake/@cpp_pt_name@-config.cmake" "." COPYONLY) 14 | 15 | include(CMakePackageConfigHelpers) 16 | write_basic_package_version_file( 17 | @cpp_pt_name@-config-version.cmake COMPATIBILITY SameMajorVersion 18 | ) 19 | 20 | install( 21 | EXPORT @cpp_pt_name@-targets 22 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/@cpp_pt_name@ 23 | NAMESPACE @cpp_pt_name@:: 24 | ) 25 | 26 | install( 27 | FILES cmake/@cpp_pt_name@-config.cmake 28 | ${CMAKE_CURRENT_BINARY_DIR}/@cpp_pt_name@-config-version.cmake 29 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/@cpp_pt_name@ 30 | ) 31 | 32 | -------------------------------------------------------------------------------- /cmake/vcpkg/bootstrap/vcpkg_autodetect_host_triplet.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2024 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | # vcpkg-tool detects it by default, but we need this info to be able to use 5 | # find_package(... NO_DEFAULT_PATH PATH ${VCPKG_INSTALLED_DIR}/${VCPKG_HOST_TRIPLET}) 6 | function(_vcpkg_autodetect_host_triplet) 7 | if (DEFINED CACHE{VCPKG_HOST_TRIPLET}) 8 | return() 9 | endif() 10 | 11 | if ("${__vcpkg_bootstrap_host}" STREQUAL "Linux") 12 | set(host_triplet_os "linux" CACHE INTERNAL "") 13 | elseif("${__vcpkg_bootstrap_host}" STREQUAL "Windows") 14 | set(host_triplet_os "windows" CACHE INTERNAL "") 15 | else() 16 | set(host_triplet_os "osx") 17 | endif() 18 | 19 | if("${__vcpkg_bootstrap_arch}" MATCHES "arm|aarch") 20 | set(host_triplet_arch "arm64") 21 | else() 22 | set(host_triplet_arch "x64") 23 | endif() 24 | 25 | set(VCPKG_HOST_TRIPLET "${host_triplet_arch}-${host_triplet_os}" 26 | CACHE STRING "Auto detected vcpkg host triplet") 27 | endfunction() 28 | -------------------------------------------------------------------------------- /.github/ci.yaml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: ${{matrix.target.os}} 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | target: [ 12 | { os: ubuntu-latest, preset: x64-linux-gcc-dynamic }, 13 | { os: ubuntu-latest, preset: x86-linux-gcc-dynamic }, 14 | { os: ubuntu-latest, preset: x64-linux-clang-dynamic }, 15 | { os: macos-latest, preset: x64-darwin-gcc-dynamic }, 16 | { os: macos-latest, preset: x64-darwin-clang-dynamic }, 17 | { os: windows-latest, preset: x64-windows-msvc-dynamic }, 18 | { os: windows-latest, preset: x64-windows-clang-dynamic }, 19 | ] 20 | 21 | steps: 22 | - uses: actions/checkout@v4 23 | 24 | - uses: ./.github/actions/install-dependencies 25 | with: 26 | preset: ${{matrix.target.preset}} 27 | 28 | - uses: ./.github/actions/vcpkg-cache 29 | 30 | - name: CMake workflow 31 | shell: bash 32 | run: | 33 | cmake --workflow --preset ${{matrix.target.preset}} 34 | -------------------------------------------------------------------------------- /cmake/presets/base.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "generators/ninja.json", 5 | "toolchains/vcpkg.json" 6 | ], 7 | "configurePresets": [ 8 | { 9 | "name": "base", 10 | "hidden": true, 11 | "inherits": [ 12 | "ninja-multi-config", 13 | "vcpkg" 14 | ], 15 | "binaryDir": "${sourceDir}/build/${presetName}", 16 | "cacheVariables": { 17 | "CMAKE_EXPORT_COMPILE_COMMANDS": true, 18 | "CMAKE_COMPILE_WARNING_AS_ERROR": true 19 | } 20 | } 21 | ], 22 | "buildPresets": [ 23 | { 24 | "name": "base", 25 | "hidden": true, 26 | "inherits": "ninja-multi-config", 27 | "configurePreset": "base" 28 | } 29 | ], 30 | "testPresets": [ 31 | { 32 | "name": "base", 33 | "hidden": true, 34 | "inherits": "ninja-multi-config", 35 | "configurePreset": "base", 36 | "output": { 37 | "outputOnFailure": true 38 | }, 39 | "execution": { 40 | "noTestsAction": "error", 41 | "stopOnFailure": true 42 | } 43 | } 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: ${{matrix.target.os}} 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | target: [ 12 | { os: ubuntu-latest, preset: x64-linux-gcc-dynamic }, 13 | { os: ubuntu-latest, preset: x86-linux-gcc-dynamic }, 14 | { os: ubuntu-latest, preset: x64-linux-clang-dynamic }, 15 | { os: ubuntu-latest, preset: x86-linux-clang-dynamic }, 16 | { os: macos-latest, preset: x64-darwin-gcc-dynamic }, 17 | { os: macos-latest, preset: x64-darwin-clang-dynamic }, 18 | { os: windows-latest, preset: x64-windows-msvc-dynamic }, 19 | { os: windows-latest, preset: x64-windows-clang-dynamic }, 20 | ] 21 | 22 | steps: 23 | - uses: actions/checkout@v4 24 | 25 | - name: Init template 26 | shell: bash 27 | run: | 28 | cmake -P init.cmake --project gat --module core --header version 29 | 30 | - uses: ./.github/actions/install-dependencies 31 | with: 32 | preset: ${{matrix.target.preset}} 33 | 34 | - uses: ./.github/actions/vcpkg-cache 35 | 36 | - name: CMake workflow 37 | shell: bash 38 | run: | 39 | cmake --workflow --preset ${{matrix.target.preset}} 40 | -------------------------------------------------------------------------------- /cmake/vcpkg/bootstrap/vcpkg_autodetect_target_triplet.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | # sets VCPKG_TARGET_TRIPLET out of VCPKG_PRESET_NAME 5 | function(_vcpkg_autodetect_target_triplet) 6 | if (DEFINED CACHE{VCPKG_TARGET_TRIPLET}) 7 | return() 8 | endif() 9 | 10 | if (NOT DEFINED VCPKG_PRESET_NAME) 11 | message(FATAL_ERROR "Missing mandatory VCPKG_PRESET_NAME cache variable") 12 | endif() 13 | 14 | # for some reason macOS is possible instead of Darwin 15 | if("${__vcpkg_bootstrap_host}" MATCHES "Darwin|macOS") 16 | string(REPLACE "darwin" "osx" VCPKG_PRESET_NAME "${VCPKG_PRESET_NAME}") 17 | endif() 18 | 19 | string(REPLACE "-" ";" triplet_parts "${VCPKG_PRESET_NAME}") 20 | 21 | # remove compiler 22 | list(REMOVE_AT triplet_parts 2) 23 | list(LENGTH triplet_parts triplet_parts_length) 24 | if(triplet_parts_length EQUAL "2") 25 | list(APPEND triplet_parts "dynamic") 26 | else() 27 | list(REMOVE_ITEM triplet_parts "static") 28 | endif() 29 | 30 | list(SUBLIST triplet_parts 0 3 triplet_parts) 31 | 32 | list(JOIN triplet_parts "-" vcpkg_target_triplet) 33 | 34 | set(VCPKG_TARGET_TRIPLET "${vcpkg_target_triplet}" 35 | CACHE STRING "Auto detected vcpkg target triplet") 36 | endfunction() 37 | -------------------------------------------------------------------------------- /src/cmake/set_cpp_pt_target_properties.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | include_guard(GLOBAL) 5 | 6 | find_package(fmt CONFIG REQUIRED) 7 | find_package(Microsoft.GSL CONFIG REQUIRED) 8 | find_package(range-v3 CONFIG REQUIRED) 9 | 10 | # sets default target properties 11 | function(set_@cpp_pt_cmake@_target_properties target type) 12 | target_compile_features(${target} ${type} cxx_std_20) 13 | set_target_properties(${target} 14 | PROPERTIES 15 | CXX_STANDARD_REQUIRED ON 16 | CXX_VISIBILITY_PRESET hidden 17 | VISIBILITY_INLINES_HIDDEN ON 18 | ) 19 | 20 | target_compile_options(${target} 21 | ${type} 22 | $<$,$>:-stdlib=libc++> 23 | ) 24 | 25 | target_link_options(${target} 26 | ${type} 27 | $<$,$>:-stdlib=libc++ -lc++abi> 28 | ) 29 | 30 | if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) 31 | target_compile_options(${target} ${type} 32 | $<$:/W4> 33 | $<$>:-Wall -Wextra -Wpedantic> 34 | ) 35 | endif() 36 | 37 | target_link_libraries(${target} 38 | ${type} 39 | fmt::fmt 40 | range-v3::range-v3 41 | Microsoft.GSL::GSL 42 | ) 43 | endfunction() 44 | -------------------------------------------------------------------------------- /cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2024 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | function(_vcpkg_update_manifest_hash) 5 | set(_VCPKG_MANIFEST_HASH "$CACHE{__VCPKG_MANIFEST_HASH}" 6 | CACHE INTERNAL "Hash of vcpkg manifest file") 7 | endfunction() 8 | 9 | # disable vcpkg manifest install step on cmake reconfigure if vcpkg.json has not 10 | # changed. 11 | function(_vcpkg_skip_install_on_reconfigure) 12 | if (DEFINED CACHE{VCPKG_MANIFEST_DIR}) 13 | set(vcpkg_manifest_file "$CACHE{VCPKG_MANIFEST_DIR}/vcpkg.json") 14 | else() 15 | set(vcpkg_manifest_file "${CMAKE_SOURCE_DIR}/vcpkg.json") 16 | endif() 17 | 18 | file(SHA512 "${vcpkg_manifest_file}" vcpkg_manifest_hash) 19 | 20 | if (DEFINED CACHE{_VCPKG_MANIFEST_HASH} AND _VCPKG_MANIFEST_HASH STREQUAL vcpkg_manifest_hash) 21 | set(VCPKG_MANIFEST_INSTALL OFF CACHE INTERNAL "") 22 | set_property(DIRECTORY APPEND 23 | PROPERTY 24 | CMAKE_CONFIGURE_DEPENDS "${vcpkg_manifest_file}" 25 | ) 26 | else() 27 | set(VCPKG_MANIFEST_INSTALL ON CACHE INTERNAL "") 28 | endif() 29 | 30 | # I was not able to propgate vcpkg_manifest_hash via defer call, so workaround 31 | # it with another cache variable. 32 | set(__VCPKG_MANIFEST_HASH "${vcpkg_manifest_hash}" CACHE INTERNAL "") 33 | 34 | # set actual hash only when vcpkg install command succeed. 35 | # The only way you to detect to assume that configuration step succeed. 36 | cmake_language(DEFER DIRECTORY ${CMAKE_SOURCE_DIR} CALL _vcpkg_update_manifest_hash) 37 | endfunction() 38 | -------------------------------------------------------------------------------- /.github/actions/install-dependencies/action.yaml: -------------------------------------------------------------------------------- 1 | name: Install dependencies 2 | 3 | inputs: 4 | preset: 5 | description: 'cmake preset' 6 | required: true 7 | default: "" 8 | 9 | runs: 10 | using: composite 11 | steps: 12 | - name: Parse preset 13 | id: preset 14 | shell: bash 15 | run: | 16 | IFS='-' read -r arch os compiler linkage <<< "${{ inputs.preset }}" 17 | echo "os=$os" >> "$GITHUB_OUTPUT" 18 | 19 | if [ -d "./.github/actions/${os}/${compiler}" ]; then 20 | echo "compiler_dir=true" >> "$GITHUB_OUTPUT" 21 | echo "compiler=$compiler" >> "$GITHUB_OUTPUT" 22 | else 23 | echo "compiler_dir=false" >> "$GITHUB_OUTPUT" 24 | fi 25 | 26 | if [ -d "./.github/actions/${os}/${arch}" ]; then 27 | echo "arch_dir=true" >> "$GITHUB_OUTPUT" 28 | echo "arch=$arch" >> "$GITHUB_OUTPUT" 29 | else 30 | echo "arch_dir=false" >> "$GITHUB_OUTPUT" 31 | fi 32 | 33 | - name: Select dependencies 34 | shell: bash 35 | run: | 36 | echo "steps.preset.outputs.arch_dir: ${{steps.preset.outputs.arch_dir}}" 37 | mkdir -p ./.selected-dependencies && 38 | cat <./.selected-dependencies/action.yml 39 | runs: 40 | using: composite 41 | steps: 42 | - uses: ./.github/actions/${{ steps.preset.outputs.os }}/base 43 | - if: ${{ steps.preset.outputs.compiler_dir }} 44 | uses: ./.github/actions/${{ steps.preset.outputs.os }}/${{ steps.preset.outputs.compiler }} 45 | - if: ${{ steps.preset.outputs.arch_dir }} 46 | uses: ./.github/actions/${{ steps.preset.outputs.os }}/${{ steps.preset.outputs.arch }} 47 | EOF 48 | 49 | - name: Install 50 | id: install 51 | uses: ./.selected-dependencies 52 | 53 | - name: Cleanup 54 | if: always() 55 | shell: bash 56 | run: rm -rf ./.selected-dependencies 57 | -------------------------------------------------------------------------------- /src/cmake/add_cpp_pt_module.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | include_guard(GLOBAL) 5 | 6 | include(set_@cpp_pt_cmake@_target_properties) 7 | 8 | include(GenerateExportHeader) 9 | include(GNUInstallDirs) 10 | 11 | # generaete header with export macro 12 | function(_@cpp_pt_cmake@_module_generate_export_headers target) 13 | set(export_file_dir "${CMAKE_CURRENT_BINARY_DIR}/include/@cpp_pt_name@") 14 | generate_export_header(${module_target} 15 | EXPORT_FILE_NAME "${export_file_dir}/${module_name}/export.hpp" 16 | ) 17 | 18 | target_include_directories( 19 | ${module_target} ${module_type} 20 | $ 21 | ) 22 | 23 | if (TARGET @cpp_pt_name@) 24 | install(DIRECTORY ${export_file_dir} TYPE INCLUDE) 25 | endif() 26 | endfunction() 27 | 28 | # sets all nessary default things 29 | function(add_@cpp_pt_cmake@_module module_name) 30 | set(module_target @cpp_pt_cmake@-${module_name}) 31 | set(module_alias @cpp_pt_name@::${module_name}) 32 | 33 | add_library(${module_target} ${ARGN}) 34 | add_library(${module_alias} ALIAS ${module_target}) 35 | 36 | get_target_property(module_target_type ${module_target} TYPE) 37 | if("${module_target_type}" STREQUAL "INTERFACE_LIBRARY") 38 | set(module_type "INTERFACE") 39 | else() 40 | set(module_type "PUBLIC") 41 | _@cpp_pt_cmake@_module_generate_export_headers(${module_target}) 42 | endif() 43 | 44 | set_@cpp_pt_cmake@_target_properties(${module_target} ${module_type}) 45 | 46 | target_include_directories( 47 | ${module_target} ${module_type} 48 | $ 49 | $ 50 | $ 51 | ) 52 | set_target_properties(${module_target} PROPERTIES EXPORT_NAME ${module_name}) 53 | 54 | target_link_libraries(${module_target} ${module_type}) 55 | 56 | if (TARGET @cpp_pt_name@) 57 | target_link_libraries(@cpp_pt_name@ INTERFACE ${module_target}) 58 | install(TARGETS ${module_target} EXPORT @cpp_pt_name@-targets) 59 | install(DIRECTORY include/@cpp_pt_name@ TYPE INCLUDE) 60 | endif() 61 | 62 | set(@cpp_pt_cmake@_module_target 63 | ${module_target} 64 | PARENT_SCOPE 65 | ) 66 | endfunction() 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C++ project template 2 | 3 | ## Template Initialization 4 | 5 | This project is a template that cannot be used before initialization. To initialize your project, you must run the following shell command: 6 | 7 | ```sh 8 | cmake -P init.cmake --project --module --header 9 | ``` 10 | 11 | - **Project name** will become your top-level CMake project name 12 | - Must be alphanumeric and begin with a character. 13 | - **Module name** will be concatenated with your project name to determine the library's namespace (`${project}::${module}`) 14 | - **Header name** will become the name of your library's main include header 15 | 16 | 17 | ## Building 18 | 19 | To build the project locally, you will need to select a [CMake](https://cmake.org/) preset that matches your system configuration. Your system's configuration is described by a [triplet](https://wiki.osdev.org/Target_Triplet). This is inspired by [rust triples](https://doc.rust-lang.org/nightly/rustc/platform-support.html). 20 | 21 | Presets for the most common system triplets are defined in [`cmake/presets/`](./cmake/presets/) and presented via [`CMakePresets.json`](./CMakePresets.json). 22 | 23 | Notice that each system triplet defines a preset for multiple compilers. If you have a compiler preference, you can pick the respective preset. If you do not have a preference, you can choose the following reccomendation (depending on your OS): 24 | 25 | - Windows: `msvc` 26 | - MacOS: `clang` 27 | - Linux: `gcc` 28 | 29 | Now you can configure and build your project: 30 | 31 | ```sh 32 | cmake --workflow --preset= 33 | ``` 34 | 35 | This is equivalend to running the following in a step-by-step proceedure: 36 | 37 | ```sh 38 | # Configure 39 | cmake --preset= 40 | # Build 41 | cmake --build --preset= 42 | # Test 43 | ctest --preset= 44 | ``` 45 | 46 | Regardless of how you build, the `build/` folder will be populated with the binaries for all of your [CMake targets](https://cmake.org/cmake/help/book/mastering-cmake/chapter/Key%20Concepts.html#targets). 47 | 48 | ## Usage 49 | 50 | By default, this template comes with a CLI entrypoint defined in [`src/cli/src/main.cpp`](src/cli/src/main.cpp), and one module/library defined in your `src` folder. The Command Line Interface contains a very basic `main` function, and can be run after building by the `build//src/cli//_cli` executable(s). 51 | 52 | Tests are run with [Catch2](https://github.com/catchorg/Catch2). They can be written in the [`tests`](tests) subdirectory, and run with CTest: 53 | 54 | ```sh 55 | ctest --preset 56 | ``` 57 | 58 | For usage within another C++ project, you can add the following to your CMake configuration: 59 | 60 | ```cmake 61 | find_package( CONFIG REQUIRED) 62 | target_link_libraries( PUBLIC ::) 63 | ``` 64 | 65 | This will require that your library is published and installed via vcpkg or found locally by setting the `CMAKE_PREFIX_PATH` environment variable in your other project during configure. -------------------------------------------------------------------------------- /cmake/presets/x64-linux-gcc.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "base.json", 5 | "os/linux.json", 6 | "compilers/gcc.json" 7 | ], 8 | "configurePresets": [ 9 | { 10 | "name": "x64-linux-gcc-static", 11 | "inherits": [ 12 | "base", 13 | "linux", 14 | "gcc" 15 | ], 16 | "displayName": "x64 linux gcc static libs" 17 | }, 18 | { 19 | "name": "x64-linux-gcc-dynamic", 20 | "inherits": "x64-linux-gcc-static", 21 | "displayName": "x64 linux gcc dynamic libs", 22 | "cacheVariables": { 23 | "BUILD_SHARED_LIBS": true 24 | } 25 | }, 26 | { 27 | "name": "x64-linux-gcc", 28 | "inherits": "x64-linux-gcc-dynamic", 29 | "displayName": "alias to x64-linux-gcc-dynamic" 30 | } 31 | ], 32 | "buildPresets": [ 33 | { 34 | "name": "x64-linux-gcc-static", 35 | "inherits": "base", 36 | "configurePreset": "x64-linux-gcc-static" 37 | }, 38 | { 39 | "name": "x64-linux-gcc-dynamic", 40 | "inherits": "base", 41 | "configurePreset": "x64-linux-gcc-dynamic" 42 | }, 43 | { 44 | "name": "x64-linux-gcc", 45 | "inherits": "x64-linux-gcc-dynamic", 46 | "configurePreset": "x64-linux-gcc" 47 | } 48 | ], 49 | "testPresets": [ 50 | { 51 | "name": "x64-linux-gcc-static", 52 | "inherits": "base", 53 | "configurePreset": "x64-linux-gcc-static" 54 | }, 55 | { 56 | "name": "x64-linux-gcc-dynamic", 57 | "inherits": "base", 58 | "configurePreset": "x64-linux-gcc-dynamic" 59 | }, 60 | { 61 | "name": "x64-linux-gcc", 62 | "inherits": "x64-linux-gcc-dynamic", 63 | "configurePreset": "x64-linux-gcc" 64 | } 65 | ], 66 | "workflowPresets": [ 67 | { 68 | "name": "x64-linux-gcc-static", 69 | "steps": [ 70 | { 71 | "type": "configure", 72 | "name": "x64-linux-gcc-static" 73 | }, 74 | { 75 | "type": "build", 76 | "name": "x64-linux-gcc-static" 77 | }, 78 | { 79 | "type": "test", 80 | "name": "x64-linux-gcc-static" 81 | } 82 | ] 83 | }, 84 | { 85 | "name": "x64-linux-gcc-dynamic", 86 | "steps": [ 87 | { 88 | "type": "configure", 89 | "name": "x64-linux-gcc-dynamic" 90 | }, 91 | { 92 | "type": "build", 93 | "name": "x64-linux-gcc-dynamic" 94 | }, 95 | { 96 | "type": "test", 97 | "name": "x64-linux-gcc-dynamic" 98 | } 99 | ] 100 | }, 101 | { 102 | "name": "x64-linux-gcc", 103 | "steps": [ 104 | { 105 | "type": "configure", 106 | "name": "x64-linux-gcc" 107 | }, 108 | { 109 | "type": "build", 110 | "name": "x64-linux-gcc" 111 | }, 112 | { 113 | "type": "test", 114 | "name": "x64-linux-gcc" 115 | } 116 | ] 117 | } 118 | ] 119 | } 120 | -------------------------------------------------------------------------------- /cmake/presets/x86-linux-gcc.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "base.json", 5 | "os/linux.json", 6 | "compilers/gcc.json" 7 | ], 8 | "configurePresets": [ 9 | { 10 | "name": "x86-linux-gcc-static", 11 | "inherits": [ 12 | "base", 13 | "linux", 14 | "x86-gcc" 15 | ], 16 | "displayName": "linux gcc static libs" 17 | }, 18 | { 19 | "name": "x86-linux-gcc-dynamic", 20 | "inherits": "x86-linux-gcc-static", 21 | "displayName": "linux gcc dynamic libs", 22 | "cacheVariables": { 23 | "BUILD_SHARED_LIBS": true 24 | } 25 | }, 26 | { 27 | "name": "x86-linux-gcc", 28 | "inherits": "x86-linux-gcc-dynamic", 29 | "displayName": "alias to x86-linux-gcc-dynamic" 30 | } 31 | ], 32 | "buildPresets": [ 33 | { 34 | "name": "x86-linux-gcc-static", 35 | "inherits": "base", 36 | "configurePreset": "x86-linux-gcc-static" 37 | }, 38 | { 39 | "name": "x86-linux-gcc-dynamic", 40 | "inherits": "base", 41 | "configurePreset": "x86-linux-gcc-dynamic" 42 | }, 43 | { 44 | "name": "x86-linux-gcc", 45 | "inherits": "x86-linux-gcc-dynamic", 46 | "configurePreset": "x86-linux-gcc" 47 | } 48 | ], 49 | "testPresets": [ 50 | { 51 | "name": "x86-linux-gcc-static", 52 | "inherits": "base", 53 | "configurePreset": "x86-linux-gcc-static" 54 | }, 55 | { 56 | "name": "x86-linux-gcc-dynamic", 57 | "inherits": "base", 58 | "configurePreset": "x86-linux-gcc-dynamic" 59 | }, 60 | { 61 | "name": "x86-linux-gcc", 62 | "inherits": "x86-linux-gcc-dynamic", 63 | "configurePreset": "x86-linux-gcc" 64 | } 65 | ], 66 | "workflowPresets": [ 67 | { 68 | "name": "x86-linux-gcc-static", 69 | "steps": [ 70 | { 71 | "type": "configure", 72 | "name": "x86-linux-gcc-static" 73 | }, 74 | { 75 | "type": "build", 76 | "name": "x86-linux-gcc-static" 77 | }, 78 | { 79 | "type": "test", 80 | "name": "x86-linux-gcc-static" 81 | } 82 | ] 83 | }, 84 | { 85 | "name": "x86-linux-gcc-dynamic", 86 | "steps": [ 87 | { 88 | "type": "configure", 89 | "name": "x86-linux-gcc-dynamic" 90 | }, 91 | { 92 | "type": "build", 93 | "name": "x86-linux-gcc-dynamic" 94 | }, 95 | { 96 | "type": "test", 97 | "name": "x86-linux-gcc-dynamic" 98 | } 99 | ] 100 | }, 101 | { 102 | "name": "x86-linux-gcc", 103 | "steps": [ 104 | { 105 | "type": "configure", 106 | "name": "x86-linux-gcc" 107 | }, 108 | { 109 | "type": "build", 110 | "name": "x86-linux-gcc" 111 | }, 112 | { 113 | "type": "test", 114 | "name": "x86-linux-gcc" 115 | } 116 | ] 117 | } 118 | ] 119 | } 120 | -------------------------------------------------------------------------------- /cmake/presets/x64-darwin-gcc.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "base.json", 5 | "os/darwin.json", 6 | "compilers/gcc.json" 7 | ], 8 | "configurePresets": [ 9 | { 10 | "name": "x64-darwin-gcc-static", 11 | "inherits": [ 12 | "base", 13 | "x64-darwin", 14 | "gcc" 15 | ], 16 | "displayName": "x64 darwin gcc static libs" 17 | }, 18 | { 19 | "name": "x64-darwin-gcc-dynamic", 20 | "inherits": "x64-darwin-gcc-static", 21 | "displayName": "x64 darwin gcc dynamic libs", 22 | "cacheVariables": { 23 | "BUILD_SHARED_LIBS": true 24 | } 25 | }, 26 | { 27 | "name": "x64-darwin-gcc", 28 | "inherits": "x64-darwin-gcc-dynamic", 29 | "displayName": "alias to x64-darwin-gcc-dynamic" 30 | } 31 | ], 32 | "buildPresets": [ 33 | { 34 | "name": "x64-darwin-gcc-static", 35 | "inherits": "base", 36 | "configurePreset": "x64-darwin-gcc-static" 37 | }, 38 | { 39 | "name": "x64-darwin-gcc-dynamic", 40 | "inherits": "base", 41 | "configurePreset": "x64-darwin-gcc-dynamic" 42 | }, 43 | { 44 | "name": "x64-darwin-gcc", 45 | "inherits": "x64-darwin-gcc-dynamic", 46 | "configurePreset": "x64-darwin-gcc" 47 | } 48 | ], 49 | "testPresets": [ 50 | { 51 | "name": "x64-darwin-gcc-static", 52 | "inherits": "base", 53 | "configurePreset": "x64-darwin-gcc-static" 54 | }, 55 | { 56 | "name": "x64-darwin-gcc-dynamic", 57 | "inherits": "base", 58 | "configurePreset": "x64-darwin-gcc-dynamic" 59 | }, 60 | { 61 | "name": "x64-darwin-gcc", 62 | "inherits": "x64-darwin-gcc-dynamic", 63 | "configurePreset": "x64-darwin-gcc" 64 | } 65 | ], 66 | "workflowPresets": [ 67 | { 68 | "name": "x64-darwin-gcc-static", 69 | "steps": [ 70 | { 71 | "type": "configure", 72 | "name": "x64-darwin-gcc-static" 73 | }, 74 | { 75 | "type": "build", 76 | "name": "x64-darwin-gcc-static" 77 | }, 78 | { 79 | "type": "test", 80 | "name": "x64-darwin-gcc-static" 81 | } 82 | ] 83 | }, 84 | { 85 | "name": "x64-darwin-gcc-dynamic", 86 | "steps": [ 87 | { 88 | "type": "configure", 89 | "name": "x64-darwin-gcc-dynamic" 90 | }, 91 | { 92 | "type": "build", 93 | "name": "x64-darwin-gcc-dynamic" 94 | }, 95 | { 96 | "type": "test", 97 | "name": "x64-darwin-gcc-dynamic" 98 | } 99 | ] 100 | }, 101 | { 102 | "name": "x64-darwin-gcc", 103 | "steps": [ 104 | { 105 | "type": "configure", 106 | "name": "x64-darwin-gcc" 107 | }, 108 | { 109 | "type": "build", 110 | "name": "x64-darwin-gcc" 111 | }, 112 | { 113 | "type": "test", 114 | "name": "x64-darwin-gcc" 115 | } 116 | ] 117 | } 118 | ] 119 | } 120 | -------------------------------------------------------------------------------- /cmake/presets/arm64-darwin-gcc.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "base.json", 5 | "os/darwin.json", 6 | "compilers/gcc.json" 7 | ], 8 | "configurePresets": [ 9 | { 10 | "name": "arm64-darwin-gcc-static", 11 | "inherits": [ 12 | "base", 13 | "arm64-darwin", 14 | "gcc" 15 | ], 16 | "displayName": "arm64 darwin gcc static libs" 17 | }, 18 | { 19 | "name": "arm64-darwin-gcc-dynamic", 20 | "inherits": "arm64-darwin-gcc-static", 21 | "displayName": "arm64 darwin gcc dynamic libs", 22 | "cacheVariables": { 23 | "BUILD_SHARED_LIBS": true 24 | } 25 | }, 26 | { 27 | "name": "arm64-darwin-gcc", 28 | "inherits": "arm64-darwin-gcc-dynamic", 29 | "displayName": "alias to arm64-darwin-gcc-dynamic" 30 | } 31 | ], 32 | "buildPresets": [ 33 | { 34 | "name": "arm64-darwin-gcc-static", 35 | "inherits": "base", 36 | "configurePreset": "arm64-darwin-gcc-static" 37 | }, 38 | { 39 | "name": "arm64-darwin-gcc-dynamic", 40 | "inherits": "base", 41 | "configurePreset": "arm64-darwin-gcc-dynamic" 42 | }, 43 | { 44 | "name": "arm64-darwin-gcc", 45 | "inherits": "arm64-darwin-gcc-dynamic", 46 | "configurePreset": "arm64-darwin-gcc" 47 | } 48 | ], 49 | "testPresets": [ 50 | { 51 | "name": "arm64-darwin-gcc-static", 52 | "inherits": "base", 53 | "configurePreset": "arm64-darwin-gcc-static" 54 | }, 55 | { 56 | "name": "arm64-darwin-gcc-dynamic", 57 | "inherits": "base", 58 | "configurePreset": "arm64-darwin-gcc-dynamic" 59 | }, 60 | { 61 | "name": "arm64-darwin-gcc", 62 | "inherits": "arm64-darwin-gcc-dynamic", 63 | "configurePreset": "arm64-darwin-gcc" 64 | } 65 | ], 66 | "workflowPresets": [ 67 | { 68 | "name": "arm64-darwin-gcc-static", 69 | "steps": [ 70 | { 71 | "type": "configure", 72 | "name": "arm64-darwin-gcc-static" 73 | }, 74 | { 75 | "type": "build", 76 | "name": "arm64-darwin-gcc-static" 77 | }, 78 | { 79 | "type": "test", 80 | "name": "arm64-darwin-gcc-static" 81 | } 82 | ] 83 | }, 84 | { 85 | "name": "arm64-darwin-gcc-dynamic", 86 | "steps": [ 87 | { 88 | "type": "configure", 89 | "name": "arm64-darwin-gcc-dynamic" 90 | }, 91 | { 92 | "type": "build", 93 | "name": "arm64-darwin-gcc-dynamic" 94 | }, 95 | { 96 | "type": "test", 97 | "name": "arm64-darwin-gcc-dynamic" 98 | } 99 | ] 100 | }, 101 | { 102 | "name": "arm64-darwin-gcc", 103 | "steps": [ 104 | { 105 | "type": "configure", 106 | "name": "arm64-darwin-gcc" 107 | }, 108 | { 109 | "type": "build", 110 | "name": "arm64-darwin-gcc" 111 | }, 112 | { 113 | "type": "test", 114 | "name": "arm64-darwin-gcc" 115 | } 116 | ] 117 | } 118 | ] 119 | } 120 | -------------------------------------------------------------------------------- /cmake/presets/x64-darwin-clang.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "base.json", 5 | "os/darwin.json", 6 | "compilers/clang.json" 7 | ], 8 | "configurePresets": [ 9 | { 10 | "name": "x64-darwin-clang-static", 11 | "inherits": [ 12 | "base", 13 | "x64-darwin", 14 | "clang" 15 | ], 16 | "displayName": "x64 darwin clang static libs" 17 | }, 18 | { 19 | "name": "x64-darwin-clang-dynamic", 20 | "inherits": "x64-darwin-clang-static", 21 | "displayName": "x64 darwin clang dynamic libs", 22 | "cacheVariables": { 23 | "BUILD_SHARED_LIBS": true 24 | } 25 | }, 26 | { 27 | "name": "x64-darwin-clang", 28 | "inherits": "x64-darwin-clang-dynamic", 29 | "displayName": "alias to x64-darwin-clang-dynamic" 30 | } 31 | ], 32 | "buildPresets": [ 33 | { 34 | "name": "x64-darwin-clang-static", 35 | "inherits": "base", 36 | "configurePreset": "x64-darwin-clang-static" 37 | }, 38 | { 39 | "name": "x64-darwin-clang-dynamic", 40 | "inherits": "base", 41 | "configurePreset": "x64-darwin-clang-dynamic" 42 | }, 43 | { 44 | "name": "x64-darwin-clang", 45 | "inherits": "x64-darwin-clang-dynamic", 46 | "configurePreset": "x64-darwin-clang" 47 | } 48 | ], 49 | "testPresets": [ 50 | { 51 | "name": "x64-darwin-clang-static", 52 | "inherits": "base", 53 | "configurePreset": "x64-darwin-clang-static" 54 | }, 55 | { 56 | "name": "x64-darwin-clang-dynamic", 57 | "inherits": "base", 58 | "configurePreset": "x64-darwin-clang-dynamic" 59 | }, 60 | { 61 | "name": "x64-darwin-clang", 62 | "inherits": "x64-darwin-clang-dynamic", 63 | "configurePreset": "x64-darwin-clang" 64 | } 65 | ], 66 | "workflowPresets": [ 67 | { 68 | "name": "x64-darwin-clang-static", 69 | "steps": [ 70 | { 71 | "type": "configure", 72 | "name": "x64-darwin-clang-static" 73 | }, 74 | { 75 | "type": "build", 76 | "name": "x64-darwin-clang-static" 77 | }, 78 | { 79 | "type": "test", 80 | "name": "x64-darwin-clang-static" 81 | } 82 | ] 83 | }, 84 | { 85 | "name": "x64-darwin-clang-dynamic", 86 | "steps": [ 87 | { 88 | "type": "configure", 89 | "name": "x64-darwin-clang-dynamic" 90 | }, 91 | { 92 | "type": "build", 93 | "name": "x64-darwin-clang-dynamic" 94 | }, 95 | { 96 | "type": "test", 97 | "name": "x64-darwin-clang-dynamic" 98 | } 99 | ] 100 | }, 101 | { 102 | "name": "x64-darwin-clang", 103 | "steps": [ 104 | { 105 | "type": "configure", 106 | "name": "x64-darwin-clang" 107 | }, 108 | { 109 | "type": "build", 110 | "name": "x64-darwin-clang" 111 | }, 112 | { 113 | "type": "test", 114 | "name": "x64-darwin-clang" 115 | } 116 | ] 117 | } 118 | ] 119 | } 120 | -------------------------------------------------------------------------------- /cmake/presets/x64-windows-msvc.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "base.json", 5 | "os/windows.json", 6 | "compilers/msvc.json" 7 | ], 8 | "configurePresets": [ 9 | { 10 | "name": "x64-windows-msvc-static", 11 | "inherits": [ 12 | "base", 13 | "windows", 14 | "msvc" 15 | ], 16 | "displayName": "x64 windows msvc static libs" 17 | }, 18 | { 19 | "name": "x64-windows-msvc-dynamic", 20 | "inherits": "x64-windows-msvc-static", 21 | "displayName": "x64 windows msvc dynamic libs", 22 | "cacheVariables": { 23 | "BUILD_SHARED_LIBS": true 24 | } 25 | }, 26 | { 27 | "name": "x64-windows-msvc", 28 | "inherits": "x64-windows-msvc-dynamic", 29 | "displayName": "alias to x64-windows-msvc-dynamic" 30 | } 31 | ], 32 | "buildPresets": [ 33 | { 34 | "name": "x64-windows-msvc-static", 35 | "inherits": "base", 36 | "configurePreset": "x64-windows-msvc-static" 37 | }, 38 | { 39 | "name": "x64-windows-msvc-dynamic", 40 | "inherits": "base", 41 | "configurePreset": "x64-windows-msvc-dynamic" 42 | }, 43 | { 44 | "name": "x64-windows-msvc", 45 | "inherits": "x64-windows-msvc-dynamic", 46 | "configurePreset": "x64-windows-msvc" 47 | } 48 | ], 49 | "testPresets": [ 50 | { 51 | "name": "x64-windows-msvc-static", 52 | "inherits": "base", 53 | "configurePreset": "x64-windows-msvc-static" 54 | }, 55 | { 56 | "name": "x64-windows-msvc-dynamic", 57 | "inherits": "base", 58 | "configurePreset": "x64-windows-msvc-dynamic" 59 | }, 60 | { 61 | "name": "x64-windows-msvc", 62 | "inherits": "x64-windows-msvc-dynamic", 63 | "configurePreset": "x64-windows-msvc" 64 | } 65 | ], 66 | "workflowPresets": [ 67 | { 68 | "name": "x64-windows-msvc-static", 69 | "steps": [ 70 | { 71 | "type": "configure", 72 | "name": "x64-windows-msvc-static" 73 | }, 74 | { 75 | "type": "build", 76 | "name": "x64-windows-msvc-static" 77 | }, 78 | { 79 | "type": "test", 80 | "name": "x64-windows-msvc-static" 81 | } 82 | ] 83 | }, 84 | { 85 | "name": "x64-windows-msvc-dynamic", 86 | "steps": [ 87 | { 88 | "type": "configure", 89 | "name": "x64-windows-msvc-dynamic" 90 | }, 91 | { 92 | "type": "build", 93 | "name": "x64-windows-msvc-dynamic" 94 | }, 95 | { 96 | "type": "test", 97 | "name": "x64-windows-msvc-dynamic" 98 | } 99 | ] 100 | }, 101 | { 102 | "name": "x64-windows-msvc", 103 | "steps": [ 104 | { 105 | "type": "configure", 106 | "name": "x64-windows-msvc" 107 | }, 108 | { 109 | "type": "build", 110 | "name": "x64-windows-msvc" 111 | }, 112 | { 113 | "type": "test", 114 | "name": "x64-windows-msvc" 115 | } 116 | ] 117 | } 118 | ] 119 | } 120 | -------------------------------------------------------------------------------- /cmake/presets/x64-windows-clang.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "base.json", 5 | "os/windows.json", 6 | "compilers/clang.json" 7 | ], 8 | "configurePresets": [ 9 | { 10 | "name": "x64-windows-clang-static", 11 | "inherits": [ 12 | "base", 13 | "windows", 14 | "clang" 15 | ], 16 | "displayName": "x64 windows clang static libs" 17 | }, 18 | { 19 | "name": "x64-windows-clang-dynamic", 20 | "inherits": "x64-windows-clang-static", 21 | "displayName": "x64 windows clang dynamic libs", 22 | "cacheVariables": { 23 | "BUILD_SHARED_LIBS": true 24 | } 25 | }, 26 | { 27 | "name": "x64-windows-clang", 28 | "inherits": "x64-windows-clang-dynamic", 29 | "displayName": "alias to x64-windows-clang-dynamic" 30 | } 31 | ], 32 | "buildPresets": [ 33 | { 34 | "name": "x64-windows-clang-static", 35 | "inherits": "base", 36 | "configurePreset": "x64-windows-clang-static" 37 | }, 38 | { 39 | "name": "x64-windows-clang-dynamic", 40 | "inherits": "base", 41 | "configurePreset": "x64-windows-clang-dynamic" 42 | }, 43 | { 44 | "name": "x64-windows-clang", 45 | "inherits": "x64-windows-clang-dynamic", 46 | "configurePreset": "x64-windows-clang" 47 | } 48 | ], 49 | "testPresets": [ 50 | { 51 | "name": "x64-windows-clang-static", 52 | "inherits": "base", 53 | "configurePreset": "x64-windows-clang-static" 54 | }, 55 | { 56 | "name": "x64-windows-clang-dynamic", 57 | "inherits": "base", 58 | "configurePreset": "x64-windows-clang-dynamic" 59 | }, 60 | { 61 | "name": "x64-windows-clang", 62 | "inherits": "x64-windows-clang-dynamic", 63 | "configurePreset": "x64-windows-clang" 64 | } 65 | ], 66 | "workflowPresets": [ 67 | { 68 | "name": "x64-windows-clang-static", 69 | "steps": [ 70 | { 71 | "type": "configure", 72 | "name": "x64-windows-clang-static" 73 | }, 74 | { 75 | "type": "build", 76 | "name": "x64-windows-clang-static" 77 | }, 78 | { 79 | "type": "test", 80 | "name": "x64-windows-clang-static" 81 | } 82 | ] 83 | }, 84 | { 85 | "name": "x64-windows-clang-dynamic", 86 | "steps": [ 87 | { 88 | "type": "configure", 89 | "name": "x64-windows-clang-dynamic" 90 | }, 91 | { 92 | "type": "build", 93 | "name": "x64-windows-clang-dynamic" 94 | }, 95 | { 96 | "type": "test", 97 | "name": "x64-windows-clang-dynamic" 98 | } 99 | ] 100 | }, 101 | { 102 | "name": "x64-windows-clang", 103 | "steps": [ 104 | { 105 | "type": "configure", 106 | "name": "x64-windows-clang" 107 | }, 108 | { 109 | "type": "build", 110 | "name": "x64-windows-clang" 111 | }, 112 | { 113 | "type": "test", 114 | "name": "x64-windows-clang" 115 | } 116 | ] 117 | } 118 | ] 119 | } 120 | -------------------------------------------------------------------------------- /cmake/presets/arm64-darwin-clang.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "base.json", 5 | "os/darwin.json", 6 | "compilers/clang.json" 7 | ], 8 | "configurePresets": [ 9 | { 10 | "name": "arm64-darwin-clang-static", 11 | "inherits": [ 12 | "base", 13 | "arm64-darwin", 14 | "clang" 15 | ], 16 | "displayName": "arm64 darwin clang static libs" 17 | }, 18 | { 19 | "name": "arm64-darwin-clang-dynamic", 20 | "inherits": "arm64-darwin-clang-static", 21 | "displayName": "arm64 darwin clang dynamic libs", 22 | "cacheVariables": { 23 | "BUILD_SHARED_LIBS": true 24 | } 25 | }, 26 | { 27 | "name": "arm64-darwin-clang", 28 | "inherits": "arm64-darwin-clang-dynamic", 29 | "displayName": "alias to arm64-darwin-clang-dynamic" 30 | } 31 | ], 32 | "buildPresets": [ 33 | { 34 | "name": "arm64-darwin-clang-static", 35 | "inherits": "base", 36 | "configurePreset": "arm64-darwin-clang-static" 37 | }, 38 | { 39 | "name": "arm64-darwin-clang-dynamic", 40 | "inherits": "base", 41 | "configurePreset": "arm64-darwin-clang-dynamic" 42 | }, 43 | { 44 | "name": "arm64-darwin-clang", 45 | "inherits": "arm64-darwin-clang-dynamic", 46 | "configurePreset": "arm64-darwin-clang" 47 | } 48 | ], 49 | "testPresets": [ 50 | { 51 | "name": "arm64-darwin-clang-static", 52 | "inherits": "base", 53 | "configurePreset": "arm64-darwin-clang-static" 54 | }, 55 | { 56 | "name": "arm64-darwin-clang-dynamic", 57 | "inherits": "base", 58 | "configurePreset": "arm64-darwin-clang-dynamic" 59 | }, 60 | { 61 | "name": "arm64-darwin-clang", 62 | "inherits": "arm64-darwin-clang-dynamic", 63 | "configurePreset": "arm64-darwin-clang" 64 | } 65 | ], 66 | "workflowPresets": [ 67 | { 68 | "name": "arm64-darwin-clang-static", 69 | "steps": [ 70 | { 71 | "type": "configure", 72 | "name": "arm64-darwin-clang-static" 73 | }, 74 | { 75 | "type": "build", 76 | "name": "arm64-darwin-clang-static" 77 | }, 78 | { 79 | "type": "test", 80 | "name": "arm64-darwin-clang-static" 81 | } 82 | ] 83 | }, 84 | { 85 | "name": "arm64-darwin-clang-dynamic", 86 | "steps": [ 87 | { 88 | "type": "configure", 89 | "name": "arm64-darwin-clang-dynamic" 90 | }, 91 | { 92 | "type": "build", 93 | "name": "arm64-darwin-clang-dynamic" 94 | }, 95 | { 96 | "type": "test", 97 | "name": "arm64-darwin-clang-dynamic" 98 | } 99 | ] 100 | }, 101 | { 102 | "name": "arm64-darwin-clang", 103 | "steps": [ 104 | { 105 | "type": "configure", 106 | "name": "arm64-darwin-clang" 107 | }, 108 | { 109 | "type": "build", 110 | "name": "arm64-darwin-clang" 111 | }, 112 | { 113 | "type": "test", 114 | "name": "arm64-darwin-clang" 115 | } 116 | ] 117 | } 118 | ] 119 | } 120 | -------------------------------------------------------------------------------- /cmake/presets/x64-linux-clang.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "base.json", 5 | "os/linux.json", 6 | "compilers/clang.json" 7 | ], 8 | "configurePresets": [ 9 | { 10 | "name": "x64-linux-clang-static", 11 | "inherits": [ 12 | "base", 13 | "linux", 14 | "clang" 15 | ], 16 | "displayName": "x64 linux clang static libs", 17 | "cacheVariables": { 18 | "VCPKG_TARGET_TRIPLET": "x64-linux-clang-static" 19 | } 20 | }, 21 | { 22 | "name": "x64-linux-clang-dynamic", 23 | "inherits": "x64-linux-clang-static", 24 | "displayName": "x64 linux clang dynamic libs", 25 | "cacheVariables": { 26 | "BUILD_SHARED_LIBS": true, 27 | "VCPKG_TARGET_TRIPLET": "x64-linux-clang-dynamic" 28 | } 29 | }, 30 | { 31 | "name": "x64-linux-clang", 32 | "inherits": "x64-linux-clang-dynamic", 33 | "displayName": "alias to x64-linux-clang-dynamic" 34 | } 35 | ], 36 | "buildPresets": [ 37 | { 38 | "name": "x64-linux-clang-static", 39 | "inherits": "base", 40 | "configurePreset": "x64-linux-clang-static" 41 | }, 42 | { 43 | "name": "x64-linux-clang-dynamic", 44 | "inherits": "base", 45 | "configurePreset": "x64-linux-clang-dynamic" 46 | }, 47 | { 48 | "name": "x64-linux-clang", 49 | "inherits": "x64-linux-clang-dynamic", 50 | "configurePreset": "x64-linux-clang" 51 | } 52 | ], 53 | "testPresets": [ 54 | { 55 | "name": "x64-linux-clang-static", 56 | "inherits": "base", 57 | "configurePreset": "x64-linux-clang-static" 58 | }, 59 | { 60 | "name": "x64-linux-clang-dynamic", 61 | "inherits": "base", 62 | "configurePreset": "x64-linux-clang-dynamic" 63 | }, 64 | { 65 | "name": "x64-linux-clang", 66 | "inherits": "x64-linux-clang-dynamic", 67 | "configurePreset": "x64-linux-clang" 68 | } 69 | ], 70 | "workflowPresets": [ 71 | { 72 | "name": "x64-linux-clang-static", 73 | "steps": [ 74 | { 75 | "type": "configure", 76 | "name": "x64-linux-clang-static" 77 | }, 78 | { 79 | "type": "build", 80 | "name": "x64-linux-clang-static" 81 | }, 82 | { 83 | "type": "test", 84 | "name": "x64-linux-clang-static" 85 | } 86 | ] 87 | }, 88 | { 89 | "name": "x64-linux-clang-dynamic", 90 | "steps": [ 91 | { 92 | "type": "configure", 93 | "name": "x64-linux-clang-dynamic" 94 | }, 95 | { 96 | "type": "build", 97 | "name": "x64-linux-clang-dynamic" 98 | }, 99 | { 100 | "type": "test", 101 | "name": "x64-linux-clang-dynamic" 102 | } 103 | ] 104 | }, 105 | { 106 | "name": "x64-linux-clang", 107 | "steps": [ 108 | { 109 | "type": "configure", 110 | "name": "x64-linux-clang" 111 | }, 112 | { 113 | "type": "build", 114 | "name": "x64-linux-clang" 115 | }, 116 | { 117 | "type": "test", 118 | "name": "x64-linux-clang" 119 | } 120 | ] 121 | } 122 | ] 123 | } 124 | -------------------------------------------------------------------------------- /cmake/presets/x86-linux-clang.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "include": [ 4 | "base.json", 5 | "os/linux.json", 6 | "compilers/clang.json" 7 | ], 8 | "configurePresets": [ 9 | { 10 | "name": "x86-linux-clang-static", 11 | "inherits": [ 12 | "base", 13 | "linux", 14 | "x86-clang" 15 | ], 16 | "displayName": "x86 linux clang static libs", 17 | "cacheVariables": { 18 | "VCPKG_TARGET_TRIPLET": "x86-linux-clang-static" 19 | } 20 | }, 21 | { 22 | "name": "x86-linux-clang-dynamic", 23 | "inherits": "x86-linux-clang-static", 24 | "displayName": "x86 linux clang dynamic libs", 25 | "cacheVariables": { 26 | "BUILD_SHARED_LIBS": true, 27 | "VCPKG_TARGET_TRIPLET": "x86-linux-clang-dynamic" 28 | } 29 | }, 30 | { 31 | "name": "x86-linux-clang", 32 | "inherits": "x86-linux-clang-dynamic", 33 | "displayName": "alias to x86-linux-clang-dynamic" 34 | } 35 | ], 36 | "buildPresets": [ 37 | { 38 | "name": "x86-linux-clang-static", 39 | "inherits": "base", 40 | "configurePreset": "x86-linux-clang-static" 41 | }, 42 | { 43 | "name": "x86-linux-clang-dynamic", 44 | "inherits": "base", 45 | "configurePreset": "x86-linux-clang-dynamic" 46 | }, 47 | { 48 | "name": "x86-linux-clang", 49 | "inherits": "x86-linux-clang-dynamic", 50 | "configurePreset": "x86-linux-clang" 51 | } 52 | ], 53 | "testPresets": [ 54 | { 55 | "name": "x86-linux-clang-static", 56 | "inherits": "base", 57 | "configurePreset": "x86-linux-clang-static" 58 | }, 59 | { 60 | "name": "x86-linux-clang-dynamic", 61 | "inherits": "base", 62 | "configurePreset": "x86-linux-clang-dynamic" 63 | }, 64 | { 65 | "name": "x86-linux-clang", 66 | "inherits": "x86-linux-clang-dynamic", 67 | "configurePreset": "x86-linux-clang" 68 | } 69 | ], 70 | "workflowPresets": [ 71 | { 72 | "name": "x86-linux-clang-static", 73 | "steps": [ 74 | { 75 | "type": "configure", 76 | "name": "x86-linux-clang-static" 77 | }, 78 | { 79 | "type": "build", 80 | "name": "x86-linux-clang-static" 81 | }, 82 | { 83 | "type": "test", 84 | "name": "x86-linux-clang-static" 85 | } 86 | ] 87 | }, 88 | { 89 | "name": "x86-linux-clang-dynamic", 90 | "steps": [ 91 | { 92 | "type": "configure", 93 | "name": "x86-linux-clang-dynamic" 94 | }, 95 | { 96 | "type": "build", 97 | "name": "x86-linux-clang-dynamic" 98 | }, 99 | { 100 | "type": "test", 101 | "name": "x86-linux-clang-dynamic" 102 | } 103 | ] 104 | }, 105 | { 106 | "name": "x86-linux-clang", 107 | "steps": [ 108 | { 109 | "type": "configure", 110 | "name": "x86-linux-clang" 111 | }, 112 | { 113 | "type": "build", 114 | "name": "x86-linux-clang" 115 | }, 116 | { 117 | "type": "test", 118 | "name": "x86-linux-clang" 119 | } 120 | ] 121 | } 122 | ] 123 | } 124 | -------------------------------------------------------------------------------- /init.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | cmake_minimum_required(VERSION 3.25) 5 | 6 | function(print_help) 7 | message( 8 | FATAL_ERROR 9 | "usage: cmake -P init.cmake --project --module --header " 10 | ) 11 | endfunction() 12 | 13 | set(cli_args "") 14 | math(EXPR range_stop "${CMAKE_ARGC}-1") 15 | foreach(index RANGE 3 ${range_stop}) 16 | list(APPEND cli_args "${CMAKE_ARGV${index}}") 17 | endforeach() 18 | 19 | cmake_parse_arguments(arg "" "--project;--module;--header" "" ${cli_args}) 20 | 21 | if(DEFINED arg_UNPARSED_ARGUMENTS 22 | OR (NOT DEFINED arg_--project 23 | OR NOT DEFINED arg_--module 24 | OR NOT DEFINED arg_--header) 25 | ) 26 | print_help() 27 | endif() 28 | 29 | find_package(Git REQUIRED) 30 | 31 | string(REPLACE " " "-" cpp_pt_name "${arg_--project}") 32 | string(REPLACE " " "_" cpp_pt_cmake "${arg_--project}") 33 | string(REPLACE " " "-" cpp_pt_module "${arg_--module}") 34 | string(REPLACE " " "-" cpp_pt_module_header "${arg_--header}") 35 | string(TOUPPER "${cpp_pt_cmake}_${cpp_pt_module}_EXPORT" cpp_pt_module_export) 36 | 37 | message(STATUS "----------------") 38 | message(STATUS "project name: ${cpp_pt_name}") 39 | message(STATUS "cmake functions: add_${cpp_pt_cmake}_") 40 | message(STATUS "module: ${cpp_pt_module}") 41 | message(STATUS "namespace: ${cpp_pt_name}::${cpp_pt_module}") 42 | message(STATUS "header: ${cpp_pt_name}/${cpp_pt_module}/${cpp_pt_module_header}.hpp") 43 | message(STATUS "----------------") 44 | 45 | function(generate path) 46 | string(REPLACE "cpp_pt" "${cpp_pt_cmake}" output_path "${path}") 47 | string(REPLACE "cpp-pt" "${cpp_pt_name}" output_path "${output_path}") 48 | string(REPLACE "module-1" "${cpp_pt_module}" output_path "${output_path}") 49 | string(REPLACE "header-1" "${cpp_pt_module_header}" output_path "${output_path}") 50 | 51 | if(IS_DIRECTORY "${path}") 52 | else() 53 | configure_file(${CMAKE_SOURCE_DIR}/${path} "${CMAKE_SOURCE_DIR}/${path}" @ONLY) 54 | endif() 55 | 56 | file(RENAME ${path} ${output_path}) 57 | endfunction() 58 | 59 | set(templates 60 | src/module-1 61 | src/${cpp_pt_module}/CMakeLists.txt 62 | src/${cpp_pt_module}/include/cpp-pt 63 | src/${cpp_pt_module}/include/${cpp_pt_name}/module-1 64 | src/${cpp_pt_module}/include/${cpp_pt_name}/${cpp_pt_module}/header-1.hpp 65 | src/${cpp_pt_module}/src/header-1.cpp 66 | src/cli/CMakeLists.txt 67 | src/cli/src/main.cpp 68 | src/cmake/add_cpp_pt_executable.cmake 69 | src/cmake/add_cpp_pt_module.cmake 70 | src/cmake/cpp-pt-config.cmake 71 | src/cmake/cpp-pt-install-targets.cmake 72 | src/cmake/set_cpp_pt_target_properties.cmake 73 | src/CMakeLists.txt 74 | tests/module-1 75 | tests/${cpp_pt_module}/header-1_test.cpp 76 | tests/${cpp_pt_module}/CMakeLists.txt 77 | tests/cmake/add_cpp_pt_test.cmake 78 | tests/CMakeLists.txt 79 | cmake/vcpkg/vcpkg.toolchain.cmake 80 | CMakeLists.txt 81 | vcpkg.json 82 | ) 83 | 84 | message(STATUS "Setting up project...") 85 | foreach(template IN LISTS templates) 86 | generate("${template}") 87 | endforeach() 88 | 89 | file(REMOVE "init.cmake") 90 | file(REMOVE "README.md") 91 | file(WRITE "README.md" "# Welcome to ${cpp_pt_name}") 92 | file(RENAME ".github/ci.yaml" ".github/workflows/ci.yaml") 93 | execute_process(COMMAND "${GIT_EXECUTABLE}" add "${CMAKE_SOURCE_DIR}") 94 | 95 | message(STATUS "----------------") 96 | message(STATUS "${cpp_pt_name} project is ready") 97 | message(STATUS "Confirm: git commit --amend") 98 | message(STATUS "Revert: git reset --hard && git clean -fd") 99 | message(STATUS "----------------") 100 | -------------------------------------------------------------------------------- /cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin 2 | # SPDX-License-Identifier: MIT 3 | 4 | # stash all local changes 5 | function(_vcpkg_stash vcpkg_root) 6 | message(STATUS "vcpkg stash all local changes") 7 | 8 | execute_process( 9 | COMMAND ${GIT_EXECUTABLE} stash 10 | WORKING_DIRECTORY ${vcpkg_root} 11 | RESULT_VARIABLE result 12 | ) 13 | 14 | if(NOT result EQUAL "0") 15 | message(FATAL_ERROR "${GIT_EXECUTABLE} stash failed with ${result}") 16 | endif() 17 | endfunction() 18 | 19 | # checkout to a specific baseline 20 | function(_vcpkg_checkout vcpkg_root vcpkg_ref) 21 | message(STATUS "vcpkg checkout to ${vcpkg_ref}") 22 | 23 | execute_process( 24 | COMMAND ${GIT_EXECUTABLE} checkout ${vcpkg_ref} 25 | WORKING_DIRECTORY ${vcpkg_root} 26 | RESULT_VARIABLE result 27 | ) 28 | 29 | if(NOT result EQUAL "0") 30 | message( 31 | FATAL_ERROR 32 | "${GIT_EXECUTABLE} checkout ${vcpkg_ref} failed with ${result}" 33 | ) 34 | endif() 35 | endfunction() # clone 36 | function(_vcpkg_clone vcpkg_root vcpkg_repo vcpkg_ref) 37 | execute_process( 38 | COMMAND ${GIT_EXECUTABLE} clone ${vcpkg_repo} ${vcpkg_root} 39 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 40 | RESULT_VARIABLE result 41 | ) 42 | 43 | if(NOT result EQUAL "0") 44 | message(FATAL_ERROR "failed to clone ${vcpkg_repo} to ${vcpkg_root}") 45 | endif() 46 | 47 | file(LOCK "${vcpkg_root}" DIRECTORY) 48 | _vcpkg_checkout(${vcpkg_root} ${vcpkg_ref}) 49 | endfunction() 50 | 51 | # boostrap 52 | function(_vcpkg_tool_bootstrap vcpkg_root) 53 | message(STATUS "Bootstrap vckpg tool") 54 | 55 | if("${__vcpkg_bootstrap_host}" STREQUAL "Windows") 56 | set(bootstrap_cmd "${vcpkg_root}/bootstrap-vcpkg.bat") 57 | else() 58 | set(bootstrap_cmd "${vcpkg_root}/bootstrap-vcpkg.sh") 59 | endif() 60 | 61 | execute_process( 62 | COMMAND ${bootstrap_cmd} -disableMetrics 63 | WORKING_DIRECTORY ${vcpkg_root} 64 | RESULT_VARIABLE result 65 | ) 66 | 67 | if(NOT result EQUAL "0") 68 | message(FATAL_ERROR "${bootstrap_cmd} failed with ${result}") 69 | endif() 70 | endfunction() 71 | 72 | # upgrade 73 | function(_vcpkg_upgrade vcpkg_root vcpkg_repo vcpkg_ref) 74 | file(LOCK "${vcpkg_root}" DIRECTORY) 75 | 76 | execute_process( 77 | COMMAND ${GIT_EXECUTABLE} rev-parse HEAD 78 | WORKING_DIRECTORY ${vcpkg_root} 79 | OUTPUT_VARIABLE current_git_hash OUTPUT_STRIP_TRAILING_WHITESPACE 80 | RESULT_VARIABLE result 81 | ) 82 | 83 | if(NOT result EQUAL "0") 84 | message( 85 | FATAL_ERROR "${GIT_EXECUTABLE} rev-parse HEAD failed with ${result}" 86 | ) 87 | endif() 88 | 89 | if("${current_git_hash}" STREQUAL "${vcpkg_ref}") 90 | return() 91 | endif() 92 | 93 | message(STATUS "Upgrade vcpkg") 94 | message(STATUS "vcpkg current commit: ${current_git_hash}") 95 | message(STATUS "vcpkg release: ${vcpkg_ref}") 96 | 97 | execute_process( 98 | COMMAND ${GIT_EXECUTABLE} remote set-url origin ${vcpkg_repo} 99 | WORKING_DIRECTORY ${vcpkg_root} 100 | RESULT_VARIABLE result 101 | ) 102 | 103 | if(NOT result EQUAL "0") 104 | message(FATAL_ERROR "failed to change origin to ${vcpkg_repo}") 105 | endif() 106 | 107 | execute_process( 108 | COMMAND ${GIT_EXECUTABLE} fetch 109 | WORKING_DIRECTORY ${vcpkg_root} 110 | RESULT_VARIABLE result 111 | ) 112 | 113 | if(NOT result EQUAL "0") 114 | message(FATAL_ERROR "${GIT_EXECUTABLE} fetch failed with ${result}") 115 | endif() 116 | 117 | _vcpkg_stash(${vcpkg_root}) 118 | _vcpkg_checkout(${vcpkg_root} ${vcpkg_ref}) 119 | _vcpkg_tool_bootstrap(${vcpkg_root}) 120 | endfunction() 121 | 122 | # find root 123 | function(_vcpkg_find_root cache_dir_name out_vcpkg_root) 124 | if(DEFINED ENV{VCPKG_INSTALLATION_ROOT}) 125 | set(root "$ENV{VCPKG_INSTALLATION_ROOT}") 126 | elseif("${__vcpkg_bootstrap_host}" STREQUAL "Windows") 127 | set(root "$ENV{LOCALAPPDATA}/vcpkg/projects/${cache_dir_name}/cache") 128 | else() 129 | set(root "$ENV{HOME}/.cache/vcpkg/projects/${cache_dir_name}") 130 | endif() 131 | 132 | set(${out_vcpkg_root} 133 | ${root} 134 | PARENT_SCOPE 135 | ) 136 | endfunction() 137 | 138 | # set vcpkg_root/toolchain_file cache variables 139 | function(_vcpkg_set_cache_variables vcpkg_root) 140 | set(_VCPKG_ROOT 141 | "${vcpkg_root}" 142 | CACHE INTERNAL "vcpkg root" 143 | ) 144 | 145 | set(_VCPKG_TOOLCHAIN_FILE 146 | "${vcpkg_root}/scripts/buildsystems/vcpkg.cmake" 147 | CACHE INTERNAL "vcpkg toolchain file" 148 | ) 149 | endfunction() 150 | 151 | # bootstrap 152 | function(_vcpkg_bootstrap) 153 | cmake_parse_arguments( 154 | PARSE_ARGV 0 "arg" 155 | "" 156 | "CACHE_DIR_NAME;REPO;REF" 157 | "" 158 | ) 159 | 160 | if(DEFINED arg_UNPARSED_ARGUMENTS) 161 | message(FATAL_ERROR 162 | "internal error: ${CMAKE_CURRENT_FUNCTION} passed extra args:" 163 | "${arg_UNPARSED_ARGUMENTS}" 164 | ) 165 | endif() 166 | 167 | find_package(Git QUIET REQUIRED) 168 | 169 | if(DEFINED CACHE{_VCPKG_ROOT}) 170 | set(vcpkg_root $CACHE{_VCPKG_ROOT}) 171 | else() 172 | _vcpkg_find_root("${arg_CACHE_DIR_NAME}" vcpkg_root) 173 | endif() 174 | 175 | if(NOT EXISTS ${vcpkg_root}) 176 | message(STATUS "Setup vcpkg") 177 | _vcpkg_clone(${vcpkg_root} ${arg_REPO} ${arg_REF}) 178 | _vcpkg_tool_bootstrap(${vcpkg_root}) 179 | else() 180 | message(STATUS "Found vcpkg in: ${vcpkg_root}") 181 | _vcpkg_upgrade(${vcpkg_root} ${arg_REPO} ${arg_REF}) 182 | endif() 183 | 184 | if(DEFINED CACHE{_VCPKG_TOOLCHAIN_FILE}) 185 | return() 186 | endif() 187 | 188 | _vcpkg_set_cache_variables("${vcpkg_root}") 189 | endfunction() 190 | --------------------------------------------------------------------------------