-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vcpkg_setup_pkgconfig_path] Add new functions to set or restore pkgc…
…onfig related environment variables (#23429) * [vcpkg_configure_meson] Fix append host path * New functions vcpkg_setup_pkgconfig_path and vcpkg_restore_pkgconfig_path * Fix bug, add cos * Apply suggestions * Apply suggestions * Apply suggestion * doc * Update docs/maintainers/vcpkg_setup_pkgconfig_path.cmake.md Co-authored-by: LilyWangLL <[email protected]> * Update scripts/cmake/vcpkg_setup_pkgconfig_path.cmake Co-authored-by: LilyWangLL <[email protected]> * Update scripts/cmake/vcpkg_configure_make.cmake * Apply suggestions * Apply suggestion * Apply suggestions Co-authored-by: Victor Romero <[email protected]> Co-authored-by: LilyWangLL <[email protected]>
- Loading branch information
1 parent
659b6b5
commit 0d7603c
Showing
7 changed files
with
78 additions
and
48 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
docs/maintainers/internal/z_vcpkg_setup_pkgconfig_path.cmake.md
This file contains 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,11 @@ | ||
# z_vcpkg_setup_pkgconfig_path | ||
|
||
Setup the generated pkgconfig file path to PKG_CONFIG_PATH environment variable or restore PKG_CONFIG_PATH environment variable. | ||
|
||
```cmake | ||
z_vcpkg_setup_pkgconfig_path(BASE_DIRS <"${CURRENT_INSTALLED_DIR}" ...>) | ||
z_vcpkg_restore_pkgconfig_path() | ||
``` | ||
|
||
`z_vcpkg_setup_pkgconfig_path` prepends `lib/pkgconfig` and `share/pkgconfig` directories for the given `BASE_DIRS` to the `PKG_CONFIG_PATH` environment variable. It creates or updates a backup of the previous value. | ||
`z_vcpkg_restore_pkgconfig_path` shall be called when leaving the scope which called `z_vcpkg_setup_pkgconfig_path` in order to restore the original value from the backup. |
This file contains 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 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 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 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 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,48 @@ | ||
#[===[ | ||
# z_vcpkg_setup_pkgconfig_path | ||
|
||
`z_vcpkg_setup_pkgconfig_path` sets up environment variables to use `pkgconfig`, such as `PKG_CONFIG` and `PKG_CONFIG_PATH`. | ||
The original values are restored with `z_vcpkg_restore_pkgconfig_path`. `BASE_DIRS` indicates the base directories to find `.pc` files; typically `${CURRENT_INSTALLED_DIR}`, or `${CURRENT_INSTALLED_DIR}/debug`. | ||
|
||
```cmake | ||
z_vcpkg_setup_pkgconfig_path(BASE_DIRS <"${CURRENT_INSTALLED_DIR}" ...>) | ||
# Build process that may transitively invoke pkgconfig | ||
z_vcpkg_restore_pkgconfig_path() | ||
``` | ||
|
||
#]===] | ||
function(z_vcpkg_setup_pkgconfig_path) | ||
cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "" "BASE_DIRS") | ||
|
||
if(NOT DEFINED arg_BASE_DIRS OR "${arg_BASE_DIRS}" STREQUAL "") | ||
message(FATAL_ERROR "BASE_DIRS is required.") | ||
endif() | ||
if(DEFINED arg_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
vcpkg_backup_env_variables(VARS PKG_CONFIG PKG_CONFIG_PATH) | ||
|
||
vcpkg_find_acquire_program(PKGCONFIG) | ||
get_filename_component(pkgconfig_path "${PKGCONFIG}" DIRECTORY) | ||
vcpkg_add_to_path("${pkgconfig_path}") | ||
|
||
set(ENV{PKG_CONFIG} "${PKGCONFIG}") # Set via native file? | ||
|
||
foreach(base_dir IN LISTS arg_BASE_DIRS) | ||
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH} "${base_dir}/share/pkgconfig/") | ||
endforeach() | ||
|
||
foreach(base_dir IN LISTS arg_BASE_DIRS) | ||
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH} "${base_dir}/lib/pkgconfig/") | ||
endforeach() | ||
endfunction() | ||
|
||
function(z_vcpkg_restore_pkgconfig_path) | ||
cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "" "") | ||
if(DEFINED arg_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
vcpkg_restore_env_variables(VARS PKG_CONFIG PKG_CONFIG_PATH) | ||
endfunction() |
This file contains 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