Skip to content

Commit

Permalink
Prefer HINTS to PATHS in cmake find modules
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bartgol committed Feb 7, 2024
1 parent 075645f commit 3a4451b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion components/cmake/modules/FindCsmShare.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
4 changes: 2 additions & 2 deletions components/cmake/modules/FindMCT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions components/cmake/modules/FindNETCDF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 3a4451b

Please sign in to comment.