CMakePackageConfigHelpers: Add a find_dependency macro

This macro handles the EXACT, REQUIRED and QUIET options
and sets an appropriate NOT_FOUND_MESSAGE for the package
if a dependency is not found.
This commit is contained in:
Stephen Kelly 2013-08-30 12:59:42 +02:00
parent 549b95f115
commit bb501a2a64
1 changed files with 37 additions and 2 deletions

View File

@ -3,7 +3,8 @@
# CONFIGURE_PACKAGE_CONFIG_FILE(<input> <output> INSTALL_DESTINATION <path> # CONFIGURE_PACKAGE_CONFIG_FILE(<input> <output> INSTALL_DESTINATION <path>
# [PATH_VARS <var1> <var2> ... <varN>] # [PATH_VARS <var1> <var2> ... <varN>]
# [NO_SET_AND_CHECK_MACRO] # [NO_SET_AND_CHECK_MACRO]
# [NO_CHECK_REQUIRED_COMPONENTS_MACRO]) # [NO_CHECK_REQUIRED_COMPONENTS_MACRO]
# [NO_FIND_DEPENDENCY_MACRO])
# #
# CONFIGURE_PACKAGE_CONFIG_FILE() should be used instead of the plain # CONFIGURE_PACKAGE_CONFIG_FILE() should be used instead of the plain
# configure_file() command when creating the <Name>Config.cmake or <Name>-config.cmake # configure_file() command when creating the <Name>Config.cmake or <Name>-config.cmake
@ -154,7 +155,7 @@ endmacro()
function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile) function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO) set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO NO_FIND_DEPENDENCY_MACRO)
set(oneValueArgs INSTALL_DESTINATION ) set(oneValueArgs INSTALL_DESTINATION )
set(multiValueArgs PATH_VARS ) set(multiValueArgs PATH_VARS )
@ -240,6 +241,40 @@ endmacro()
") ")
endif() endif()
if(NOT CCF_NO_FIND_DEPENDENCY_MACRO)
set(PACKAGE_INIT "${PACKAGE_INIT}
macro(find_dependency dep)
if (NOT \${dep}_FOUND)
if (\${ARGV1})
set(version \${ARGV1})
endif()
set(exact_arg)
if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION_EXACT)
set(exact_arg EXACT)
endif()
set(quiet_arg)
if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
set(quiet_arg QUIET)
endif()
set(required_arg)
if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
set(required_arg REQUIRED)
endif()
find_package(\${dep} \${version} \${exact_arg} \${quiet_arg} \${required_arg})
if (NOT \${dep}_FOUND)
set(\${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE \"\${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency \${dep} could not be found.\")
set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
return()
endif()
set(required_arg)
set(quiet_arg)
set(exact_arg)
endif()
endmacro()
")
endif()
set(PACKAGE_INIT "${PACKAGE_INIT} set(PACKAGE_INIT "${PACKAGE_INIT}
####################################################################################") ####################################################################################")