From 31370231c30aac202fb6e87718496377887e762f Mon Sep 17 00:00:00 2001 From: Luca Bertagna Date: Wed, 24 Nov 2021 11:43:06 -0700 Subject: [PATCH] Fix usage of find_package_handle_standard_args The old code handled the standard args in find_package per component (via find_package_component() -> find_package_handle_standard_args() ). Newer versions of CMake issues warnings for this usage since find_package_handle_standard_args() sets _FOUND variables based on the passed to the function (which in this case is based on the Package Component Name e.g. NetCDF_C_FOUND) which in this case can differ from the flag that the caller expects (which would be based on the Package Name, e.g. NetCDF_FOUND) Also note that CMake now supports handling all package components in find_package_handle_standard_args() via the HANDLE_COMPONENTS option. So this fix moves find_package_handle_standard_args() call from find_package_component() to the appropriate Find.cmake file (and now passes the Package name instead of the Package component name) and handles all package components in a single call. --- cmake/FindGPTL.cmake | 3 +++ cmake/FindHDF5.cmake | 3 +++ cmake/FindMPE.cmake | 3 +++ cmake/FindMPISERIAL.cmake | 3 +++ cmake/FindNetCDF.cmake | 3 +++ cmake/FindPnetCDF.cmake | 3 +++ cmake/LibFind.cmake | 20 +++++++++++--------- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/cmake/FindGPTL.cmake b/cmake/FindGPTL.cmake index c223c1b34..cc154c800 100644 --- a/cmake/FindGPTL.cmake +++ b/cmake/FindGPTL.cmake @@ -70,3 +70,6 @@ foreach (GPTL_comp IN LISTS GPTL_FIND_VALID_COMPONENTS) endif () endforeach () + +# Handle QUIET/REQUIRED, and set _FOUND if all required components were found +find_package_handle_standard_args (GPTL HANDLE_COMPONENTS) diff --git a/cmake/FindHDF5.cmake b/cmake/FindHDF5.cmake index 1473a7e64..b135c39ac 100644 --- a/cmake/FindHDF5.cmake +++ b/cmake/FindHDF5.cmake @@ -123,3 +123,6 @@ foreach (HDF5_comp IN LISTS HDF5_FIND_VALID_COMPONENTS) endif () endforeach () + +# Handle QUIET/REQUIRED, and set _FOUND if all required components were found +find_package_handle_standard_args (HDF5 HANDLE_COMPONENTS) diff --git a/cmake/FindMPE.cmake b/cmake/FindMPE.cmake index 5a964172d..7909c1139 100644 --- a/cmake/FindMPE.cmake +++ b/cmake/FindMPE.cmake @@ -48,3 +48,6 @@ foreach (NCDFcomp IN LISTS MPE_FIND_VALID_COMPONENTS) endif () endforeach () + +# Handle QUIET/REQUIRED, and set _FOUND if all required components were found +find_package_handle_standard_args (MPE HANDLE_COMPONENTS) diff --git a/cmake/FindMPISERIAL.cmake b/cmake/FindMPISERIAL.cmake index 09906eb7a..5db5f5e28 100644 --- a/cmake/FindMPISERIAL.cmake +++ b/cmake/FindMPISERIAL.cmake @@ -42,3 +42,6 @@ foreach (MPISERIAL_comp IN LISTS MPISERIAL_FIND_VALID_COMPONENTS) endif () endforeach () + +# Handle QUIET/REQUIRED, and set _FOUND if all required components were found +find_package_handle_standard_args (MPISERIAL HANDLE_COMPONENTS) diff --git a/cmake/FindNetCDF.cmake b/cmake/FindNetCDF.cmake index b439fed5a..172f77fa7 100644 --- a/cmake/FindNetCDF.cmake +++ b/cmake/FindNetCDF.cmake @@ -152,3 +152,6 @@ foreach (NCDFcomp IN LISTS NetCDF_FIND_VALID_COMPONENTS) endif () endforeach () + +# Handle QUIET/REQUIRED, and set _FOUND if all required components were found +find_package_handle_standard_args (NetCDF HANDLE_COMPONENTS) diff --git a/cmake/FindPnetCDF.cmake b/cmake/FindPnetCDF.cmake index 7b846e643..a1f85cd04 100644 --- a/cmake/FindPnetCDF.cmake +++ b/cmake/FindPnetCDF.cmake @@ -69,3 +69,6 @@ foreach (PNCDFcomp IN LISTS PnetCDF_FIND_VALID_COMPONENTS) endif () endforeach () + +# Handle QUIET/REQUIRED, and set _FOUND if all required components were found +find_package_handle_standard_args (PnetCDF HANDLE_COMPONENTS) diff --git a/cmake/LibFind.cmake b/cmake/LibFind.cmake index c197d21b8..138606ec0 100644 --- a/cmake/LibFind.cmake +++ b/cmake/LibFind.cmake @@ -297,15 +297,18 @@ function (find_package_component PKG) endforeach () - # handle the QUIETLY and REQUIRED arguments and - # set NetCDF_C_FOUND to TRUE if all listed variables are TRUE - find_package_handle_standard_args (${PKGCOMP} DEFAULT_MSG - ${PKGCOMP}_LIBRARY - ${PKGCOMP}_INCLUDE_DIR) + # Use find_package_handle_standard_args only if this is not a component-specific + # call, to avoid cmake errors. If this is a component specific call, the upstream + # Find.cmake module will take care of calling the macro, using HANDLE_COMPONENTS + if (NOT COMP) + find_package_handle_standard_args (${PKGCOMP} DEFAULT_MSG + ${PKGCOMP}_LIBRARY + ${PKGCOMP}_INCLUDE_DIR) + elseif (${PKGCOMP}_LIBRARY AND ${PKGCOMP}_INCLUDE_DIR) + set (${PKGCOMP}_FOUND TRUE) + endif() + mark_as_advanced (${PKGCOMP}_INCLUDE_DIR ${PKGCOMP}_LIBRARY) - - # HACK For bug in CMake v3.0: - set (${PKGCOMP}_FOUND ${${PKGCOMPUP}_FOUND}) # Set return variables if (${PKGCOMP}_FOUND) @@ -320,7 +323,6 @@ function (find_package_component PKG) set (${PKGCOMP}_LIBRARY ${${PKGCOMP}_LIBRARY} PARENT_SCOPE) set (${PKGCOMP}_LIBRARIES ${${PKGCOMP}_LIBRARIES} PARENT_SCOPE) set (${PKGCOMP}_IS_SHARED ${${PKGCOMP}_IS_SHARED} PARENT_SCOPE) - endif () endfunction ()