From 1cdec386530c6b844389b96c199e723a1e4e71c7 Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Fri, 16 Jul 2021 08:24:23 -0700 Subject: [PATCH] Fix cmake warnings, FindPASTIX/FindPTSCOTCH. We were getting a lot of warnings due to nested `find_package` calls within `Find***.cmake` files. The recommended approach is to use [`find_dependency`](https://cmake.org/cmake/help/latest/module/CMakeFindDependencyMacro.html) in package configuration files. I made this change for all instances. Case mismatches between `Find.cmake` and calling `find_package(`) also lead to warnings. Fixed for `FindPASTIX.cmake` and `FindSCOTCH.cmake`. `FindBLASEXT.cmake` was broken due to calling `find_package_handle_standard_args(BLAS ...)`. The package name must match, otherwise the `find_package(BLASEXT)` falsely thinks the package wasn't found. I changed to `BLASEXT`, but then also copied that value to `BLAS_FOUND` for compatibility. `FindPastix.cmake` had a typo that incorrectly added `PTSCOTCH` when looking for the `SCOTCH` component. `FindPTSCOTCH` incorrectly added `***-NOTFOUND` to include/library lists, corrupting them. This led to cmake errors down-the-line. Fixes #2288. --- cmake/FindBLAS.cmake | 5 +-- cmake/FindBLASEXT.cmake | 28 ++++++++------- cmake/FindComputeCpp.cmake | 3 +- cmake/FindFFTW.cmake | 3 +- cmake/FindHWLOC.cmake | 5 +-- cmake/FindLAPACK.cmake | 7 ++-- cmake/{FindPastix.cmake => FindPASTIX.cmake} | 36 ++++++++++---------- cmake/FindPTSCOTCH.cmake | 33 +++++++++--------- cmake/{FindScotch.cmake => FindSCOTCH.cmake} | 5 +-- cmake/FindTriSYCL.cmake | 9 ++--- 10 files changed, 72 insertions(+), 62 deletions(-) rename cmake/{FindPastix.cmake => FindPASTIX.cmake} (96%) rename cmake/{FindScotch.cmake => FindSCOTCH.cmake} (99%) diff --git a/cmake/FindBLAS.cmake b/cmake/FindBLAS.cmake index 7d1f81b03..1bb8f1965 100644 --- a/cmake/FindBLAS.cmake +++ b/cmake/FindBLAS.cmake @@ -147,6 +147,7 @@ mark_as_advanced(BLAS_VERBOSE) include(CheckFunctionExists) include(CheckFortranFunctionExists) +include(CMakeFindDependencyMacro) set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) @@ -509,9 +510,9 @@ if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All") if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED) - find_package(Threads) + find_dependency(Threads) else() - find_package(Threads REQUIRED) + find_dependency(Threads REQUIRED) endif() set(BLAS_SEARCH_LIBS "") diff --git a/cmake/FindBLASEXT.cmake b/cmake/FindBLASEXT.cmake index 0fe7fb849..69a941897 100644 --- a/cmake/FindBLASEXT.cmake +++ b/cmake/FindBLASEXT.cmake @@ -41,18 +41,19 @@ # License text for the above reference.) # macro to factorize this call +include(CMakeFindDependencyMacro) macro(find_package_blas) if(BLASEXT_FIND_REQUIRED) if(BLASEXT_FIND_QUIETLY) - find_package(BLAS REQUIRED QUIET) + find_dependency(BLAS REQUIRED QUIET) else() - find_package(BLAS REQUIRED) + find_dependency(BLAS REQUIRED) endif() else() if(BLASEXT_FIND_QUIETLY) - find_package(BLAS QUIET) + find_dependency(BLAS QUIET) else() - find_package(BLAS) + find_dependency(BLAS) endif() endif() endmacro() @@ -316,7 +317,7 @@ if(BLA_VENDOR MATCHES "Intel*") "\n (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)") message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES") endif() - find_package_handle_standard_args(BLAS DEFAULT_MSG + find_package_handle_standard_args(BLASEXT DEFAULT_MSG BLAS_SEQ_LIBRARIES BLAS_LIBRARY_DIRS BLAS_INCLUDE_DIRS) @@ -324,14 +325,14 @@ if(BLA_VENDOR MATCHES "Intel*") if(NOT BLASEXT_FIND_QUIETLY) message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES") endif() - find_package_handle_standard_args(BLAS DEFAULT_MSG + find_package_handle_standard_args(BLASEXT DEFAULT_MSG BLAS_PAR_LIBRARIES) endif() else() if(NOT BLASEXT_FIND_QUIETLY) message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES") endif() - find_package_handle_standard_args(BLAS DEFAULT_MSG + find_package_handle_standard_args(BLASEXT DEFAULT_MSG BLAS_SEQ_LIBRARIES BLAS_LIBRARY_DIRS BLAS_INCLUDE_DIRS) @@ -343,14 +344,14 @@ elseif(BLA_VENDOR MATCHES "ACML*") "\n (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)") message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES") endif() - find_package_handle_standard_args(BLAS DEFAULT_MSG + find_package_handle_standard_args(BLASEXT DEFAULT_MSG BLAS_SEQ_LIBRARIES BLAS_LIBRARY_DIRS) if(BLAS_PAR_LIBRARIES) if(NOT BLASEXT_FIND_QUIETLY) message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES") endif() - find_package_handle_standard_args(BLAS DEFAULT_MSG + find_package_handle_standard_args(BLASEXT DEFAULT_MSG BLAS_PAR_LIBRARIES) endif() elseif(BLA_VENDOR MATCHES "IBMESSL*") @@ -360,21 +361,24 @@ elseif(BLA_VENDOR MATCHES "IBMESSL*") "\n (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)") message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES") endif() - find_package_handle_standard_args(BLAS DEFAULT_MSG + find_package_handle_standard_args(BLASEXT DEFAULT_MSG BLAS_SEQ_LIBRARIES BLAS_LIBRARY_DIRS) if(BLAS_PAR_LIBRARIES) if(NOT BLASEXT_FIND_QUIETLY) message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES") endif() - find_package_handle_standard_args(BLAS DEFAULT_MSG + find_package_handle_standard_args(BLASEXT DEFAULT_MSG BLAS_PAR_LIBRARIES) endif() else() if(NOT BLASEXT_FIND_QUIETLY) message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES") endif() - find_package_handle_standard_args(BLAS DEFAULT_MSG + find_package_handle_standard_args(BLASEXT DEFAULT_MSG BLAS_SEQ_LIBRARIES BLAS_LIBRARY_DIRS) endif() + +# Callers expect BLAS_FOUND to be set as well. +set(BLAS_FOUND BLASEXT_FOUND) diff --git a/cmake/FindComputeCpp.cmake b/cmake/FindComputeCpp.cmake index 3cca5150e..1c271f0fe 100644 --- a/cmake/FindComputeCpp.cmake +++ b/cmake/FindComputeCpp.cmake @@ -41,7 +41,8 @@ set(COMPUTECPP_BITCODE "spir64" CACHE STRING "Bitcode type to use as SYCL target in compute++") mark_as_advanced(COMPUTECPP_BITCODE) -find_package(OpenCL REQUIRED) +include(CMakeFindDependencyMacro) +find_dependency(OpenCL REQUIRED) # Find ComputeCpp package diff --git a/cmake/FindFFTW.cmake b/cmake/FindFFTW.cmake index fad476d0d..ed55c5fad 100644 --- a/cmake/FindFFTW.cmake +++ b/cmake/FindFFTW.cmake @@ -22,7 +22,8 @@ if( NOT FFTW_ROOT AND ENV{FFTWDIR} ) endif() # Check if we can use PkgConfig -find_package(PkgConfig) +include(CMakeFindDependencyMacro) +find_dependency(PkgConfig) #Determine from PKG if( PKG_CONFIG_FOUND AND NOT FFTW_ROOT ) diff --git a/cmake/FindHWLOC.cmake b/cmake/FindHWLOC.cmake index 483291518..522f52157 100644 --- a/cmake/FindHWLOC.cmake +++ b/cmake/FindHWLOC.cmake @@ -65,8 +65,9 @@ endif() # Optionally use pkg-config to detect include/library dirs (if pkg-config is available) # ------------------------------------------------------------------------------------- -include(FindPkgConfig) -find_package(PkgConfig QUIET) +include(CMakeFindDependencyMacro) +# include(FindPkgConfig) +find_dependency(PkgConfig QUIET) if( PKG_CONFIG_EXECUTABLE AND NOT HWLOC_GIVEN_BY_USER ) pkg_search_module(HWLOC hwloc) diff --git a/cmake/FindLAPACK.cmake b/cmake/FindLAPACK.cmake index 284a4529c..3fd738807 100644 --- a/cmake/FindLAPACK.cmake +++ b/cmake/FindLAPACK.cmake @@ -26,6 +26,7 @@ include(CheckFunctionExists) +include(CMakeFindDependencyMacro) # This macro checks for the existence of the combination of fortran libraries # given by _list. If the combination is found, this macro checks (using the @@ -88,7 +89,7 @@ macro(check_lapack_libraries DEFINITIONS LIBRARIES _prefix _name _flags _list _b set(${LIBRARIES} ${_libraries_found}) # Some C++ linkers require the f2c library to link with Fortran libraries. # I do not know which ones, thus I just add the f2c library if it is available. - find_package( F2C QUIET ) + find_dependency( F2C QUIET ) if ( F2C_FOUND ) set(${DEFINITIONS} ${${DEFINITIONS}} ${F2C_DEFINITIONS}) set(${LIBRARIES} ${${LIBRARIES}} ${F2C_LIBRARIES}) @@ -135,9 +136,9 @@ endmacro() # LAPACK requires BLAS if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) - find_package(BLAS) + find_dependency(BLAS) else() - find_package(BLAS REQUIRED) + find_dependency(BLAS REQUIRED) endif() if (NOT BLAS_FOUND) diff --git a/cmake/FindPastix.cmake b/cmake/FindPASTIX.cmake similarity index 96% rename from cmake/FindPastix.cmake rename to cmake/FindPASTIX.cmake index 3b47d5ce3..db1427b0a 100644 --- a/cmake/FindPastix.cmake +++ b/cmake/FindPASTIX.cmake @@ -118,7 +118,7 @@ if( PASTIX_FIND_COMPONENTS ) if (${component} STREQUAL "SCOTCH") set(PASTIX_LOOK_FOR_SCOTCH ON) endif() - if (${component} STREQUAL "SCOTCH") + if (${component} STREQUAL "PTSCOTCH") set(PASTIX_LOOK_FOR_PTSCOTCH ON) endif() if (${component} STREQUAL "METIS") @@ -133,14 +133,14 @@ endif() # Required dependencies # --------------------- - +include(CMakeFindDependencyMacro) if (NOT PASTIX_FIND_QUIETLY) message(STATUS "Looking for PASTIX - Try to detect pthread") endif() if (PASTIX_FIND_REQUIRED) - find_package(Threads REQUIRED QUIET) + find_dependency(Threads REQUIRED QUIET) else() - find_package(Threads QUIET) + find_dependency(Threads QUIET) endif() set(PASTIX_EXTRA_LIBRARIES "") if( THREADS_FOUND ) @@ -198,9 +198,9 @@ if (NOT PASTIX_FIND_QUIETLY) message(STATUS "Looking for PASTIX - Try to detect HWLOC") endif() if (PASTIX_FIND_REQUIRED) - find_package(HWLOC REQUIRED QUIET) + find_dependency(HWLOC REQUIRED QUIET) else() - find_package(HWLOC QUIET) + find_dependency(HWLOC QUIET) endif() # PASTIX depends on BLAS @@ -209,9 +209,9 @@ if (NOT PASTIX_FIND_QUIETLY) message(STATUS "Looking for PASTIX - Try to detect BLAS") endif() if (PASTIX_FIND_REQUIRED) - find_package(BLASEXT REQUIRED QUIET) + find_dependency(BLASEXT REQUIRED QUIET) else() - find_package(BLASEXT QUIET) + find_dependency(BLASEXT QUIET) endif() # Optional dependencies @@ -230,9 +230,9 @@ if (NOT MPI_FOUND AND PASTIX_LOOK_FOR_MPI) set(MPI_C_COMPILER mpicc) endif() if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_MPI) - find_package(MPI REQUIRED QUIET) + find_dependency(MPI REQUIRED QUIET) else() - find_package(MPI QUIET) + find_dependency(MPI QUIET) endif() if (MPI_FOUND) mark_as_advanced(MPI_LIBRARY) @@ -272,10 +272,10 @@ if( NOT STARPU_FOUND AND PASTIX_LOOK_FOR_STARPU) endif() # set the list of optional dependencies we may discover if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_STARPU) - find_package(STARPU ${PASTIX_STARPU_VERSION} REQUIRED + find_dependency(STARPU ${PASTIX_STARPU_VERSION} REQUIRED COMPONENTS ${STARPU_COMPONENT_LIST}) else() - find_package(STARPU ${PASTIX_STARPU_VERSION} + find_dependency(STARPU ${PASTIX_STARPU_VERSION} COMPONENTS ${STARPU_COMPONENT_LIST}) endif() @@ -288,9 +288,9 @@ if (NOT SCOTCH_FOUND AND PASTIX_LOOK_FOR_SCOTCH) message(STATUS "Looking for PASTIX - Try to detect SCOTCH") endif() if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_SCOTCH) - find_package(SCOTCH REQUIRED QUIET) + find_dependency(SCOTCH REQUIRED QUIET) else() - find_package(SCOTCH QUIET) + find_dependency(SCOTCH QUIET) endif() endif() @@ -301,9 +301,9 @@ if (NOT PTSCOTCH_FOUND AND PASTIX_LOOK_FOR_PTSCOTCH) message(STATUS "Looking for PASTIX - Try to detect PTSCOTCH") endif() if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_PTSCOTCH) - find_package(PTSCOTCH REQUIRED QUIET) + find_dependency(PTSCOTCH REQUIRED QUIET) else() - find_package(PTSCOTCH QUIET) + find_dependency(PTSCOTCH QUIET) endif() endif() @@ -314,9 +314,9 @@ if (NOT METIS_FOUND AND PASTIX_LOOK_FOR_METIS) message(STATUS "Looking for PASTIX - Try to detect METIS") endif() if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_METIS) - find_package(METIS REQUIRED QUIET) + find_dependency(METIS REQUIRED QUIET) else() - find_package(METIS QUIET) + find_dependency(METIS QUIET) endif() endif() diff --git a/cmake/FindPTSCOTCH.cmake b/cmake/FindPTSCOTCH.cmake index 51eecf1af..6ccc743e6 100644 --- a/cmake/FindPTSCOTCH.cmake +++ b/cmake/FindPTSCOTCH.cmake @@ -79,20 +79,21 @@ if( PTSCOTCH_FIND_COMPONENTS ) endif() # PTSCOTCH depends on Threads, try to find it +include(CMakeFindDependencyMacro) if (NOT THREADS_FOUND) if (PTSCOTCH_FIND_REQUIRED) - find_package(Threads REQUIRED) + find_dependency(Threads REQUIRED) else() - find_package(Threads) + find_dependency(Threads) endif() endif() # PTSCOTCH depends on MPI, try to find it if (NOT MPI_FOUND) if (PTSCOTCH_FIND_REQUIRED) - find_package(MPI REQUIRED) + find_dependency(MPI REQUIRED) else() - find_package(MPI) + find_dependency(MPI) endif() endif() @@ -148,18 +149,18 @@ else() foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find}) set(PTSCOTCH_${ptscotch_hdr}_DIRS "PTSCOTCH_${ptscotch_hdr}_DIRS-NOTFOUND") find_path(PTSCOTCH_${ptscotch_hdr}_DIRS - NAMES ${ptscotch_hdr} - HINTS ${PTSCOTCH_DIR} - PATH_SUFFIXES "include" "include/scotch") + NAMES ${ptscotch_hdr} + HINTS ${PTSCOTCH_DIR} + PATH_SUFFIXES "include" "include/scotch") mark_as_advanced(PTSCOTCH_${ptscotch_hdr}_DIRS) endforeach() else() foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find}) set(PTSCOTCH_${ptscotch_hdr}_DIRS "PTSCOTCH_${ptscotch_hdr}_DIRS-NOTFOUND") find_path(PTSCOTCH_${ptscotch_hdr}_DIRS - NAMES ${ptscotch_hdr} - HINTS ${_inc_env} - PATH_SUFFIXES "scotch") + NAMES ${ptscotch_hdr} + HINTS ${_inc_env} + PATH_SUFFIXES "scotch") mark_as_advanced(PTSCOTCH_${ptscotch_hdr}_DIRS) endforeach() endif() @@ -171,7 +172,6 @@ foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find}) if (PTSCOTCH_${ptscotch_hdr}_DIRS) list(APPEND PTSCOTCH_INCLUDE_DIRS "${PTSCOTCH_${ptscotch_hdr}_DIRS}") else () - set(PTSCOTCH_INCLUDE_DIRS "PTSCOTCH_INCLUDE_DIRS-NOTFOUND") if (NOT PTSCOTCH_FIND_QUIETLY) message(STATUS "Looking for ptscotch -- ${ptscotch_hdr} not found") endif() @@ -229,16 +229,16 @@ else() foreach(ptscotch_lib ${PTSCOTCH_libs_to_find}) set(PTSCOTCH_${ptscotch_lib}_LIBRARY "PTSCOTCH_${ptscotch_lib}_LIBRARY-NOTFOUND") find_library(PTSCOTCH_${ptscotch_lib}_LIBRARY - NAMES ${ptscotch_lib} - HINTS ${PTSCOTCH_DIR} - PATH_SUFFIXES lib lib32 lib64) + NAMES ${ptscotch_lib} + HINTS ${PTSCOTCH_DIR} + PATH_SUFFIXES lib lib32 lib64) endforeach() else() foreach(ptscotch_lib ${PTSCOTCH_libs_to_find}) set(PTSCOTCH_${ptscotch_lib}_LIBRARY "PTSCOTCH_${ptscotch_lib}_LIBRARY-NOTFOUND") find_library(PTSCOTCH_${ptscotch_lib}_LIBRARY - NAMES ${ptscotch_lib} - HINTS ${_lib_env}) + NAMES ${ptscotch_lib} + HINTS ${_lib_env}) endforeach() endif() endif() @@ -255,7 +255,6 @@ foreach(ptscotch_lib ${PTSCOTCH_libs_to_find}) list(APPEND PTSCOTCH_LIBRARIES "${PTSCOTCH_${ptscotch_lib}_LIBRARY}") list(APPEND PTSCOTCH_LIBRARY_DIRS "${${ptscotch_lib}_lib_path}") else () - list(APPEND PTSCOTCH_LIBRARIES "${PTSCOTCH_${ptscotch_lib}_LIBRARY}") if (NOT PTSCOTCH_FIND_QUIETLY) message(STATUS "Looking for ptscotch -- lib ${ptscotch_lib} not found") endif() diff --git a/cmake/FindScotch.cmake b/cmake/FindSCOTCH.cmake similarity index 99% rename from cmake/FindScotch.cmake rename to cmake/FindSCOTCH.cmake index af00eb0f2..11b971a92 100644 --- a/cmake/FindScotch.cmake +++ b/cmake/FindSCOTCH.cmake @@ -71,11 +71,12 @@ if( SCOTCH_FIND_COMPONENTS ) endif() # SCOTCH may depend on Threads, try to find it +include(CMakeFindDependencyMacro) if (NOT THREADS_FOUND) if (SCOTCH_FIND_REQUIRED) - find_package(Threads REQUIRED) + find_dependency(Threads REQUIRED) else() - find_package(Threads) + find_dependency(Threads) endif() endif() diff --git a/cmake/FindTriSYCL.cmake b/cmake/FindTriSYCL.cmake index 278596865..810423907 100644 --- a/cmake/FindTriSYCL.cmake +++ b/cmake/FindTriSYCL.cmake @@ -67,8 +67,9 @@ set(CXX_STANDARD_REQUIRED ON) # Find OpenCL package +include(CMakeFindDependencyMacro) if(TRISYCL_OPENCL) - find_package(OpenCL REQUIRED) + find_dependency(OpenCL REQUIRED) if(UNIX) set(BOOST_COMPUTE_INCPATH /usr/include/compute CACHE PATH "Path to Boost.Compute headers (default is: /usr/include/compute)") @@ -77,11 +78,11 @@ endif() # Find OpenMP package if(TRISYCL_OPENMP) - find_package(OpenMP REQUIRED) + find_dependency(OpenMP REQUIRED) endif() # Find Boost -find_package(Boost 1.58 REQUIRED COMPONENTS chrono log) +find_dependency(Boost 1.58 REQUIRED COMPONENTS chrono log) # If debug or trace we need boost log if(TRISYCL_DEBUG OR TRISYCL_DEBUG_STRUCTORS OR TRISYCL_TRACE_KERNEL) @@ -90,7 +91,7 @@ else() set(LOG_NEEDED OFF) endif() -find_package(Threads REQUIRED) +find_dependency(Threads REQUIRED) # Find triSYCL directory if (TRISYCL_INCLUDES AND TRISYCL_LIBRARIES)