Skip to content

Commit f7d76ba

Browse files
authored
Cmake update (LLNL#5)
* Modify how cmake find/use NetCDF * Clean up cmake scripts
1 parent 8b80e6a commit f7d76ba

File tree

6 files changed

+102
-32
lines changed

6 files changed

+102
-32
lines changed

CMakeLists.txt

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
cmake_minimum_required(VERSION 3.1)
2-
project (PFiSM)
2+
project (AMPE)
33

4-
set (CMAKE_CXX_STANDARD 11)
4+
set(CMAKE_CXX_STANDARD 11)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_CXX_EXTENSIONS OFF)
77

8-
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
8+
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules)
99

10-
#set(MPI_CXX_COMPILER CMAKE_CXX_COMPILER)
1110
find_package(MPI)
1211
if(MPI_FOUND)
1312
message(STATUS
@@ -40,7 +39,9 @@ endif()
4039
link_directories( ${SAMRAI_DIR}/lib )
4140
link_directories( ${HYPRE_DIR}/lib )
4241
link_directories( ${SUNDIALS_DIR}/lib )
43-
link_directories( ${NETCDF_DIR}/lib )
42+
43+
find_package(netCDF REQUIRED)
44+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
4445

4546
set( PROJECT_LINK_LIBS1 libSAMRAI_tbox.a )
4647
set( PROJECT_LINK_LIBS2 libSAMRAI_math.a )
@@ -66,13 +67,12 @@ set( PROJECT_LINK_LIBS_HYPRE libHYPRE.so )
6667
set( PROJECT_LINK_LIBS_CVODE libsundials_cvode.a )
6768
set( PROJECT_LINK_LIBS_CPODES libsundials_cpodes.a )
6869

69-
set( PROJECT_LINK_LIBS_NETCDFCXX libnetcdf_c++4.a )
70-
set( PROJECT_LINK_LIBS_NETCDF libnetcdf.a )
70+
set( PROJECT_LINK_LIBS_NETCDFCXX NetCDF::NetCDF )
71+
set( PROJECT_LINK_LIBS_NETCDF NetCDF::NetCDF )
7172

7273
include_directories( ${SAMRAI_DIR}/include )
7374
include_directories( ${HYPRE_DIR}/include )
7475
include_directories( ${SUNDIALS_DIR}/include )
75-
include_directories( ${NETCDF_DIR}/include )
7676

7777
enable_testing()
7878

@@ -86,6 +86,3 @@ set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -std=c++11")
8686
add_subdirectory(source)
8787

8888
add_subdirectory(tests)
89-
90-
91-

cmake_modules/FindnetCDF.cmake

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#[==[
2+
Provides the following variables:
3+
4+
* `NetCDF_FOUND`: Whether NetCDF was found or not.
5+
* `NetCDF_INCLUDE_DIRS`: Include directories necessary to use NetCDF.
6+
* `NetCDF_LIBRARIES`: Libraries necessary to use NetCDF.
7+
* `NetCDF_VERSION`: The version of NetCDF found.
8+
* `NetCDF::NetCDF`: A target to use with `target_link_libraries`.
9+
Adapted from https://github.com/Kitware/VTK/blob/master/CMake/FindNetCDF.cmake
10+
Downloaded 10/29/2019
11+
#]==]
12+
13+
# Try to find a CMake-built NetCDF.
14+
message(STATUS "Searching for NetCDF...")
15+
find_package(netCDF CONFIG QUIET)
16+
if (netCDF_FOUND)
17+
# Forward the variables in a consistent way.
18+
set(NetCDF_FOUND "${netCDF_FOUND}")
19+
set(NetCDF_INCLUDE_DIRS "${netCDF_INCLUDE_DIR}")
20+
set(NetCDF_LIBRARIES "${netCDF_LIBRARIES}")
21+
set(NetCDF_VERSION "${NetCDFVersion}")
22+
if (NOT TARGET NetCDF::NetCDF)
23+
add_library(NetCDF::NetCDF INTERFACE IMPORTED)
24+
set_target_properties(NetCDF::NetCDF PROPERTIES
25+
INTERFACE_LINK_LIBRARIES "${NetCDF_LIBRARIES}")
26+
endif ()
27+
# Skip the rest of the logic in this file.
28+
return ()
29+
endif ()
30+
31+
message(STATUS "Searching for PkgConfig...")
32+
find_package(PkgConfig QUIET)
33+
if (PkgConfig_FOUND)
34+
pkg_check_modules(_NetCDF QUIET netcdf IMPORTED_TARGET)
35+
if (_NetCDF_FOUND)
36+
# Forward the variables in a consistent way.
37+
set(NetCDF_FOUND "${_NetCDF_FOUND}")
38+
set(NetCDF_INCLUDE_DIRS "${_NetCDF_INCLUDE_DIRS}")
39+
set(NetCDF_LIBRARIES "${_NetCDF_LIBRARIES}")
40+
set(NetCDF_VERSION "${_NetCDF_VERSION}")
41+
if (NOT TARGET NetCDF::NetCDF)
42+
add_library(NetCDF::NetCDF INTERFACE IMPORTED)
43+
set_target_properties(NetCDF::NetCDF PROPERTIES
44+
INTERFACE_LINK_LIBRARIES "PkgConfig::_NetCDF")
45+
endif ()
46+
message(STATUS "NetCDF_LIBRARIES: ${NetCDF_LIBRARIES}")
47+
# Skip the rest of the logic in this file.
48+
return ()
49+
endif ()
50+
endif ()
51+
52+
message(STATUS "Searching for path to NetCDF include...")
53+
find_path(NetCDF_INCLUDE_DIR
54+
NAMES netcdf.h
55+
DOC "netcdf include directories")
56+
mark_as_advanced(NetCDF_INCLUDE_DIR)
57+
58+
find_library(NetCDF_LIBRARY
59+
NAMES netcdf
60+
DOC "netcdf library")
61+
mark_as_advanced(NetCDF_LIBRARY)
62+
63+
if (NetCDF_INCLUDE_DIR)
64+
file(STRINGS "${NetCDF_INCLUDE_DIR}/netcdf_meta.h" _netcdf_version_lines
65+
REGEX "#define[ \t]+NC_VERSION_(MAJOR|MINOR|PATCH|NOTE)")
66+
string(REGEX REPLACE ".*NC_VERSION_MAJOR *\([0-9]*\).*" "\\1" _netcdf_version_major "${_netcdf_version_lines}")
67+
string(REGEX REPLACE ".*NC_VERSION_MINOR *\([0-9]*\).*" "\\1" _netcdf_version_minor "${_netcdf_version_lines}")
68+
string(REGEX REPLACE ".*NC_VERSION_PATCH *\([0-9]*\).*" "\\1" _netcdf_version_patch "${_netcdf_version_lines}")
69+
string(REGEX REPLACE ".*NC_VERSION_NOTE *\"\([^\"]*\)\".*" "\\1" _netcdf_version_note "${_netcdf_version_lines}")
70+
set(NetCDF_VERSION "${_netcdf_version_major}.${_netcdf_version_minor}.${_netcdf_version_patch}${_netcdf_version_note}")
71+
unset(_netcdf_version_major)
72+
unset(_netcdf_version_minor)
73+
unset(_netcdf_version_patch)
74+
unset(_netcdf_version_note)
75+
unset(_netcdf_version_lines)
76+
endif ()
77+
78+
include(FindPackageHandleStandardArgs)
79+
find_package_handle_standard_args(NetCDF
80+
REQUIRED_VARS NetCDF_LIBRARY NetCDF_INCLUDE_DIR
81+
VERSION_VAR NetCDF_VERSION)
82+
83+
if (NetCDF_FOUND)
84+
set(NetCDF_INCLUDE_DIRS "${NetCDF_INCLUDE_DIR}")
85+
set(NetCDF_LIBRARIES "${NetCDF_LIBRARY}")
86+
message(STATUS "NetCDF libraries: ${NetCDF_LIBRARIES}")
87+
if (NOT TARGET NetCDF::NetCDF)
88+
add_library(NetCDF::NetCDF UNKNOWN IMPORTED)
89+
set_target_properties(NetCDF::NetCDF PROPERTIES
90+
IMPORTED_LOCATION "${NetCDF_LIBRARY}"
91+
INTERFACE_INCLUDE_DIRECTORIES "${NetCDF_INCLUDE_DIR}")
92+
endif ()
93+
endif ()

scripts/cades_condo_cmake_2d

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ cmake -DCMAKE_CXX_COMPILER=mpiCC -DCMAKE_C_COMPILER=mpicc \
1111
-DSAMRAI_DIR=$PWD/or-condo-login-mpiCC-mpif77-opt/base/SAMRAI \
1212
-DHYPRE_DIR=$HOME/hypre/hypre-2.11.1/src/hypre \
1313
-DSUNDIALS_DIR=$PWD/or-condo-login-mpiCC-mpif77-opt/base/sundials \
14-
-DNETCDF_DIR=$NETCDF_DIR \
1514
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
1615
-DNDIM="2" \
1716
..

scripts/cades_condo_cmake_3d

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ cmake -DCMAKE_CXX_COMPILER=mpiCC -DCMAKE_C_COMPILER=mpicc \
1111
-DSAMRAI_DIR=$PWD/or-condo-login-mpiCC-mpif77-opt/base/SAMRAI \
1212
-DHYPRE_DIR=$HOME/hypre/hypre-2.11.1/src/hypre \
1313
-DSUNDIALS_DIR=$PWD/or-condo-login-mpiCC-mpif77-opt/base/sundials \
14-
-DNETCDF_DIR=$NETCDF_DIR \
1514
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
1615
-DNDIM="3" \
1716
..

scripts/quartz_cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ cmake -DCMAKE_CXX_COMPILER=mpic++ -DCMAKE_C_COMPILER=mpicc \
1212
-DSAMRAI_DIR=$PWD/quartz-mpic++-mpif77-opt/base/SAMRAI \
1313
-DHYPRE_DIR=/usr/gapps/phasefield/hypre/2.15.0 \
1414
-DSUNDIALS_DIR=$PWD/quartz-mpic++-mpif77-opt/base/sundials \
15-
-DNETCDF_DIR=/usr/gapps/phasefield/lib/netcdf-cxx-intel \
1615
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
16+
-DCMAKE_PREFIX_PATH=/usr/gapps/phasefield/lib/netcdf-cxx-intel \
1717
-DNDIM="2" \
1818
..
1919

scripts/titan_cmake

-18
This file was deleted.

0 commit comments

Comments
 (0)