vcpkg/scripts/cmake/vcpkg_internal_get_cmake_vars.cmake
nicole mazzuca 0e1dc12185
[rollup] Rollup PR 2021-07-16 (#19001)
* [rollup:2021-07-16 1/7] PR #18201 (@JackBoosY)

[vcpkg-cmake] Add check for unused cmake variables

* [rollup:2021-07-16 2/7] PR #18397 (@strega-nil)

[vcpkg_list] add new function

* [rollup:2021-07-16 3/7] PR #18782 (@strega-nil)

[scripts-audit] vcpkg_build_ninja

* [rollup:2021-07-16 4/7] PR #18784 (@strega-nil)

[scripts-audit] vcpkg_minimum_required

* [rollup:2021-07-16 5/7] PR #18785 (@strega-nil)

[scripts-audit] vcpkg_replace_string

* [rollup:2021-07-16 6/7] PR #18786 (@strega-nil)

[scripts-audit] windows scripts

* [rollup:2021-07-16 7/7] PR #18945 (@strega-nil)

[many ports] remove deprecated vcpkg_check_features call [1/5]

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
Co-authored-by: PhoebeHui <20694052+PhoebeHui@users.noreply.github.com>
2021-07-20 10:24:58 -07:00

69 lines
2.6 KiB
CMake

#[===[.md:
# vcpkg_internal_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
vcpkg_internal_get_cmake_vars(
[OUTPUT_FILE <output_file_with_vars>]
[OPTIONS <-DUSE_THIS_IN_ALL_BUILDS=1>...]
)
```
## Parameters
### OPTIONS
Additional options to pass to the test configure call
### OUTPUT_FILE
Variable to return the path to the generated cmake file with the detected `CMAKE_` variables set as `VCKPG_DETECTED_`
## Notes
If possible avoid usage in portfiles.
## Examples
* [vcpkg_configure_make](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_configure_make.cmake)
#]===]
function(vcpkg_internal_get_cmake_vars)
cmake_parse_arguments(PARSE_ARGV 0 _gcv "" "OUTPUT_FILE" "OPTIONS")
if(_gcv_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} was passed unparsed arguments: '${_gcv_UNPARSED_ARGUMENTS}'")
endif()
if(NOT _gcv_OUTPUT_FILE)
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} requires parameter OUTPUT_FILE!")
endif()
if(${_gcv_OUTPUT_FILE})
debug_message("OUTPUT_FILE ${${_gcv_OUTPUT_FILE}}")
else()
set(DEFAULT_OUT "${CURRENT_BUILDTREES_DIR}/cmake-vars-${TARGET_TRIPLET}.cmake.log") # So that the file gets included in CI artifacts.
set(${_gcv_OUTPUT_FILE} "${DEFAULT_OUT}" PARENT_SCOPE)
set(${_gcv_OUTPUT_FILE} "${DEFAULT_OUT}")
endif()
vcpkg_configure_cmake(
SOURCE_PATH "${SCRIPTS}/get_cmake_vars"
OPTIONS ${_gcv_OPTIONS} "-DVCPKG_BUILD_TYPE=${VCPKG_BUILD_TYPE}"
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}
Z_VCPKG_IGNORE_UNUSED_VARIABLES
)
set(_include_string)
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
string(APPEND _include_string "include(\"${CURRENT_BUILDTREES_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(\"${CURRENT_BUILDTREES_DIR}/cmake-vars-${TARGET_TRIPLET}-dbg.cmake.log\")\n")
endif()
file(WRITE "${${_gcv_OUTPUT_FILE}}" "${_include_string}")
endfunction()