mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-01-14 13:28:01 +08:00
[vcpkg_setup_pkgconfig_path] Add new functions to set or restore pkgconfig 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 <94091114+LilyWangLL@users.noreply.github.com> * Update scripts/cmake/vcpkg_setup_pkgconfig_path.cmake Co-authored-by: LilyWangLL <94091114+LilyWangLL@users.noreply.github.com> * Update scripts/cmake/vcpkg_configure_make.cmake * Apply suggestions * Apply suggestion * Apply suggestions Co-authored-by: Victor Romero <viromer@microsoft.com> Co-authored-by: LilyWangLL <94091114+LilyWangLL@users.noreply.github.com>
This commit is contained in:
parent
659b6b5eea
commit
0d7603c4ef
@ -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.
|
@ -64,6 +64,7 @@
|
||||
- [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)
|
||||
- [z\_vcpkg\_setup\_pkgconfig\_path](internal/z_vcpkg_setup_pkgconfig_path.md)
|
||||
|
||||
## Scripts from Ports
|
||||
|
||||
|
@ -611,10 +611,6 @@ function(vcpkg_configure_make)
|
||||
endif()
|
||||
endif()
|
||||
debug_message("ENV{LIBS}:$ENV{LIBS}")
|
||||
vcpkg_find_acquire_program(PKGCONFIG)
|
||||
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static" AND NOT PKGCONFIG STREQUAL "--static")
|
||||
set(PKGCONFIG "${PKGCONFIG} --static") # Is this still required or was the PR changing the pc files accordingly merged?
|
||||
endif()
|
||||
|
||||
# Run autoconf if necessary
|
||||
if (arg_AUTOCONFIG OR requires_autoconfig)
|
||||
@ -767,13 +763,10 @@ function(vcpkg_configure_make)
|
||||
endif()
|
||||
|
||||
# Setup PKG_CONFIG_PATH
|
||||
set(pkgconfig_installed_dir "${CURRENT_INSTALLED_DIR}${path_suffix_${current_buildtype}}/lib/pkgconfig")
|
||||
set(pkgconfig_installed_share_dir "${CURRENT_INSTALLED_DIR}/share/pkgconfig")
|
||||
if(ENV{PKG_CONFIG_PATH})
|
||||
set(backup_env_pkg_config_path_${current_buildtype} $ENV{PKG_CONFIG_PATH})
|
||||
set(ENV{PKG_CONFIG_PATH} "${pkgconfig_installed_dir}${VCPKG_HOST_PATH_SEPARATOR}${pkgconfig_installed_share_dir}${VCPKG_HOST_PATH_SEPARATOR}$ENV{PKG_CONFIG_PATH}")
|
||||
if ("${current_buildtype}" STREQUAL "DEBUG")
|
||||
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}/debug")
|
||||
else()
|
||||
set(ENV{PKG_CONFIG_PATH} "${pkgconfig_installed_dir}${VCPKG_HOST_PATH_SEPARATOR}${pkgconfig_installed_share_dir}")
|
||||
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}")
|
||||
endif()
|
||||
|
||||
# Setup environment
|
||||
@ -794,7 +787,6 @@ function(vcpkg_configure_make)
|
||||
set(link_config_backup "$ENV{_LINK_}")
|
||||
set(ENV{_LINK_} "${LINK_ENV_${current_buildtype}}")
|
||||
endif()
|
||||
set(ENV{PKG_CONFIG} "${PKGCONFIG}")
|
||||
|
||||
vcpkg_list(APPEND lib_env_vars LIB LIBPATH LIBRARY_PATH) # LD_LIBRARY_PATH)
|
||||
foreach(lib_env_var IN LISTS lib_env_vars)
|
||||
@ -834,13 +826,7 @@ function(vcpkg_configure_make)
|
||||
file(RENAME "${target_dir}/config.log" "${CURRENT_BUILDTREES_DIR}/config.log-${TARGET_TRIPLET}-${short_name_${current_buildtype}}.log")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(backup_env_pkg_config_path_${current_buildtype})
|
||||
set(ENV{PKG_CONFIG_PATH} "${backup_env_pkg_config_path_${current_buildtype}}")
|
||||
else()
|
||||
unset(ENV{PKG_CONFIG_PATH})
|
||||
endif()
|
||||
unset(backup_env_pkg_config_path_${current_buildtype})
|
||||
z_vcpkg_restore_pkgconfig_path()
|
||||
|
||||
if(link_config_backup)
|
||||
set(ENV{_LINK_} "${link_config_backup}")
|
||||
|
@ -438,13 +438,6 @@ function(vcpkg_configure_meson)
|
||||
vcpkg_list(APPEND arg_OPTIONS_RELEASE "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}','${CURRENT_INSTALLED_DIR}/debug']")
|
||||
endif()
|
||||
|
||||
if(NOT arg_NO_PKG_CONFIG)
|
||||
vcpkg_find_acquire_program(PKGCONFIG)
|
||||
get_filename_component(PKGCONFIG_PATH ${PKGCONFIG} DIRECTORY)
|
||||
vcpkg_add_to_path("${PKGCONFIG_PATH}")
|
||||
set(pkgconfig_share_dir "${CURRENT_INSTALLED_DIR}/share/pkgconfig/")
|
||||
endif()
|
||||
|
||||
set(buildtypes)
|
||||
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
|
||||
set(buildname "DEBUG")
|
||||
@ -466,11 +459,12 @@ function(vcpkg_configure_meson)
|
||||
message(STATUS "Configuring ${TARGET_TRIPLET}-${suffix_${buildtype}}")
|
||||
file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${suffix_${buildtype}}")
|
||||
#setting up PKGCONFIG
|
||||
vcpkg_backup_env_variables(VARS PKG_CONFIG PKG_CONFIG_PATH)
|
||||
if(NOT arg_NO_PKG_CONFIG)
|
||||
set(ENV{PKG_CONFIG} "${PKGCONFIG}") # Set via native file?
|
||||
set(pkgconfig_installed_dir "${CURRENT_INSTALLED_DIR}/${path_suffix_${buildtype}}lib/pkgconfig/")
|
||||
vcpkg_host_path_list(APPEND ENV{PKG_CONFIG_PATH} "${pkgconfig_installed_dir}" "${pkgconfig_share_dir}" "$ENV{PKG_CONFIG_PATH}")
|
||||
if ("${buildtype}" STREQUAL "DEBUG")
|
||||
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}/debug")
|
||||
else()
|
||||
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
vcpkg_execute_required_process(
|
||||
@ -494,7 +488,9 @@ function(vcpkg_configure_meson)
|
||||
endif()
|
||||
message(STATUS "Configuring ${TARGET_TRIPLET}-${suffix_${buildtype}} done")
|
||||
|
||||
vcpkg_restore_env_variables(VARS PKG_CONFIG PKG_CONFIG_PATH)
|
||||
if(NOT arg_NO_PKG_CONFIG)
|
||||
z_vcpkg_restore_pkgconfig_path()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
vcpkg_restore_env_variables(VARS INCLUDE)
|
||||
|
@ -55,19 +55,8 @@ function(vcpkg_configure_qmake)
|
||||
set(ENV{QMAKE_MACOSX_DEPLOYMENT_TARGET} ${VCPKG_OSX_DEPLOYMENT_TARGET})
|
||||
endif()
|
||||
|
||||
vcpkg_backup_env_variables(VARS PKG_CONFIG_PATH)
|
||||
|
||||
vcpkg_find_acquire_program(PKGCONFIG)
|
||||
set(ENV{PKG_CONFIG} "${PKGCONFIG}")
|
||||
get_filename_component(PKGCONFIG_PATH "${PKGCONFIG}" DIRECTORY)
|
||||
vcpkg_add_to_path("${PKGCONFIG_PATH}")
|
||||
|
||||
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
|
||||
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH}
|
||||
"${CURRENT_INSTALLED_DIR}/lib/pkgconfig"
|
||||
"${CURRENT_INSTALLED_DIR}/share/pkgconfig"
|
||||
"${CURRENT_PACKAGES_DIR}/lib/pkgconfig"
|
||||
"${CURRENT_PACKAGES_DIR}/share/pkgconfig")
|
||||
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}" "${CURRENT_PACKAGES_DIR}")
|
||||
|
||||
set(current_binary_dir "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
|
||||
|
||||
@ -98,15 +87,11 @@ function(vcpkg_configure_qmake)
|
||||
file(RENAME "${current_binary_dir}/config.log" "${CURRENT_BUILDTREES_DIR}/internal-config-${TARGET_TRIPLET}-rel.log")
|
||||
endif()
|
||||
|
||||
vcpkg_restore_env_variables(VARS PKG_CONFIG_PATH)
|
||||
z_vcpkg_restore_pkgconfig_path()
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
|
||||
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH}
|
||||
"${CURRENT_INSTALLED_DIR}/debug/lib/pkgconfig"
|
||||
"${CURRENT_INSTALLED_DIR}/share/pkgconfig"
|
||||
"${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig"
|
||||
"${CURRENT_PACKAGES_DIR}/share/pkgconfig")
|
||||
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}/debug" "${CURRENT_PACKAGES_DIR}/debug")
|
||||
|
||||
set(current_binary_dir "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
|
||||
|
||||
@ -135,6 +120,8 @@ function(vcpkg_configure_qmake)
|
||||
file(REMOVE "${CURRENT_BUILDTREES_DIR}/internal-config-${TARGET_TRIPLET}-dbg.log")
|
||||
file(RENAME "${current_binary_dir}/config.log" "${CURRENT_BUILDTREES_DIR}/internal-config-${TARGET_TRIPLET}-dbg.log")
|
||||
endif()
|
||||
|
||||
z_vcpkg_restore_pkgconfig_path()
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
48
scripts/cmake/z_vcpkg_setup_pkgconfig_path.cmake
Normal file
48
scripts/cmake/z_vcpkg_setup_pkgconfig_path.cmake
Normal file
@ -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()
|
@ -61,6 +61,7 @@ include("${SCRIPTS}/cmake/z_vcpkg_forward_output_variable.cmake")
|
||||
include("${SCRIPTS}/cmake/z_vcpkg_function_arguments.cmake")
|
||||
include("${SCRIPTS}/cmake/z_vcpkg_get_cmake_vars.cmake")
|
||||
include("${SCRIPTS}/cmake/z_vcpkg_prettify_command_line.cmake")
|
||||
include("${SCRIPTS}/cmake/z_vcpkg_setup_pkgconfig_path.cmake")
|
||||
|
||||
function(debug_message)
|
||||
if(PORT_DEBUG)
|
||||
|
Loading…
x
Reference in New Issue
Block a user