CMake/Tests/RunCMake/FindPkgConfig/FindPkgConfig_GET_VARIABLE_DEFINE_VARIABLES.cmake
Corentin Noël e0d00b9218 FindPkgConfig: Allow to override variables when calling pkg_get_variable
This is specifically useful when building applications within containers as we
sometimes need to redefine the prefix used in a variable.
2023-09-19 09:08:48 +02:00

20 lines
707 B
CMake

# Prepare environment and variables
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
if(WIN32)
set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}\\pc-bletch")
else()
set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/pc-bletch")
endif()
find_package(PkgConfig REQUIRED)
pkg_check_modules(BLETCH QUIET bletch)
if (NOT BLETCH_FOUND)
message(FATAL_ERROR "Failed to find embedded package bletch via CMAKE_PREFIX_PATH")
endif ()
pkg_get_variable(bletchvar bletch exec_prefix DEFINE_VARIABLES prefix=customprefix)
if (NOT bletchvar STREQUAL "customprefix")
message(FATAL_ERROR "Failed to fetch variable exec_prefix from embedded package bletch with prefix overridden to customprefix")
endif ()