diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f0b5db7..da89879a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,11 +84,16 @@ jobs: fail-fast: false matrix: presets: - - {os: {name: ubuntu-latest, type: linux}, compiler: {name: gcc, type: gcc}} - - {os: {name: ubuntu-latest, type: linux}, compiler: {name: llvm, type: clang}} - - {os: {name: macos-latest, type: osx}, compiler: {name: gcc, type: gcc}} - - {os: {name: macos-latest, type: osx}, compiler: {name: llvm, type: clang}} + - {os: {name: ubuntu-latest, type: linux}, compiler: {name: gcc-11, type: gcc}} + - {os: {name: ubuntu-latest, type: linux}, compiler: {name: llvm, type: llvm}} + - {os: {name: ubuntu-latest, type: mingw-dynamic-linux}, compiler: {name: mingw, type: mingw}} + - {os: {name: macos-latest, type: osx}, compiler: {name: applellvm, type: llvm}} + - {os: {name: macos-latest, type: osx}, compiler: {name: llvm, type: llvm}} + # setup-cpp doesn't support mingw on macOS yet + # - {os: {name: macos-latest, type: mingw-dynamic-darwin}, compiler: {name: mingw, type: mingw}} - {os: {name: windows-latest, type: windows}, compiler: {name: msvc, type: msvc}} + - {os: {name: windows-latest, type: windows}, compiler: {name: llvm, type: llvm}} + - {os: {name: windows-latest, type: mingw-dynamic-windows}, compiler: {name: mingw, type: mingw-gcc}} arch: - {name: x64, type: x64} vcpkg: @@ -100,6 +105,22 @@ jobs: with: fetch-depth: 0 + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/vcpkg + ./build/vcpkg_installed + ~/.cache/pip + ${{ env.HOME }}/.cache/vcpkg/archives + ${{ env.XDG_CACHE_HOME }}/vcpkg/archives + ${{ env.LOCALAPPDATA }}\vcpkg\archives + ${{ env.APPDATA }}\vcpkg\archives + key: | + ${{ matrix.arch.name }}-${{ matrix.presets.os.name }}-${{ matrix.presets.compiler.name }}-${{ matrix.vcpkg }}-${{ hashFiles('./vcpkg.json') }} + restore-keys: | + ${{ matrix.arch.name }}-${{ matrix.presets.os.name }}-${{ matrix.presets.compiler.name }}-${{ matrix.vcpkg }}-${{ hashFiles('./vcpkg.json') }} + - uses: aminya/setup-cpp@v1 with: compiler: ${{ matrix.presets.compiler.name }} @@ -108,20 +129,34 @@ jobs: ninja: true vcpkg: ${{ matrix.vcpkg }} ccache: true - doxygen: true - graphviz: true python: true - gcovr: true opencppcoverage: true - - name: Install Python dependencies + - name: Gcc Lcov + if: contains(matrix.presets.compiler.type, 'gcc') && contains(matrix.presets.os.type, 'linux') + run: | + sudo apt-get update + sudo apt-get install lcov + + - name: Gcovr + if: contains(matrix.presets.compiler.type, 'mingw') && contains(matrix.presets.os.type, 'mingw') run: | - python -m pip install --upgrade pip - pip install -r docs/requirements.txt + pip install gcovr + + - name: Target Windows on Linux (Mingw-w64) + if: contains(matrix.presets.compiler.type, 'mingw') && contains(matrix.presets.os.type, 'linux') + run: | + sudo apt-get update && sudo apt-get install mingw-w64 wine wine64 powershell + sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix + sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix + wine64 true || true + echo "wait 10s for wine registry to be created" && sleep 10 + sed -i '/"PATH"/ s|"$|;Z:/usr/lib/gcc/x86_64-w64-mingw32/10-posix;Z:/usr/x86_64-w64-mingw32/lib"|g' ~/.wine/system.reg && echo "wine registry updated" + - name: Configure CMake run: | - cmake -S . --preset=${{ matrix.arch.type }}-${{ matrix.presets.os.type }}-${{ matrix.presets.compiler.type }} -DCMAKE_BUILD_TYPE=Debug -DCODE_COVERAGE=ON -DBUILD_TESTING=ON + cmake -S . --preset=${{ matrix.arch.type }}-${{ matrix.presets.os.type }}-${{ matrix.presets.compiler.type }} -DCMAKE_BUILD_TYPE=Debug -DCODE_COVERAGE=ON -DBUILD_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=TRUE - name: Coverage run: | diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 83c45d77..0a860379 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -29,7 +29,6 @@ jobs: compiler: gcc cmake: true ninja: true - vcpkg: true ccache: true doxygen: true graphviz: true @@ -40,12 +39,10 @@ jobs: pip install -r docs/requirements.txt - name: Configure - env: - VCPKG_ROOT: /home/runner/vcpkg - run: cmake -S . --preset=x64-Debug-GNUC -DBUILD_TESTING=OFF -DCODE_COVERAGE=OFF + run: cmake -S . --preset=x64-linux-gcc -DBUILD_TESTING=OFF -DCODE_COVERAGE=OFF - name: Build Docs - run: cmake --build out/build/x64-Debug-GNUC --target ss-cpp-docs + run: cmake --build out/build/x64-linux-gcc --target ss-cpp-docs - name: Deploy preview uses: rossjrw/pr-preview-action@v1 diff --git a/.vscode/launch.json b/.vscode/launch.json index 8f0b4a47..8bff417d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,37 +15,6 @@ "environment": [], "console": "integratedTerminal" }, - { - "name": "(gdb) Launch jni", - "type": "cppdbg", - "request": "launch", - "program": "${command:cmake.launchTargetPath}", - "args": [], - "stopAtEntry": false, - "cwd": ".", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - // jvm handle sigsegv self, see - // https://medium.com/@pirogov.alexey/gdb-debug-native-part-of-java-application-c-c-libraries-and-jdk-6593af3b4f3f - "description": "Disable segfaults from jvm", - "text": "handle SIGSEGV nostop noprint pass", - "ignoreFailures": true, - }, - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - }, - { - "description": "Set Disassembly Flavor to Intel", - "text": "-gdb-set disassembly-flavor intel", - "ignoreFailures": true - } - ] - }, { "name": "(gdb) Launch", "type": "cppdbg", diff --git a/.vscode/settings.json b/.vscode/settings.json index c4ed526f..f9992d65 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "cmake.useCMakePresets": "always", - "cmake.options.statusBarVisibility": "visible", + "cmake.options.statusBarVisibility": "icon", "files.exclude": { "**/.clangd/**": true }, @@ -97,6 +97,8 @@ "cwctype": "cpp", "memory_resource": "cpp", "numbers": "cpp", - "semaphore": "cpp" + "semaphore": "cpp", + "codecvt": "cpp", + "source_location": "cpp" } } diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b7be046..7e2bc0d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.25) message(STATUS "CMAKE VERSION:${CMAKE_VERSION}") # Project settings @@ -28,8 +28,8 @@ include(cmake-modules/test/Default) include(cmake-modules/test/GoogleTest) include(cmake-modules/test/Sanitizer) include(cmake-modules/test/Valgrind) -include(cmake-modules/install/Common) include(cmake-modules/install/Default) +include(cmake-modules/install/Common) include(cmake-modules/install/InstallDependency) include(cmake-modules/install/Runpath) @@ -44,9 +44,6 @@ include(ConfigureVersion) include(ConfigureDocs) include(ConfigureCoverage) -# Package dependencies using find_package -find_package(absl CONFIG REQUIRED) - add_subdirectory(src) # Print project final information diff --git a/CMakePresets.json b/CMakePresets.json index 92726f2c..5f1e39d4 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -6,10 +6,14 @@ "patch": 0 }, "include": [ - "cmake/presets/x64-windows-msvc.json", - "cmake/presets/x64-linux-clang.json", + "cmake/presets/x64-linux-llvm.json", "cmake/presets/x64-linux-gcc.json", - "cmake/presets/x64-osx-clang.json", - "cmake/presets/x64-osx-gcc.json" + "cmake/presets/x64-mingw-dynamic-windows-mingw-gcc.json", + "cmake/presets/x64-mingw-dynamic-darwin-mingw.json", + "cmake/presets/x64-mingw-dynamic-linux-mingw.json", + "cmake/presets/x64-osx-gcc.json", + "cmake/presets/x64-osx-llvm.json", + "cmake/presets/x64-windows-llvm.json", + "cmake/presets/x64-windows-msvc.json" ] } diff --git a/cmake/ConfigureCoverage.cmake b/cmake/ConfigureCoverage.cmake index eb3953b5..94df47d4 100644 --- a/cmake/ConfigureCoverage.cmake +++ b/cmake/ConfigureCoverage.cmake @@ -1,9 +1,28 @@ +#[[ +This file is used to configure code coverage for all targets in the project. + +It supports detecting and using the following coverage tools: + - gcov (GNU gcov) + - llvm-cov (LLVM's llvm-cov) + - lcov (GNU lcov) + - opencppcoverage (OpenCppCoverage) + +]] + include_guard(GLOBAL) +# cmake-format: off include(cmake-modules/test/Coverage) +list(APPEND _excludes "${CMAKE_BINARY_DIR}" "${VCPKG_INSTALLED_DIR}") + +if(UNIX) + list(APPEND _excludes "/usr" "/usr/local" "/opt" "/opt/local") +endif() + add_code_coverage_all_targets( - EXCLUDE_DIRS - "${VCPKG_INSTALLED_DIR}" - "${CMAKE_BINARY_DIR}" - "/usr" + EXCLUDE_DIRS ${_excludes} INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/src") +unset(_exclude_dirs) +unset(_excludes) + +# cmake-format: on diff --git a/cmake/ConfigureDocs.cmake b/cmake/ConfigureDocs.cmake index f7733cdb..282d1904 100644 --- a/cmake/ConfigureDocs.cmake +++ b/cmake/ConfigureDocs.cmake @@ -1,11 +1,14 @@ -# Build the target by issuing: cmake --build . --target -# ${CMAKE_PROJECT_NAME}-docs +#[[ +This file creates targets to generate documentation: + + - Doxygen: ${CMAKE_PROJECT_NAME}-doxygen + - Sphinx: ${CMAKE_PROJECT_NAME}-docs +]] include(cmake-modules/configure/ConfigDoxygen) configdoxygen() if(DOXYGEN_FOUND) - # Generate XML OUTPUT for breathe set(DOXYGEN_GENERATE_HTML NO) set(DOXYGEN_GENERATE_XML YES) @@ -43,5 +46,4 @@ if(DOXYGEN_FOUND) OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/_build/html) endif() - endif() diff --git a/cmake/ConfigureVersion.cmake b/cmake/ConfigureVersion.cmake index 3a81c18f..72d6b065 100644 --- a/cmake/ConfigureVersion.cmake +++ b/cmake/ConfigureVersion.cmake @@ -1,3 +1,11 @@ +#[[ +This file configures the version of the project based on the git commit. + +It creates a header file ${CMAKE_BINARY_DIR}/git/include with the version +information, which can be included in the project. + +]] + include_guard(GLOBAL) include(cmake-modules/configure/GitTools) diff --git a/cmake/build_configuration.md b/cmake/build_configuration.md new file mode 100644 index 00000000..0fdae7f2 --- /dev/null +++ b/cmake/build_configuration.md @@ -0,0 +1,10 @@ +# SS-CPP Build Congfiguration + +## Triplets = {Architecture}-{Target-Compiling-OS/Toolchain}-{Distribution} + +- Architecture: x86, x64, arm, arm64, ppc64le, s390x, wasm32, etc. +- Target-Compiling-OS/Toolchain: windows, linux, macos, freebsd, android, ios, mingw, etc. +- Distribution: dynamic, static, release, etc. +- Compiler(Optional): MSVC, GCC, Clang, MinGW + +More about triplets, see: diff --git a/cmake/presets/arch/x64.json b/cmake/presets/arch/x64.json index 6a576af2..e7ea25b7 100644 --- a/cmake/presets/arch/x64.json +++ b/cmake/presets/arch/x64.json @@ -11,7 +11,10 @@ "value": "host=x64", "strategy": "external" }, - "hidden": true + "hidden": true, + "cacheVariables": { + "VCPKG_TARGET_ARCHITECTURE": "x64" + } } ] } diff --git a/cmake/presets/base.json b/cmake/presets/base.json index 004f2d9d..0a547cb6 100644 --- a/cmake/presets/base.json +++ b/cmake/presets/base.json @@ -13,6 +13,7 @@ "vcpkg" ], "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", "cacheVariables": { "CMAKE_EXPORT_COMPILE_COMMANDS": true, "CMAKE_COMPILE_WARNING_AS_ERROR": true, diff --git a/cmake/presets/compilers/llvm.json b/cmake/presets/compilers/llvm.json new file mode 100644 index 00000000..f673547f --- /dev/null +++ b/cmake/presets/compilers/llvm.json @@ -0,0 +1,21 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "llvm", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + }, + { + "name": "llvm-cl", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl" + } + } + ] +} diff --git a/cmake/presets/compilers/mingw.json b/cmake/presets/compilers/mingw.json new file mode 100644 index 00000000..302a8985 --- /dev/null +++ b/cmake/presets/compilers/mingw.json @@ -0,0 +1,9 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "mingw", + "hidden": true + } + ] +} diff --git a/cmake/presets/triplets/x64-linux.json b/cmake/presets/triplets/x64-linux.json index dcbccbd8..00a3e242 100644 --- a/cmake/presets/triplets/x64-linux.json +++ b/cmake/presets/triplets/x64-linux.json @@ -11,7 +11,8 @@ "x64" ], "cacheVariables": { - "VCPKG_TARGET_TRIPLET": "x64-linux" + "VCPKG_TARGET_TRIPLET": "x64-linux", + "VCPKG_HOST_TRIPLET": "x64-linux" } } ] diff --git a/cmake/presets/triplets/x64-mingw-dynamic.json b/cmake/presets/triplets/x64-mingw-dynamic.json new file mode 100644 index 00000000..d4060956 --- /dev/null +++ b/cmake/presets/triplets/x64-mingw-dynamic.json @@ -0,0 +1,20 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-mingw-dynamic", + "VCPKG_HOST_TRIPLET": "x64-mingw-dynamic", + "VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/cmake/vcpkg/scripts/toolchains/mingw.cmake" + } + } + ] +} diff --git a/cmake/presets/triplets/x64-osx.json b/cmake/presets/triplets/x64-osx.json index bc0c0d32..636f85f7 100644 --- a/cmake/presets/triplets/x64-osx.json +++ b/cmake/presets/triplets/x64-osx.json @@ -11,7 +11,8 @@ "x64" ], "cacheVariables": { - "VCPKG_TARGET_TRIPLET": "x64-osx" + "VCPKG_TARGET_TRIPLET": "x64-osx", + "VCPKG_HOST_TRIPLET": "x64-osx" } } ] diff --git a/cmake/presets/triplets/x64-windows.json b/cmake/presets/triplets/x64-windows.json index 929700c0..afe4ef00 100644 --- a/cmake/presets/triplets/x64-windows.json +++ b/cmake/presets/triplets/x64-windows.json @@ -11,7 +11,8 @@ "x64" ], "cacheVariables": { - "VCPKG_TARGET_TRIPLET": "x64-windows" + "VCPKG_TARGET_TRIPLET": "x64-windows", + "VCPKG_HOST_TRIPLET": "x64-windows" } } ] diff --git a/cmake/presets/x64-linux-gcc.json b/cmake/presets/x64-linux-gcc.json index 3fad2305..fdbc8794 100644 --- a/cmake/presets/x64-linux-gcc.json +++ b/cmake/presets/x64-linux-gcc.json @@ -2,6 +2,7 @@ "version": 6, "include": [ "base.json", + "os/linux.json", "compilers/gcc.json", "triplets/x64-linux.json" ], @@ -10,6 +11,7 @@ "name": "x64-linux-gcc", "inherits": [ "base", + "linux", "gcc", "x64-linux" ] diff --git a/cmake/presets/x64-linux-llvm.json b/cmake/presets/x64-linux-llvm.json new file mode 100644 index 00000000..cc9b6052 --- /dev/null +++ b/cmake/presets/x64-linux-llvm.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/linux.json", + "compilers/llvm.json", + "triplets/x64-linux.json" + ], + "configurePresets": [ + { + "name": "x64-linux-llvm", + "inherits": [ + "base", + "linux", + "llvm", + "x64-linux" + ] + } + ], + "buildPresets": [ + { + "name": "x64-linux-llvm", + "inherits": "base", + "configurePreset": "x64-linux-llvm" + } + ], + "testPresets": [ + { + "name": "x64-linux-llvm", + "inherits": "base", + "configurePreset": "x64-linux-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-linux-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-linux-llvm" + }, + { + "type": "build", + "name": "x64-linux-llvm" + }, + { + "type": "test", + "name": "x64-linux-llvm" + } + ] + } + ] +} diff --git a/cmake/presets/x64-mingw-dynamic-darwin-mingw.json b/cmake/presets/x64-mingw-dynamic-darwin-mingw.json new file mode 100644 index 00000000..7d87f43c --- /dev/null +++ b/cmake/presets/x64-mingw-dynamic-darwin-mingw.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/darwin.json", + "compilers/mingw.json", + "triplets/x64-mingw-dynamic.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic-darwin-mingw", + "inherits": [ + "base", + "darwin", + "mingw", + "x64-mingw-dynamic" + ] + } + ], + "buildPresets": [ + { + "name": "x64-mingw-dynamic-darwin-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-darwin-mingw" + } + ], + "testPresets": [ + { + "name": "x64-mingw-dynamic-darwin-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-darwin-mingw" + } + ], + "workflowPresets": [ + { + "name": "x64-mingw-dynamic-darwin-mingw", + "steps": [ + { + "type": "configure", + "name": "x64-mingw-dynamic-darwin-mingw" + }, + { + "type": "build", + "name": "x64-mingw-dynamic-darwin-mingw" + }, + { + "type": "test", + "name": "x64-mingw-dynamic-darwin-mingw" + } + ] + } + ] +} diff --git a/cmake/presets/x64-mingw-dynamic-linux-mingw.json b/cmake/presets/x64-mingw-dynamic-linux-mingw.json new file mode 100644 index 00000000..4905059b --- /dev/null +++ b/cmake/presets/x64-mingw-dynamic-linux-mingw.json @@ -0,0 +1,56 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/linux.json", + "compilers/mingw.json", + "triplets/x64-mingw-dynamic.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic-linux-mingw", + "inherits": [ + "base", + "linux", + "mingw", + "x64-mingw-dynamic" + ], + "cacheVariables": { + "USE_SANITIZER": "FALSE" + } + } + ], + "buildPresets": [ + { + "name": "x64-mingw-dynamic-linux-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-linux-mingw" + } + ], + "testPresets": [ + { + "name": "x64-mingw-dynamic-linux-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-linux-mingw" + } + ], + "workflowPresets": [ + { + "name": "x64-mingw-dynamic-linux-mingw", + "steps": [ + { + "type": "configure", + "name": "x64-mingw-dynamic-linux-mingw" + }, + { + "type": "build", + "name": "x64-mingw-dynamic-linux-mingw" + }, + { + "type": "test", + "name": "x64-mingw-dynamic-linux-mingw" + } + ] + } + ] +} diff --git a/cmake/presets/x64-mingw-dynamic-windows-mingw-gcc.json b/cmake/presets/x64-mingw-dynamic-windows-mingw-gcc.json new file mode 100644 index 00000000..85aa2fb0 --- /dev/null +++ b/cmake/presets/x64-mingw-dynamic-windows-mingw-gcc.json @@ -0,0 +1,56 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/mingw.json", + "triplets/x64-mingw-dynamic.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw-gcc", + "inherits": [ + "base", + "windows", + "mingw", + "x64-mingw-dynamic" + ], + "cacheVariables": { + "USE_SANITIZER": "FALSE" + } + } + ], + "buildPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw-gcc", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-windows-mingw-gcc" + } + ], + "testPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw-gcc", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-windows-mingw-gcc" + } + ], + "workflowPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw-gcc", + "steps": [ + { + "type": "configure", + "name": "x64-mingw-dynamic-windows-mingw-gcc" + }, + { + "type": "build", + "name": "x64-mingw-dynamic-windows-mingw-gcc" + }, + { + "type": "test", + "name": "x64-mingw-dynamic-windows-mingw-gcc" + } + ] + } + ] +} diff --git a/cmake/presets/x64-osx-gcc.json b/cmake/presets/x64-osx-gcc.json index c2688bef..405af6c6 100644 --- a/cmake/presets/x64-osx-gcc.json +++ b/cmake/presets/x64-osx-gcc.json @@ -2,6 +2,7 @@ "version": 6, "include": [ "base.json", + "os/darwin.json", "compilers/gcc.json", "triplets/x64-osx.json" ], @@ -10,6 +11,7 @@ "name": "x64-osx-gcc", "inherits": [ "base", + "darwin", "gcc", "x64-osx" ] diff --git a/cmake/presets/x64-osx-llvm.json b/cmake/presets/x64-osx-llvm.json new file mode 100644 index 00000000..fc43d065 --- /dev/null +++ b/cmake/presets/x64-osx-llvm.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/darwin.json", + "compilers/llvm.json", + "triplets/x64-osx.json" + ], + "configurePresets": [ + { + "name": "x64-osx-llvm", + "inherits": [ + "base", + "darwin", + "llvm", + "x64-osx" + ] + } + ], + "buildPresets": [ + { + "name": "x64-osx-llvm", + "inherits": "base", + "configurePreset": "x64-osx-llvm" + } + ], + "testPresets": [ + { + "name": "x64-osx-llvm", + "inherits": "base", + "configurePreset": "x64-osx-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-osx-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-osx-llvm" + }, + { + "type": "build", + "name": "x64-osx-llvm" + }, + { + "type": "test", + "name": "x64-osx-llvm" + } + ] + } + ] +} diff --git a/cmake/presets/x64-windows-llvm.json b/cmake/presets/x64-windows-llvm.json new file mode 100644 index 00000000..fdcf92f9 --- /dev/null +++ b/cmake/presets/x64-windows-llvm.json @@ -0,0 +1,56 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/llvm.json", + "triplets/x64-windows.json" + ], + "configurePresets": [ + { + "name": "x64-windows-llvm", + "inherits": [ + "base", + "windows", + "llvm-cl", + "x64-windows" + ], + "cacheVariables": { + "USE_SANITIZER": "FALSE" + } + } + ], + "buildPresets": [ + { + "name": "x64-windows-llvm", + "inherits": "base", + "configurePreset": "x64-windows-llvm" + } + ], + "testPresets": [ + { + "name": "x64-windows-llvm", + "inherits": "base", + "configurePreset": "x64-windows-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-windows-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-windows-llvm" + }, + { + "type": "build", + "name": "x64-windows-llvm" + }, + { + "type": "test", + "name": "x64-windows-llvm" + } + ] + } + ] +} diff --git a/cmake/vcpkg/bootstrap/vcpkg-config.cmake b/cmake/vcpkg/bootstrap/vcpkg-config.cmake index b788223c..3dc8bca4 100644 --- a/cmake/vcpkg/bootstrap/vcpkg-config.cmake +++ b/cmake/vcpkg/bootstrap/vcpkg-config.cmake @@ -1,5 +1,8 @@ -# SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin -# SPDX-License-Identifier: MIT +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] include_guard(GLOBAL) diff --git a/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake b/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake index e285663a..461458b3 100644 --- a/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake +++ b/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake @@ -1,5 +1,8 @@ -# SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin -# SPDX-License-Identifier: MIT +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] # stash all local changes function(_vcpkg_stash vcpkg_root) @@ -19,6 +22,19 @@ endfunction() function(_vcpkg_checkout vcpkg_root vcpkg_ref) message(STATUS "vcpkg checkout to ${vcpkg_ref}") + if(EXISTS "${vcpkg_root}/.git/shallow") + message(WARNING "vcpkg is shallow, unshallowing...") + execute_process( + COMMAND ${GIT_EXECUTABLE} fetch --unshallow + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message( + FATAL_ERROR "${GIT_EXECUTABLE} fetch --unshallow failed with ${result}") + endif() + endif() + execute_process( COMMAND ${GIT_EXECUTABLE} checkout ${vcpkg_ref} WORKING_DIRECTORY ${vcpkg_root} @@ -68,6 +84,17 @@ endfunction() function(_vcpkg_upgrade vcpkg_root vcpkg_repo vcpkg_ref) file(LOCK "${vcpkg_root}" DIRECTORY) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --is-inside-work-tree + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE in_git_work_tree + OUTPUT_QUIET ERROR_QUIET) + + if(NOT in_git_work_tree EQUAL 0) + message(WARNING "vcpkg not found in git work tree, skipping upgrade") + return() + endif() + execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY ${vcpkg_root} diff --git a/cmake/vcpkg/bootstrap/vcpkg_configure.cmake b/cmake/vcpkg/bootstrap/vcpkg_configure.cmake index 2da4b844..206cf2da 100644 --- a/cmake/vcpkg/bootstrap/vcpkg_configure.cmake +++ b/cmake/vcpkg/bootstrap/vcpkg_configure.cmake @@ -1,5 +1,8 @@ -# SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin -# SPDX-License-Identifier: MIT +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] # bootstrap and configure vcpkg function(vcpkg_configure) diff --git a/cmake/vcpkg/scripts/toolchains/mingw.cmake b/cmake/vcpkg/scripts/toolchains/mingw.cmake new file mode 100644 index 00000000..6147d02e --- /dev/null +++ b/cmake/vcpkg/scripts/toolchains/mingw.cmake @@ -0,0 +1,77 @@ +if(NOT _VCPKG_MINGW_TOOLCHAIN) + set(_VCPKG_MINGW_TOOLCHAIN 1) + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(CMAKE_CROSSCOMPILING + OFF + CACHE BOOL "") + endif() + + # Need to override MinGW from VCPKG_CMAKE_SYSTEM_NAME + set(CMAKE_SYSTEM_NAME + Windows + CACHE STRING "" FORCE) + + if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") + set(CMAKE_SYSTEM_PROCESSOR + i686 + CACHE STRING "") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(CMAKE_SYSTEM_PROCESSOR + x86_64 + CACHE STRING "") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm") + set(CMAKE_SYSTEM_PROCESSOR + armv7 + CACHE STRING "") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") + set(CMAKE_SYSTEM_PROCESSOR + aarch64 + CACHE STRING "") + endif() + + foreach(lang C CXX) + set(CMAKE_${lang}_COMPILER_TARGET + "${CMAKE_SYSTEM_PROCESSOR}-windows-gnu" + CACHE STRING "") + endforeach() + + find_program(CMAKE_C_COMPILER "${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-gcc") + find_program(CMAKE_CXX_COMPILER "${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-g++") + + find_program(CMAKE_RC_COMPILER + "${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-windres") + if(NOT CMAKE_RC_COMPILER) + find_program(CMAKE_RC_COMPILER "windres") + endif() + + get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) + if(NOT _CMAKE_IN_TRY_COMPILE) + string(APPEND CMAKE_C_FLAGS_INIT " ${VCPKG_C_FLAGS} ") + string(APPEND CMAKE_CXX_FLAGS_INIT " ${VCPKG_CXX_FLAGS} ") + string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " ${VCPKG_C_FLAGS_DEBUG} ") + string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " ${VCPKG_CXX_FLAGS_DEBUG} ") + string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " ${VCPKG_C_FLAGS_RELEASE} ") + string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " ${VCPKG_CXX_FLAGS_RELEASE} ") + + string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ") + string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ") + if(VCPKG_CRT_LINKAGE STREQUAL "static") + string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT "-static ") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT "-static ") + string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT "-static ") + endif() + string(APPEND CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT + " ${VCPKG_LINKER_FLAGS_DEBUG} ") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT + " ${VCPKG_LINKER_FLAGS_DEBUG} ") + string(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT + " ${VCPKG_LINKER_FLAGS_DEBUG} ") + string(APPEND CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT + " ${VCPKG_LINKER_FLAGS_RELEASE} ") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT + " ${VCPKG_LINKER_FLAGS_RELEASE} ") + string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT + " ${VCPKG_LINKER_FLAGS_RELEASE} ") + endif() +endif() diff --git a/cmake/vcpkg/triplets/x64-mingw-dynamic.cmake b/cmake/vcpkg/triplets/x64-mingw-dynamic.cmake new file mode 100644 index 00000000..51642b38 --- /dev/null +++ b/cmake/vcpkg/triplets/x64-mingw-dynamic.cmake @@ -0,0 +1,11 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) +set(VCPKG_ENV_PASSTHROUGH PATH) + +set(VCPKG_CMAKE_SYSTEM_NAME MinGW) +set(VCPKG_POLICY_DLLS_WITHOUT_LIBS enabled) + +# Use the custom mingw toolchain +set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE + "${CMAKE_CURRENT_LIST_DIR}/../scripts/toolchains/mingw.cmake") diff --git a/cmake/vcpkg/vcpkg.toolchain.cmake b/cmake/vcpkg/vcpkg.toolchain.cmake index 59de932b..4457913b 100644 --- a/cmake/vcpkg/vcpkg.toolchain.cmake +++ b/cmake/vcpkg/vcpkg.toolchain.cmake @@ -1,5 +1,8 @@ -# SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin -# SPDX-License-Identifier: MIT +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] include_guard(GLOBAL) @@ -14,26 +17,26 @@ endif() unset(IN_TRY_COMPILE) # Vcpkg build environment + +file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json) +string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline) + +# Respect VCPKG_ROOT environment variable if set if(DEFINED ENV{VCPKG_ROOT}) set(VCPKG_ROOT "$ENV{VCPKG_ROOT}") - # set cmake tool chain - file(TO_CMAKE_PATH ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake - vcpkg_toolchain_file) -else() - include(${CMAKE_CURRENT_LIST_DIR}/bootstrap/vcpkg-config.cmake) - - file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json) - string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline) - - vcpkg_configure( - CACHE_DIR_NAME ss-cpp REPO https://github.com/microsoft/vcpkg.git REF - ${_builtin_baseline}) - set(vcpkg_toolchain_file $CACHE{_VCPKG_TOOLCHAIN_FILE}) + set(_VCPKG_ROOT + "$ENV{VCPKG_ROOT}" + CACHE PATH "Vcpkg root directory") endif() +include(${CMAKE_CURRENT_LIST_DIR}/bootstrap/vcpkg-config.cmake) + +vcpkg_configure(CACHE_DIR_NAME ss-cpp REPO + https://github.com/microsoft/vcpkg.git REF ${_builtin_baseline}) + set(VCPKG_VERBOSE ON CACHE BOOL "Vcpkg VCPKG_VERBOSE") -message(STATUS "vcpkg_toolchain_file:${vcpkg_toolchain_file}") -include(${vcpkg_toolchain_file}) +message(STATUS "vcpkg_toolchain_file:$CACHE{_VCPKG_TOOLCHAIN_FILE}") +include("$CACHE{_VCPKG_TOOLCHAIN_FILE}") diff --git a/copier.yml b/copier.yml index bc98c5eb..35f7b32d 100644 --- a/copier.yml +++ b/copier.yml @@ -164,8 +164,3 @@ add_compile_target: default: true help: Whether to add a compile lib target type: bool - -add_jni_target: - default: false - help: Whether to add a jni target based on Java invocation API - type: bool diff --git a/docs/development/build_configuration.md b/docs/development/build_configuration.md new file mode 100644 index 00000000..9ad0999e --- /dev/null +++ b/docs/development/build_configuration.md @@ -0,0 +1,2 @@ +```{include} ../../cmake/build_configuration.md +``` diff --git a/docs/development/index.md b/docs/development/index.md index 1c080fa3..5bc72cc6 100644 --- a/docs/development/index.md +++ b/docs/development/index.md @@ -4,4 +4,5 @@ :maxdepth: 1 cmake_workflow +build_configuration ``` diff --git a/docs/requirements.txt b/docs/requirements.txt index 991724ad..f9b0fa53 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,4 +3,3 @@ furo==2024.1.29 sphinx==7.1.2 sphinx-copybutton==0.5.2 myst-parser==2.0.0 -sphinxcontrib-moderncmakedomain==3.27.0 diff --git a/src/compile/CMakeLists.txt b/src/compile/CMakeLists.txt index 7457733a..38c492ab 100644 --- a/src/compile/CMakeLists.txt +++ b/src/compile/CMakeLists.txt @@ -1,7 +1,7 @@ set(target_name compile) # requirement for compile -find_package(proxy CONFIG REQUIRED) +find_package(spdlog CONFIG REQUIRED) file(GLOB_RECURSE _srcs "src/*.cpp") file(GLOB_RECURSE _hdrs "include/*.hpp") @@ -25,10 +25,7 @@ target_compile_options( ${target_name}-shared PRIVATE "$<$:/source-charset:utf-8>") -target_link_libraries( - ${target_name}-shared - PRIVATE msft_proxy - PRIVATE absl::log) +target_link_libraries(${target_name}-shared PRIVATE spdlog::spdlog) set_target_properties( ${target_name}-shared @@ -46,8 +43,7 @@ target_sources(${target_name}-static PRIVATE ${_srcs} ${_hdrs}) set(static_define ${target_name}_STATIC_DEFINE) string(TOUPPER ${static_define} static_define) -target_compile_definitions(${target_name}-static - PUBLIC ${static_define}) +target_compile_definitions(${target_name}-static PUBLIC ${static_define}) target_include_interface_directories( ${target_name}-static ${CMAKE_CURRENT_BINARY_DIR}/include @@ -57,11 +53,7 @@ target_compile_options( ${target_name}-static PRIVATE "$<$:/source-charset:utf-8>") -# Static dependencies, such as absl, do no need to export when installing -target_link_libraries( - ${target_name}-static - PRIVATE msft_proxy - PRIVATE absl::log) +target_link_libraries(${target_name}-static PRIVATE spdlog::spdlog) # msvc layout in solution source_group("impl" REGULAR_EXPRESSION "impl/.*\\.[h|cpp]") @@ -89,8 +81,7 @@ install_target( LICENSE_FILE_LIST ${CMAKE_SOURCE_DIR}/LICENSE DEPENDENCIES - msft_proxy - absl::log) + spdlog::spdlog) install_dependency(TARGETS ${target_name}-shared ${target_name}-static) diff --git a/src/compile/include/impl/impl.hpp b/src/compile/include/impl/impl.hpp deleted file mode 100644 index ab4729b3..00000000 --- a/src/compile/include/impl/impl.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include -#include "compile_export.hpp" -#include "proxy/proxy.h" - -#define STRINGIFY(x) #x -#define MACRO_STRINGIFY(x) STRINGIFY(x) - -namespace compile { -namespace geo { - -// proxy-runtime-polymorphism,see -// https://github.com/microsoft/proxy -// https://devblogs.microsoft.com/cppblog/proxy-runtime-polymorphism-made-easier-than-ever/ - -// Abstraction Draw interface for polymorphic call -struct COMPILE_EXPORT Draw : pro::dispatch { -public: - template - void operator()(const T& self, std::ostream& out) { - self.Draw(out); - } -}; - -// Abstraction Area interface for polymorphic call -struct COMPILE_EXPORT Area : pro::dispatch { -public: - template - double operator()(const T& self) { - return self.Area(); - } -}; - -// Interface facade for Draw, Area -struct COMPILE_EXPORT DrawableFacade : pro::facade {}; - -// Client API - Consumer -std::string COMPILE_EXPORT PrintDrawableToString(const pro::proxy& p); - -// Client API - Producer -pro::proxy COMPILE_EXPORT CreateRectangleAsDrawable(int width, int height); - -}; // namespace geo -}; // namespace compile diff --git a/src/compile/src/compile.cpp b/src/compile/src/compile.cpp index 1e83f8e5..785fb781 100644 --- a/src/compile/src/compile.cpp +++ b/src/compile/src/compile.cpp @@ -1,8 +1,6 @@ #include "compile.hpp" -#include #include "git.h" -#include "impl/impl.hpp" namespace compile { namespace info { diff --git a/src/compile/src/impl/impl.cpp b/src/compile/src/impl/impl.cpp deleted file mode 100644 index ae746dcd..00000000 --- a/src/compile/src/impl/impl.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "impl/impl.hpp" - -#include - -namespace compile { -// Implementation (No base class) -class Rectangle { -public: - void Draw(std::ostream& out) const { out << "{Rectangle: width = " << width_ << ", height = " << height_ << "}"; } - void SetWidth(double width) { width_ = width; } - void SetHeight(double height) { height_ = height; } - double Area() const { return width_ * height_; } - -private: - double width_; - double height_; -}; - -namespace geo { - -pro::proxy CreateRectangleAsDrawable(int width, int height) { - Rectangle rect; - rect.SetWidth(width); - rect.SetHeight(height); - return pro::make_proxy(rect); // No heap allocation is expected -} - -std::string PrintDrawableToString(const pro::proxy& p) { - std::stringstream result; - result << "shape = "; - p.invoke(result); // Polymorphic call - result << ", area = " << p.invoke(); // Polymorphic call - return std::move(result).str(); -} -}; // namespace geo -}; // namespace compile diff --git a/src/compile/tests/CMakeLists.txt b/src/compile/tests/CMakeLists.txt index a3dae781..6bbfa956 100644 --- a/src/compile/tests/CMakeLists.txt +++ b/src/compile/tests/CMakeLists.txt @@ -8,6 +8,4 @@ foreach(_file ${files}) target_code_coverage(${file_basename} ALL) gtest_discover_tests(${file_basename}) copy_sanitizer_runtime(${file_basename}) - - # add_test(NAME ${file_basename}_test COMMAND $) endforeach() diff --git a/src/compile/tests/test_compile_impl.cpp b/src/compile/tests/test_compile_impl.cpp deleted file mode 100644 index 2480ffce..00000000 --- a/src/compile/tests/test_compile_impl.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "impl/impl.hpp" - -TEST(geo, create_rect) { - const auto drawable = compile::geo::CreateRectangleAsDrawable(100, 100); - GTEST_ASSERT_EQ("shape = {Rectangle: width = 100, height = 100}, area = 10000", - compile::geo::PrintDrawableToString(drawable)); -} diff --git a/src/executable/CMakeLists.txt b/src/executable/CMakeLists.txt index 5cf02a04..a9ec9f25 100644 --- a/src/executable/CMakeLists.txt +++ b/src/executable/CMakeLists.txt @@ -2,13 +2,15 @@ # and tests internally set(target_name_private executable_private) +find_package(spdlog CONFIG REQUIRED) + add_library(${target_name_private} INTERFACE) target_include_interface_directories( ${target_name_private} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/git/include) -target_link_libraries(${target_name_private} INTERFACE absl::log) +target_link_libraries(${target_name_private} INTERFACE spdlog::spdlog) # The main target only contains main logits. Here it is recommended to put the # parts that need to be verified and tested in the target target_name_private @@ -20,7 +22,7 @@ add_executable(${target_name} ${_srcs}) target_code_coverage(${target_name} ALL) copy_sanitizer_runtime(${target_name}) -target_link_libraries(${target_name} PRIVATE absl::log_initialize absl::log +target_link_libraries(${target_name} PRIVATE spdlog::spdlog ${target_name_private}) install(TARGETS ${target_name} diff --git a/src/executable/include/helpers.hpp b/src/executable/include/helpers.hpp index c6d451d0..ec5f5e5b 100644 --- a/src/executable/include/helpers.hpp +++ b/src/executable/include/helpers.hpp @@ -1,12 +1,11 @@ #pragma once -#include "absl/log/log.h" +#include namespace executable { namespace helpers { inline int some_fun() { - LOG(INFO) << "Hello " - << "helpers!"; + spdlog::info("Hello helpers!"); return 0; } } // namespace helpers diff --git a/src/executable/src/main.cpp b/src/executable/src/main.cpp index b0f70a5c..7e9e3295 100644 --- a/src/executable/src/main.cpp +++ b/src/executable/src/main.cpp @@ -1,12 +1,9 @@ -#include "absl/log/globals.h" -#include "absl/log/initialize.h" -#include "absl/log/log.h" +#include + #include "git.h" #include "helpers.hpp" int main() { - absl::InitializeLog(); - absl::SetStderrThreshold(absl::LogSeverity::kInfo); - LOG(INFO) << "Get a returned value: " << executable::helpers::some_fun() << " ; Version: " << git::ProjectVersion(); + spdlog::info("Get a returned value: {} ; Version: {}", executable::helpers::some_fun(), git::ProjectVersion()); return 0; } diff --git a/src/header_only/CMakeLists.txt b/src/header_only/CMakeLists.txt index 139c7283..5f18a266 100644 --- a/src/header_only/CMakeLists.txt +++ b/src/header_only/CMakeLists.txt @@ -1,12 +1,14 @@ set(target_name header_only) +find_package(spdlog CONFIG REQUIRED) + add_library(${target_name} INTERFACE) target_include_interface_directories( ${target_name} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/git/include) -target_link_libraries(${target_name} INTERFACE absl::log) +target_link_libraries(${target_name} INTERFACE spdlog::spdlog) install_target( NAME @@ -21,7 +23,7 @@ install_target( LICENSE_FILE_LIST ${CMAKE_SOURCE_DIR}/LICENSE DEPENDENCIES - absl::log) + spdlog::spdlog) # Test if(BUILD_TESTING) diff --git a/src/header_only/include/header_only/header_only.hpp b/src/header_only/include/header_only/header_only.hpp index 2c3c78e2..1b16dab1 100644 --- a/src/header_only/include/header_only/header_only.hpp +++ b/src/header_only/include/header_only/header_only.hpp @@ -1,21 +1,17 @@ #pragma once -#include "absl/log/log.h" +#include #include "git.h" namespace header_only { namespace common { inline int some_fun() { - LOG(INFO) << git::ProjectVersion(); - return 0; -} - -constexpr int some_constexpr_fun() { + spdlog::info("{}", git::ProjectVersion()); return 0; } const std::string_view const_string() { - LOG(INFO) << "Calling " << __FUNCTION__; + spdlog::info("Calling {}", __FUNCTION__); return "This is a header_only only const string"; } } // namespace common diff --git a/src/header_only/tests/CMakeLists.txt b/src/header_only/tests/CMakeLists.txt index b9217175..820c2cb5 100644 --- a/src/header_only/tests/CMakeLists.txt +++ b/src/header_only/tests/CMakeLists.txt @@ -7,6 +7,4 @@ foreach(_file ${files}) target_code_coverage(${file_basename} ALL) gtest_discover_tests(${file_basename}) copy_sanitizer_runtime(${file_basename}) - - # add_test(NAME ${file_basename}_test COMMAND $) endforeach() diff --git a/template/.vscode/launch.json.jinja b/template/.vscode/launch.json.jinja index 7c2028ad..8bff417d 100644 --- a/template/.vscode/launch.json.jinja +++ b/template/.vscode/launch.json.jinja @@ -15,39 +15,6 @@ "environment": [], "console": "integratedTerminal" }, -[%- if add_header_only_target == true %] - { - "name": "(gdb) Launch jni", - "type": "cppdbg", - "request": "launch", - "program": "${command:cmake.launchTargetPath}", - "args": [], - "stopAtEntry": false, - "cwd": ".", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - // jvm handle sigsegv self, see - // https://medium.com/@pirogov.alexey/gdb-debug-native-part-of-java-application-c-c-libraries-and-jdk-6593af3b4f3f - "description": "Disable segfaults from jvm", - "text": "handle SIGSEGV nostop noprint pass", - "ignoreFailures": true, - }, - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - }, - { - "description": "Set Disassembly Flavor to Intel", - "text": "-gdb-set disassembly-flavor intel", - "ignoreFailures": true - } - ] - }, -[%- endif %] { "name": "(gdb) Launch", "type": "cppdbg", diff --git a/template/.vscode/settings.json b/template/.vscode/settings.json index c4ed526f..f9992d65 100644 --- a/template/.vscode/settings.json +++ b/template/.vscode/settings.json @@ -1,6 +1,6 @@ { "cmake.useCMakePresets": "always", - "cmake.options.statusBarVisibility": "visible", + "cmake.options.statusBarVisibility": "icon", "files.exclude": { "**/.clangd/**": true }, @@ -97,6 +97,8 @@ "cwctype": "cpp", "memory_resource": "cpp", "numbers": "cpp", - "semaphore": "cpp" + "semaphore": "cpp", + "codecvt": "cpp", + "source_location": "cpp" } } diff --git a/template/CMakeLists.txt.jinja b/template/CMakeLists.txt.jinja index 23facbd9..afbd68a6 100644 --- a/template/CMakeLists.txt.jinja +++ b/template/CMakeLists.txt.jinja @@ -1,26 +1,8 @@ [%- from pathjoin("includes", "variable.jinja") import repo_url with context -%] -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.25) message(STATUS "CMAKE VERSION:${CMAKE_VERSION}") -# Vcpkg build environment -if(DEFINED ENV{VCPKG_ROOT}) - message(STATUS "VCPKG_ROOT:$ENV{VCPKG_ROOT}") - set(VCPKG_ROOT "$ENV{VCPKG_ROOT}") -else() - message( - FATAL_ERROR "Missing VCPKG_ROOT, please check the existence of VCPKG_ROOT") -endif() - -# set cmake tool chain -file(TO_CMAKE_PATH ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake - vcpkg_toolchain_file) -set(CMAKE_TOOLCHAIN_FILE ${vcpkg_toolchain_file}) - -set(VCPKG_VERBOSE - ON - CACHE BOOL "Vcpkg VCPKG_VERBOSE") - # Project settings project( {{ repo_name }} @@ -48,8 +30,8 @@ include(cmake-modules/test/Default) include(cmake-modules/test/GoogleTest) include(cmake-modules/test/Sanitizer) include(cmake-modules/test/Valgrind) -include(cmake-modules/install/Common) include(cmake-modules/install/Default) +include(cmake-modules/install/Common) include(cmake-modules/install/InstallDependency) include(cmake-modules/install/Runpath) @@ -70,9 +52,6 @@ include(ConfigureCPMDependencies) include(ConfigureConanDependencies) [%- endif %] -# Package dependencies using find_package -find_package(absl CONFIG REQUIRED) - add_subdirectory(src) # Print project final information diff --git a/template/CMakePresets.json b/template/CMakePresets.json index f646b2de..5f1e39d4 100644 --- a/template/CMakePresets.json +++ b/template/CMakePresets.json @@ -1,216 +1,19 @@ { "version": 6, - "configurePresets": [ - { - "name": "default", - "displayName": "Basic Config", - "description": "Basic build using Ninja generator", - "generator": "Ninja", - "hidden": true, - "binaryDir": "${sourceDir}/out/build/${presetName}", - "installDir": "${sourceDir}/out/install/${presetName}", - "cacheVariables": { - "CMAKE_VERBOSE_MAKEFILE": "FALSE" - } - }, - { - "name": "x64", - "architecture": { - "value": "x64", - "strategy": "external" - }, - "hidden": true - }, - { - "name": "x86", - "architecture": { - "value": "x86", - "strategy": "external" - }, - "hidden": true - }, - { - "name": "Debug", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - }, - "hidden": true - }, - { - "name": "Release", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo" - }, - "hidden": true - }, - { - "name": "MSVC", - "hidden": true, - "cacheVariables": { - "CMAKE_C_COMPILER": "cl", - "CMAKE_CXX_COMPILER": "cl" - }, - "toolset": { - "value": "host=x64", - "strategy": "external" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - }, - { - "name": "Clang", - "hidden": true, - "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Linux" - }, - "toolset": { - "value": "host=x64", - "strategy": "external" - } - }, - { - "name": "ClangCL", - "hidden": true, - "cacheVariables": { - "CMAKE_C_COMPILER": "clang-cl", - "CMAKE_CXX_COMPILER": "clang-cl" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - }, - "toolset": { - "value": "host=x64", - "strategy": "external" - } - }, - { - "name": "GNUC", - "hidden": true, - "cacheVariables": { - "CMAKE_C_COMPILER": "gcc", - "CMAKE_CXX_COMPILER": "g++" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Linux" - }, - "toolset": { - "value": "host=x64", - "strategy": "external" - } - }, - { - "name": "x64-Debug-MSVC", - "description": "MSVC for x64 (Debug)", - "inherits": [ - "default", - "x64", - "Debug", - "MSVC" - ] - }, - { - "name": "x64-Release-MSVC", - "description": "MSVC for x64 (Release)", - "inherits": [ - "default", - "x64", - "Release", - "MSVC" - ] - }, - { - "name": "x64-Debug-Clang", - "description": "Clang/LLVM for x64 (Debug)", - "inherits": [ - "default", - "x64", - "Debug", - "Clang" - ] - }, - { - "name": "x64-Release-Clang", - "description": "Clang/LLVM for x64 (Release)", - "inherits": [ - "default", - "x64", - "Release", - "Clang" - ] - }, - { - "name": "x64-Debug-ClangCL", - "description": "Clang/LLVM for x64 (Debug)", - "inherits": [ - "default", - "x64", - "Debug", - "ClangCL" - ] - }, - { - "name": "x64-Release-ClangCL", - "description": "ClangCL/LLVM for x64 (Release)", - "inherits": [ - "default", - "x64", - "Release", - "ClangCL" - ] - }, - { - "name": "x64-Debug-GNUC", - "description": "GNUC for x64 (Debug)", - "inherits": [ - "default", - "x64", - "Debug", - "GNUC" - ] - }, - { - "name": "x64-Release-GNUC", - "description": "GNUC for x64 (Release)", - "inherits": [ - "default", - "x64", - "Release", - "GNUC" - ] - } - ], - "buildPresets": [ - { - "name": "default", - "configurePreset": "default" - } - ], - "testPresets": [ - { - "name": "default", - "configurePreset": "default", - "output": { - "outputOnFailure": true - }, - "execution": { - "noTestsAction": "error", - "stopOnFailure": true, - "timeout": 180, - "jobs": 8 - } - } + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 + }, + "include": [ + "cmake/presets/x64-linux-llvm.json", + "cmake/presets/x64-linux-gcc.json", + "cmake/presets/x64-mingw-dynamic-windows-mingw-gcc.json", + "cmake/presets/x64-mingw-dynamic-darwin-mingw.json", + "cmake/presets/x64-mingw-dynamic-linux-mingw.json", + "cmake/presets/x64-osx-gcc.json", + "cmake/presets/x64-osx-llvm.json", + "cmake/presets/x64-windows-llvm.json", + "cmake/presets/x64-windows-msvc.json" ] } diff --git a/template/[% if docs_type == 'sphinx' %]docs[% endif %]/development/build_configuration.md b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/development/build_configuration.md new file mode 100644 index 00000000..9ad0999e --- /dev/null +++ b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/development/build_configuration.md @@ -0,0 +1,2 @@ +```{include} ../../cmake/build_configuration.md +``` diff --git a/template/[% if docs_type == 'sphinx' %]docs[% endif %]/development/index.md b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/development/index.md index 1c080fa3..5bc72cc6 100644 --- a/template/[% if docs_type == 'sphinx' %]docs[% endif %]/development/index.md +++ b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/development/index.md @@ -4,4 +4,5 @@ :maxdepth: 1 cmake_workflow +build_configuration ``` diff --git a/template/[% if docs_type == 'sphinx' %]docs[% endif %]/requirements.txt b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/requirements.txt index 991724ad..f9b0fa53 100644 --- a/template/[% if docs_type == 'sphinx' %]docs[% endif %]/requirements.txt +++ b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/requirements.txt @@ -3,4 +3,3 @@ furo==2024.1.29 sphinx==7.1.2 sphinx-copybutton==0.5.2 myst-parser==2.0.0 -sphinxcontrib-moderncmakedomain==3.27.0 diff --git a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/ci.yml b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/ci.yml index 6c8219fe..da89879a 100644 --- a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/ci.yml +++ b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/ci.yml @@ -74,9 +74,105 @@ jobs: exit 1 \ ) + checks: + runs-on: ${{ matrix.presets.os.name }} + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + presets: + - {os: {name: ubuntu-latest, type: linux}, compiler: {name: gcc-11, type: gcc}} + - {os: {name: ubuntu-latest, type: linux}, compiler: {name: llvm, type: llvm}} + - {os: {name: ubuntu-latest, type: mingw-dynamic-linux}, compiler: {name: mingw, type: mingw}} + - {os: {name: macos-latest, type: osx}, compiler: {name: applellvm, type: llvm}} + - {os: {name: macos-latest, type: osx}, compiler: {name: llvm, type: llvm}} + # setup-cpp doesn't support mingw on macOS yet + # - {os: {name: macos-latest, type: mingw-dynamic-darwin}, compiler: {name: mingw, type: mingw}} + - {os: {name: windows-latest, type: windows}, compiler: {name: msvc, type: msvc}} + - {os: {name: windows-latest, type: windows}, compiler: {name: llvm, type: llvm}} + - {os: {name: windows-latest, type: mingw-dynamic-windows}, compiler: {name: mingw, type: mingw-gcc}} + arch: + - {name: x64, type: x64} + vcpkg: + - true + - false + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/vcpkg + ./build/vcpkg_installed + ~/.cache/pip + ${{ env.HOME }}/.cache/vcpkg/archives + ${{ env.XDG_CACHE_HOME }}/vcpkg/archives + ${{ env.LOCALAPPDATA }}\vcpkg\archives + ${{ env.APPDATA }}\vcpkg\archives + key: | + ${{ matrix.arch.name }}-${{ matrix.presets.os.name }}-${{ matrix.presets.compiler.name }}-${{ matrix.vcpkg }}-${{ hashFiles('./vcpkg.json') }} + restore-keys: | + ${{ matrix.arch.name }}-${{ matrix.presets.os.name }}-${{ matrix.presets.compiler.name }}-${{ matrix.vcpkg }}-${{ hashFiles('./vcpkg.json') }} + + - uses: aminya/setup-cpp@v1 + with: + compiler: ${{ matrix.presets.compiler.name }} + vcvarsall: ${{ contains(matrix.presets.os.type, 'windows' )}} + cmake: true + ninja: true + vcpkg: ${{ matrix.vcpkg }} + ccache: true + python: true + opencppcoverage: true + + - name: Gcc Lcov + if: contains(matrix.presets.compiler.type, 'gcc') && contains(matrix.presets.os.type, 'linux') + run: | + sudo apt-get update + sudo apt-get install lcov + + - name: Gcovr + if: contains(matrix.presets.compiler.type, 'mingw') && contains(matrix.presets.os.type, 'mingw') + run: | + pip install gcovr + + - name: Target Windows on Linux (Mingw-w64) + if: contains(matrix.presets.compiler.type, 'mingw') && contains(matrix.presets.os.type, 'linux') + run: | + sudo apt-get update && sudo apt-get install mingw-w64 wine wine64 powershell + sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix + sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix + wine64 true || true + echo "wait 10s for wine registry to be created" && sleep 10 + sed -i '/"PATH"/ s|"$|;Z:/usr/lib/gcc/x86_64-w64-mingw32/10-posix;Z:/usr/x86_64-w64-mingw32/lib"|g' ~/.wine/system.reg && echo "wine registry updated" + + + - name: Configure CMake + run: | + cmake -S . --preset=${{ matrix.arch.type }}-${{ matrix.presets.os.type }}-${{ matrix.presets.compiler.type }} -DCMAKE_BUILD_TYPE=Debug -DCODE_COVERAGE=ON -DBUILD_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=TRUE + + - name: Coverage + run: | + cmake --build out/build/${{ matrix.arch.type }}-${{ matrix.presets.os.type }}-${{ matrix.presets.compiler.type }} --target ccov-all + + - name: Upload coverage report + uses: codecov/codecov-action@v4.1.0 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: out/build/${{ matrix.arch.type }}-${{ matrix.presets.os.type }}-${{ matrix.presets.compiler.type }}/code_coverage/coverage.xml + flags: ${{ matrix.arch.type }}-${{ matrix.presets.os.type }}-${{ matrix.presets.compiler.type }} + name: ${{ matrix.arch.type }}-${{ matrix.presets.os.type }}-${{ matrix.presets.compiler.type }}-coverage + pass: if: always() - needs: [pre-commit, consistency] + needs: [pre-commit, consistency, checks] runs-on: ubuntu-latest timeout-minutes: 2 steps: diff --git a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/preview.yml.jinja b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/preview.yml.jinja index 7938d3b3..46d978bf 100644 --- a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/preview.yml.jinja +++ b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/preview.yml.jinja @@ -29,7 +29,6 @@ jobs: compiler: gcc cmake: true ninja: true - vcpkg: true ccache: true doxygen: true graphviz: true @@ -40,12 +39,10 @@ jobs: pip install -r docs/requirements.txt - name: Configure - env: - VCPKG_ROOT: /home/runner/vcpkg - run: cmake -S . --preset=x64-Debug-GNUC -DBUILD_TESTING=OFF -DCODE_COVERAGE=OFF + run: cmake -S . --preset=x64-linux-gcc -DBUILD_TESTING=OFF -DCODE_COVERAGE=OFF - name: Build Docs - run: cmake --build out/build/x64-Debug-GNUC --target {{ repo_name }}-docs + run: cmake --build out/build/x64-linux-gcc --target {{ repo_name }}-docs - name: Deploy preview uses: rossjrw/pr-preview-action@v1 diff --git a/template/cmake/ConfigureCoverage.cmake b/template/cmake/ConfigureCoverage.cmake index cf877530..94df47d4 100644 --- a/template/cmake/ConfigureCoverage.cmake +++ b/template/cmake/ConfigureCoverage.cmake @@ -1,12 +1,28 @@ +#[[ +This file is used to configure code coverage for all targets in the project. + +It supports detecting and using the following coverage tools: + - gcov (GNU gcov) + - llvm-cov (LLVM's llvm-cov) + - lcov (GNU lcov) + - opencppcoverage (OpenCppCoverage) + +]] + include_guard(GLOBAL) # cmake-format: off include(cmake-modules/test/Coverage) +list(APPEND _excludes "${CMAKE_BINARY_DIR}" "${VCPKG_INSTALLED_DIR}") + +if(UNIX) + list(APPEND _excludes "/usr" "/usr/local" "/opt" "/opt/local") +endif() + add_code_coverage_all_targets( - EXCLUDE_DIRS - "${VCPKG_INSTALLED_DIR}" - "${CMAKE_BINARY_DIR}" - "/usr" + EXCLUDE_DIRS ${_excludes} INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/src") +unset(_exclude_dirs) +unset(_excludes) # cmake-format: on diff --git a/template/cmake/ConfigureDocs.cmake.jinja b/template/cmake/ConfigureDocs.cmake.jinja index e02a01fb..470b0231 100644 --- a/template/cmake/ConfigureDocs.cmake.jinja +++ b/template/cmake/ConfigureDocs.cmake.jinja @@ -1,11 +1,14 @@ -# Build the target by issuing: cmake --build . --target -# ${CMAKE_PROJECT_NAME}-docs +#[[ +This file creates targets to generate documentation: + + - Doxygen: ${CMAKE_PROJECT_NAME}-doxygen + - Sphinx: ${CMAKE_PROJECT_NAME}-docs +]] include(cmake-modules/configure/ConfigDoxygen) configdoxygen() if(DOXYGEN_FOUND) - # Generate XML OUTPUT for breathe set(DOXYGEN_GENERATE_HTML NO) set(DOXYGEN_GENERATE_XML YES) @@ -49,5 +52,4 @@ if(DOXYGEN_FOUND) OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/_build/html) endif() - endif() diff --git a/template/cmake/ConfigureVersion.cmake b/template/cmake/ConfigureVersion.cmake index 3a81c18f..72d6b065 100644 --- a/template/cmake/ConfigureVersion.cmake +++ b/template/cmake/ConfigureVersion.cmake @@ -1,3 +1,11 @@ +#[[ +This file configures the version of the project based on the git commit. + +It creates a header file ${CMAKE_BINARY_DIR}/git/include with the version +information, which can be included in the project. + +]] + include_guard(GLOBAL) include(cmake-modules/configure/GitTools) diff --git a/template/cmake/build_configuration.md b/template/cmake/build_configuration.md new file mode 100644 index 00000000..0fdae7f2 --- /dev/null +++ b/template/cmake/build_configuration.md @@ -0,0 +1,10 @@ +# SS-CPP Build Congfiguration + +## Triplets = {Architecture}-{Target-Compiling-OS/Toolchain}-{Distribution} + +- Architecture: x86, x64, arm, arm64, ppc64le, s390x, wasm32, etc. +- Target-Compiling-OS/Toolchain: windows, linux, macos, freebsd, android, ios, mingw, etc. +- Distribution: dynamic, static, release, etc. +- Compiler(Optional): MSVC, GCC, Clang, MinGW + +More about triplets, see: diff --git a/template/cmake/presets/arch/x64.json b/template/cmake/presets/arch/x64.json new file mode 100644 index 00000000..e7ea25b7 --- /dev/null +++ b/template/cmake/presets/arch/x64.json @@ -0,0 +1,20 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "x64", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "toolset": { + "value": "host=x64", + "strategy": "external" + }, + "hidden": true, + "cacheVariables": { + "VCPKG_TARGET_ARCHITECTURE": "x64" + } + } + ] +} diff --git a/template/cmake/presets/base.json b/template/cmake/presets/base.json new file mode 100644 index 00000000..0a547cb6 --- /dev/null +++ b/template/cmake/presets/base.json @@ -0,0 +1,47 @@ +{ + "version": 6, + "include": [ + "generators/ninja.json", + "toolchains/vcpkg.json" + ], + "configurePresets": [ + { + "name": "base", + "hidden": true, + "inherits": [ + "ninja-multi-config", + "vcpkg" + ], + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "CMAKE_COMPILE_WARNING_AS_ERROR": true, + "CMAKE_VERBOSE_MAKEFILE": "FALSE" + } + } + ], + "buildPresets": [ + { + "name": "base", + "hidden": true, + "inherits": "ninja-multi-config", + "configurePreset": "base" + } + ], + "testPresets": [ + { + "name": "base", + "hidden": true, + "inherits": "ninja-multi-config", + "configurePreset": "base", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + } + ] +} diff --git a/cmake/presets/compilers/clang.json b/template/cmake/presets/compilers/gcc.json similarity index 53% rename from cmake/presets/compilers/clang.json rename to template/cmake/presets/compilers/gcc.json index a1398178..d920fb4c 100644 --- a/cmake/presets/compilers/clang.json +++ b/template/cmake/presets/compilers/gcc.json @@ -2,11 +2,11 @@ "version": 6, "configurePresets": [ { - "name": "clang", + "name": "gcc", "hidden": true, "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++" + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" } } ] diff --git a/template/cmake/presets/compilers/llvm.json b/template/cmake/presets/compilers/llvm.json new file mode 100644 index 00000000..f673547f --- /dev/null +++ b/template/cmake/presets/compilers/llvm.json @@ -0,0 +1,21 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "llvm", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + }, + { + "name": "llvm-cl", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl" + } + } + ] +} diff --git a/template/cmake/presets/compilers/mingw.json b/template/cmake/presets/compilers/mingw.json new file mode 100644 index 00000000..302a8985 --- /dev/null +++ b/template/cmake/presets/compilers/mingw.json @@ -0,0 +1,9 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "mingw", + "hidden": true + } + ] +} diff --git a/template/cmake/presets/compilers/msvc.json b/template/cmake/presets/compilers/msvc.json new file mode 100644 index 00000000..712dce12 --- /dev/null +++ b/template/cmake/presets/compilers/msvc.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "msvc", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ] +} diff --git a/template/cmake/presets/generators/ninja.json b/template/cmake/presets/generators/ninja.json new file mode 100644 index 00000000..907ec805 --- /dev/null +++ b/template/cmake/presets/generators/ninja.json @@ -0,0 +1,40 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "ninja", + "hidden": true, + "generator": "Ninja" + }, + { + "name": "ninja-multi-config", + "hidden": true, + "generator": "Ninja Multi-Config" + } + ], + "buildPresets": [ + { + "name": "ninja", + "hidden": true + }, + { + "name": "ninja-multi-config", + "hidden": true, + "configurePreset": "ninja-multi-config", + "configuration": "Debug" + } + ], + "testPresets": [ + { + "name": "ninja", + "hidden": true, + "configurePreset": "ninja" + }, + { + "name": "ninja-multi-config", + "hidden": true, + "configurePreset": "ninja-multi-config", + "configuration": "Debug" + } + ] +} diff --git a/template/cmake/presets/os/darwin.json b/template/cmake/presets/os/darwin.json new file mode 100644 index 00000000..e3f3fbe9 --- /dev/null +++ b/template/cmake/presets/os/darwin.json @@ -0,0 +1,28 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "darwin", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + } + ], + "buildPresets": [ + { + "name": "darwin", + "hidden": true, + "configurePreset": "darwin" + } + ], + "testPresets": [ + { + "name": "darwin", + "hidden": true, + "configurePreset": "darwin" + } + ] +} diff --git a/template/cmake/presets/os/linux.json b/template/cmake/presets/os/linux.json new file mode 100644 index 00000000..684e0786 --- /dev/null +++ b/template/cmake/presets/os/linux.json @@ -0,0 +1,28 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "linux", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + } + ], + "buildPresets": [ + { + "name": "linux", + "hidden": true, + "configurePreset": "linux" + } + ], + "testPresets": [ + { + "name": "linux", + "hidden": true, + "configurePreset": "linux" + } + ] +} diff --git a/template/cmake/presets/os/windows.json b/template/cmake/presets/os/windows.json new file mode 100644 index 00000000..9f78bad8 --- /dev/null +++ b/template/cmake/presets/os/windows.json @@ -0,0 +1,28 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "windows", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "buildPresets": [ + { + "name": "windows", + "hidden": true, + "configurePreset": "windows" + } + ], + "testPresets": [ + { + "name": "windows", + "hidden": true, + "configurePreset": "windows" + } + ] +} diff --git a/template/cmake/presets/toolchains/vcpkg.json b/template/cmake/presets/toolchains/vcpkg.json new file mode 100644 index 00000000..8536b5f9 --- /dev/null +++ b/template/cmake/presets/toolchains/vcpkg.json @@ -0,0 +1,15 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "vcpkg", + "hidden": true, + "toolchainFile": "${sourceDir}/cmake/vcpkg/vcpkg.toolchain.cmake", + "cacheVariables": { + "VCPKG_INSTALL_OPTIONS": "--no-print-usage", + "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake/vcpkg/triplets", + "VCPKG_OVERLAY_PORTS": "${sourceDir}/cmake/vcpkg/ports" + } + } + ] +} diff --git a/template/cmake/presets/triplets/x64-linux.json b/template/cmake/presets/triplets/x64-linux.json new file mode 100644 index 00000000..00a3e242 --- /dev/null +++ b/template/cmake/presets/triplets/x64-linux.json @@ -0,0 +1,19 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-linux", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-linux", + "VCPKG_HOST_TRIPLET": "x64-linux" + } + } + ] +} diff --git a/template/cmake/presets/triplets/x64-mingw-dynamic.json b/template/cmake/presets/triplets/x64-mingw-dynamic.json new file mode 100644 index 00000000..d4060956 --- /dev/null +++ b/template/cmake/presets/triplets/x64-mingw-dynamic.json @@ -0,0 +1,20 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-mingw-dynamic", + "VCPKG_HOST_TRIPLET": "x64-mingw-dynamic", + "VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/cmake/vcpkg/scripts/toolchains/mingw.cmake" + } + } + ] +} diff --git a/template/cmake/presets/triplets/x64-osx.json b/template/cmake/presets/triplets/x64-osx.json new file mode 100644 index 00000000..636f85f7 --- /dev/null +++ b/template/cmake/presets/triplets/x64-osx.json @@ -0,0 +1,19 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-osx", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-osx", + "VCPKG_HOST_TRIPLET": "x64-osx" + } + } + ] +} diff --git a/template/cmake/presets/triplets/x64-windows.json b/template/cmake/presets/triplets/x64-windows.json new file mode 100644 index 00000000..afe4ef00 --- /dev/null +++ b/template/cmake/presets/triplets/x64-windows.json @@ -0,0 +1,19 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-windows", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-windows", + "VCPKG_HOST_TRIPLET": "x64-windows" + } + } + ] +} diff --git a/cmake/presets/x64-linux-clang.json b/template/cmake/presets/x64-linux-gcc.json similarity index 57% rename from cmake/presets/x64-linux-clang.json rename to template/cmake/presets/x64-linux-gcc.json index 4ab4155a..fdbc8794 100644 --- a/cmake/presets/x64-linux-clang.json +++ b/template/cmake/presets/x64-linux-gcc.json @@ -2,48 +2,50 @@ "version": 6, "include": [ "base.json", - "compilers/clang.json", + "os/linux.json", + "compilers/gcc.json", "triplets/x64-linux.json" ], "configurePresets": [ { - "name": "x64-linux-clang", + "name": "x64-linux-gcc", "inherits": [ "base", - "clang", + "linux", + "gcc", "x64-linux" ] } ], "buildPresets": [ { - "name": "x64-linux-clang", + "name": "x64-linux-gcc", "inherits": "base", - "configurePreset": "x64-linux-clang" + "configurePreset": "x64-linux-gcc" } ], "testPresets": [ { - "name": "x64-linux-clang", + "name": "x64-linux-gcc", "inherits": "base", - "configurePreset": "x64-linux-clang" + "configurePreset": "x64-linux-gcc" } ], "workflowPresets": [ { - "name": "x64-linux-clang", + "name": "x64-linux-gcc", "steps": [ { "type": "configure", - "name": "x64-linux-clang" + "name": "x64-linux-gcc" }, { "type": "build", - "name": "x64-linux-clang" + "name": "x64-linux-gcc" }, { "type": "test", - "name": "x64-linux-clang" + "name": "x64-linux-gcc" } ] } diff --git a/template/cmake/presets/x64-linux-llvm.json b/template/cmake/presets/x64-linux-llvm.json new file mode 100644 index 00000000..cc9b6052 --- /dev/null +++ b/template/cmake/presets/x64-linux-llvm.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/linux.json", + "compilers/llvm.json", + "triplets/x64-linux.json" + ], + "configurePresets": [ + { + "name": "x64-linux-llvm", + "inherits": [ + "base", + "linux", + "llvm", + "x64-linux" + ] + } + ], + "buildPresets": [ + { + "name": "x64-linux-llvm", + "inherits": "base", + "configurePreset": "x64-linux-llvm" + } + ], + "testPresets": [ + { + "name": "x64-linux-llvm", + "inherits": "base", + "configurePreset": "x64-linux-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-linux-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-linux-llvm" + }, + { + "type": "build", + "name": "x64-linux-llvm" + }, + { + "type": "test", + "name": "x64-linux-llvm" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-mingw-dynamic-darwin-mingw.json b/template/cmake/presets/x64-mingw-dynamic-darwin-mingw.json new file mode 100644 index 00000000..7d87f43c --- /dev/null +++ b/template/cmake/presets/x64-mingw-dynamic-darwin-mingw.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/darwin.json", + "compilers/mingw.json", + "triplets/x64-mingw-dynamic.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic-darwin-mingw", + "inherits": [ + "base", + "darwin", + "mingw", + "x64-mingw-dynamic" + ] + } + ], + "buildPresets": [ + { + "name": "x64-mingw-dynamic-darwin-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-darwin-mingw" + } + ], + "testPresets": [ + { + "name": "x64-mingw-dynamic-darwin-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-darwin-mingw" + } + ], + "workflowPresets": [ + { + "name": "x64-mingw-dynamic-darwin-mingw", + "steps": [ + { + "type": "configure", + "name": "x64-mingw-dynamic-darwin-mingw" + }, + { + "type": "build", + "name": "x64-mingw-dynamic-darwin-mingw" + }, + { + "type": "test", + "name": "x64-mingw-dynamic-darwin-mingw" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-mingw-dynamic-linux-mingw.json b/template/cmake/presets/x64-mingw-dynamic-linux-mingw.json new file mode 100644 index 00000000..4905059b --- /dev/null +++ b/template/cmake/presets/x64-mingw-dynamic-linux-mingw.json @@ -0,0 +1,56 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/linux.json", + "compilers/mingw.json", + "triplets/x64-mingw-dynamic.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic-linux-mingw", + "inherits": [ + "base", + "linux", + "mingw", + "x64-mingw-dynamic" + ], + "cacheVariables": { + "USE_SANITIZER": "FALSE" + } + } + ], + "buildPresets": [ + { + "name": "x64-mingw-dynamic-linux-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-linux-mingw" + } + ], + "testPresets": [ + { + "name": "x64-mingw-dynamic-linux-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-linux-mingw" + } + ], + "workflowPresets": [ + { + "name": "x64-mingw-dynamic-linux-mingw", + "steps": [ + { + "type": "configure", + "name": "x64-mingw-dynamic-linux-mingw" + }, + { + "type": "build", + "name": "x64-mingw-dynamic-linux-mingw" + }, + { + "type": "test", + "name": "x64-mingw-dynamic-linux-mingw" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-mingw-dynamic-windows-mingw-gcc.json b/template/cmake/presets/x64-mingw-dynamic-windows-mingw-gcc.json new file mode 100644 index 00000000..85aa2fb0 --- /dev/null +++ b/template/cmake/presets/x64-mingw-dynamic-windows-mingw-gcc.json @@ -0,0 +1,56 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/mingw.json", + "triplets/x64-mingw-dynamic.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw-gcc", + "inherits": [ + "base", + "windows", + "mingw", + "x64-mingw-dynamic" + ], + "cacheVariables": { + "USE_SANITIZER": "FALSE" + } + } + ], + "buildPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw-gcc", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-windows-mingw-gcc" + } + ], + "testPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw-gcc", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-windows-mingw-gcc" + } + ], + "workflowPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw-gcc", + "steps": [ + { + "type": "configure", + "name": "x64-mingw-dynamic-windows-mingw-gcc" + }, + { + "type": "build", + "name": "x64-mingw-dynamic-windows-mingw-gcc" + }, + { + "type": "test", + "name": "x64-mingw-dynamic-windows-mingw-gcc" + } + ] + } + ] +} diff --git a/cmake/presets/x64-osx-clang.json b/template/cmake/presets/x64-osx-gcc.json similarity index 58% rename from cmake/presets/x64-osx-clang.json rename to template/cmake/presets/x64-osx-gcc.json index da0298db..405af6c6 100644 --- a/cmake/presets/x64-osx-clang.json +++ b/template/cmake/presets/x64-osx-gcc.json @@ -2,48 +2,50 @@ "version": 6, "include": [ "base.json", - "compilers/clang.json", + "os/darwin.json", + "compilers/gcc.json", "triplets/x64-osx.json" ], "configurePresets": [ { - "name": "x64-osx-clang", + "name": "x64-osx-gcc", "inherits": [ "base", - "clang", + "darwin", + "gcc", "x64-osx" ] } ], "buildPresets": [ { - "name": "x64-osx-clang", + "name": "x64-osx-gcc", "inherits": "base", - "configurePreset": "x64-osx-clang" + "configurePreset": "x64-osx-gcc" } ], "testPresets": [ { - "name": "x64-osx-clang", + "name": "x64-osx-gcc", "inherits": "base", - "configurePreset": "x64-osx-clang" + "configurePreset": "x64-osx-gcc" } ], "workflowPresets": [ { - "name": "x64-osx-clang", + "name": "x64-osx-gcc", "steps": [ { "type": "configure", - "name": "x64-osx-clang" + "name": "x64-osx-gcc" }, { "type": "build", - "name": "x64-osx-clang" + "name": "x64-osx-gcc" }, { "type": "test", - "name": "x64-osx-clang" + "name": "x64-osx-gcc" } ] } diff --git a/template/cmake/presets/x64-osx-llvm.json b/template/cmake/presets/x64-osx-llvm.json new file mode 100644 index 00000000..fc43d065 --- /dev/null +++ b/template/cmake/presets/x64-osx-llvm.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/darwin.json", + "compilers/llvm.json", + "triplets/x64-osx.json" + ], + "configurePresets": [ + { + "name": "x64-osx-llvm", + "inherits": [ + "base", + "darwin", + "llvm", + "x64-osx" + ] + } + ], + "buildPresets": [ + { + "name": "x64-osx-llvm", + "inherits": "base", + "configurePreset": "x64-osx-llvm" + } + ], + "testPresets": [ + { + "name": "x64-osx-llvm", + "inherits": "base", + "configurePreset": "x64-osx-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-osx-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-osx-llvm" + }, + { + "type": "build", + "name": "x64-osx-llvm" + }, + { + "type": "test", + "name": "x64-osx-llvm" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-windows-llvm.json b/template/cmake/presets/x64-windows-llvm.json new file mode 100644 index 00000000..fdcf92f9 --- /dev/null +++ b/template/cmake/presets/x64-windows-llvm.json @@ -0,0 +1,56 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/llvm.json", + "triplets/x64-windows.json" + ], + "configurePresets": [ + { + "name": "x64-windows-llvm", + "inherits": [ + "base", + "windows", + "llvm-cl", + "x64-windows" + ], + "cacheVariables": { + "USE_SANITIZER": "FALSE" + } + } + ], + "buildPresets": [ + { + "name": "x64-windows-llvm", + "inherits": "base", + "configurePreset": "x64-windows-llvm" + } + ], + "testPresets": [ + { + "name": "x64-windows-llvm", + "inherits": "base", + "configurePreset": "x64-windows-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-windows-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-windows-llvm" + }, + { + "type": "build", + "name": "x64-windows-llvm" + }, + { + "type": "test", + "name": "x64-windows-llvm" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-windows-msvc.json b/template/cmake/presets/x64-windows-msvc.json new file mode 100644 index 00000000..f63a9647 --- /dev/null +++ b/template/cmake/presets/x64-windows-msvc.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/msvc.json", + "triplets/x64-windows.json" + ], + "configurePresets": [ + { + "name": "x64-windows-msvc", + "inherits": [ + "base", + "windows", + "msvc", + "x64-windows" + ] + } + ], + "buildPresets": [ + { + "name": "x64-windows-msvc", + "inherits": "base", + "configurePreset": "x64-windows-msvc" + } + ], + "testPresets": [ + { + "name": "x64-windows-msvc", + "inherits": "base", + "configurePreset": "x64-windows-msvc" + } + ], + "workflowPresets": [ + { + "name": "x64-windows-msvc", + "steps": [ + { + "type": "configure", + "name": "x64-windows-msvc" + }, + { + "type": "build", + "name": "x64-windows-msvc" + }, + { + "type": "test", + "name": "x64-windows-msvc" + } + ] + } + ] +} diff --git a/template/cmake/vcpkg/bootstrap/vcpkg-config.cmake b/template/cmake/vcpkg/bootstrap/vcpkg-config.cmake new file mode 100644 index 00000000..3dc8bca4 --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg-config.cmake @@ -0,0 +1,17 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +include_guard(GLOBAL) + +# CMAKE_HOST_* variables are not available during first configure on windows. +cmake_host_system_information(RESULT __vcpkg_bootstrap_host QUERY OS_NAME) +cmake_host_system_information(RESULT __vcpkg_bootstrap_arch QUERY OS_PLATFORM) + +set(__vcpkg_bootstrap_list_dir "${CMAKE_CURRENT_LIST_DIR}") + +include(${__vcpkg_bootstrap_list_dir}/vcpkg_skip_install_on_reconfigure.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_bootstrap.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_configure.cmake) diff --git a/template/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake b/template/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake new file mode 100644 index 00000000..461458b3 --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake @@ -0,0 +1,199 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +# stash all local changes +function(_vcpkg_stash vcpkg_root) + message(STATUS "vcpkg stash all local changes") + + execute_process( + COMMAND ${GIT_EXECUTABLE} stash + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${GIT_EXECUTABLE} stash failed with ${result}") + endif() +endfunction() + +# checkout to a specific baseline +function(_vcpkg_checkout vcpkg_root vcpkg_ref) + message(STATUS "vcpkg checkout to ${vcpkg_ref}") + + if(EXISTS "${vcpkg_root}/.git/shallow") + message(WARNING "vcpkg is shallow, unshallowing...") + execute_process( + COMMAND ${GIT_EXECUTABLE} fetch --unshallow + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message( + FATAL_ERROR "${GIT_EXECUTABLE} fetch --unshallow failed with ${result}") + endif() + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} checkout ${vcpkg_ref} + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message( + FATAL_ERROR + "${GIT_EXECUTABLE} checkout ${vcpkg_ref} failed with ${result}") + endif() +endfunction() # clone +function(_vcpkg_clone vcpkg_root vcpkg_repo vcpkg_ref) + execute_process( + COMMAND ${GIT_EXECUTABLE} clone ${vcpkg_repo} ${vcpkg_root} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "failed to clone ${vcpkg_repo} to ${vcpkg_root}") + endif() + + file(LOCK "${vcpkg_root}" DIRECTORY) + _vcpkg_checkout(${vcpkg_root} ${vcpkg_ref}) +endfunction() + +# bootstrap +function(_vcpkg_tool_bootstrap vcpkg_root) + message(STATUS "Bootstrap vckpg tool") + + if("${__vcpkg_bootstrap_host}" STREQUAL "Windows") + set(bootstrap_cmd "${vcpkg_root}/bootstrap-vcpkg.bat") + else() + set(bootstrap_cmd "${vcpkg_root}/bootstrap-vcpkg.sh") + endif() + + execute_process( + COMMAND ${bootstrap_cmd} -disableMetrics + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${bootstrap_cmd} failed with ${result}") + endif() +endfunction() + +# upgrade +function(_vcpkg_upgrade vcpkg_root vcpkg_repo vcpkg_ref) + file(LOCK "${vcpkg_root}" DIRECTORY) + + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --is-inside-work-tree + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE in_git_work_tree + OUTPUT_QUIET ERROR_QUIET) + + if(NOT in_git_work_tree EQUAL 0) + message(WARNING "vcpkg not found in git work tree, skipping upgrade") + return() + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + WORKING_DIRECTORY ${vcpkg_root} + OUTPUT_VARIABLE current_git_hash + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message( + FATAL_ERROR "${GIT_EXECUTABLE} rev-parse HEAD failed with ${result}") + endif() + + if("${current_git_hash}" STREQUAL "${vcpkg_ref}") + return() + endif() + + message(STATUS "Upgrade vcpkg") + message(STATUS "vcpkg current commit: ${current_git_hash}") + message(STATUS "vcpkg release: ${vcpkg_ref}") + + execute_process( + COMMAND ${GIT_EXECUTABLE} remote set-url origin ${vcpkg_repo} + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "failed to change origin to ${vcpkg_repo}") + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} fetch + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${GIT_EXECUTABLE} fetch failed with ${result}") + endif() + + _vcpkg_stash(${vcpkg_root}) + _vcpkg_checkout(${vcpkg_root} ${vcpkg_ref}) + _vcpkg_tool_bootstrap(${vcpkg_root}) +endfunction() + +# find root +function(_vcpkg_find_root cache_dir_name out_vcpkg_root) + if(DEFINED ENV{VCPKG_INSTALLATION_ROOT}) + set(root "$ENV{VCPKG_INSTALLATION_ROOT}") + elseif("${__vcpkg_bootstrap_host}" STREQUAL "Windows") + set(root "$ENV{LOCALAPPDATA}/vcpkg/projects/${cache_dir_name}/cache") + else() + set(root "$ENV{HOME}/.cache/vcpkg/projects/${cache_dir_name}") + endif() + + set(${out_vcpkg_root} + ${root} + PARENT_SCOPE) +endfunction() + +# set vcpkg_root/toolchain_file cache variables +function(_vcpkg_set_cache_variables vcpkg_root) + set(_VCPKG_ROOT + "${vcpkg_root}" + CACHE INTERNAL "vcpkg root") + + set(_VCPKG_TOOLCHAIN_FILE + "${vcpkg_root}/scripts/buildsystems/vcpkg.cmake" + CACHE INTERNAL "vcpkg toolchain file") +endfunction() + +# bootstrap +function(_vcpkg_bootstrap) + cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "CACHE_DIR_NAME;REPO;REF" "") + + if(DEFINED arg_UNPARSED_ARGUMENTS) + message( + FATAL_ERROR "internal error: ${CMAKE_CURRENT_FUNCTION} passed extra args:" + "${arg_UNPARSED_ARGUMENTS}") + endif() + + find_package(Git QUIET REQUIRED) + + if(DEFINED CACHE{_VCPKG_ROOT}) + set(vcpkg_root $CACHE{_VCPKG_ROOT}) + else() + _vcpkg_find_root("${arg_CACHE_DIR_NAME}" vcpkg_root) + endif() + + if(NOT EXISTS ${vcpkg_root}) + message(STATUS "Setup vcpkg") + _vcpkg_clone(${vcpkg_root} ${arg_REPO} ${arg_REF}) + _vcpkg_tool_bootstrap(${vcpkg_root}) + else() + message(STATUS "Found vcpkg in: ${vcpkg_root}") + _vcpkg_upgrade(${vcpkg_root} ${arg_REPO} ${arg_REF}) + endif() + + if(DEFINED CACHE{_VCPKG_TOOLCHAIN_FILE}) + return() + endif() + + _vcpkg_set_cache_variables("${vcpkg_root}") +endfunction() diff --git a/template/cmake/vcpkg/bootstrap/vcpkg_configure.cmake b/template/cmake/vcpkg/bootstrap/vcpkg_configure.cmake new file mode 100644 index 00000000..206cf2da --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg_configure.cmake @@ -0,0 +1,11 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +# bootstrap and configure vcpkg +function(vcpkg_configure) + _vcpkg_bootstrap(${ARGN}) + _vcpkg_skip_install_on_reconfigure() +endfunction() diff --git a/template/cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake b/template/cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake new file mode 100644 index 00000000..3e31381b --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake @@ -0,0 +1,46 @@ +# SPDX-FileCopyrightText: Copyright 2024 Mikhail Svetkin +# SPDX-License-Identifier: MIT + +function(_vcpkg_update_manifest_hash) + set(_VCPKG_MANIFEST_HASH + "$CACHE{__VCPKG_MANIFEST_HASH}" + CACHE INTERNAL "Hash of vcpkg manifest file") +endfunction() + +# disable vcpkg manifest install step on cmake reconfigure if vcpkg.json has not +# changed. +function(_vcpkg_skip_install_on_reconfigure) + if(DEFINED CACHE{VCPKG_MANIFEST_DIR}) + set(vcpkg_manifest_file "$CACHE{VCPKG_MANIFEST_DIR}/vcpkg.json") + else() + set(vcpkg_manifest_file "${CMAKE_SOURCE_DIR}/vcpkg.json") + endif() + + file(SHA512 "${vcpkg_manifest_file}" vcpkg_manifest_hash) + + if(DEFINED CACHE{_VCPKG_MANIFEST_HASH} AND _VCPKG_MANIFEST_HASH STREQUAL + vcpkg_manifest_hash) + set(VCPKG_MANIFEST_INSTALL + OFF + CACHE INTERNAL "") + set_property( + DIRECTORY + APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS "${vcpkg_manifest_file}") + else() + set(VCPKG_MANIFEST_INSTALL + ON + CACHE INTERNAL "") + endif() + + # I was not able to propgate vcpkg_manifest_hash via defer call, so workaround + # it with another cache variable. + set(__VCPKG_MANIFEST_HASH + "${vcpkg_manifest_hash}" + CACHE INTERNAL "") + + # set actual hash only when vcpkg install command succeed. The only way you to + # detect to assume that configuration step succeed. + cmake_language(DEFER DIRECTORY ${CMAKE_SOURCE_DIR} CALL + _vcpkg_update_manifest_hash) +endfunction() diff --git a/cmake/vcpkg/triplets/.placeholder b/template/cmake/vcpkg/ports/.placeholder similarity index 100% rename from cmake/vcpkg/triplets/.placeholder rename to template/cmake/vcpkg/ports/.placeholder diff --git a/template/cmake/vcpkg/scripts/toolchains/mingw.cmake b/template/cmake/vcpkg/scripts/toolchains/mingw.cmake new file mode 100644 index 00000000..6147d02e --- /dev/null +++ b/template/cmake/vcpkg/scripts/toolchains/mingw.cmake @@ -0,0 +1,77 @@ +if(NOT _VCPKG_MINGW_TOOLCHAIN) + set(_VCPKG_MINGW_TOOLCHAIN 1) + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(CMAKE_CROSSCOMPILING + OFF + CACHE BOOL "") + endif() + + # Need to override MinGW from VCPKG_CMAKE_SYSTEM_NAME + set(CMAKE_SYSTEM_NAME + Windows + CACHE STRING "" FORCE) + + if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") + set(CMAKE_SYSTEM_PROCESSOR + i686 + CACHE STRING "") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(CMAKE_SYSTEM_PROCESSOR + x86_64 + CACHE STRING "") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm") + set(CMAKE_SYSTEM_PROCESSOR + armv7 + CACHE STRING "") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") + set(CMAKE_SYSTEM_PROCESSOR + aarch64 + CACHE STRING "") + endif() + + foreach(lang C CXX) + set(CMAKE_${lang}_COMPILER_TARGET + "${CMAKE_SYSTEM_PROCESSOR}-windows-gnu" + CACHE STRING "") + endforeach() + + find_program(CMAKE_C_COMPILER "${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-gcc") + find_program(CMAKE_CXX_COMPILER "${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-g++") + + find_program(CMAKE_RC_COMPILER + "${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-windres") + if(NOT CMAKE_RC_COMPILER) + find_program(CMAKE_RC_COMPILER "windres") + endif() + + get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) + if(NOT _CMAKE_IN_TRY_COMPILE) + string(APPEND CMAKE_C_FLAGS_INIT " ${VCPKG_C_FLAGS} ") + string(APPEND CMAKE_CXX_FLAGS_INIT " ${VCPKG_CXX_FLAGS} ") + string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " ${VCPKG_C_FLAGS_DEBUG} ") + string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " ${VCPKG_CXX_FLAGS_DEBUG} ") + string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " ${VCPKG_C_FLAGS_RELEASE} ") + string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " ${VCPKG_CXX_FLAGS_RELEASE} ") + + string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ") + string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ") + if(VCPKG_CRT_LINKAGE STREQUAL "static") + string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT "-static ") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT "-static ") + string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT "-static ") + endif() + string(APPEND CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT + " ${VCPKG_LINKER_FLAGS_DEBUG} ") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT + " ${VCPKG_LINKER_FLAGS_DEBUG} ") + string(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT + " ${VCPKG_LINKER_FLAGS_DEBUG} ") + string(APPEND CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT + " ${VCPKG_LINKER_FLAGS_RELEASE} ") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT + " ${VCPKG_LINKER_FLAGS_RELEASE} ") + string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT + " ${VCPKG_LINKER_FLAGS_RELEASE} ") + endif() +endif() diff --git a/template/cmake/vcpkg/triplets/x64-mingw-dynamic.cmake b/template/cmake/vcpkg/triplets/x64-mingw-dynamic.cmake new file mode 100644 index 00000000..51642b38 --- /dev/null +++ b/template/cmake/vcpkg/triplets/x64-mingw-dynamic.cmake @@ -0,0 +1,11 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) +set(VCPKG_ENV_PASSTHROUGH PATH) + +set(VCPKG_CMAKE_SYSTEM_NAME MinGW) +set(VCPKG_POLICY_DLLS_WITHOUT_LIBS enabled) + +# Use the custom mingw toolchain +set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE + "${CMAKE_CURRENT_LIST_DIR}/../scripts/toolchains/mingw.cmake") diff --git a/template/cmake/vcpkg/vcpkg.toolchain.cmake.jinja b/template/cmake/vcpkg/vcpkg.toolchain.cmake.jinja new file mode 100644 index 00000000..bc5b9b5e --- /dev/null +++ b/template/cmake/vcpkg/vcpkg.toolchain.cmake.jinja @@ -0,0 +1,42 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +include_guard(GLOBAL) + +cmake_minimum_required(VERSION 3.25) + +get_property(IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) + +if(IN_TRY_COMPILE) + return() +endif() + +unset(IN_TRY_COMPILE) + +# Vcpkg build environment + +file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json) +string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline) + +# Respect VCPKG_ROOT environment variable if set +if(DEFINED ENV{VCPKG_ROOT}) + set(VCPKG_ROOT "$ENV{VCPKG_ROOT}") + set(_VCPKG_ROOT + "$ENV{VCPKG_ROOT}" + CACHE PATH "Vcpkg root directory") +endif() + +include(${CMAKE_CURRENT_LIST_DIR}/bootstrap/vcpkg-config.cmake) + +vcpkg_configure(CACHE_DIR_NAME {{ repo_name}} REPO + https://github.com/microsoft/vcpkg.git REF ${_builtin_baseline}) + +set(VCPKG_VERBOSE + ON + CACHE BOOL "Vcpkg VCPKG_VERBOSE") + +message(STATUS "vcpkg_toolchain_file:$CACHE{_VCPKG_TOOLCHAIN_FILE}") +include("$CACHE{_VCPKG_TOOLCHAIN_FILE}") diff --git a/template/src/CMakeLists.txt.jinja b/template/src/CMakeLists.txt.jinja index 18574d49..cf3b69a5 100644 --- a/template/src/CMakeLists.txt.jinja +++ b/template/src/CMakeLists.txt.jinja @@ -10,7 +10,3 @@ add_subdirectory(executable) # A header-only library add_subdirectory(header_only) [%- endif %] -[%- if add_jni_target == true %] -# A jni target -add_subdirectory(jni) -[%- endif %] diff --git a/template/src/[% if add_compile_target == true %]compile[% endif %]/CMakeLists.txt b/template/src/[% if add_compile_target == true %]compile[% endif %]/CMakeLists.txt index b4e54574..38c492ab 100644 --- a/template/src/[% if add_compile_target == true %]compile[% endif %]/CMakeLists.txt +++ b/template/src/[% if add_compile_target == true %]compile[% endif %]/CMakeLists.txt @@ -1,7 +1,7 @@ set(target_name compile) # requirement for compile -find_package(proxy CONFIG REQUIRED) +find_package(spdlog CONFIG REQUIRED) file(GLOB_RECURSE _srcs "src/*.cpp") file(GLOB_RECURSE _hdrs "include/*.hpp") @@ -25,10 +25,7 @@ target_compile_options( ${target_name}-shared PRIVATE "$<$:/source-charset:utf-8>") -target_link_libraries( - ${target_name}-shared - PRIVATE msft_proxy - PRIVATE absl::log) +target_link_libraries(${target_name}-shared PRIVATE spdlog::spdlog) set_target_properties( ${target_name}-shared @@ -36,7 +33,6 @@ set_target_properties( CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1 SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR} - OUTPUT_NAME "${target_name}" MACOSX_RPATH ON) # static library @@ -45,8 +41,9 @@ target_code_coverage(${target_name}-static ALL) target_sources(${target_name}-static PRIVATE ${_srcs} ${_hdrs}) -target_compile_definitions(${target_name}-static - INTERFACE ${target_name}_STATIC_DEFINE) +set(static_define ${target_name}_STATIC_DEFINE) +string(TOUPPER ${static_define} static_define) +target_compile_definitions(${target_name}-static PUBLIC ${static_define}) target_include_interface_directories( ${target_name}-static ${CMAKE_CURRENT_BINARY_DIR}/include @@ -56,11 +53,7 @@ target_compile_options( ${target_name}-static PRIVATE "$<$:/source-charset:utf-8>") -# Static dependencies, such as absl, do no need to export when installing -target_link_libraries( - ${target_name}-static - PRIVATE msft_proxy - PRIVATE absl::log) +target_link_libraries(${target_name}-static PRIVATE spdlog::spdlog) # msvc layout in solution source_group("impl" REGULAR_EXPRESSION "impl/.*\\.[h|cpp]") @@ -88,8 +81,7 @@ install_target( LICENSE_FILE_LIST ${CMAKE_SOURCE_DIR}/LICENSE DEPENDENCIES - msft_proxy - absl::log) + spdlog::spdlog) install_dependency(TARGETS ${target_name}-shared ${target_name}-static) diff --git a/template/src/[% if add_compile_target == true %]compile[% endif %]/include/impl/impl.hpp b/template/src/[% if add_compile_target == true %]compile[% endif %]/include/impl/impl.hpp deleted file mode 100644 index ab4729b3..00000000 --- a/template/src/[% if add_compile_target == true %]compile[% endif %]/include/impl/impl.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include -#include "compile_export.hpp" -#include "proxy/proxy.h" - -#define STRINGIFY(x) #x -#define MACRO_STRINGIFY(x) STRINGIFY(x) - -namespace compile { -namespace geo { - -// proxy-runtime-polymorphism,see -// https://github.com/microsoft/proxy -// https://devblogs.microsoft.com/cppblog/proxy-runtime-polymorphism-made-easier-than-ever/ - -// Abstraction Draw interface for polymorphic call -struct COMPILE_EXPORT Draw : pro::dispatch { -public: - template - void operator()(const T& self, std::ostream& out) { - self.Draw(out); - } -}; - -// Abstraction Area interface for polymorphic call -struct COMPILE_EXPORT Area : pro::dispatch { -public: - template - double operator()(const T& self) { - return self.Area(); - } -}; - -// Interface facade for Draw, Area -struct COMPILE_EXPORT DrawableFacade : pro::facade {}; - -// Client API - Consumer -std::string COMPILE_EXPORT PrintDrawableToString(const pro::proxy& p); - -// Client API - Producer -pro::proxy COMPILE_EXPORT CreateRectangleAsDrawable(int width, int height); - -}; // namespace geo -}; // namespace compile diff --git a/template/src/[% if add_compile_target == true %]compile[% endif %]/src/compile.cpp b/template/src/[% if add_compile_target == true %]compile[% endif %]/src/compile.cpp index 1e83f8e5..785fb781 100644 --- a/template/src/[% if add_compile_target == true %]compile[% endif %]/src/compile.cpp +++ b/template/src/[% if add_compile_target == true %]compile[% endif %]/src/compile.cpp @@ -1,8 +1,6 @@ #include "compile.hpp" -#include #include "git.h" -#include "impl/impl.hpp" namespace compile { namespace info { diff --git a/template/src/[% if add_compile_target == true %]compile[% endif %]/src/impl/impl.cpp b/template/src/[% if add_compile_target == true %]compile[% endif %]/src/impl/impl.cpp deleted file mode 100644 index ae746dcd..00000000 --- a/template/src/[% if add_compile_target == true %]compile[% endif %]/src/impl/impl.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "impl/impl.hpp" - -#include - -namespace compile { -// Implementation (No base class) -class Rectangle { -public: - void Draw(std::ostream& out) const { out << "{Rectangle: width = " << width_ << ", height = " << height_ << "}"; } - void SetWidth(double width) { width_ = width; } - void SetHeight(double height) { height_ = height; } - double Area() const { return width_ * height_; } - -private: - double width_; - double height_; -}; - -namespace geo { - -pro::proxy CreateRectangleAsDrawable(int width, int height) { - Rectangle rect; - rect.SetWidth(width); - rect.SetHeight(height); - return pro::make_proxy(rect); // No heap allocation is expected -} - -std::string PrintDrawableToString(const pro::proxy& p) { - std::stringstream result; - result << "shape = "; - p.invoke(result); // Polymorphic call - result << ", area = " << p.invoke(); // Polymorphic call - return std::move(result).str(); -} -}; // namespace geo -}; // namespace compile diff --git a/template/src/[% if add_compile_target == true %]compile[% endif %]/tests/CMakeLists.txt b/template/src/[% if add_compile_target == true %]compile[% endif %]/tests/CMakeLists.txt index a3dae781..6bbfa956 100644 --- a/template/src/[% if add_compile_target == true %]compile[% endif %]/tests/CMakeLists.txt +++ b/template/src/[% if add_compile_target == true %]compile[% endif %]/tests/CMakeLists.txt @@ -8,6 +8,4 @@ foreach(_file ${files}) target_code_coverage(${file_basename} ALL) gtest_discover_tests(${file_basename}) copy_sanitizer_runtime(${file_basename}) - - # add_test(NAME ${file_basename}_test COMMAND $) endforeach() diff --git a/template/src/[% if add_compile_target == true %]compile[% endif %]/tests/test_compile_impl.cpp b/template/src/[% if add_compile_target == true %]compile[% endif %]/tests/test_compile_impl.cpp deleted file mode 100644 index 2480ffce..00000000 --- a/template/src/[% if add_compile_target == true %]compile[% endif %]/tests/test_compile_impl.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "impl/impl.hpp" - -TEST(geo, create_rect) { - const auto drawable = compile::geo::CreateRectangleAsDrawable(100, 100); - GTEST_ASSERT_EQ("shape = {Rectangle: width = 100, height = 100}, area = 10000", - compile::geo::PrintDrawableToString(drawable)); -} diff --git a/template/src/[% if add_executable_target == true %]executable[% endif %]/CMakeLists.txt b/template/src/[% if add_executable_target == true %]executable[% endif %]/CMakeLists.txt index 5cf02a04..a9ec9f25 100644 --- a/template/src/[% if add_executable_target == true %]executable[% endif %]/CMakeLists.txt +++ b/template/src/[% if add_executable_target == true %]executable[% endif %]/CMakeLists.txt @@ -2,13 +2,15 @@ # and tests internally set(target_name_private executable_private) +find_package(spdlog CONFIG REQUIRED) + add_library(${target_name_private} INTERFACE) target_include_interface_directories( ${target_name_private} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/git/include) -target_link_libraries(${target_name_private} INTERFACE absl::log) +target_link_libraries(${target_name_private} INTERFACE spdlog::spdlog) # The main target only contains main logits. Here it is recommended to put the # parts that need to be verified and tested in the target target_name_private @@ -20,7 +22,7 @@ add_executable(${target_name} ${_srcs}) target_code_coverage(${target_name} ALL) copy_sanitizer_runtime(${target_name}) -target_link_libraries(${target_name} PRIVATE absl::log_initialize absl::log +target_link_libraries(${target_name} PRIVATE spdlog::spdlog ${target_name_private}) install(TARGETS ${target_name} diff --git a/template/src/[% if add_executable_target == true %]executable[% endif %]/include/helpers.hpp b/template/src/[% if add_executable_target == true %]executable[% endif %]/include/helpers.hpp index c6d451d0..ec5f5e5b 100644 --- a/template/src/[% if add_executable_target == true %]executable[% endif %]/include/helpers.hpp +++ b/template/src/[% if add_executable_target == true %]executable[% endif %]/include/helpers.hpp @@ -1,12 +1,11 @@ #pragma once -#include "absl/log/log.h" +#include namespace executable { namespace helpers { inline int some_fun() { - LOG(INFO) << "Hello " - << "helpers!"; + spdlog::info("Hello helpers!"); return 0; } } // namespace helpers diff --git a/template/src/[% if add_executable_target == true %]executable[% endif %]/src/main.cpp b/template/src/[% if add_executable_target == true %]executable[% endif %]/src/main.cpp index b0f70a5c..7e9e3295 100644 --- a/template/src/[% if add_executable_target == true %]executable[% endif %]/src/main.cpp +++ b/template/src/[% if add_executable_target == true %]executable[% endif %]/src/main.cpp @@ -1,12 +1,9 @@ -#include "absl/log/globals.h" -#include "absl/log/initialize.h" -#include "absl/log/log.h" +#include + #include "git.h" #include "helpers.hpp" int main() { - absl::InitializeLog(); - absl::SetStderrThreshold(absl::LogSeverity::kInfo); - LOG(INFO) << "Get a returned value: " << executable::helpers::some_fun() << " ; Version: " << git::ProjectVersion(); + spdlog::info("Get a returned value: {} ; Version: {}", executable::helpers::some_fun(), git::ProjectVersion()); return 0; } diff --git a/template/src/[% if add_header_only_target == true %]header_only[% endif %]/CMakeLists.txt b/template/src/[% if add_header_only_target == true %]header_only[% endif %]/CMakeLists.txt index 139c7283..5f18a266 100644 --- a/template/src/[% if add_header_only_target == true %]header_only[% endif %]/CMakeLists.txt +++ b/template/src/[% if add_header_only_target == true %]header_only[% endif %]/CMakeLists.txt @@ -1,12 +1,14 @@ set(target_name header_only) +find_package(spdlog CONFIG REQUIRED) + add_library(${target_name} INTERFACE) target_include_interface_directories( ${target_name} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/git/include) -target_link_libraries(${target_name} INTERFACE absl::log) +target_link_libraries(${target_name} INTERFACE spdlog::spdlog) install_target( NAME @@ -21,7 +23,7 @@ install_target( LICENSE_FILE_LIST ${CMAKE_SOURCE_DIR}/LICENSE DEPENDENCIES - absl::log) + spdlog::spdlog) # Test if(BUILD_TESTING) diff --git a/template/src/[% if add_header_only_target == true %]header_only[% endif %]/include/header_only/header_only.hpp b/template/src/[% if add_header_only_target == true %]header_only[% endif %]/include/header_only/header_only.hpp index 2c3c78e2..1b16dab1 100644 --- a/template/src/[% if add_header_only_target == true %]header_only[% endif %]/include/header_only/header_only.hpp +++ b/template/src/[% if add_header_only_target == true %]header_only[% endif %]/include/header_only/header_only.hpp @@ -1,21 +1,17 @@ #pragma once -#include "absl/log/log.h" +#include #include "git.h" namespace header_only { namespace common { inline int some_fun() { - LOG(INFO) << git::ProjectVersion(); - return 0; -} - -constexpr int some_constexpr_fun() { + spdlog::info("{}", git::ProjectVersion()); return 0; } const std::string_view const_string() { - LOG(INFO) << "Calling " << __FUNCTION__; + spdlog::info("Calling {}", __FUNCTION__); return "This is a header_only only const string"; } } // namespace common diff --git a/template/src/[% if add_header_only_target == true %]header_only[% endif %]/tests/CMakeLists.txt b/template/src/[% if add_header_only_target == true %]header_only[% endif %]/tests/CMakeLists.txt index b9217175..820c2cb5 100644 --- a/template/src/[% if add_header_only_target == true %]header_only[% endif %]/tests/CMakeLists.txt +++ b/template/src/[% if add_header_only_target == true %]header_only[% endif %]/tests/CMakeLists.txt @@ -7,6 +7,4 @@ foreach(_file ${files}) target_code_coverage(${file_basename} ALL) gtest_discover_tests(${file_basename}) copy_sanitizer_runtime(${file_basename}) - - # add_test(NAME ${file_basename}_test COMMAND $) endforeach() diff --git a/template/src/[% if add_jni_target == true %]jni[% endif %]/CMakeLists.txt b/template/src/[% if add_jni_target == true %]jni[% endif %]/CMakeLists.txt deleted file mode 100644 index ed40097f..00000000 --- a/template/src/[% if add_jni_target == true %]jni[% endif %]/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -set(target_name jni) - -find_package(JNI REQUIRED) -find_package(Java REQUIRED) -include(UseJava) - -add_library(${target_name} INTERFACE) - -target_include_interface_directories( - ${target_name} ${JNI_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_BINARY_DIR}/git/include) - -target_link_libraries(${target_name} INTERFACE absl::log ${JAVA_JVM_LIBRARY}) - -install_target( - NAME - ${target_name} - VERSION - ${CMAKE_PROJECT_VERSION} - TARGETS - ${target_name} - INCLUDES - ${CMAKE_CURRENT_SOURCE_DIR}/include/ - ${CMAKE_BINARY_DIR}/git/include/ - LICENSE_FILE_LIST - ${CMAKE_SOURCE_DIR}/LICENSE - DEPENDENCIES - absl::log - PRE_EXCLUDE_REGEXES - "jvm\.*") - -# Test -if(BUILD_TESTING) - add_subdirectory(tests) -endif() diff --git a/template/src/[% if add_jni_target == true %]jni[% endif %]/include/jvm_util.hpp b/template/src/[% if add_jni_target == true %]jni[% endif %]/include/jvm_util.hpp deleted file mode 100644 index e32f440c..00000000 --- a/template/src/[% if add_jni_target == true %]jni[% endif %]/include/jvm_util.hpp +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include -#include -#include -#include "absl/log/log.h" -#include "jni.h" -#include "jni_md.h" - -// Disable leak detection from sanitizer, see -// https://stackoverflow.com/questions/51060801/how-to-suppress-leaksanitizer-report-when-running-under-fsanitize-address -#ifdef __cplusplus -extern "C" { - const char *__asan_default_options() { - return "detect_leaks=0"; - } -} -#endif - -namespace jvm { -class Jvm { -public: - JNIEnv *jvm_env() { return env; } - - static Jvm &instance(const JavaVMInitArgs &vm_args = {}) { - static auto singleton = Jvm(vm_args); - return singleton; - } - - void call(std::function callback) { return callback(env); } - -private: - Jvm(const JavaVMInitArgs &vm_args = {}) { - jint res = JNI_CreateJavaVM(&vm, (void **)&env, (void *)&vm_args); - if (res < 0) { - LOG(INFO) << "Init JVM failed"; - exit(-1); - } - //=============== Display JVM version ======================================= - jint ver = env->GetVersion(); - LOG(INFO) << "Loaded JVM Version " << ((ver >> 16) & 0x0f) << "." << (ver & 0x0f); - } - - ~Jvm() { // Shutdown the VM. But it never calls this - if (vm) { - vm->DestroyJavaVM(); - } - vm = nullptr; - } - - Jvm(const Jvm &) = delete; - Jvm &operator=(const Jvm &) = delete; - JavaVM *vm{nullptr}; - JNIEnv *env{nullptr}; -}; - -} // namespace jvm diff --git a/template/src/[% if add_jni_target == true %]jni[% endif %]/tests/CMakeLists.txt b/template/src/[% if add_jni_target == true %]jni[% endif %]/tests/CMakeLists.txt deleted file mode 100644 index 03fed9f6..00000000 --- a/template/src/[% if add_jni_target == true %]jni[% endif %]/tests/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# create a jar in cmake, see -# https://stackoverflow.com/questions/14542872/what-is-the-correct-way-to-use-add-jar-with-java-bindings-produced-by-swig - -file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/class) -file(GLOB java_files "java/*.java") -add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/build.jar - COMMAND ${Java_JAVAC_EXECUTABLE} -d ${CMAKE_CURRENT_BINARY_DIR}/class - ${java_files} - COMMAND ${Java_JAR_EXECUTABLE} -cfM ${CMAKE_CURRENT_BINARY_DIR}/build.jar -C - ${CMAKE_CURRENT_BINARY_DIR}/class . - DEPENDS ${java_files} - VERBATIM) -add_jar(test_jar SOURCE ${java_files} - INCLUDE_JARS ${CMAKE_CURRENT_BINARY_DIR}/build.jar) -add_custom_command( - TARGET test_jar - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${CMAKE_CURRENT_BINARY_DIR}/test_jar.jar ${CMAKE_BINARY_DIR}/bin - VERBATIM) - -file(GLOB files "*.cpp") -foreach(_file ${files}) - get_filename_component(file_basename ${_file} NAME_WE) - add_executable(${file_basename} ${_file}) - target_link_libraries(${file_basename} PRIVATE GTest::gtest_main jni - absl::log) - target_code_coverage(${file_basename} ALL) - gtest_discover_tests(${file_basename}) - copy_sanitizer_runtime(${file_basename}) - add_dependencies(${file_basename} test_jar) -endforeach() diff --git a/template/src/[% if add_jni_target == true %]jni[% endif %]/tests/java/MyTest.java b/template/src/[% if add_jni_target == true %]jni[% endif %]/tests/java/MyTest.java deleted file mode 100644 index a2fb0ec1..00000000 --- a/template/src/[% if add_jni_target == true %]jni[% endif %]/tests/java/MyTest.java +++ /dev/null @@ -1,8 +0,0 @@ -public class MyTest { - private static int magic_counter=777; - - public static void mymain() { // <=== We will call this - System.out.println("Hello, World in java from mymain"); - System.out.println(magic_counter); - } -} diff --git a/template/src/[% if add_jni_target == true %]jni[% endif %]/tests/test_jni.cpp b/template/src/[% if add_jni_target == true %]jni[% endif %]/tests/test_jni.cpp deleted file mode 100644 index 9d6bead6..00000000 --- a/template/src/[% if add_jni_target == true %]jni[% endif %]/tests/test_jni.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include "absl/log/globals.h" -#include "absl/log/initialize.h" -#include "absl/log/log.h" -#include "jvm_util.hpp" - -TEST(jvm, JvmInitFail) { - ASSERT_EXIT(jvm::Jvm::instance(), - ::testing::ExitedWithCode(255), // will exit -1 - ".*" // match anything output - ); -} - -TEST(jvm, JvmCallJava) { - const jint jvm_version = JNI_VERSION_19; - std::vector vm_options{ - JavaVMOption{ - .optionString = (char*)"-Djava.class.path=test_jar.jar", - .extraInfo = nullptr, - }, - }; - JavaVMInitArgs vm_args; - vm_args.version = jvm_version; // minimum Java version - vm_args.options = vm_options.data(); // JVM invocation options - vm_args.nOptions = vm_options.size(); - vm_args.ignoreUnrecognized = 1; // invalid options make the JVM init fail - - jvm::Jvm::instance(vm_args).call([](JNIEnv* env) { - // Construct a String - jstring jstr = env->NewStringUTF("Hello World"); - - // Get the method that you want to call - jmethodID to_lower = - env->GetMethodID(env->FindClass("java/lang/String"), "toLowerCase", "()Ljava/lang/String;"); - - // Call the method on the object - jobject result = env->CallObjectMethod(jstr, to_lower); - - // Get a C-style string - const char* str = env->GetStringUTFChars((jstring)result, NULL); - - LOG(INFO) << str; - - // Clean up - env->ReleaseStringUTFChars(jstr, str); - }); - - jvm::Jvm::instance().call([](JNIEnv* env) { - jclass j_my_test = env->FindClass("MyTest"); - jmethodID j_mymain = env->GetStaticMethodID(j_my_test, "mymain", "()V"); - if (j_my_test && j_mymain) - env->CallStaticVoidMethod(j_my_test, j_mymain); - }); -} diff --git a/template/vcpkg.json.jinja b/template/vcpkg.json.jinja index fc34bf04..dab1fa4b 100644 --- a/template/vcpkg.json.jinja +++ b/template/vcpkg.json.jinja @@ -2,13 +2,10 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "{{ repo_name }}", "description": "{{ project_description }}", - "builtin-baseline": "710677da49b03885c65c8b5ca43072d4b1acde75", + "builtin-baseline": "0719a71389654b88d827501d88e37e58ea8cbd70", "dependencies": [ [%- if add_compile_target == true or add_executable_target == true or add_header_only_target == true %] - "abseil", -[%- endif %] -[%- if add_compile_target == true %] - "proxy", + "spdlog", [%- endif %] [%- if use_conan == true %] "cmake-conan", @@ -22,14 +19,8 @@ "overrides": [ [%- if add_compile_target == true or add_executable_target == true or add_header_only_target == true %] { - "name": "abseil", - "version": "20230802.1" - }, -[%- endif %] -[%- if add_compile_target == true %] - { - "name": "proxy", - "version": "1.1.1" + "name": "spdlog", + "version": "1.13.0" }, [%- endif %] [%- if use_conan == true %] @@ -46,7 +37,7 @@ [%- endif %] { "name": "cmake-modules", - "version": "1.3.11" + "version": "1.3.15" }, { "name": "robotology-cmake-ycm", @@ -57,7 +48,7 @@ "registries": [ { "kind": "git", - "baseline": "c7d87c82d5cdc491063aaf92665f74d30abab481", + "baseline": "7bb7d6b2b5d4ca7d532596d98fd5ff73d6bd4ae0", "repository": "https://github.com/msclock/cmake-registry", "packages": [ [%- if use_conan == true %] @@ -71,6 +62,12 @@ "vcpkg-cmake-module" ] } + ], + "overlay-ports": [ + "cmake/vcpkg/ports" + ], + "overlay-triplets": [ + "cmake/vcpkg/triplets" ] } } diff --git a/vcpkg.json b/vcpkg.json index 520060ae..8db855cf 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -2,25 +2,20 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "ss-cpp", "description": "A development-focused Cpp project template.", - "builtin-baseline": "710677da49b03885c65c8b5ca43072d4b1acde75", + "builtin-baseline": "0719a71389654b88d827501d88e37e58ea8cbd70", "dependencies": [ - "abseil", - "proxy", + "spdlog", "cmake-modules", "robotology-cmake-ycm" ], "overrides": [ { - "name": "abseil", - "version": "20230802.1" - }, - { - "name": "proxy", - "version": "1.1.1" + "name": "spdlog", + "version": "1.13.0" }, { "name": "cmake-modules", - "version": "1.3.11" + "version": "1.3.15" }, { "name": "robotology-cmake-ycm", @@ -28,16 +23,10 @@ } ], "vcpkg-configuration": { - "overlay-ports": [ - "cmake/vcpkg/ports" - ], - "overlay-triplets": [ - "cmake/vcpkg/triplets" - ], "registries": [ { "kind": "git", - "baseline": "c7d87c82d5cdc491063aaf92665f74d30abab481", + "baseline": "7bb7d6b2b5d4ca7d532596d98fd5ff73d6bd4ae0", "repository": "https://github.com/msclock/cmake-registry", "packages": [ "cmake-modules", @@ -45,6 +34,12 @@ "vcpkg-cmake-module" ] } + ], + "overlay-ports": [ + "cmake/vcpkg/ports" + ], + "overlay-triplets": [ + "cmake/vcpkg/triplets" ] } }