diff --git a/.copier-answers.yml b/.copier-answers.yml index 03844f4..81b3170 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,4 +1,4 @@ -_commit: v1.6.10 +_commit: v1.6.11 _src_path: gh:serious-scaffold/ss-cpp author_email: msclock@qq.com author_name: msclock diff --git a/Makefile b/Makefile index 340f985..fa7f9ce 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ pre-commit: _PRESET_ARGS = --preset $(PRESET) cmake-configure: - cmake -S . $(_PRESET_ARGS) $(CONFIGURE) $(if $(FRESH_CMAKE_CACHE),--fresh) + cmake -S . $(_PRESET_ARGS) $(CONFIGURE) cmake-build-template-%: cmake --build $(_PRESET_ARGS) --target $* @@ -72,13 +72,13 @@ test-build-test-install: test-build-test cmake-install cmake-uninstall test-build-test-install-ccov: test-build-test-install cmake-build-template-ccov-all test-coverage: - $(MAKE) test-build-test-install-ccov CONFIGURE="-DBUILD_TESTING=ON -DCODE_COVERAGE=ON $(CONFIGURE)" FRESH_CMAKE_CACHE=1 + $(MAKE) test-build-test-install-ccov CONFIGURE="-DBUILD_TESTING=ON -DCODE_COVERAGE=ON $(CONFIGURE) --fresh" test-valgrind: - $(MAKE) test-build-memcheck CONFIGURE="-DBUILD_TESTING=ON -DUSE_VALGRIND=ON $(CONFIGURE)" FRESH_CMAKE_CACHE=1 + $(MAKE) test-build-memcheck CONFIGURE="-DBUILD_TESTING=ON -DUSE_VALGRIND=ON $(CONFIGURE) --fresh" test-sanitizer-template-%: - $(MAKE) test-build-test CONFIGURE="-DBUILD_TESTING=ON -DUSE_SANITIZER=$* $(CONFIGURE)" FRESH_CMAKE_CACHE=1 + $(MAKE) test-build-test CONFIGURE="-DBUILD_TESTING=ON -DUSE_SANITIZER=$* $(CONFIGURE) --fresh" test-sanitizer-address: test-sanitizer-template-address @@ -91,10 +91,10 @@ test-sanitizer-undefined: test-sanitizer-template-undefined test-sanitizer: test-sanitizer-template-address test-sanitizer-template-leak test-sanitizer-template-memory test-sanitizer-template-undefined test-cppcheck: - $(MAKE) test-build CONFIGURE="-DBUILD_TESTING=ON -DUSE_CPPCHECK=ON $(CONFIGURE)" FRESH_CMAKE_CACHE=1 + $(MAKE) test-build CONFIGURE="-DBUILD_TESTING=ON -DUSE_CPPCHECK=ON $(CONFIGURE) --fresh" test-clang-tidy: - $(MAKE) test-build CONFIGURE="-DBUILD_TESTING=ON -DUSE_CLANGTIDY=ON $(CONFIGURE)" FRESH_CMAKE_CACHE=1 + $(MAKE) test-build CONFIGURE="-DBUILD_TESTING=ON -DUSE_CLANGTIDY=ON $(CONFIGURE) --fresh" ######################################################################################## # Documentation diff --git a/cmake/presets/base.json b/cmake/presets/base.json index e929d27..f1b7667 100644 --- a/cmake/presets/base.json +++ b/cmake/presets/base.json @@ -20,6 +20,21 @@ "CMAKE_BUILD_TYPE": "Debug", "CMAKE_VERBOSE_MAKEFILE": "FALSE" } + }, + { + "name": "base-config", + "hidden": true, + "inherits": [ + "ninja-config", + "vcpkg" + ], + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "CMAKE_COMPILE_WARNING_AS_ERROR": false, + "CMAKE_VERBOSE_MAKEFILE": "FALSE" + } } ], "buildPresets": [ @@ -28,6 +43,18 @@ "hidden": true, "inherits": "ninja", "configurePreset": "base" + }, + { + "name": "base-config-relwithdebinfo", + "hidden": true, + "inherits": "ninja-config-relwithdebinfo", + "configurePreset": "base-config" + }, + { + "name": "base-config-debug", + "hidden": true, + "inherits": "ninja-config-debug", + "configurePreset": "base-config" } ], "testPresets": [ @@ -43,6 +70,32 @@ "noTestsAction": "error", "stopOnFailure": true } + }, + { + "name": "base-config-relwithdebinfo", + "hidden": true, + "inherits": "ninja-config-relwithdebinfo", + "configurePreset": "base-config", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + }, + { + "name": "base-config-debug", + "hidden": true, + "inherits": "ninja-config-debug", + "configurePreset": "base-config", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } } ] } diff --git a/cmake/presets/default.json b/cmake/presets/default.json index 6905bcb..7423711 100644 --- a/cmake/presets/default.json +++ b/cmake/presets/default.json @@ -9,6 +9,12 @@ "inherits": [ "base" ] + }, + { + "name": "default-config", + "inherits": [ + "base-config" + ] } ], "buildPresets": [ @@ -16,6 +22,16 @@ "name": "default", "inherits": "base", "configurePreset": "default" + }, + { + "name": "default-config-relwithdebinfo", + "inherits": "base-config-relwithdebinfo", + "configurePreset": "default-config" + }, + { + "name": "default-config-debug", + "inherits": "base-config-debug", + "configurePreset": "default-config" } ], "testPresets": [ @@ -23,25 +39,16 @@ "name": "default", "inherits": "base", "configurePreset": "default" - } - ], - "workflowPresets": [ + }, { - "name": "default", - "steps": [ - { - "type": "configure", - "name": "default" - }, - { - "type": "build", - "name": "default" - }, - { - "type": "test", - "name": "default" - } - ] + "name": "default-config-relwithdebinfo", + "inherits": "base-config-relwithdebinfo", + "configurePreset": "default-config" + }, + { + "name": "default-config-debug", + "inherits": "base-config-debug", + "configurePreset": "default-config" } ] } diff --git a/cmake/presets/generators/ninja.json b/cmake/presets/generators/ninja.json index 3f639a9..424407d 100644 --- a/cmake/presets/generators/ninja.json +++ b/cmake/presets/generators/ninja.json @@ -7,7 +7,7 @@ "generator": "Ninja" }, { - "name": "ninja-multi-config", + "name": "ninja-config", "hidden": true, "generator": "Ninja Multi-Config" } @@ -19,10 +19,16 @@ "configurePreset": "ninja" }, { - "name": "ninja-multi-config", + "name": "ninja-config-relwithdebinfo", "hidden": true, - "configurePreset": "ninja-multi-config", + "configurePreset": "ninja-config", "configuration": "RelWithDebInfo" + }, + { + "name": "ninja-config-debug", + "hidden": true, + "configurePreset": "ninja-config", + "configuration": "Debug" } ], "testPresets": [ @@ -32,10 +38,16 @@ "configurePreset": "ninja" }, { - "name": "ninja-multi-config", + "name": "ninja-config-relwithdebinfo", "hidden": true, - "configurePreset": "ninja-multi-config", + "configurePreset": "ninja-config", "configuration": "RelWithDebInfo" + }, + { + "name": "ninja-config-debug", + "hidden": true, + "configurePreset": "ninja-config", + "configuration": "Debug" } ] } diff --git a/cmake/presets/x64-linux-gcc.json b/cmake/presets/x64-linux-gcc.json index fdbc879..5971ffc 100644 --- a/cmake/presets/x64-linux-gcc.json +++ b/cmake/presets/x64-linux-gcc.json @@ -30,24 +30,5 @@ "inherits": "base", "configurePreset": "x64-linux-gcc" } - ], - "workflowPresets": [ - { - "name": "x64-linux-gcc", - "steps": [ - { - "type": "configure", - "name": "x64-linux-gcc" - }, - { - "type": "build", - "name": "x64-linux-gcc" - }, - { - "type": "test", - "name": "x64-linux-gcc" - } - ] - } ] } diff --git a/cmake/presets/x64-linux-llvm.json b/cmake/presets/x64-linux-llvm.json index cc9b605..9fbc624 100644 --- a/cmake/presets/x64-linux-llvm.json +++ b/cmake/presets/x64-linux-llvm.json @@ -30,24 +30,5 @@ "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-windows-mingw.json b/cmake/presets/x64-mingw-dynamic-windows-mingw.json index bae53dc..1300509 100644 --- a/cmake/presets/x64-mingw-dynamic-windows-mingw.json +++ b/cmake/presets/x64-mingw-dynamic-windows-mingw.json @@ -31,24 +31,5 @@ "inherits": "base", "configurePreset": "x64-mingw-dynamic-windows-mingw" } - ], - "workflowPresets": [ - { - "name": "x64-mingw-dynamic-windows-mingw", - "steps": [ - { - "type": "configure", - "name": "x64-mingw-dynamic-windows-mingw" - }, - { - "type": "build", - "name": "x64-mingw-dynamic-windows-mingw" - }, - { - "type": "test", - "name": "x64-mingw-dynamic-windows-mingw" - } - ] - } ] } diff --git a/cmake/presets/x64-mingw-static-windows-mingw.json b/cmake/presets/x64-mingw-static-windows-mingw.json index 31a6f44..a21a0c2 100644 --- a/cmake/presets/x64-mingw-static-windows-mingw.json +++ b/cmake/presets/x64-mingw-static-windows-mingw.json @@ -30,24 +30,5 @@ "inherits": "base", "configurePreset": "x64-mingw-static-windows-mingw" } - ], - "workflowPresets": [ - { - "name": "x64-mingw-static-windows-mingw", - "steps": [ - { - "type": "configure", - "name": "x64-mingw-static-windows-mingw" - }, - { - "type": "build", - "name": "x64-mingw-static-windows-mingw" - }, - { - "type": "test", - "name": "x64-mingw-static-windows-mingw" - } - ] - } ] } diff --git a/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake b/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake index f93973d..c697a0c 100644 --- a/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake +++ b/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake @@ -23,7 +23,10 @@ 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...") + message( + WARNING + "vcpkg is shallow now and unshallow to retrieve the Git tree object hash for a specific version port......" + ) execute_process( COMMAND ${GIT_EXECUTABLE} fetch --unshallow WORKING_DIRECTORY ${vcpkg_root} @@ -78,7 +81,24 @@ function(_vcpkg_tool_bootstrap vcpkg_root) RESULT_VARIABLE result) if(NOT result EQUAL "0") - message(FATAL_ERROR "${bootstrap_cmd} failed with ${result}") + if(CMAKE_HOST_UNIX) + message(STATUS "Retry to build vcpkg from source...") + set(bootstrap_impl "${vcpkg_root}/scripts/bootstrap.sh") + file(READ "${bootstrap_impl}" file_contents) + string(REPLACE [[elif [ "$ARCH" = "x86_64" ]; then]] + [[elif [ "$ARCH" = "" ]; then]] file_contents + "${file_contents}") + file(WRITE "${bootstrap_impl}" "${file_contents}") + + execute_process( + COMMAND ${bootstrap_cmd} -disableMetrics + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + endif() + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${bootstrap_cmd} failed with ${result}") + endif() endif() endfunction() @@ -109,7 +129,7 @@ function(_vcpkg_upgrade vcpkg_root vcpkg_repo vcpkg_ref) message(STATUS "Upgrade vcpkg") message(STATUS "vcpkg current commit: ${current_git_hash}") - message(STATUS "vcpkg release: ${vcpkg_ref}") + message(STATUS "vcpkg target commit: ${vcpkg_ref}") execute_process( COMMAND ${GIT_EXECUTABLE} remote set-url origin ${vcpkg_repo} @@ -136,9 +156,7 @@ endfunction() # find root function(_vcpkg_find_root cache_dir_name out_vcpkg_root) - if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "") - set(root "$ENV{VCPKG_ROOT}") - elseif("${__vcpkg_bootstrap_host}" STREQUAL "Windows") + if("${__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}") diff --git a/cmake/vcpkg/bootstrap/vcpkg_configure.cmake b/cmake/vcpkg/bootstrap/vcpkg_configure.cmake index 2f63cc3..527c070 100644 --- a/cmake/vcpkg/bootstrap/vcpkg_configure.cmake +++ b/cmake/vcpkg/bootstrap/vcpkg_configure.cmake @@ -36,8 +36,26 @@ function(_vcpkg_export_mode) message(STATUS "Disable manifest mode for using vcpkg exported artifacts") endfunction() +macro(detect_vcpkg) + # Respect environment variable VCPKG_ROOT and VCPKG_INSTALLATION_ROOT if set + if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "") + set(_VCPKG_ROOT + "$ENV{VCPKG_ROOT}" + CACHE PATH "Vcpkg root directory" FORCE) + elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT} + AND NOT "$ENV{VCPKG_INSTALLATION_ROOT}" STREQUAL "") + set(_VCPKG_ROOT + "$ENV{VCPKG_INSTALLATION_ROOT}" + CACHE PATH "Vcpkg root directory" FORCE) + else() + unset(_VCPKG_ROOT CACHE) + endif() +endmacro() + # bootstrap and configure vcpkg macro(vcpkg_configure) + detect_vcpkg() + if(NOT VCPKG_EXPORT_MODE) _vcpkg_bootstrap(${ARGN}) _vcpkg_skip_install_on_reconfigure() diff --git a/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake b/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake index d379e46..af2054e 100644 --- a/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake +++ b/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake @@ -176,7 +176,7 @@ endfunction() macro(_vcpkg_load_triplet) if(NOT DEFINED VCPKG_TARGET_TRIPLET) message( - WARNING + STATUS "VCPKG_TARGET_TRIPLET is not defined, detecting triplet from the system" ) diff --git a/cmake/vcpkg/vcpkg.toolchain.cmake b/cmake/vcpkg/vcpkg.toolchain.cmake index 8fe94d0..1a15984 100644 --- a/cmake/vcpkg/vcpkg.toolchain.cmake +++ b/cmake/vcpkg/vcpkg.toolchain.cmake @@ -19,29 +19,13 @@ unset(IN_TRY_COMPILE) # Load the common settings include(${CMAKE_CURRENT_LIST_DIR}/scripts/build_type.cmake) -# Vcpkg build environment -file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json) -string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline) - -# Respect environment variable VCPKG_ROOT and VCPKG_INSTALLATION_ROOT if set -if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "") - set(_VCPKG_ROOT - "$ENV{VCPKG_ROOT}" - CACHE PATH "Vcpkg root directory" FORCE) -elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT} - AND NOT "$ENV{VCPKG_INSTALLATION_ROOT}" STREQUAL "") - set(_VCPKG_ROOT - "$ENV{VCPKG_INSTALLATION_ROOT}" - CACHE PATH "Vcpkg root directory" FORCE) -else() - unset(_VCPKG_ROOT CACHE) -endif() - include(${CMAKE_CURRENT_LIST_DIR}/bootstrap/vcpkg-config.cmake) set(VCPKG_VERBOSE ON CACHE BOOL "Vcpkg VCPKG_VERBOSE") +file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json) +string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline) vcpkg_configure(CACHE_DIR_NAME cppfront-practice REPO https://github.com/microsoft/vcpkg.git REF ${_builtin_baseline})