Hi all,

On second thought, I think the interface of
find_package_handle_standard_args() is a bit counter-intuitive. Why
should it matter to the (ignorant) user that list-variables are treated
different from "ordinary" values. That doesn't make sense IMHO.

I've taken the time to rewrite find_package_handle_standard_args() in
such a way that you can now supply any variable as argument to be
checked. If the argument is a list, each member in the list will be
tested. It makes the function even shorter, because there's no need to
do a separate test on _VAR1 anymore. I think this change won't break any
existing code. Any comments are appreciated.

I've attached the new function. Or would it be better to post a patch
file? Or should I open an issue for this and upload the file there?
Anyway, here it is. 

Best regards,
Marcel Loose.

On Thu, 2009-05-14 at 14:10 +0200, Marcel Loose wrote:
> Hi Denis,
> 
> I think I understand what's going wrong.
> I collect the *values* from the variables returned by find_library() in
> XXX_LIBRARIES, not the names of these variables.
> 
> So, instead of passing LIB1 LIB2 LIB3 to
> find_package_handle_standard_args() I'm actually passing ${LIB1} ${LIB2}
> ${LIB3}, which is, of course, quite different.
> 
> What's the best way to proceed. Should I collect the names of variables
> used in the find_library() calls in a separate list variable and use
> that for find_package_handle_standard_args(), or should I just handle
> the REQUIRED and QUIET stuff myself in this case. Any recommendations?
> 
> Best regards,
> Marcel Loose.
> 
> On Thu, 2009-05-14 at 04:45 -0700, Denis Scherbakov wrote:
> > 
> > > Yes, that's right. But...
> > > 
> > > The number of libraries I need to find depends on the
> > > COMPONENTS that
> > > were specified by the user in his CMakeLists.txt file. So I
> > > cannot hard
> > > code these variables as arguments to
> > > find_package_handle_standard_args(). That's why I chose to
> > > collect them
> > > in XXX-LIBRARIES first and pass that variable.
> > > 
> > > So, I'm still stuck I'm afraid.
> > 
> > You may pass a LIST of variables, this also works.
> > 
> > INCLUDE(FindPackageHandleStandardArgs)
> > 
> > LIST(APPEND myList "GSL_LIBRARIES" "GSL_LIBRARY" "GSL_CBLAS_LIBRARY" 
> > "GSL_INCLUDE_DIR")
> > 
> > FIND_PACKAGE_HANDLE_STANDARD_ARGS(GSL DEFAULT_MSG ${myList})
> > 
> > Denis
> > 
> > 
> >       
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: 
> http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

# FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME (DEFAULT_MSG|"Custom failure message") 
VAR1 ... )
#    This macro is intended to be used in FindXXX.cmake modules files.
#    It handles the REQUIRED and QUIET argument to FIND_PACKAGE() and
#    it also sets the <UPPERCASED_NAME>_FOUND variable.
#    The package is found if all variables listed are TRUE.
#    Example:
#
#    FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARIES 
LIBXML2_INCLUDE_DIR)
#
#    LibXml2 is considered to be found, if both LIBXML2_LIBRARIES and 
#    LIBXML2_INCLUDE_DIR are valid. Then also LIBXML2_FOUND is set to TRUE.
#    If it is not found and REQUIRED was used, it fails with FATAL_ERROR, 
#    independent whether QUIET was used or not.
#    If it is found, the location is reported using the VAR1 argument, so 
#    here a message "Found LibXml2: /usr/lib/libxml2.so" will be printed out.
#    If the second argument is DEFAULT_MSG, the message in the failure case 
will 
#    be "Could NOT find LibXml2", if you don't like this message you can specify
#    your own custom failure message there.

INCLUDE(FindPackageMessage)
FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FAIL_MSG _VAR1 )

  SET(ARGS)
  FOREACH(_ARG ${_VAR1} ${ARGN})
    LIST(APPEND ARGS ${${_ARG}})
  ENDFOREACH(_ARG)

  IF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
    SET(_FAIL_MESSAGE "Could NOT find ${_NAME}")
  ELSE("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
    SET(_FAIL_MESSAGE "${_FAIL_MSG}")
  ENDIF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")

  STRING(TOUPPER ${_NAME} _NAME_UPPER)

  # Check if all passed variables are valid. 
  # Collect all variables which were not found, so they can be printed, so the 
  # user knows better what went wrong (#6375)
  SET(MISSING_VARS "")
  SET(DETAILS "")
  SET(${_NAME_UPPER}_FOUND TRUE)
  FOREACH(_CURRENT_VAR ${ARGS})
    IF(NOT _CURRENT_VAR)
      SET(${_NAME_UPPER}_FOUND FALSE)
      SET(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}")
    ELSE(NOT _CURRENT_VAR)
      SET(DETAILS "${DETAILS}[${_CURRENT_VAR}]")
    ENDIF(NOT _CURRENT_VAR)
  ENDFOREACH(_CURRENT_VAR)

  IF (${_NAME_UPPER}_FOUND)
    FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${ARGS}" "${DETAILS}")
  ELSE (${_NAME_UPPER}_FOUND)
    IF (${_NAME}_FIND_REQUIRED)
        MESSAGE(FATAL_ERROR "${_FAIL_MESSAGE} (missing: ${MISSING_VARS})")
    ELSE (${_NAME}_FIND_REQUIRED)
      IF (NOT ${_NAME}_FIND_QUIETLY)
        MESSAGE(STATUS "${_FAIL_MESSAGE}  (missing: ${MISSING_VARS})")
      ENDIF (NOT ${_NAME}_FIND_QUIETLY)
    ENDIF (${_NAME}_FIND_REQUIRED)
  ENDIF (${_NAME_UPPER}_FOUND)

  SET(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE)

ENDFUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS)
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to