Skip to content

Commit 215a253

Browse files
authored
[z_vcpkg_setup_pkgconfig_path] debug needs share/pkgconfig (microsoft#36151)
Pass `share/pkgconfig` instead of `debug/share/pkgconfig`: The `share` location is for config-independent data. Integrate `CURRENT_PACKAGES_DIR` locations. Change the function interface to take a CONFIG parameter instead of prefix list (suggested below). Use `z_vcpkg_setup_pkgconfig_path` also for `vcpkg_fixup_pkgconfig` (which already had proper handling of `CURRENT_PACKAGES_DIR` and `share`). Remove redundant trailing slash. Extend unit test. Fixes consuming `wayland-protocols` and similar.
1 parent 836a2d6 commit 215a253

File tree

6 files changed

+43
-35
lines changed

6 files changed

+43
-35
lines changed

scripts/cmake/vcpkg_configure_make.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,8 @@ function(vcpkg_configure_make)
809809
set(relative_build_path .)
810810
endif()
811811

812-
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}${path_suffix_${current_buildtype}}")
812+
# Setup PKG_CONFIG_PATH
813+
z_vcpkg_setup_pkgconfig_path(CONFIG "${current_buildtype}")
813814

814815
# Setup environment
815816
set(ENV{CPPFLAGS} "${CPPFLAGS_${current_buildtype}}")

scripts/cmake/vcpkg_configure_meson.cmake

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,7 @@ function(vcpkg_configure_meson)
418418
file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${suffix_${buildtype}}")
419419
#setting up PKGCONFIG
420420
if(NOT arg_NO_PKG_CONFIG)
421-
if ("${buildtype}" STREQUAL "DEBUG")
422-
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}/debug")
423-
else()
424-
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}")
425-
endif()
421+
z_vcpkg_setup_pkgconfig_path(CONFIG "${buildtype}")
426422
endif()
427423

428424
z_vcpkg_meson_setup_variables(${buildtype})

scripts/cmake/vcpkg_configure_qmake.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function(vcpkg_configure_qmake)
7575
endif()
7676

7777
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
78-
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}" "${CURRENT_PACKAGES_DIR}")
78+
z_vcpkg_setup_pkgconfig_path(CONFIG RELEASE)
7979

8080
set(current_binary_dir "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
8181

@@ -120,7 +120,7 @@ function(vcpkg_configure_qmake)
120120
endif()
121121

122122
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
123-
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}/debug" "${CURRENT_PACKAGES_DIR}/debug")
123+
z_vcpkg_setup_pkgconfig_path(CONFIG DEBUG)
124124

125125
set(current_binary_dir "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
126126

scripts/cmake/vcpkg_fixup_pkgconfig.cmake

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,7 @@ function(z_vcpkg_fixup_pkgconfig_check_files arg_file arg_config)
116116
set(path_suffix_DEBUG /debug)
117117
set(path_suffix_RELEASE "")
118118

119-
if(DEFINED ENV{PKG_CONFIG_PATH})
120-
set(backup_env_pkg_config_path "$ENV{PKG_CONFIG_PATH}")
121-
else()
122-
unset(backup_env_pkg_config_path)
123-
endif()
124-
125-
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH}
126-
"${CURRENT_PACKAGES_DIR}${path_suffix_${arg_config}}/lib/pkgconfig"
127-
"${CURRENT_PACKAGES_DIR}/share/pkgconfig"
128-
"${CURRENT_INSTALLED_DIR}${path_suffix_${arg_config}}/lib/pkgconfig"
129-
"${CURRENT_INSTALLED_DIR}/share/pkgconfig"
130-
)
119+
z_vcpkg_setup_pkgconfig_path(CONFIG "${arg_config}")
131120

132121
# First make sure everything is ok with the package and its deps
133122
cmake_path(GET arg_file STEM LAST_ONLY package_name)
@@ -149,11 +138,8 @@ function(z_vcpkg_fixup_pkgconfig_check_files arg_file arg_config)
149138
else()
150139
debug_message("pkg-config --exists ${package_name} output: ${output}")
151140
endif()
152-
if(DEFINED backup_env_pkg_config_path)
153-
set(ENV{PKG_CONFIG_PATH} "${backup_env_pkg_config_path}")
154-
else()
155-
unset(ENV{PKG_CONFIG_PATH})
156-
endif()
141+
142+
z_vcpkg_restore_pkgconfig_path()
157143
endfunction()
158144

159145
function(vcpkg_fixup_pkgconfig)

scripts/cmake/z_vcpkg_setup_pkgconfig_path.cmake

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function(z_vcpkg_setup_pkgconfig_path)
2-
cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "" "BASE_DIRS")
2+
cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "CONFIG" "")
33

4-
if(NOT DEFINED arg_BASE_DIRS OR "${arg_BASE_DIRS}" STREQUAL "")
5-
message(FATAL_ERROR "BASE_DIRS is required.")
4+
if("${arg_CONFIG}" STREQUAL "")
5+
message(FATAL_ERROR "CONFIG is required.")
66
endif()
77
if(DEFINED arg_UNPARSED_ARGUMENTS)
88
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
@@ -22,13 +22,19 @@ function(z_vcpkg_setup_pkgconfig_path)
2222

2323
set(ENV{PKG_CONFIG} "${PKGCONFIG}") # Set via native file?
2424

25-
foreach(base_dir IN LISTS arg_BASE_DIRS)
26-
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH} "${base_dir}/share/pkgconfig/")
27-
endforeach()
28-
29-
foreach(base_dir IN LISTS arg_BASE_DIRS)
30-
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH} "${base_dir}/lib/pkgconfig/")
25+
foreach(prefix IN ITEMS "${CURRENT_INSTALLED_DIR}" "${CURRENT_PACKAGES_DIR}")
26+
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH} "${prefix}/share/pkgconfig")
27+
if(arg_CONFIG STREQUAL "RELEASE")
28+
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH} "${prefix}/lib/pkgconfig")
29+
# search order is lib, share, external
30+
elseif(arg_CONFIG STREQUAL "DEBUG")
31+
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH} "${prefix}/debug/lib/pkgconfig")
32+
# search order is debug/lib, share, external
33+
else()
34+
message(FATAL_ERROR "CONFIG must be either RELEASE or DEBUG.")
35+
endif()
3136
endforeach()
37+
# total search order is current packages dir, current installed dir, external
3238
endfunction()
3339

3440
function(z_vcpkg_restore_pkgconfig_path)

scripts/test_ports/unit-test-cmake/test-z_vcpkg_setup_pkgconfig_path.cmake

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,23 @@ set(ENV{PKG_CONFIG} "/a/pkgconf")
88
set(ENV{PKG_CONFIG_PATH} "1")
99
set(saved_path "$ENV{PATH}")
1010

11-
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "/2")
11+
block(SCOPE_FOR VARIABLES)
12+
13+
set(CURRENT_PACKAGES_DIR "P")
14+
set(CURRENT_INSTALLED_DIR "I")
15+
16+
z_vcpkg_setup_pkgconfig_path(CONFIG RELEASE)
17+
unit_test_check_variable_equal([[]] ENV{PKG_CONFIG} [[/a/pkgconf]])
18+
unit_test_match([[]] ENV{PKG_CONFIG_PATH} "^P.lib.pkgconfig.P.share.pkgconfig.I.lib.pkgconfig.I.share.pkgconfig.1\$")
19+
20+
z_vcpkg_restore_pkgconfig_path()
21+
unit_test_check_variable_equal([[]] ENV{PKG_CONFIG} [[/a/pkgconf]])
22+
unit_test_check_variable_equal([[]] ENV{PKG_CONFIG_PATH} "1")
23+
24+
z_vcpkg_setup_pkgconfig_path(CONFIG DEBUG)
1225
unit_test_check_variable_equal([[]] ENV{PKG_CONFIG} [[/a/pkgconf]])
1326
unit_test_check_variable_not_equal([[]] ENV{PKG_CONFIG_PATH} "1")
27+
unit_test_match([[]] ENV{PKG_CONFIG_PATH} "^P.debug.lib.pkgconfig.P.share.pkgconfig.I.debug.lib.pkgconfig.I.share.pkgconfig.1\$")
1428

1529
z_vcpkg_restore_pkgconfig_path()
1630
unit_test_check_variable_equal([[]] ENV{PKG_CONFIG} [[/a/pkgconf]])
@@ -20,3 +34,8 @@ unit_test_check_variable_equal([[]] ENV{PKG_CONFIG_PATH} "1")
2034
# It is hard to see which side effects a restore would have, so
2135
# this is expected behaviour for now.
2236
unit_test_check_variable_not_equal([[]] ENV{PATH} "${saved_path}")
37+
38+
unit_test_ensure_fatal_error([[ z_vcpkg_setup_pkgconfig_path() ]])
39+
unit_test_ensure_fatal_error([[ z_vcpkg_setup_pkgconfig_path(CONFIG unknown) ]])
40+
41+
endblock()

0 commit comments

Comments
 (0)