FindPkgConfig: small refactoring

This commit is contained in:
Daniele E. Domenichelli 2014-03-17 17:50:29 +01:00
parent fb4aff058d
commit 453d2b2438
1 changed files with 31 additions and 24 deletions

View File

@ -136,6 +136,31 @@ macro(_pkgconfig_parse_options _result _is_req _is_silent _no_cmake_path _no_cma
list(REMOVE_ITEM ${_result} "NO_CMAKE_ENVIRONMENT_PATH")
endmacro()
# Add the content of a variable or an environment variable to a list of
# paths
# Usage:
# - _pkgconfig_add_extra_path(_extra_paths VAR)
# - _pkgconfig_add_extra_path(_extra_paths ENV VAR)
function(_pkgconfig_add_extra_path _extra_paths_var _var)
set(_is_env 0)
if(_var STREQUAL "ENV")
set(_var ${ARGV2})
set(_is_env 1)
endif()
if(NOT _is_env)
if(NOT "${${_var}}" STREQUAL "")
list(APPEND ${_extra_paths_var} ${CMAKE_PREFIX_PATH})
endif()
else()
if(NOT "$ENV{${_var}}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{${_var}}" _path)
list(APPEND ${_extra_paths_var} ${_path})
unset(_path)
endif()
endif()
set(${_extra_paths_var} ${${_extra_paths_var}} PARENT_SCOPE)
endfunction()
###
macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cmake_environment_path _prefix)
_pkgconfig_unset(${_prefix}_FOUND)
@ -179,33 +204,15 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
set(_extra_paths)
if(NOT _no_cmake_path)
if(NOT "${CMAKE_PREFIX_PATH}" STREQUAL "")
list(APPEND _extra_paths ${CMAKE_PREFIX_PATH})
endif()
if(NOT "${CMAKE_FRAMEWORK_PATH}" STREQUAL "")
list(APPEND _extra_paths ${CMAKE_FRAMEWORK_PATH})
endif()
if(NOT "${CMAKE_APPBUNDLE_PATH}" STREQUAL "")
list(APPEND _extra_paths ${CMAKE_FRAMEWORK_PATH})
endif()
_pkgconfig_add_extra_path(_extra_paths CMAKE_PREFIX_PATH)
_pkgconfig_add_extra_path(_extra_paths CMAKE_FRAMEWORK_PATH)
_pkgconfig_add_extra_path(_extra_paths CMAKE_APPBUNDLE_PATH)
endif()
if(NOT _no_cmake_environment_path)
if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{CMAKE_PREFIX_PATH}" _path)
list(APPEND _extra_paths ${_path})
unset(_path)
endif()
if(NOT "$ENV{CMAKE_FRAMEWORK_PATH}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{CMAKE_FRAMEWORK_PATH}" _path)
list(APPEND _extra_paths ${_path})
unset(_path)
endif()
if(NOT "$ENV{CMAKE_APPBUNDLE_PATH}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{CMAKE_APPBUNDLE_PATH}" _path)
list(APPEND _extra_paths ${_path})
unset(_path)
endif()
_pkgconfig_add_extra_path(_extra_paths ENV CMAKE_PREFIX_PATH)
_pkgconfig_add_extra_path(_extra_paths ENV CMAKE_FRAMEWORK_PATH)
_pkgconfig_add_extra_path(_extra_paths ENV CMAKE_APPBUNDLE_PATH)
endif()
if(NOT "${_extra_paths}" STREQUAL "")