-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[scripts-audit] z_vcpkg_get_cmake_vars #18839
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
Closed
strega-nil
wants to merge
8
commits into
microsoft:master
from
strega-nil:scripts-audit/z_vcpkg_get_cmake_vars
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2a2a167
[scripts-audit] rename vcpkg_internal_get_cmake_vars
strega-nil 71f6e16
[scripts-audit] audit z_vcpkg_get_cmake_vars
strega-nil 372c764
remove VCPKG_BUILD_TYPE
strega-nil ab9c5c9
docs regeneration
strega-nil 82be2cb
support depending on vcpkg-cmake
strega-nil 2838deb
Neumann-A's CRs
strega-nil 1fd25cd
fix calls to vcpkg_internal_get_cmake_vars
strega-nil 0045609
add vcpkg_get_cmake_vars to vcpkg-cmake
strega-nil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 0 additions & 31 deletions
31
docs/maintainers/internal/vcpkg_internal_get_cmake_vars.md
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 `<out-var>` 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
docs/maintainers/ports/vcpkg-cmake/vcpkg_cmake_get_vars.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # vcpkg_cmake_get_vars | ||
|
|
||
| The latest version of this document lives in the [vcpkg repo](https://github.com/Microsoft/vcpkg/blob/master/docs/maintainers/ports/vcpkg-cmake/vcpkg_cmake_get_vars.md). | ||
|
|
||
| Runs a cmake configure with a dummy project to extract certain cmake variables | ||
|
|
||
| ## Usage | ||
| ```cmake | ||
| vcpkg_cmake_get_vars(<out-var>) | ||
| ``` | ||
|
|
||
| `vcpkg_cmake_get_vars(<out-var>)` sets `<out-var>` to | ||
| a path to a generated CMake file, with the detected `CMAKE_*` variables | ||
| re-exported as `VCPKG_DETECTED_CMAKE_*`. | ||
|
|
||
| ## Notes | ||
| Avoid usage in portfiles. | ||
|
|
||
| All calls to `vcpkg_cmake_get_vars` will result in the same output file; | ||
| the output file is not generated multiple times. | ||
|
|
||
| ### Basic Usage | ||
|
|
||
| ```cmake | ||
| vcpkg_cmake_get_vars(cmake_vars_file) | ||
| include("${cmake_vars_file}") | ||
| message(STATUS "detected CXX flags: ${VCPKG_DETECTED_CMAKE_CXX_FLAGS}") | ||
| ``` | ||
|
|
||
| ## Source | ||
| [ports/vcpkg-cmake/vcpkg\_cmake\_get\_vars.cmake](https://github.com/Microsoft/vcpkg/blob/master/ports/vcpkg-cmake/vcpkg_cmake_get_vars.cmake) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
|
|
||
| set(VCPKG_LANGUAGES "C;CXX" CACHE STRING "Languages to enables for this project") | ||
|
|
||
| set(OUTPUT_STRING) | ||
| # Build default checklists | ||
| list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_CROSSCOMPILING | ||
| CMAKE_SYSTEM_NAME | ||
| CMAKE_HOST_SYSTEM_NAME | ||
| CMAKE_SYSTEM_PROCESSOR | ||
| CMAKE_HOST_SYSTEM_PROCESSOR) | ||
| if(CMAKE_SYSTEM_NAME MATCHES "Darwin") | ||
| list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_OSX_DEPLOYMENT_TARGET | ||
| CMAKE_OSX_SYSROOT) | ||
| endif() | ||
| # Programs to check | ||
| set(PROGLIST AR RANLIB STRIP NM OBJDUMP DLLTOOL MT LINKER) | ||
| foreach(prog IN LISTS PROGLIST) | ||
| list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${prog}) | ||
| endforeach() | ||
| set(COMPILERS ${VCPKG_LANGUAGES} RC) | ||
| foreach(prog IN LISTS COMPILERS) | ||
| list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${prog}_COMPILER) | ||
| endforeach() | ||
| # Variables to check | ||
| foreach(_lang IN LISTS VCPKG_LANGUAGES) | ||
| list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_STANDARD_INCLUDE_DIRECTORIES) | ||
| list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_STANDARD_LIBRARIES) | ||
| list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_STANDARD) | ||
| list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_COMPILE_FEATURES) | ||
| list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_EXTENSION) | ||
| # Probably never required since implicit. | ||
| #list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES) | ||
| #list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_IMPLICIT_INCLUDE_DIRECTORIES) | ||
| #list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_IMPLICIT_LINK_DIRECTORIES) | ||
| #list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_IMPLICIT_LINK_LIBRARIES) | ||
| endforeach() | ||
| list(REMOVE_DUPLICATES VCPKG_DEFAULT_VARS_TO_CHECK) | ||
|
|
||
| # Environment variables to check. | ||
| list(APPEND VCPKG_DEFAULT_ENV_VARS_TO_CHECK PATH INCLUDE C_INCLUDE_PATH CPLUS_INCLUDE_PATH LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH) | ||
| list(REMOVE_DUPLICATES VCPKG_DEFAULT_ENV_VARS_TO_CHECK) | ||
|
|
||
| #Flags to check. Flags are a bit special since they are configuration aware. | ||
| set(FLAGS ${VCPKG_LANGUAGES} RC SHARED_LINKER STATIC_LINKER EXE_LINKER) | ||
| foreach(flag IN LISTS FLAGS) | ||
| list(APPEND VCPKG_DEFAULT_FLAGS_TO_CHECK CMAKE_${flag}_FLAGS) | ||
| endforeach() | ||
| list(REMOVE_DUPLICATES VCPKG_DEFAULT_FLAGS_TO_CHECK) | ||
|
|
||
| #Language-specific flags. | ||
| foreach(_lang IN LISTS VCPKG_LANGUAGES) | ||
| list(APPEND VCPKG_LANG_FLAGS CMAKE_${_lang}_FLAGS) | ||
| endforeach() | ||
| list(REMOVE_DUPLICATES VCPKG_LANG_FLAGS) | ||
|
|
||
| # TODO if ever necessary: Properties to check | ||
|
|
||
| set(VCPKG_VAR_PREFIX "VCPKG_DETECTED" CACHE STRING "Variable prefix to use for detected flags") | ||
| set(VCPKG_VARS_TO_CHECK "${VCPKG_DEFAULT_VARS_TO_CHECK}" CACHE STRING "Variables to check. If not given there is a list of defaults") | ||
| set(VCPKG_FLAGS_TO_CHECK "${VCPKG_DEFAULT_FLAGS_TO_CHECK}" CACHE STRING "Variables to check. If not given there is a list of defaults") | ||
| set(VCPKG_ENV_VARS_TO_CHECK "${VCPKG_DEFAULT_ENV_VARS_TO_CHECK}" CACHE STRING "Variables to check. If not given there is a list of defaults") | ||
|
|
||
| if(NOT VCPKG_OUTPUT_FILE) | ||
| message(FATAL_ERROR "VCPKG_OUTPUT_FILE is required to be defined") | ||
| endif() | ||
|
|
||
| if(NOT CMAKE_BUILD_TYPE) | ||
| message(FATAL_ERROR "CMAKE_BUILD_TYPE is required to be defined") | ||
| else() | ||
| string(TOUPPER "${CMAKE_BUILD_TYPE}" VCPKG_CONFIGS) | ||
| endif() | ||
|
|
||
|
|
||
| project(get_cmake_vars LANGUAGES ${VCPKG_LANGUAGES}) | ||
|
|
||
| foreach(VAR IN LISTS VCPKG_VARS_TO_CHECK) | ||
| string(APPEND OUTPUT_STRING "set(${VCPKG_VAR_PREFIX}_${VAR} \"${${VAR}}\")\n") | ||
| endforeach() | ||
|
|
||
| foreach(_env IN LISTS VCPKG_ENV_VARS_TO_CHECK) | ||
| if(CMAKE_HOST_WIN32) | ||
| string(REPLACE "\\" "/" ENV_${_env} "$ENV{${_env}}") | ||
| string(APPEND OUTPUT_STRING "set(${VCPKG_VAR_PREFIX}_ENV_${_env} \"${ENV_${_env}}\")\n") | ||
| else() | ||
| string(APPEND OUTPUT_STRING "set(${VCPKG_VAR_PREFIX}_ENV_${_env} \"$ENV{${_env}}\")\n") | ||
| endif() | ||
| endforeach() | ||
|
|
||
| macro(_vcpkg_adjust_flags flag_var) | ||
| if(MSVC) # Transform MSVC /flags to -flags due to bash scripts intepreting /flag as a path. | ||
| string(REGEX REPLACE "(^| )/" "\\1-" ${flag_var} "${${flag_var}}") | ||
| endif() | ||
| if(CMAKE_SYSTEM_NAME MATCHES "Darwin") | ||
| if("${flag_var}" IN_LIST VCPKG_LANG_FLAGS) | ||
| # macOS - append arch and isysroot if cross-compiling | ||
| if(NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}") | ||
|
|
||
| foreach(arch IN LISTS CMAKE_OSX_ARCHITECTURES) | ||
| string(APPEND ${flag_var} " -arch ${arch}") | ||
| endforeach() | ||
| string(APPEND ${flag_var} " -isysroot ${CMAKE_OSX_SYSROOT}") | ||
| endif() | ||
| endif() | ||
| endif() | ||
| endmacro() | ||
|
|
||
| foreach(flag IN LISTS VCPKG_FLAGS_TO_CHECK) | ||
| string(STRIP "${${flag}}" ${flag}) # Strip leading and trailing whitespaces | ||
| _vcpkg_adjust_flags(${flag}) | ||
| string(APPEND OUTPUT_STRING "set(${VCPKG_VAR_PREFIX}_RAW_${flag} \" ${${flag}}\")\n") | ||
| foreach(config IN LISTS VCPKG_CONFIGS) | ||
| string(STRIP "${${flag}_${config}}" ${flag}_${config}) | ||
| _vcpkg_adjust_flags(${flag}_${config}) | ||
| string(APPEND OUTPUT_STRING "set(${VCPKG_VAR_PREFIX}_RAW_${flag}_${config} \"${CMAKE_${flag}_FLAGS_${config}}\")\n") | ||
| set(COMBINED_${flag}_${config} "${${flag}} ${${flag}_${config}}") | ||
| string(STRIP "${COMBINED_${flag}_${config}}" COMBINED_${flag}_${config}) | ||
| string(APPEND OUTPUT_STRING "set(${VCPKG_VAR_PREFIX}_${flag}_${config} \"${COMBINED_${flag}_${config}}\")\n") | ||
| endforeach() | ||
| endforeach() | ||
|
|
||
|
|
||
| file(WRITE "${VCPKG_OUTPUT_FILE}" "${OUTPUT_STRING}") | ||
|
|
||
| # Programs: | ||
| # CMAKE_AR | ||
| # CMAKE_<LANG>_COMPILER_AR (Wrapper) | ||
| # CMAKE_RANLIB | ||
| # CMAKE_<LANG>_COMPILER_RANLIB | ||
| # CMAKE_STRIP | ||
| # CMAKE_NM | ||
| # CMAKE_OBJDUMP | ||
| # CMAKE_DLLTOOL | ||
| # CMAKE_MT | ||
| # CMAKE_LINKER | ||
| # CMAKE_C_COMPILER | ||
| # CMAKE_CXX_COMPILER | ||
| # CMAKE_RC_COMPILER | ||
|
|
||
| # Flags: | ||
| # CMAKE_<LANG>_FLAGS | ||
| # CMAKE_<LANG>_FLAGS_<CONFIG> | ||
| # CMAKE_RC_FLAGS | ||
| # CMAKE_SHARED_LINKER_FLAGS | ||
| # CMAKE_STATIC_LINKER_FLAGS | ||
| # CMAKE_STATIC_LINKER_FLAGS_<CONFIG> | ||
| # CMAKE_EXE_LINKER_FLAGS | ||
| # CMAKE_EXE_LINKER_FLAGS_<CONFIG> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| include("${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_configure.cmake") | ||
| include("${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_build.cmake") | ||
| include("${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_install.cmake") | ||
| include("${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_get_vars.cmake") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| { | ||
| "name": "vcpkg-cmake", | ||
| "version-date": "2021-06-25", | ||
| "port-version": 5 | ||
| "version-date": "2021-07-26" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.