2022-06-08 07:26:51 +08:00
|
|
|
include_guard(GLOBAL)
|
2021-04-07 01:53:41 +08:00
|
|
|
|
|
|
|
function(x_vcpkg_pkgconfig_get_modules)
|
2023-06-24 03:07:47 +08:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 0 "arg" "CFLAGS;LIBS;LIBRARIES;LIBRARIES_DIR;INCLUDE_DIRS;USE_MSVC_SYNTAX_ON_WINDOWS" "PREFIX" "MODULES")
|
2021-04-07 01:53:41 +08:00
|
|
|
if(NOT DEFINED arg_PREFIX OR arg_PREFIX STREQUAL "")
|
|
|
|
message(FATAL_ERROR "x_vcpkg_pkgconfig_get_modules requires parameter PREFIX!")
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED arg_MODULES OR arg_MODULES STREQUAL "")
|
|
|
|
message(FATAL_ERROR "x_vcpkg_pkgconfig_get_modules requires parameter MODULES!")
|
|
|
|
endif()
|
|
|
|
if(DEFINED arg_UNPARSED_ARGUMENTS)
|
|
|
|
message(FATAL_ERROR "extra arguments passed to x_vcpkg_pkgconfig_get_modules: ${arg_UNPARSED_ARGUMENTS}")
|
|
|
|
endif()
|
2023-06-24 03:07:47 +08:00
|
|
|
set(msvc "")
|
|
|
|
if(arg_USE_MSVC_SYNTAX_ON_WINDOWS AND VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
|
|
|
|
set(msvc "--msvc-syntax")
|
|
|
|
endif()
|
2021-04-07 01:53:41 +08:00
|
|
|
|
2022-02-01 13:09:40 +08:00
|
|
|
set(PKGCONFIG "${CURRENT_INSTALLED_DIR}/../@HOST_TRIPLET@/tools/pkgconf/pkgconf@VCPKG_HOST_EXECUTABLE_SUFFIX@")
|
|
|
|
|
2021-04-07 01:53:41 +08:00
|
|
|
set(backup_PKG_CONFIG_PATH "$ENV{PKG_CONFIG_PATH}")
|
|
|
|
|
|
|
|
set(var_suffixes)
|
|
|
|
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
|
2021-06-10 06:25:20 +08:00
|
|
|
z_vcpkg_set_pkgconfig_path("${CURRENT_INSTALLED_DIR}/lib/pkgconfig${VCPKG_HOST_PATH_SEPARATOR}${CURRENT_PACKAGES_DIR}/lib/pkgconfig" "${backup_PKG_CONFIG_PATH}")
|
2021-04-07 01:53:41 +08:00
|
|
|
if(arg_LIBS)
|
|
|
|
execute_process(
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND "${PKGCONFIG}" ${msvc} --libs ${arg_MODULES}
|
2021-04-07 01:53:41 +08:00
|
|
|
OUTPUT_VARIABLE ${arg_PREFIX}_LIBS_RELEASE
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2021-04-07 01:53:41 +08:00
|
|
|
)
|
|
|
|
list(APPEND var_suffixes LIBS_RELEASE)
|
|
|
|
endif()
|
|
|
|
if(arg_LIBRARIES)
|
|
|
|
execute_process(
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND "${PKGCONFIG}" ${msvc} --libs-only-l ${arg_MODULES}
|
2021-04-07 01:53:41 +08:00
|
|
|
OUTPUT_VARIABLE ${arg_PREFIX}_LIBRARIES_RELEASE
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2021-04-07 01:53:41 +08:00
|
|
|
)
|
|
|
|
list(APPEND var_suffixes LIBRARIES_RELEASE)
|
|
|
|
endif()
|
|
|
|
if(arg_LIBRARIES_DIRS)
|
|
|
|
execute_process(
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND "${PKGCONFIG}" ${msvc} --libs-only-L ${arg_MODULES}
|
2021-04-07 01:53:41 +08:00
|
|
|
OUTPUT_VARIABLE ${arg_PREFIX}_LIBRARIES_DIRS_RELEASE
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2021-04-07 01:53:41 +08:00
|
|
|
)
|
|
|
|
list(APPEND var_suffixes LIBRARIES_DIRS_RELEASE)
|
|
|
|
endif()
|
|
|
|
if(arg_INCLUDE_DIRS)
|
|
|
|
execute_process(
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND "${PKGCONFIG}" ${msvc} --cflags-only-I ${arg_MODULES}
|
2021-04-07 01:53:41 +08:00
|
|
|
OUTPUT_VARIABLE ${arg_PREFIX}_INCLUDE_DIRS_RELEASE
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2021-04-07 01:53:41 +08:00
|
|
|
)
|
|
|
|
list(APPEND var_suffixes INCLUDE_DIRS_RELEASE)
|
|
|
|
endif()
|
2022-02-17 05:00:36 +08:00
|
|
|
if(arg_CFLAGS)
|
|
|
|
execute_process(
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND "${PKGCONFIG}" ${msvc} --cflags ${arg_MODULES}
|
2022-02-17 05:00:36 +08:00
|
|
|
OUTPUT_VARIABLE ${arg_PREFIX}_CFLAGS_RELEASE
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2022-02-17 05:00:36 +08:00
|
|
|
)
|
|
|
|
list(APPEND var_suffixes CFLAGS_RELEASE)
|
|
|
|
endif()
|
2021-04-07 01:53:41 +08:00
|
|
|
endif()
|
|
|
|
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
|
2021-06-10 06:25:20 +08:00
|
|
|
z_vcpkg_set_pkgconfig_path("${CURRENT_INSTALLED_DIR}/debug/lib/pkgconfig${VCPKG_HOST_PATH_SEPARATOR}${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig" "${backup_PKG_CONFIG_PATH}")
|
2021-04-07 01:53:41 +08:00
|
|
|
if(arg_LIBS)
|
|
|
|
execute_process(
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND "${PKGCONFIG}" ${msvc} --libs ${arg_MODULES}
|
2021-04-07 01:53:41 +08:00
|
|
|
OUTPUT_VARIABLE ${arg_PREFIX}_LIBS_DEBUG
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2021-04-07 01:53:41 +08:00
|
|
|
)
|
|
|
|
list(APPEND var_suffixes LIBS_DEBUG)
|
|
|
|
endif()
|
|
|
|
if(arg_LIBRARIES)
|
|
|
|
execute_process(
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND "${PKGCONFIG}" ${msvc} --libs-only-l ${arg_MODULES}
|
2021-04-07 01:53:41 +08:00
|
|
|
OUTPUT_VARIABLE ${arg_PREFIX}_LIBRARIES_DEBUG
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2021-04-07 01:53:41 +08:00
|
|
|
)
|
|
|
|
list(APPEND var_suffixes LIBRARIES_DEBUG)
|
|
|
|
endif()
|
|
|
|
if(arg_LIBRARIES_DIRS)
|
|
|
|
execute_process(
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND "${PKGCONFIG}" ${msvc} --libs-only-L ${arg_MODULES}
|
2021-04-07 01:53:41 +08:00
|
|
|
OUTPUT_VARIABLE ${arg_PREFIX}_LIBRARIES_DIRS_DEBUG
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2021-04-07 01:53:41 +08:00
|
|
|
)
|
|
|
|
list(APPEND var_suffixes LIBRARIES_DIRS_DEBUG)
|
|
|
|
endif()
|
|
|
|
if(arg_INCLUDE_DIRS)
|
|
|
|
execute_process(
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND "${PKGCONFIG}" ${msvc} --cflags-only-I ${arg_MODULES}
|
2021-04-07 01:53:41 +08:00
|
|
|
OUTPUT_VARIABLE ${arg_PREFIX}_INCLUDE_DIRS_DEBUG
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2021-04-07 01:53:41 +08:00
|
|
|
)
|
|
|
|
list(APPEND var_suffixes INCLUDE_DIRS_DEBUG)
|
|
|
|
endif()
|
2022-02-17 05:00:36 +08:00
|
|
|
if(arg_CFLAGS)
|
|
|
|
execute_process(
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND "${PKGCONFIG}" ${msvc} --cflags ${arg_MODULES}
|
2022-02-17 05:00:36 +08:00
|
|
|
OUTPUT_VARIABLE ${arg_PREFIX}_CFLAGS_DEBUG
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-06-24 03:07:47 +08:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2022-02-17 05:00:36 +08:00
|
|
|
)
|
|
|
|
list(APPEND var_suffixes CFLAGS_DEBUG)
|
|
|
|
endif()
|
2021-04-07 01:53:41 +08:00
|
|
|
endif()
|
|
|
|
set(ENV{PKG_CONFIG_PATH} "${backup_PKG_CONFIG_PATH}")
|
|
|
|
|
|
|
|
foreach(_var IN LISTS var_suffixes)
|
|
|
|
set("${arg_PREFIX}_${_var}" "${${arg_PREFIX}_${_var}}" PARENT_SCOPE)
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(z_vcpkg_set_pkgconfig_path _path _backup)
|
|
|
|
if(NOT _backup STREQUAL "")
|
|
|
|
set(ENV{PKG_CONFIG_PATH} "${_path}${VCPKG_HOST_PATH_SEPARATOR}${_backup}")
|
|
|
|
else()
|
|
|
|
set(ENV{PKG_CONFIG_PATH} "${_path}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|