From a65eed86e051721595df92c04cd7a15ff2fde4ba Mon Sep 17 00:00:00 2001 From: Carlisle Wishard Date: Fri, 14 Oct 2022 15:53:41 -0400 Subject: [PATCH] Added the NetCDF libraries --- CMakeLists.txt | 2 ++ cmake/Modules/SetUpNetCDF.cmake | 9 +++++++++ src/CMakeLists.txt | 8 ++++++++ 3 files changed, 19 insertions(+) create mode 100644 cmake/Modules/SetUpNetCDF.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 93c669a3d..df809a500 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ INCLUDE(${CMAKE_MODULE_PATH}/SetFortranFlags.cmake) # about Fortran. INCLUDE(${CMAKE_MODULE_PATH}/SetParallelizationLibrary.cmake) +INCLUDE(${CMAKE_MODULE_PATH}/SetUpNetCDF.cmake) + # There is an error in CMAKE with this flag for pgf90. Unset it GET_FILENAME_COMPONENT(FCNAME ${CMAKE_Fortran_COMPILER} NAME) IF(FCNAME STREQUAL "pgf90") diff --git a/cmake/Modules/SetUpNetCDF.cmake b/cmake/Modules/SetUpNetCDF.cmake new file mode 100644 index 000000000..eac9cb543 --- /dev/null +++ b/cmake/Modules/SetUpNetCDF.cmake @@ -0,0 +1,9 @@ +# Find NetCDF if not already found +IF(NOT NETCDF_FOUND) + ENABLE_LANGUAGE(C) # Some libraries need a C compiler to find + FIND_PACKAGE(NETCDF REQUIRED) + SET(NETCDF_FOUND TRUE CACHE INTERNAL "NETCDF was found" FORCE) + SET(NETCDFFORTRAN_FOUND TRUE CACHE INTERNAL "NETCDFFORTRAN was found" FORCE) + SET(NETCDF_LIBRARIES ${NETCDF_LIBRARIES} CACHE INTERNAL "NETCDF LIBS" FORCE) + SET(NETCDFFORTRAN_LIBRARIES ${NETCDFFORTRAN_LIBRARIES} CACHE INTERNAL "NETCDFFORTRAN LIBS" FORCE) +ENDIF(NOT NETCDF_FOUND) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ee3c64528..7b4960f43 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -97,6 +97,14 @@ SET(FOO_src ${SRC}/discard/discard.f90 # Define the executable in terms of the source files ADD_EXECUTABLE(${FOOEXE} ${FOO_src}) +##################################################### +# Add the needed libraries and special compiler flags +##################################################### + +# Uncomment if you need to link to BLAS and LAPACK +TARGET_LINK_LIBRARIES(${FOOEXE} ${NETCDF_LIBRARIES} + ${NETCDFFORTRAN_LIBRARIES}) + ##################################### # Tell how to install this executable #####################################