From 3a4451becda7f76a8254da2c1118a5586819c50c Mon Sep 17 00:00:00 2001 From: Luca Bertagna Date: Wed, 7 Feb 2024 10:15:12 -0700 Subject: [PATCH] Prefer HINTS to PATHS in cmake find modules In the list of paths searched by CMake, the content of the HINTS arg appears early on, while the content of PATHS is down the list. In particular, between HINTS and PATHS in that list there are - system paths - cmake package registry These can cause system installation of a tpl or previous installation of a tpl to be picked up instead of the passed PATHS arg --- components/cmake/modules/FindCsmShare.cmake | 2 +- components/cmake/modules/FindMCT.cmake | 4 ++-- components/cmake/modules/FindNETCDF.cmake | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/cmake/modules/FindCsmShare.cmake b/components/cmake/modules/FindCsmShare.cmake index 275a29b059eb..9d6763a83d7b 100644 --- a/components/cmake/modules/FindCsmShare.cmake +++ b/components/cmake/modules/FindCsmShare.cmake @@ -24,7 +24,7 @@ endif() set(CSM_SHARE "${INSTALL_SHAREDPATH}/${COMP_INTERFACE}/${ESMFDIR}/${NINST_VALUE}/csm_share") # Look for libcsm_share in the complex path we built above -find_library(CSM_SHARE_LIB csm_share REQUIRED PATHS ${CSM_SHARE}) +find_library(CSM_SHARE_LIB csm_share REQUIRED HINTS ${CSM_SHARE}) set(CSM_LIBS ${CSM_SHARE_LIB};mct;spio) set(CSM_INCLS ${CSM_SHARE}) diff --git a/components/cmake/modules/FindMCT.cmake b/components/cmake/modules/FindMCT.cmake index 068aead89f7f..766cdb26893e 100644 --- a/components/cmake/modules/FindMCT.cmake +++ b/components/cmake/modules/FindMCT.cmake @@ -16,8 +16,8 @@ if (TARGET mct) endif() # Look for libmct in INSTALL_SHAREDPATH/lib -find_library(MCT_LIB mct REQUIRED PATHS ${INSTALL_SHAREDPATH}/lib) -find_library(MPEU_LIB mpeu REQUIRED PATHS ${INSTALL_SHAREDPATH}/lib $ENV{mct_ROOT}) +find_library(MCT_LIB mct REQUIRED HINTS ${INSTALL_SHAREDPATH}/lib) +find_library(MPEU_LIB mpeu REQUIRED HINTS ${INSTALL_SHAREDPATH}/lib $ENV{mct_ROOT}) # Create the interface library, and set target properties add_library(mct INTERFACE) diff --git a/components/cmake/modules/FindNETCDF.cmake b/components/cmake/modules/FindNETCDF.cmake index 90d4abb3fb4f..cd3bfc06799b 100644 --- a/components/cmake/modules/FindNETCDF.cmake +++ b/components/cmake/modules/FindNETCDF.cmake @@ -24,7 +24,7 @@ function(get_netcdf_libs ncpath nfpath) # Fall back to find_library if (NOT nclibs) - find_library(nclibs_temp netcdf REQUIRED PATHS ${ncpath}/lib ${ncpath}/lib64) + find_library(nclibs_temp netcdf REQUIRED HINTS ${ncpath}/lib ${ncpath}/lib64) set(nclibs ${nclibs_temp}) endif() @@ -34,7 +34,7 @@ function(get_netcdf_libs ncpath nfpath) endif() if (NOT nflibs) - find_library(nflibs_temp netcdff REQUIRED PATHS ${nfpath}/lib ${nfpath}/lib64) + find_library(nflibs_temp netcdff REQUIRED HINTS ${nfpath}/lib ${nfpath}/lib64) set(nflibs ${nflibs_temp}) endif() @@ -53,8 +53,8 @@ function(create_netcdf_target) # Pnetcdf is optional, and only if not running serial if (NOT MPILIB STREQUAL mpi-serial) if (PNETCDF_PATH) - find_library(pnetcdf_lib pnetcdf REQUIRED PATHS ${PNETCDF_PATH}/lib) - find_path (pnetcdf_incdir pnetcdf.h REQUIRED PATHS ${PNETCDF_PATH}/include) + find_library(pnetcdf_lib pnetcdf REQUIRED HINTS ${PNETCDF_PATH}/lib) + find_path (pnetcdf_incdir pnetcdf.h REQUIRED HINTS ${PNETCDF_PATH}/include) endif() endif() @@ -71,8 +71,8 @@ function(create_netcdf_target) endif () get_netcdf_libs(${NETCDF_C_PATH} ${NETCDF_FORTRAN_PATH}) - find_path (netcdf_c_incdir netcdf.h REQUIRED PATHS ${NETCDF_C_PATH}/include) - find_path (netcdf_f_incdir netcdf.inc REQUIRED PATHS ${NETCDF_FORTRAN_PATH}/include) + find_path (netcdf_c_incdir netcdf.h REQUIRED HINTS ${NETCDF_C_PATH}/include) + find_path (netcdf_f_incdir netcdf.inc REQUIRED HINTS ${NETCDF_FORTRAN_PATH}/include) elseif (NETCDF_FORTRAN_PATH) message(FATAL_ERROR "NETCDF_FORTRAN_PATH specified without NETCDF_C_PATH") @@ -84,8 +84,8 @@ function(create_netcdf_target) endif () get_netcdf_libs(${NETCDF_PATH} ${NETCDF_PATH}) - find_path(netcdf_c_incdir netcdf.h REQUIRED PATHS ${NETCDF_PATH}/include) - find_path(netcdf_f_incdir netcdf.inc REQUIRED PATHS ${NETCDF_PATH}/include) + find_path(netcdf_c_incdir netcdf.h REQUIRED HINTS ${NETCDF_PATH}/include) + find_path(netcdf_f_incdir netcdf.inc REQUIRED HINTS ${NETCDF_PATH}/include) else() message(FATAL_ERROR "NETCDF not found: Define NETCDF_PATH or NETCDF_C_PATH and NETCDF_FORTRAN_PATH in config_machines.xml or config_compilers.xml")