[vcpkg-cmake] Update parallel vcpkg_cmake_configure (#21507)

* Revise generator selection

If the host is x86, assume that msbuild is requested for windows.
If msbuild is requested and suitable, use it.
Else if a particular generator is requested, use it.
Else if ninja is available, use it.
Else on non-windows host, use "Unix Makefiles".

* Revise ninja_host detection

* Revise parallel configure detection

* Consolidate ninja path setup

* Update documentation

* Use portable chdir

* [ms-gltf] Use new generator selection

* Update versions
This commit is contained in:
Kai Pastor 2022-07-25 21:23:04 +02:00 committed by GitHub
parent 1aa8ac7a05
commit 49868fd552
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 40 deletions

View file

@ -55,16 +55,17 @@ Disables passing `/utf-8` when using the [built-in Windows toolchain][VCPKG_CHAI
This is needed for libraries that set their own source code's character set when targeting MSVC. See the [MSVC documentation for `/utf-8`](https://docs.microsoft.com/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8) for more information. This is needed for libraries that set their own source code's character set when targeting MSVC. See the [MSVC documentation for `/utf-8`](https://docs.microsoft.com/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8) for more information.
### WINDOWS_USE_MSBUILD ### WINDOWS_USE_MSBUILD
Use MSBuild instead of [Ninja][ninja] when targeting a Windows platform. Use MSBuild instead of another generator when targeting a Windows platform.
By default vcpkg prefers to use Ninja as the CMake Generator for all platforms. However, there are edge cases where MSBuild has different behavior than Ninja. This flag should only be passed if the project requires MSBuild to build correctly. By default vcpkg prefers to use Ninja as the CMake Generator for all platforms. However, there are edge cases where MSBuild has different behavior than Ninja. This flag should only be passed if the project requires MSBuild to build correctly.
This flag has no effect for MinGW targets.
### GENERATOR ### GENERATOR
Specifies the Generator to use. Specifies the Generator to use.
This is useful if the project-specific buildsystem has been wrapped in a CMake script that won't perform an actual build. If used for this purpose, it should be set to `"Ninja"`. By default vcpkg prefers to use Ninja as the CMake Generator for all platforms,
or "Unix Makefiles" for non-Windows platforms when Ninja is not available.
This should not be passed alongside [`WINDOWS_USE_MSBUILD`](#windows_use_msbuild). This parameter can be used for edge cases where project-specific buildsystems depend on a particular generator.
### LOGFILE_BASE ### LOGFILE_BASE
An alternate root name for the configure logs. An alternate root name for the configure logs.

View file

@ -23,14 +23,9 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
# note: Platform-native buildsystem will be more helpful to launch/debug the tests/samples. # note: Platform-native buildsystem will be more helpful to launch/debug the tests/samples.
# note: The PDB file path is making Ninja fails to install. # note: The PDB file path is making Ninja fails to install.
# For Windows, we rely on /MP. The other platforms should be able to build with PREFER_NINJA. # For Windows, we rely on /MP. The other platforms should be able to build with PREFER_NINJA.
set(WINDOWS_USE_MSBUILD)
if(VCPKG_TARGET_IS_WINDOWS)
set(WINDOWS_USE_MSBUILD "WINDOWS_USE_MSBUILD")
endif()
vcpkg_cmake_configure( vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}" SOURCE_PATH "${SOURCE_PATH}"
${WINDOWS_USE_MSBUILD} WINDOWS_USE_MSBUILD
OPTIONS OPTIONS
${FEATURE_OPTIONS} ${FEATURE_OPTIONS}
) )

View file

@ -1,6 +1,7 @@
{ {
"name": "ms-gltf", "name": "ms-gltf",
"version-date": "2022-06-28", "version-date": "2022-06-28",
"port-version": 1,
"description": "glTF-SDK is a C++ Software Development Kit for glTF", "description": "glTF-SDK is a C++ Software Development Kit for glTF",
"homepage": "https://github.com/microsoft/glTF-SDK", "homepage": "https://github.com/microsoft/glTF-SDK",
"license": "MIT", "license": "MIT",

View file

@ -1,6 +1,6 @@
{ {
"name": "vcpkg-cmake", "name": "vcpkg-cmake",
"version-date": "2022-07-02", "version-date": "2022-07-18",
"documentation": "https://vcpkg.io/en/docs/maintainers/ports/vcpkg-cmake.html", "documentation": "https://vcpkg.io/en/docs/maintainers/ports/vcpkg-cmake.html",
"license": "MIT" "license": "MIT"
} }

View file

@ -60,22 +60,28 @@ function(vcpkg_cmake_configure)
endif() endif()
endif() endif()
set(ninja_can_be_used ON) # Ninja as generator set(ninja_host ON) # Ninja availability
set(ninja_host ON) # Ninja as parallel configurator if(host_architecture STREQUAL "x86" OR DEFINED ENV{VCPKG_FORCE_SYSTEM_BINARIES})
if(host_architecture STREQUAL "x86")
# Prebuilt ninja binaries are only provided for x64 hosts # Prebuilt ninja binaries are only provided for x64 hosts
set(ninja_can_be_used OFF) find_program(NINJA NAMES ninja ninja-build)
set(ninja_host OFF) if(NOT NINJA)
set(ninja_host OFF)
set(arg_DISABLE_PARALLEL_CONFIGURE ON)
set(arg_WINDOWS_USE_MSBUILD ON)
endif()
endif() endif()
set(generator "Ninja") set(generator "")
if(DEFINED arg_GENERATOR) set(architecture_options "")
set(generator "${arg_GENERATOR}") if(arg_WINDOWS_USE_MSBUILD AND VCPKG_HOST_IS_WINDOWS AND VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
elseif(arg_WINDOWS_USE_MSBUILD OR NOT ninja_can_be_used)
set(generator "")
set(arch "")
z_vcpkg_get_visual_studio_generator(OUT_GENERATOR generator OUT_ARCH arch) z_vcpkg_get_visual_studio_generator(OUT_GENERATOR generator OUT_ARCH arch)
vcpkg_list(APPEND architecture_options "-A${arch}")
elseif(DEFINED arg_GENERATOR)
set(generator "${arg_GENERATOR}")
elseif(ninja_host)
set(generator "Ninja")
elseif(NOT VCPKG_HOST_IS_WINDOWS)
set(generator "Unix Makefiles")
endif() endif()
if(NOT generator) if(NOT generator)
@ -86,12 +92,13 @@ function(vcpkg_cmake_configure)
"${VCPKG_CMAKE_SYSTEM_NAME}-${VCPKG_TARGET_ARCHITECTURE}-${VCPKG_PLATFORM_TOOLSET}") "${VCPKG_CMAKE_SYSTEM_NAME}-${VCPKG_TARGET_ARCHITECTURE}-${VCPKG_PLATFORM_TOOLSET}")
endif() endif()
# If we use Ninja, make sure it's on PATH if(generator STREQUAL "Ninja")
if(generator STREQUAL "Ninja" AND NOT DEFINED ENV{VCPKG_FORCE_SYSTEM_BINARIES})
vcpkg_find_acquire_program(NINJA) vcpkg_find_acquire_program(NINJA)
vcpkg_list(APPEND arg_OPTIONS "-DCMAKE_MAKE_PROGRAM=${NINJA}")
# If we use Ninja, it must be on PATH for CMake's ExternalProject,
# cf. https://gitlab.kitware.com/cmake/cmake/-/issues/23355.
get_filename_component(ninja_path "${NINJA}" DIRECTORY) get_filename_component(ninja_path "${NINJA}" DIRECTORY)
vcpkg_add_to_path("${ninja_path}") vcpkg_add_to_path("${ninja_path}")
vcpkg_list(APPEND arg_OPTIONS "-DCMAKE_MAKE_PROGRAM=${NINJA}")
endif() endif()
set(build_dir_release "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel") set(build_dir_release "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
@ -172,10 +179,6 @@ function(vcpkg_cmake_configure)
"-DVCPKG_MANIFEST_INSTALL=OFF" "-DVCPKG_MANIFEST_INSTALL=OFF"
) )
if(DEFINED arch AND NOT arch STREQUAL "")
vcpkg_list(APPEND arg_OPTIONS "-A${arch}")
endif()
# Sets configuration variables for macOS builds # Sets configuration variables for macOS builds
foreach(config_var IN ITEMS INSTALL_NAME_DIR OSX_DEPLOYMENT_TARGET OSX_SYSROOT OSX_ARCHITECTURES) foreach(config_var IN ITEMS INSTALL_NAME_DIR OSX_DEPLOYMENT_TARGET OSX_SYSROOT OSX_ARCHITECTURES)
if(DEFINED VCPKG_${config_var}) if(DEFINED VCPKG_${config_var})
@ -197,25 +200,22 @@ function(vcpkg_cmake_configure)
vcpkg_list(SET rel_command vcpkg_list(SET rel_command
"${CMAKE_COMMAND}" "${arg_SOURCE_PATH}" "${CMAKE_COMMAND}" "${arg_SOURCE_PATH}"
-G "${generator}" -G "${generator}"
${architecture_options}
"-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}" "-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}"
${arg_OPTIONS} ${arg_OPTIONS_RELEASE}) ${arg_OPTIONS} ${arg_OPTIONS_RELEASE})
vcpkg_list(SET dbg_command vcpkg_list(SET dbg_command
"${CMAKE_COMMAND}" "${arg_SOURCE_PATH}" "${CMAKE_COMMAND}" "${arg_SOURCE_PATH}"
-G "${generator}" -G "${generator}"
${architecture_options}
"-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_BUILD_TYPE=Debug"
"-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}/debug" "-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}/debug"
${arg_OPTIONS} ${arg_OPTIONS_DEBUG}) ${arg_OPTIONS} ${arg_OPTIONS_DEBUG})
if(ninja_host AND CMAKE_HOST_WIN32 AND NOT arg_DISABLE_PARALLEL_CONFIGURE) if(NOT arg_DISABLE_PARALLEL_CONFIGURE)
vcpkg_list(APPEND arg_OPTIONS "-DCMAKE_DISABLE_SOURCE_CHANGES=ON") vcpkg_list(APPEND arg_OPTIONS "-DCMAKE_DISABLE_SOURCE_CHANGES=ON")
vcpkg_find_acquire_program(NINJA) vcpkg_find_acquire_program(NINJA)
if(NOT DEFINED ninja_path)
# if ninja_path was defined above, we've already done this
get_filename_component(ninja_path "${NINJA}" DIRECTORY)
vcpkg_add_to_path("${ninja_path}")
endif()
#parallelize the configure step #parallelize the configure step
set(ninja_configure_contents set(ninja_configure_contents

View file

@ -7,11 +7,12 @@ function(z_vcpkg_configure_cmake_both_or_neither_set var1 var2)
endif() endif()
endfunction() endfunction()
function(z_vcpkg_configure_cmake_build_cmakecache out_var whereat build_type) function(z_vcpkg_configure_cmake_build_cmakecache out_var whereat build_type)
set(line "build ${whereat}/CMakeCache.txt: CreateProcess\n process = cmd /c \"cd ${whereat} &&") set(line "build ${whereat}/CMakeCache.txt: CreateProcess\n")
string(APPEND line " process = \"${CMAKE_COMMAND}\" -E chdir \"${whereat}\"")
foreach(arg IN LISTS "${build_type}_command") foreach(arg IN LISTS "${build_type}_command")
string(APPEND line " \"${arg}\"") string(APPEND line " \"${arg}\"")
endforeach() endforeach()
set("${out_var}" "${${out_var}}${line}\"\n\n" PARENT_SCOPE) set("${out_var}" "${${out_var}}${line}\n\n" PARENT_SCOPE)
endfunction() endfunction()
function(z_vcpkg_get_visual_studio_generator) function(z_vcpkg_get_visual_studio_generator)

View file

@ -4742,7 +4742,7 @@
}, },
"ms-gltf": { "ms-gltf": {
"baseline": "2022-06-28", "baseline": "2022-06-28",
"port-version": 0 "port-version": 1
}, },
"ms-gsl": { "ms-gsl": {
"baseline": "4.0.0", "baseline": "4.0.0",
@ -7421,7 +7421,7 @@
"port-version": 0 "port-version": 0
}, },
"vcpkg-cmake": { "vcpkg-cmake": {
"baseline": "2022-07-02", "baseline": "2022-07-18",
"port-version": 0 "port-version": 0
}, },
"vcpkg-cmake-config": { "vcpkg-cmake-config": {

View file

@ -1,5 +1,10 @@
{ {
"versions": [ "versions": [
{
"git-tree": "b189e4d23ebe85437573b386d94b06b3f9fb6238",
"version-date": "2022-06-28",
"port-version": 1
},
{ {
"git-tree": "a9a91635168ea77faa39adb73b27483797fa8967", "git-tree": "a9a91635168ea77faa39adb73b27483797fa8967",
"version-date": "2022-06-28", "version-date": "2022-06-28",

View file

@ -1,5 +1,10 @@
{ {
"versions": [ "versions": [
{
"git-tree": "a7b618b7782f3c841d7fd2d84a6ba3619815362a",
"version-date": "2022-07-18",
"port-version": 0
},
{ {
"git-tree": "94abbd71a7fe495e883b13c077312f6d419cbc41", "git-tree": "94abbd71a7fe495e883b13c077312f6d419cbc41",
"version-date": "2022-07-02", "version-date": "2022-07-02",