From cd763be63360e7424194677365591e0f919df952 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Thu, 25 Apr 2024 16:20:48 -0700 Subject: [PATCH] Replace manual config queries with list constructed variable query --- cmake/modules/FindnetCDF-Fortran.cmake | 19 +++++++++++--- cmake/modules/FindnetCDF.cmake | 35 +++++++++++++++++++------- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/cmake/modules/FindnetCDF-Fortran.cmake b/cmake/modules/FindnetCDF-Fortran.cmake index 0ead239a57..045a31585d 100644 --- a/cmake/modules/FindnetCDF-Fortran.cmake +++ b/cmake/modules/FindnetCDF-Fortran.cmake @@ -43,7 +43,6 @@ else() execute_process( COMMAND ${NETCDF-FORTRAN_PROGRAM} --prefix OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF-Fortran_PREFIX ) execute_process( COMMAND ${NETCDF-FORTRAN_PROGRAM} --flibs OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF-Fortran_FLIBS ) execute_process( COMMAND ${NETCDF-FORTRAN_PROGRAM} --version OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF-Fortran_VERSION_RAW ) - execute_process( COMMAND ${NETCDF-FORTRAN_PROGRAM} --has-nc4 OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF-Fortran_NC4_YES ) # check for large file support find_file( netCDF-Fortran_INCLUDE_FILE netcdf.inc ${netCDF-Fortran_INCLUDE_DIR} ) @@ -59,11 +58,25 @@ else() string( REPLACE " " ";" netCDF-Fortran_VERSION_LIST ${netCDF-Fortran_VERSION_RAW} ) list( GET netCDF-Fortran_VERSION_LIST -1 netCDF-Fortran_VERSION ) - # Convert to YES/NO - Note cannot be generator expression if you want to use it during configuration time - string( TOUPPER ${netCDF-Fortran_NC4_YES} netCDF-Fortran_NC4 ) + # These do not pull all options available from nc-config out, but rather mirrors what is available from netCDFConfig.cmake.in + set( + netCDF-Fortran_QUERY_YES_OPTIONS + dap + nc2 + nc4 + f90 + f03 + ) set( netCDF-Fortran_DEFINITIONS ) set( netCDF-Fortran_LIBRARY_DIR ${netCDF-Fortran_PREFIX}/lib ) + foreach( NF_QUERY ${netCDF-Fortran_QUERY_YES_OPTIONS} ) + execute_process( COMMAND ${NETCDF-FORTRAN_PROGRAM} --has-${NF_QUERY} OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF-Fortran_${NF_QUERY}_LOWERCASE ) + string( TOUPPER ${NF_QUERY} NF_QUERY_UPPERCASE ) + string( TOUPPER ${netCDF-Fortran_${NF_QUERY}_LOWERCASE} NF_ANSWER_UPPERCASE ) + # Convert to netCDF-Fortran_HAS_* = YES/NO - Note this cannot be generator expression if you want to use it during configuration time + set( netCDF-Fortran_HAS_${NF_QUERY_UPPERCASE} ${NF_ANSWER_UPPERCASE} ) + endforeach() set( netCDF-Fortran_LIBRARIES $<$:${netCDF-Fortran_FLIBS}> diff --git a/cmake/modules/FindnetCDF.cmake b/cmake/modules/FindnetCDF.cmake index 518ec95348..ab58103148 100644 --- a/cmake/modules/FindnetCDF.cmake +++ b/cmake/modules/FindnetCDF.cmake @@ -45,9 +45,32 @@ else() execute_process( COMMAND ${NETCDF_PROGRAM} --prefix OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_PREFIX ) execute_process( COMMAND ${NETCDF_PROGRAM} --libs OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_CLIBS ) execute_process( COMMAND ${NETCDF_PROGRAM} --version OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_VERSION_RAW ) - execute_process( COMMAND ${NETCDF_PROGRAM} --has-nc4 OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_NC4_YES ) - execute_process( COMMAND ${NETCDF_PROGRAM} --has-pnetcdf OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_PNETCDF_YES ) - execute_process( COMMAND ${NETCDF_PROGRAM} --has-parallel OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_PARALLEL_YES ) + + # These do not pull all options available from nc-config out, but rather mirrors what is available from netCDFConfig.cmake.in + set( + netCDF_QUERY_YES_OPTIONS + dap + dap2 + dap4 + nc2 + nc4 + hdf5 + hdf4 + pnetcdf + parallel + + # These are not part of the config but used in this to provide the properly linking + szlib + zstd + ) + + foreach( NC_QUERY ${netCDF_QUERY_YES_OPTIONS} ) + execute_process( COMMAND ${NETCDF_PROGRAM} --has-${NC_QUERY} OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_${NC_QUERY}_LOWERCASE ) + string( TOUPPER ${NC_QUERY} NC_QUERY_UPPERCASE ) + string( TOUPPER ${netCDF_${NC_QUERY}_LOWERCASE} NC_ANSWER_UPPERCASE ) + # Convert to netCDF_HAS_* = YES/NO - Note this cannot be generator expression if you want to use it during configuration time + set( netCDF_HAS_${NC_QUERY_UPPERCASE} ${NC_ANSWER_UPPERCASE} ) + endforeach() # check for large file support find_file( netCDF_INCLUDE_FILE netcdf.h ${netCDF_INCLUDE_DIR} ) @@ -63,13 +86,7 @@ else() string( REPLACE " " ";" netCDF_VERSION_LIST ${netCDF_VERSION_RAW} ) list( GET netCDF_VERSION_LIST -1 netCDF_VERSION ) - # Convert to YES/NO - Note cannot be generator expression if you want to use it during configuration time - string( TOUPPER ${netCDF_NC4_YES} netCDF_NC4 ) - string( TOUPPER ${netCDF_PNETCDF_YES} netCDF_PNETCDF ) - string( TOUPPER ${netCDF_PARALLEL_YES} netCDF_PARALLEL ) - set( netCDF_DEFINITIONS ) - set( netCDF_LIBRARIES # All supported language variants will need this regardless - this may conflict with the RPATH in any # supplemental packages so be careful to use compatible langauge versions of netCDF