[scripts-audit] CMake buildsystem (#20885)

* [scripts-audit] vcpkg_configure_cmake

Start auditing vcpkg_configure_cmake

* [scripts-audit] vcpkg_build_cmake

* [scripts-audit] vcpkg_install_cmake

* wow that was a dumb bug

* fix x86 configure, fix `if` guidelines

* Billy's CRs

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
This commit is contained in:
nicole mazzuca 2021-11-05 16:55:14 -07:00 committed by GitHub
parent efdf9346ab
commit 297f1b8ea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 201 additions and 218 deletions

View File

@ -20,7 +20,7 @@ The target passed to the cmake build command (`cmake --build . --target <target>
be passed.
### ADD_BIN_TO_PATH
Adds the appropriate Release and Debug `bin\` directories to the path during the build such that executables can run against the in-tree DLLs.
Adds the appropriate Release and Debug `bin` directories to the path during the build such that executables can run against the in-tree DLLs.
## Notes:
This command should be preceded by a call to [`vcpkg_configure_cmake()`](vcpkg_configure_cmake.md).

View File

@ -18,7 +18,7 @@ The target passed to the cmake build command (`cmake --build . --target <target>
be passed.
### ADD_BIN_TO_PATH
Adds the appropriate Release and Debug `bin\` directories to the path during the build such that executables can run against the in-tree DLLs.
Adds the appropriate Release and Debug `bin` directories to the path during the build such that executables can run against the in-tree DLLs.
## Notes:
This command should be preceded by a call to [`vcpkg_configure_cmake()`](vcpkg_configure_cmake.md).
@ -44,73 +44,79 @@ function(vcpkg_build_cmake)
message(FATAL_ERROR "The ${PORT} port already depends on vcpkg-cmake; using both vcpkg-cmake and vcpkg_build_cmake in the same port is unsupported.")
endif()
if(NOT arg_LOGFILE_ROOT)
if(NOT DEFINED arg_LOGFILE_ROOT)
set(arg_LOGFILE_ROOT "build")
endif()
set(PARALLEL_ARG)
set(NO_PARALLEL_ARG)
vcpkg_list(SET build_param)
vcpkg_list(SET parallel_param)
vcpkg_list(SET no_parallel_param)
if(Z_VCPKG_CMAKE_GENERATOR MATCHES "Ninja")
set(BUILD_ARGS "-v") # verbose output
set(PARALLEL_ARG "-j${VCPKG_CONCURRENCY}")
set(NO_PARALLEL_ARG "-j1")
elseif(Z_VCPKG_CMAKE_GENERATOR MATCHES "Visual Studio")
set(BUILD_ARGS
if("${Z_VCPKG_CMAKE_GENERATOR}" STREQUAL "Ninja")
vcpkg_list(SET build_param "-v") # verbose output
vcpkg_list(SET parallel_param "-j${VCPKG_CONCURRENCY}")
vcpkg_list(SET no_parallel_param "-j1")
elseif("${Z_VCPKG_CMAKE_GENERATOR}" MATCHES "^Visual Studio")
vcpkg_list(SET build_param
"/p:VCPkgLocalAppDataDisabled=true"
"/p:UseIntelMKL=No"
)
set(PARALLEL_ARG "/m")
elseif(Z_VCPKG_CMAKE_GENERATOR MATCHES "NMake")
vcpkg_list(SET parallel_param "/m")
elseif("${Z_VCPKG_CMAKE_GENERATOR}" STREQUAL "NMake Makefiles")
# No options are currently added for nmake builds
else()
message(FATAL_ERROR "Unrecognized GENERATOR setting from vcpkg_configure_cmake(). Valid generators are: Ninja, Visual Studio, and NMake Makefiles")
endif()
vcpkg_list(SET target_param)
if(arg_TARGET)
set(TARGET_PARAM "--target" ${arg_TARGET})
else()
set(TARGET_PARAM)
vcpkg_list(SET target_param "--target" "${arg_TARGET}")
endif()
foreach(BUILDTYPE "debug" "release")
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL BUILDTYPE)
if(BUILDTYPE STREQUAL "debug")
set(SHORT_BUILDTYPE "dbg")
set(CONFIG "Debug")
foreach(build_type IN ITEMS debug release)
if(NOT DEFINED VCPKG_BUILD_TYPE OR "${VCPKG_BUILD_TYPE}" STREQUAL "${build_type}")
if("${build_type}" STREQUAL "debug")
set(short_build_type "dbg")
set(config "Debug")
else()
set(SHORT_BUILDTYPE "rel")
set(CONFIG "Release")
set(short_build_type "rel")
set(config "Release")
endif()
message(STATUS "Building ${TARGET_TRIPLET}-${SHORT_BUILDTYPE}")
message(STATUS "Building ${TARGET_TRIPLET}-${short_build_type}")
if(arg_ADD_BIN_TO_PATH)
set(_BACKUP_ENV_PATH "$ENV{PATH}")
if(BUILDTYPE STREQUAL "debug")
vcpkg_backup_env_variables(VARS PATH)
if("${build_type}" STREQUAL "debug")
vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}/debug/bin")
else()
vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}/bin")
endif()
endif()
if (arg_DISABLE_PARALLEL)
if(arg_DISABLE_PARALLEL)
vcpkg_execute_build_process(
COMMAND ${CMAKE_COMMAND} --build . --config ${CONFIG} ${TARGET_PARAM} -- ${BUILD_ARGS} ${NO_PARALLEL_ARG}
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${SHORT_BUILDTYPE}
LOGNAME "${arg_LOGFILE_ROOT}-${TARGET_TRIPLET}-${SHORT_BUILDTYPE}"
COMMAND
"${CMAKE_COMMAND}" --build . --config "${config}" ${target_param}
-- ${build_param} ${no_parallel_param}
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${short_build_type}"
LOGNAME "${arg_LOGFILE_ROOT}-${TARGET_TRIPLET}-${short_build_type}"
)
else()
vcpkg_execute_build_process(
COMMAND ${CMAKE_COMMAND} --build . --config ${CONFIG} ${TARGET_PARAM} -- ${BUILD_ARGS} ${PARALLEL_ARG}
NO_PARALLEL_COMMAND ${CMAKE_COMMAND} --build . --config ${CONFIG} ${TARGET_PARAM} -- ${BUILD_ARGS} ${NO_PARALLEL_ARG}
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${SHORT_BUILDTYPE}
LOGNAME "${arg_LOGFILE_ROOT}-${TARGET_TRIPLET}-${SHORT_BUILDTYPE}"
COMMAND
"${CMAKE_COMMAND}" --build . --config "${config}" ${target_param}
-- ${build_param} ${parallel_param}
NO_PARALLEL_COMMAND
"${CMAKE_COMMAND}" --build . --config "${config}" ${target_param}
-- ${build_param} ${no_parallel_param}
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${short_build_type}"
LOGNAME "${arg_LOGFILE_ROOT}-${TARGET_TRIPLET}-${short_build_type}"
)
endif()
if(arg_ADD_BIN_TO_PATH)
set(ENV{PATH} "${_BACKUP_ENV_PATH}")
vcpkg_restore_env_variables(VARS PATH)
endif()
endif()
endforeach()

View File

@ -82,6 +82,23 @@ This command supplies many common arguments to CMake. To see the full list, exam
* [opencv](https://github.com/Microsoft/vcpkg/blob/master/ports/opencv/portfile.cmake)
#]===]
function(z_vcpkg_configure_cmake_both_or_neither_set var1 var2)
if(DEFINED "${var1}" AND NOT DEFINED "${var2}")
message(FATAL_ERROR "If ${var1} is set, ${var2} must be set.")
endif()
if(NOT DEFINED "${var1}" AND DEFINED "${var2}")
message(FATAL_ERROR "If ${var2} is set, ${var1} must be set.")
endif()
endfunction()
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} &&")
foreach(arg IN LISTS "${build_type}_command")
string(APPEND line " \"${arg}\"")
endforeach()
set("${out_var}" "${${out_var}}${line}\"\n\n" PARENT_SCOPE)
endfunction()
function(vcpkg_configure_cmake)
cmake_parse_arguments(PARSE_ARGV 0 arg
"PREFER_NINJA;DISABLE_PARALLEL_CONFIGURE;NO_CHARSET_FLAG;Z_GET_CMAKE_VARS_USAGE"
@ -93,16 +110,17 @@ function(vcpkg_configure_cmake)
message(FATAL_ERROR "The ${PORT} port already depends on vcpkg-cmake; using both vcpkg-cmake and vcpkg_configure_cmake in the same port is unsupported.")
endif()
if(NOT VCPKG_PLATFORM_TOOLSET)
message(FATAL_ERROR "Vcpkg has been updated with VS2017 support; "
"however, vcpkg.exe must be rebuilt by re-running bootstrap-vcpkg.bat\n")
if(DEFINED arg_UNPARSED_ARGUMENTS)
message(WARNING "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
endif()
if(NOT DEFINED arg_SOURCE_PATH)
message(FATAL_ERROR "SOURCE_PATH must be specified")
endif()
if(NOT DEFINED arg_LOGNAME)
set(arg_LOGNAME "config-${TARGET_TRIPLET}")
endif()
if(NOT arg_LOGNAME)
set(arg_LOGNAME config-${TARGET_TRIPLET})
endif()
set(manually_specified_variables "")
vcpkg_list(SET manually_specified_variables)
if(arg_Z_GET_CMAKE_VARS_USAGE)
set(configuring_message "Getting CMake variables for ${TARGET_TRIPLET}")
@ -110,153 +128,123 @@ function(vcpkg_configure_cmake)
set(configuring_message "Configuring ${TARGET_TRIPLET}")
foreach(option IN LISTS arg_OPTIONS arg_OPTIONS_RELEASE arg_OPTIONS_DEBUG)
if(option MATCHES "^-D([^:=]*)[:=]")
list(APPEND manually_specified_variables "${CMAKE_MATCH_1}")
if("${option}" MATCHES "^-D([^:=]*)[:=]")
vcpkg_list(APPEND manually_specified_variables "${CMAKE_MATCH_1}")
endif()
endforeach()
list(REMOVE_DUPLICATES manually_specified_variables)
list(REMOVE_ITEM manually_specified_variables ${arg_MAYBE_UNUSED_VARIABLES})
vcpkg_list(REMOVE_DUPLICATES manually_specified_variables)
foreach(maybe_unused_var IN LISTS arg_MAYBE_UNUSED_VARIABLES)
vcpkg_list(REMOVE_ITEM manually_specified_variables "${maybe_unused_var}")
endforeach()
debug_message("manually specified variables: ${manually_specified_variables}")
endif()
if(CMAKE_HOST_WIN32)
set(ninja_can_be_used ON) # Ninja as generator
set(ninja_host ON) # Ninja as parallel configurator
if(VCPKG_HOST_IS_WINDOWS)
if(DEFINED ENV{PROCESSOR_ARCHITEW6432})
set(arg_HOST_ARCHITECTURE $ENV{PROCESSOR_ARCHITEW6432})
set(host_arch "$ENV{PROCESSOR_ARCHITEW6432}")
else()
set(arg_HOST_ARCHITECTURE $ENV{PROCESSOR_ARCHITECTURE})
set(host_arch "$ENV{PROCESSOR_ARCHITECTURE}")
endif()
if("${host_arch}" STREQUAL "x86")
# Prebuilt ninja binaries are only provided for x64 hosts
set(ninja_can_be_used OFF)
set(ninja_host OFF)
elseif(VCPKG_TARGET_IS_UWP)
# Ninja and MSBuild have many differences when targeting UWP, so use MSBuild to maximize existing compatibility
set(ninja_can_be_used OFF)
endif()
endif()
set(NINJA_CAN_BE_USED ON) # Ninja as generator
set(NINJA_HOST ON) # Ninja as parallel configurator
set(generator "")
set(generator_arch "")
if(DEFINED arg_GENERATOR)
set(generator "${arg_GENERATOR}")
elseif(arg_PREFER_NINJA AND ninja_can_be_used)
set(generator "Ninja")
elseif(VCPKG_CHAINLOAD_TOOLCHAIN_FILE OR NOT VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_MINGW)
set(generator "Ninja")
if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
set(_TARGETTING_UWP 1)
endif()
if(arg_HOST_ARCHITECTURE STREQUAL "x86")
# Prebuilt ninja binaries are only provided for x64 hosts
set(NINJA_CAN_BE_USED OFF)
set(NINJA_HOST OFF)
elseif(_TARGETTING_UWP)
# Ninja and MSBuild have many differences when targetting UWP, so use MSBuild to maximize existing compatibility
set(NINJA_CAN_BE_USED OFF)
endif()
if(arg_GENERATOR)
set(GENERATOR ${arg_GENERATOR})
elseif(arg_PREFER_NINJA AND NINJA_CAN_BE_USED)
set(GENERATOR "Ninja")
elseif(VCPKG_CHAINLOAD_TOOLCHAIN_FILE OR (VCPKG_CMAKE_SYSTEM_NAME AND NOT _TARGETTING_UWP))
set(GENERATOR "Ninja")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v120")
set(GENERATOR "Visual Studio 12 2013")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v120")
set(GENERATOR "Visual Studio 12 2013 Win64")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v120")
set(GENERATOR "Visual Studio 12 2013 ARM")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v140")
set(GENERATOR "Visual Studio 14 2015")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v140")
set(GENERATOR "Visual Studio 14 2015 Win64")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v140")
set(GENERATOR "Visual Studio 14 2015 ARM")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v141")
set(GENERATOR "Visual Studio 15 2017")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v141")
set(GENERATOR "Visual Studio 15 2017 Win64")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v141")
set(GENERATOR "Visual Studio 15 2017 ARM")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v141")
set(GENERATOR "Visual Studio 15 2017")
set(ARCH "ARM64")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v142")
set(GENERATOR "Visual Studio 16 2019")
set(ARCH "Win32")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v142")
set(GENERATOR "Visual Studio 16 2019")
set(ARCH "x64")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v142")
set(GENERATOR "Visual Studio 16 2019")
set(ARCH "ARM")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v142")
set(GENERATOR "Visual Studio 16 2019")
set(ARCH "ARM64")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v143")
set(GENERATOR "Visual Studio 17 2022")
set(ARCH "Win32")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v143")
set(GENERATOR "Visual Studio 17 2022")
set(ARCH "x64")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v143")
set(GENERATOR "Visual Studio 17 2022")
set(ARCH "ARM")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64" AND VCPKG_PLATFORM_TOOLSET STREQUAL "v143")
set(GENERATOR "Visual Studio 17 2022")
set(ARCH "ARM64")
else()
if(NOT VCPKG_CMAKE_SYSTEM_NAME)
set(VCPKG_CMAKE_SYSTEM_NAME Windows)
if("${VCPKG_PLATFORM_TOOLSET}" STREQUAL "v120" AND NOT "${VCPKG_TARGET_ARCHITECTURE}" STREQUAL "arm64")
set(generator "Visual Studio 12 2013")
elseif("${VCPKG_PLATFORM_TOOLSET}" STREQUAL "v140" AND NOT "${VCPKG_TARGET_ARCHITECTURE}" STREQUAL "arm64")
set(generator "Visual Studio 14 2015")
elseif("${VCPKG_PLATFORM_TOOLSET}" STREQUAL "v141")
set(generator "Visual Studio 15 2017")
elseif("${VCPKG_PLATFORM_TOOLSET}" STREQUAL "v142")
set(generator "Visual Studio 16 2019")
elseif("${VCPKG_PLATFORM_TOOLSET}" STREQUAL "v143")
set(generator "Visual Studio 17 2022")
endif()
if("${VCPKG_TARGET_ARCHITECTURE}" STREQUAL "x86")
set(generator_arch "Win32")
elseif("${VCPKG_TARGET_ARCHITECTURE}" STREQUAL "x64")
set(generator_arch "x64")
elseif("${VCPKG_TARGET_ARCHITECTURE}" STREQUAL "arm")
set(generator_arch "ARM")
elseif("${VCPKG_TARGET_ARCHITECTURE}" STREQUAL "arm64")
set(generator_arch "ARM64")
endif()
if("${generator}" STREQUAL "" OR "${generator_arch}" STREQUAL "")
message(FATAL_ERROR
"Unable to determine appropriate generator for triplet ${TARGET_TRIPLET}:
platform toolset: ${VCPKG_PLATFORM_TOOLSET}
architecture : ${VCPKG_TARGET_ARCHITECTURE}")
endif()
message(FATAL_ERROR "Unable to determine appropriate generator for: "
"${VCPKG_CMAKE_SYSTEM_NAME}-${VCPKG_TARGET_ARCHITECTURE}-${VCPKG_PLATFORM_TOOLSET}")
endif()
# If we use Ninja, make sure it's on PATH
if(GENERATOR STREQUAL "Ninja" AND NOT DEFINED ENV{VCPKG_FORCE_SYSTEM_BINARIES})
if("${generator}" STREQUAL "Ninja" AND NOT DEFINED ENV{VCPKG_FORCE_SYSTEM_BINARIES})
vcpkg_find_acquire_program(NINJA)
get_filename_component(NINJA_PATH ${NINJA} DIRECTORY)
get_filename_component(NINJA_PATH "${NINJA}" DIRECTORY)
vcpkg_add_to_path("${NINJA_PATH}")
list(APPEND arg_OPTIONS "-DCMAKE_MAKE_PROGRAM=${NINJA}")
vcpkg_list(APPEND arg_OPTIONS "-DCMAKE_MAKE_PROGRAM=${NINJA}")
endif()
file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)
file(REMOVE_RECURSE
"${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
"${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
if(DEFINED VCPKG_CMAKE_SYSTEM_NAME)
list(APPEND arg_OPTIONS "-DCMAKE_SYSTEM_NAME=${VCPKG_CMAKE_SYSTEM_NAME}")
if(_TARGETTING_UWP AND NOT DEFINED VCPKG_CMAKE_SYSTEM_VERSION)
vcpkg_list(APPEND arg_OPTIONS "-DCMAKE_SYSTEM_NAME=${VCPKG_CMAKE_SYSTEM_NAME}")
if(VCPKG_TARGET_IS_UWP AND NOT DEFINED VCPKG_CMAKE_SYSTEM_VERSION)
set(VCPKG_CMAKE_SYSTEM_VERSION 10.0)
elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Android" AND NOT DEFINED VCPKG_CMAKE_SYSTEM_VERSION)
elseif(VCPKG_TARGET_IS_ANDROID AND NOT DEFINED VCPKG_CMAKE_SYSTEM_VERSION)
set(VCPKG_CMAKE_SYSTEM_VERSION 21)
endif()
endif()
if(DEFINED VCPKG_CMAKE_SYSTEM_VERSION)
list(APPEND arg_OPTIONS "-DCMAKE_SYSTEM_VERSION=${VCPKG_CMAKE_SYSTEM_VERSION}")
vcpkg_list(APPEND arg_OPTIONS "-DCMAKE_SYSTEM_VERSION=${VCPKG_CMAKE_SYSTEM_VERSION}")
endif()
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
list(APPEND arg_OPTIONS -DBUILD_SHARED_LIBS=ON)
elseif(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
list(APPEND arg_OPTIONS -DBUILD_SHARED_LIBS=OFF)
if("${VCPKG_LIBRARY_LINKAGE}" STREQUAL "dynamic")
vcpkg_list(APPEND arg_OPTIONS -DBUILD_SHARED_LIBS=ON)
elseif("${VCPKG_LIBRARY_LINKAGE}" STREQUAL "static")
vcpkg_list(APPEND arg_OPTIONS -DBUILD_SHARED_LIBS=OFF)
else()
message(FATAL_ERROR
"Invalid setting for VCPKG_LIBRARY_LINKAGE: \"${VCPKG_LIBRARY_LINKAGE}\". "
"It must be \"static\" or \"dynamic\"")
"Invalid setting for VCPKG_LIBRARY_LINKAGE: \"${VCPKG_LIBRARY_LINKAGE}\".
It must be \"static\" or \"dynamic\"")
endif()
macro(check_both_vars_are_set var1 var2)
if((NOT DEFINED ${var1} OR NOT DEFINED ${var2}) AND (DEFINED ${var1} OR DEFINED ${var2}))
message(FATAL_ERROR "Both ${var1} and ${var2} must be set.")
endif()
endmacro()
z_vcpkg_configure_cmake_both_or_neither_set(VCPKG_CXX_FLAGS_DEBUG VCPKG_C_FLAGS_DEBUG)
z_vcpkg_configure_cmake_both_or_neither_set(VCPKG_CXX_FLAGS_RELEASE VCPKG_C_FLAGS_RELEASE)
z_vcpkg_configure_cmake_both_or_neither_set(VCPKG_CXX_FLAGS VCPKG_C_FLAGS)
check_both_vars_are_set(VCPKG_CXX_FLAGS_DEBUG VCPKG_C_FLAGS_DEBUG)
check_both_vars_are_set(VCPKG_CXX_FLAGS_RELEASE VCPKG_C_FLAGS_RELEASE)
check_both_vars_are_set(VCPKG_CXX_FLAGS VCPKG_C_FLAGS)
set(VCPKG_SET_CHARSET_FLAG ON)
set(vcpkg_set_charset_flag ON)
if(arg_NO_CHARSET_FLAG)
set(VCPKG_SET_CHARSET_FLAG OFF)
set(vcpkg_set_charset_flag OFF)
endif()
if(NOT VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
if(NOT DEFINED VCPKG_CMAKE_SYSTEM_NAME OR _TARGETTING_UWP)
if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/windows.cmake")
elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/linux.cmake")
@ -275,11 +263,10 @@ function(vcpkg_configure_cmake)
endif()
endif()
list(JOIN VCPKG_TARGET_ARCHITECTURE "\;" target_architecure_string)
list(APPEND arg_OPTIONS
vcpkg_list(APPEND arg_OPTIONS
"-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}"
"-DVCPKG_TARGET_TRIPLET=${TARGET_TRIPLET}"
"-DVCPKG_SET_CHARSET_FLAG=${VCPKG_SET_CHARSET_FLAG}"
"-DVCPKG_SET_CHARSET_FLAG=${vcpkg_set_charset_flag}"
"-DVCPKG_PLATFORM_TOOLSET=${VCPKG_PLATFORM_TOOLSET}"
"-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON"
"-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON"
@ -299,118 +286,108 @@ function(vcpkg_configure_cmake)
"-DVCPKG_LINKER_FLAGS=${VCPKG_LINKER_FLAGS}"
"-DVCPKG_LINKER_FLAGS_RELEASE=${VCPKG_LINKER_FLAGS_RELEASE}"
"-DVCPKG_LINKER_FLAGS_DEBUG=${VCPKG_LINKER_FLAGS_DEBUG}"
"-DVCPKG_TARGET_ARCHITECTURE=${target_architecure_string}"
"-DVCPKG_TARGET_ARCHITECTURE=${VCPKG_TARGET_ARCHITECTURE}"
"-DCMAKE_INSTALL_LIBDIR:STRING=lib"
"-DCMAKE_INSTALL_BINDIR:STRING=bin"
"-D_VCPKG_ROOT_DIR=${VCPKG_ROOT_DIR}"
"-DZ_VCPKG_ROOT_DIR=${VCPKG_ROOT_DIR}"
"-D_VCPKG_INSTALLED_DIR=${_VCPKG_INSTALLED_DIR}"
"-DVCPKG_MANIFEST_INSTALL=OFF"
)
if(DEFINED ARCH)
list(APPEND arg_OPTIONS
"-A${ARCH}"
)
if(NOT "${generator_arch}" STREQUAL "")
vcpkg_list(APPEND arg_OPTIONS "-A${generator_arch}")
endif()
# Sets configuration variables for macOS builds
foreach(config_var INSTALL_NAME_DIR OSX_DEPLOYMENT_TARGET OSX_SYSROOT OSX_ARCHITECTURES)
if(DEFINED VCPKG_${config_var})
list(JOIN VCPKG_${config_var} "\;" config_var_value)
list(APPEND arg_OPTIONS "-DCMAKE_${config_var}=${config_var_value}")
foreach(config_var IN ITEMS INSTALL_NAME_DIR OSX_DEPLOYMENT_TARGET OSX_SYSROOT OSX_ARCHITECTURES)
if(DEFINED "VCPKG_${config_var}")
vcpkg_list(APPEND arg_OPTIONS "-DCMAKE_${config_var}=${VCPKG_${config_var}}")
endif()
endforeach()
set(rel_command
${CMAKE_COMMAND} ${arg_SOURCE_PATH} "${arg_OPTIONS}" "${arg_OPTIONS_RELEASE}"
-G ${GENERATOR}
vcpkg_list(SET rel_command
"${CMAKE_COMMAND}" "${arg_SOURCE_PATH}" ${arg_OPTIONS} ${arg_OPTIONS_RELEASE}
-G "${generator}"
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR})
set(dbg_command
${CMAKE_COMMAND} ${arg_SOURCE_PATH} "${arg_OPTIONS}" "${arg_OPTIONS_DEBUG}"
-G ${GENERATOR}
"-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}")
vcpkg_list(SET dbg_command
"${CMAKE_COMMAND}" "${arg_SOURCE_PATH}" ${arg_OPTIONS} ${arg_OPTIONS_DEBUG}
-G "${generator}"
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}/debug)
"-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}/debug")
if(NINJA_HOST AND CMAKE_HOST_WIN32 AND NOT arg_DISABLE_PARALLEL_CONFIGURE)
list(APPEND arg_OPTIONS "-DCMAKE_DISABLE_SOURCE_CHANGES=ON")
if(ninja_host AND CMAKE_HOST_WIN32 AND NOT arg_DISABLE_PARALLEL_CONFIGURE)
vcpkg_list(APPEND arg_OPTIONS "-DCMAKE_DISABLE_SOURCE_CHANGES=ON")
vcpkg_find_acquire_program(NINJA)
get_filename_component(NINJA_PATH ${NINJA} DIRECTORY)
get_filename_component(NINJA_PATH "${NINJA}" DIRECTORY)
vcpkg_add_to_path("${NINJA_PATH}")
#parallelize the configure step
set(_contents
"rule CreateProcess\n command = $process\n\n"
set(ninja_configure_contents
"rule CreateProcess\n command = \$process\n\n"
)
macro(_build_cmakecache whereat build_type)
set(${build_type}_line "build ${whereat}/CMakeCache.txt: CreateProcess\n process = cmd /c \"cd ${whereat} &&")
foreach(arg ${${build_type}_command})
set(${build_type}_line "${${build_type}_line} \"${arg}\"")
endforeach()
set(_contents "${_contents}${${build_type}_line}\"\n\n")
endmacro()
if(NOT DEFINED VCPKG_BUILD_TYPE)
_build_cmakecache(".." "rel")
_build_cmakecache("../../${TARGET_TRIPLET}-dbg" "dbg")
elseif(VCPKG_BUILD_TYPE STREQUAL "release")
_build_cmakecache(".." "rel")
elseif(VCPKG_BUILD_TYPE STREQUAL "debug")
_build_cmakecache("../../${TARGET_TRIPLET}-dbg" "dbg")
if(NOT DEFINED VCPKG_BUILD_TYPE OR "${VCPKG_BUILD_TYPE}" STREQUAL "release")
z_vcpkg_configure_cmake_build_cmakecache(ninja_configure_contents ".." "rel")
endif()
if(NOT DEFINED VCPKG_BUILD_TYPE OR "${VCPKG_BUILD_TYPE}" STREQUAL "debug")
z_vcpkg_configure_cmake_build_cmakecache(ninja_configure_contents "../../${TARGET_TRIPLET}-dbg" "dbg")
endif()
file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vcpkg-parallel-configure)
file(WRITE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vcpkg-parallel-configure/build.ninja "${_contents}")
file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vcpkg-parallel-configure")
file(WRITE
"${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vcpkg-parallel-configure/build.ninja"
"${ninja_configure_contents}")
message(STATUS "${configuring_message}")
vcpkg_execute_required_process(
COMMAND ninja -v
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vcpkg-parallel-configure
LOGNAME ${arg_LOGNAME}
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vcpkg-parallel-configure"
LOGNAME "${arg_LOGNAME}"
)
list(APPEND config_logs
vcpkg_list(APPEND config_logs
"${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-out.log"
"${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-err.log")
else()
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
if(NOT DEFINED VCPKG_BUILD_TYPE OR "${VCPKG_BUILD_TYPE}" STREQUAL "debug")
message(STATUS "${configuring_message}-dbg")
file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)
file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
vcpkg_execute_required_process(
COMMAND ${dbg_command}
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg
LOGNAME ${arg_LOGNAME}-dbg
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
LOGNAME "${arg_LOGNAME}-dbg"
)
list(APPEND config_logs
vcpkg_list(APPEND config_logs
"${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-dbg-out.log"
"${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-dbg-err.log")
endif()
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
if(NOT DEFINED VCPKG_BUILD_TYPE OR "${VCPKG_BUILD_TYPE}" STREQUAL "release")
message(STATUS "${configuring_message}-rel")
file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
vcpkg_execute_required_process(
COMMAND ${rel_command}
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
LOGNAME ${arg_LOGNAME}-rel
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
LOGNAME "${arg_LOGNAME}-rel"
)
list(APPEND config_logs
vcpkg_list(APPEND config_logs
"${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-rel-out.log"
"${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-rel-err.log")
endif()
endif()
# Check unused variables
set(all_unused_variables)
vcpkg_list(SET all_unused_variables)
foreach(config_log IN LISTS config_logs)
if (NOT EXISTS "${config_log}")
if(NOT EXISTS "${config_log}")
continue()
endif()
file(READ "${config_log}" log_contents)
debug_message("Reading configure log ${config_log}...")
if(NOT log_contents MATCHES "Manually-specified variables were not used by the project:\n\n(( [^\n]*\n)*)")
if(NOT "${log_contents}" MATCHES "Manually-specified variables were not used by the project:\n\n(( [^\n]*\n)*)")
continue()
endif()
string(STRIP "${CMAKE_MATCH_1}" unused_variables) # remove leading ` ` and trailing `\n`
@ -418,18 +395,18 @@ function(vcpkg_configure_cmake)
debug_message("unused variables: ${unused_variables}")
foreach(unused_variable IN LISTS unused_variables)
if(unused_variable IN_LIST manually_specified_variables)
if("${unused_variable}" IN_LIST manually_specified_variables)
debug_message("manually specified unused variable: ${unused_variable}")
list(APPEND all_unused_variables "${unused_variable}")
vcpkg_list(APPEND all_unused_variables "${unused_variable}")
else()
debug_message("unused variable (not manually specified): ${unused_variable}")
endif()
endforeach()
endforeach()
if(DEFINED all_unused_variables)
list(REMOVE_DUPLICATES all_unused_variables)
list(JOIN all_unused_variables "\n " all_unused_variables)
if(NOT "${all_unused_variables}" STREQUAL "")
vcpkg_list(REMOVE_DUPLICATES all_unused_variables)
vcpkg_list(JOIN all_unused_variables "\n " all_unused_variables)
message(WARNING "The following variables are not used in CMakeLists.txt:
${all_unused_variables}
Please recheck them and remove the unnecessary options from the `vcpkg_configure_cmake` call.
@ -437,6 +414,6 @@ If these options should still be passed for whatever reason, please use the `MAY
endif()
if(NOT arg_Z_GET_CMAKE_VARS_USAGE)
set(Z_VCPKG_CMAKE_GENERATOR "${GENERATOR}" PARENT_SCOPE)
set(Z_VCPKG_CMAKE_GENERATOR "${generator}" PARENT_SCOPE)
endif()
endfunction()

View File

@ -34,15 +34,15 @@ function(vcpkg_install_cmake)
message(FATAL_ERROR "vcpkg_cmake_install was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
endif()
set(args)
vcpkg_list(SET params)
foreach(arg IN ITEMS DISABLE_PARALLEL ADD_BIN_TO_PATH)
if(arg_${arg})
list(APPEND args "${arg}")
vcpkg_list(APPEND params "${arg}")
endif()
endforeach()
vcpkg_build_cmake(Z_VCPKG_DISABLE_DEPRECATION MESSAGE
${args}
${params}
LOGFILE_ROOT install
TARGET install
)