Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scripts-audit] z_vcpkg_get_cmake_vars #18837

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions docs/maintainers/internal/vcpkg_internal_get_cmake_vars.md

This file was deleted.

36 changes: 36 additions & 0 deletions docs/maintainers/internal/z_vcpkg_get_cmake_vars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# z_vcpkg_get_cmake_vars

The latest version of this document lives in the [vcpkg repo](https://github.com/Microsoft/vcpkg/blob/master/docs/).

**Only for internal use in vcpkg helpers. Behavior and arguments will change without notice.**
Runs a cmake configure with a dummy project to extract certain cmake variables

## Usage
```cmake
z_vcpkg_get_cmake_vars(<out-var>)
```

`z_vcpkg_get_cmake_vars(cmake_vars_file)` sets `CMAKE_VARS_FILE` to
a path to a generated CMake file, with the detected `CMAKE_*` variables
re-exported as `VCPKG_DETECTED_*`.

## Notes
Avoid usage in portfiles.

All calls to `z_vcpkg_get_cmake_vars` will result in the same output file;
the output file is not generated multiple times.

## Examples

* [vcpkg_configure_make](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_configure_make.cmake)

### Basic Usage

```cmake
z_vcpkg_get_cmake_vars(cmake_vars_file)
include("${cmake_vars_file}")
message(STATUS "detected CXX flags: ${VCPKG_DETECTED_CXX_FLAGS}")
```

## Source
[scripts/cmake/z\_vcpkg\_get\_cmake\_vars.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/z_vcpkg_get_cmake_vars.cmake)
2 changes: 1 addition & 1 deletion docs/maintainers/portfile-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@

## Internal Functions

- [vcpkg\_internal\_get\_cmake\_vars](internal/vcpkg_internal_get_cmake_vars.md)
- [z\_vcpkg\_apply\_patches](internal/z_vcpkg_apply_patches.md)
- [z\_vcpkg\_function\_arguments](internal/z_vcpkg_function_arguments.md)
- [z\_vcpkg\_get\_cmake\_vars](internal/z_vcpkg_get_cmake_vars.md)
- [z\_vcpkg\_prettify\_command\_line](internal/z_vcpkg_prettify_command_line.md)

## Scripts from Ports
Expand Down
2 changes: 1 addition & 1 deletion docs/regenerate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function ParseCmakeDocComment

Get-ChildItem "$VcpkgRoot/scripts/cmake" -Filter '*.cmake' | ForEach-Object {
$docs = ParseCmakeDocComment $_
[Bool]$isInternalFunction = $_.Name.StartsWith("vcpkg_internal") -or $_.Name.StartsWith("z_vcpkg")
[Bool]$isInternalFunction = $_.Name.StartsWith("z_vcpkg")

if ($docs.IsDeprecated -and $null -eq $docs.ActualDocumentation)
{
Expand Down
7 changes: 2 additions & 5 deletions scripts/cmake/vcpkg_build_make.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ You can use the alias [`vcpkg_install_make()`](vcpkg_install_make.md) function i
#]===]

function(vcpkg_build_make)
if(NOT _VCPKG_CMAKE_VARS_FILE)
# vcpkg_build_make called without using vcpkg_configure_make before
vcpkg_internal_get_cmake_vars(OUTPUT_FILE _VCPKG_CMAKE_VARS_FILE)
endif()
include("${_VCPKG_CMAKE_VARS_FILE}")
z_vcpkg_get_cmake_vars(cmake_vars_file)
include("${cmake_vars_file}")

# parse parameters such that semicolons in options arguments to COMMAND don't get erased
cmake_parse_arguments(PARSE_ARGV 0 _bc "ADD_BIN_TO_PATH;ENABLE_INSTALL;DISABLE_PARALLEL" "LOGFILE_ROOT;BUILD_TARGET;SUBPATH;MAKEFILE;INSTALL_TARGET" "")
Expand Down
7 changes: 3 additions & 4 deletions scripts/cmake/vcpkg_configure_make.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ function(vcpkg_configure_make)
"SOURCE_PATH;PROJECT_SUBPATH;PRERUN_SHELL;BUILD_TRIPLET"
"OPTIONS;OPTIONS_DEBUG;OPTIONS_RELEASE;CONFIGURE_ENVIRONMENT_VARIABLES;CONFIG_DEPENDENT_ENVIRONMENT;ADDITIONAL_MSYS_PACKAGES"
)
vcpkg_internal_get_cmake_vars(OUTPUT_FILE _VCPKG_CMAKE_VARS_FILE)
set(_VCPKG_CMAKE_VARS_FILE "${_VCPKG_CMAKE_VARS_FILE}" PARENT_SCOPE)
debug_message("Including cmake vars from: ${_VCPKG_CMAKE_VARS_FILE}")
include("${_VCPKG_CMAKE_VARS_FILE}")
z_vcpkg_get_cmake_vars(cmake_vars_file)
debug_message("Including cmake vars from: ${cmake_vars_file}")
include("${cmake_vars_file}")
if(DEFINED VCPKG_MAKE_BUILD_TRIPLET)
set(_csc_BUILD_TRIPLET ${VCPKG_MAKE_BUILD_TRIPLET}) # Triplet overwrite for crosscompiling
endif()
Expand Down
67 changes: 0 additions & 67 deletions scripts/cmake/vcpkg_internal_get_cmake_vars.cmake

This file was deleted.

64 changes: 64 additions & 0 deletions scripts/cmake/z_vcpkg_get_cmake_vars.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#[===[.md:
# z_vcpkg_get_cmake_vars

**Only for internal use in vcpkg helpers. Behavior and arguments will change without notice.**
Runs a cmake configure with a dummy project to extract certain cmake variables

## Usage
```cmake
z_vcpkg_get_cmake_vars(<out-var>)
```

`z_vcpkg_get_cmake_vars(cmake_vars_file)` sets `CMAKE_VARS_FILE` to
a path to a generated CMake file, with the detected `CMAKE_*` variables
re-exported as `VCPKG_DETECTED_*`.

## Notes
Avoid usage in portfiles.

All calls to `z_vcpkg_get_cmake_vars` will result in the same output file;
the output file is not generated multiple times.

## Examples

* [vcpkg_configure_make](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_configure_make.cmake)

### Basic Usage

```cmake
z_vcpkg_get_cmake_vars(cmake_vars_file)
include("${cmake_vars_file}")
message(STATUS "detected CXX flags: ${VCPKG_DETECTED_CXX_FLAGS}")
```
#]===]

function(z_vcpkg_get_cmake_vars out_file)
cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "")

if(DEFINED arg_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
endif()

if(NOT DEFINED CACHE{Z_VCPKG_GET_CMAKE_VARS_FILE})
set(Z_VCPKG_GET_CMAKE_VARS_FILE "${CURRENT_BUILDTREES_DIR}/cmake-vars-${TARGET_TRIPLET}.cmake.log"
CACHE PATH "The file to include to access the CMake variables from a generated project.")
vcpkg_configure_cmake(
SOURCE_PATH "${SCRIPTS}/get_cmake_vars"
OPTIONS_DEBUG "-DVCPKG_OUTPUT_FILE:PATH=${CURRENT_BUILDTREES_DIR}/cmake-vars-${TARGET_TRIPLET}-dbg.cmake.log"
OPTIONS_RELEASE "-DVCPKG_OUTPUT_FILE:PATH=${CURRENT_BUILDTREES_DIR}/cmake-vars-${TARGET_TRIPLET}-rel.cmake.log"
PREFER_NINJA
LOGNAME get-cmake-vars-${TARGET_TRIPLET}
)

set(include_string "")
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
string(APPEND include_string "include(\"\${CMAKE_CURRENT_LIST_DIR}/cmake-vars-${TARGET_TRIPLET}-rel.cmake.log\")\n")
endif()
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
string(APPEND include_string "include(\"\${CMAKE_CURRENT_LIST_DIR}/cmake-vars-${TARGET_TRIPLET}-dbg.cmake.log\")\n")
endif()
file(WRITE "${Z_VCPKG_GET_CMAKE_VARS_FILE}" "${include_string}")
endif()

set("${out_file}" "${Z_VCPKG_GET_CMAKE_VARS_FILE}" PARENT_SCOPE)
endfunction()
2 changes: 1 addition & 1 deletion scripts/ports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ if(CMD MATCHES "^BUILD$")
include("${SCRIPTS}/cmake/vcpkg_install_msbuild.cmake")
include("${SCRIPTS}/cmake/vcpkg_install_nmake.cmake")
include("${SCRIPTS}/cmake/vcpkg_install_qmake.cmake")
include("${SCRIPTS}/cmake/vcpkg_internal_get_cmake_vars.cmake")
include("${SCRIPTS}/cmake/vcpkg_replace_string.cmake")
include("${SCRIPTS}/cmake/vcpkg_test_cmake.cmake")

include("${SCRIPTS}/cmake/z_vcpkg_apply_patches.cmake")
include("${SCRIPTS}/cmake/z_vcpkg_get_cmake_vars.cmake")
include("${SCRIPTS}/cmake/z_vcpkg_prettify_command_line.cmake")

include("${CURRENT_PORT_DIR}/portfile.cmake")
Expand Down