Skip to content

Commit 0788ac8

Browse files
authored
Install cmake module files (#282)
* copies FindESMF.cmake into cmake directory in installation
1 parent 82ba326 commit 0788ac8

File tree

7 files changed

+93
-1
lines changed

7 files changed

+93
-1
lines changed

build/common.mk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,16 @@ else
552552
export ESMF_INSTALL_DOCDIR_ABSPATH = $(ESMF_INSTALL_DOCDIR)
553553
endif
554554

555+
ifndef ESMF_INSTALL_CMAKEDIR
556+
ESMF_INSTALL_CMAKEDIR := cmake
557+
endif
558+
pathtype := $(shell $(ESMF_DIR)/scripts/pathtype $(ESMF_INSTALL_CMAKEDIR))
559+
ifeq ($(pathtype),rel)
560+
export ESMF_INSTALL_CMAKEDIR_ABSPATH = $(ESMF_INSTALL_PREFIX_ABSPATH)/$(ESMF_INSTALL_CMAKEDIR)
561+
else
562+
export ESMF_INSTALL_CMAKEDIR_ABSPATH = $(ESMF_INSTALL_CMAKEDIR)
563+
endif
564+
555565
#-------------------------------------------------------------------------------
556566
# Set ESMFMKFILE here in order to be available for installcheck target
557567
#-------------------------------------------------------------------------------
@@ -654,6 +664,9 @@ ESMF_APPSDIR = $(ESMF_BUILD)/apps/apps$(ESMF_BOPT)/$(ESMF_OS).$(ESMF_COMPILE
654664
# unified nuopc executable directory
655665
ESMF_ESMXDIR = $(ESMF_BUILD)/src/addon/ESMX
656666

667+
# cmake modules directory
668+
ESMF_CMAKEDIR = $(ESMF_DIR)/cmake
669+
657670
# include file directory
658671
ESMF_INCDIR = $(ESMF_BUILD)/src/include
659672

cmake/FindESMF.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212
# Set ESMFMKFILE as defined by system env variable. If it's not explicitly set
1313
# try to find esmf.mk file in default locations (ESMF_ROOT, CMAKE_PREFIX_PATH,
1414
# etc)
15+
16+
# - Common Usage
17+
#
18+
# Where to look for this FindESMF.cmake file
19+
# list(APPEND CMAKE_MODULE_PATH "<PATH_TO_THIS_FILE>")
20+
# <PATH_TO_THIS_FILE> is to be replaced with the directory for this file
21+
#
22+
# How to locate ESMF libraries and create target
23+
# find_package(ESMF <X.Y.Z> MODULE REQUIRED)
24+
# <X.Y.Z> is to be replaced with the minimum version required
25+
#
26+
# How to link targets
27+
# target_link_libraries(<CMAKE_TARGET> PUBLIC ESMF::ESMF)
28+
# <CMAKE_TARGET> is to be replaced with your CMake target
29+
1530
if(NOT DEFINED ESMFMKFILE)
1631
if(NOT DEFINED ENV{ESMFMKFILE})
1732
find_path(ESMFMKFILE_PATH esmf.mk PATH_SUFFIXES lib lib64)

cmake/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# CMake Modules Provided by ESMF
2+
3+
The ESMF team provides CMake[1] modules that are useful when ESMF is needed
4+
within a CMake based build system. These modules can find libraries, create
5+
targets, and set variables within the scope of a CMake build. They may be
6+
used as is or customized for application specific build systems. Typically,
7+
CMake module files are copied into a project and maintained along with the
8+
project's build system. For more information about installing the provided
9+
modules see the ESMF User's Guide[2].
10+
11+
Provided modules:
12+
13+
- FindESMF.cmake
14+
15+
### FindESMF.cmake
16+
17+
The FindESMF.cmake module provided by ESMF utilizes a CMake variable,
18+
named ESMFMKFILE, to locate the esmf.mk file. The esmf.mk file is parsed to locate
19+
ESMF libraries and create CMake targets for ESMF. If the ESMF library is not
20+
found then ESMF_FOUND is set to FALSE, a warning is displayed, and find_package
21+
fails (when REQUIRED is set).
22+
23+
If the ESMFMKFILE variable is not set then FindESMF.cmake will look for an
24+
environment variable with the same name. If ESMFMKFILE is not set in either
25+
context then CMake will search default paths, including ESMF_ROOT, for the
26+
esmf.mk file.
27+
28+
Usage in CMake:
29+
```
30+
# Where to look for the FindESMF.cmake file
31+
# <PATH_TO_FINDESMF> is to be replaced with the location of FindESMF.cmake
32+
33+
list(APPEND CMAKE_MODULE_PATH "<PATH_TO_FINDESMF>")
34+
35+
# How to locate ESMF libraries and create target
36+
# <X.Y.Z> is to be replaced with the minimum version required
37+
38+
find_package(ESMF <X.Y.Z> MODULE REQUIRED)
39+
40+
# How to link targets
41+
# <CMAKE_TARGET> is to be replaced with your CMake target
42+
43+
target_link_libraries(<CMAKE_TARGET> PUBLIC ESMF::ESMF)
44+
```
45+
46+
## Links
47+
48+
- [1] https://cmake.org/cmake/help/book/mastering-cmake/index.html
49+
- [2] https://earthsystemmodeling.org/doc/

makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ endif
337337
-@echo "ESMF_INSTALL_LIBDIR: $(ESMF_INSTALL_LIBDIR)"
338338
-@echo "ESMF_INSTALL_BINDIR: $(ESMF_INSTALL_BINDIR)"
339339
-@echo "ESMF_INSTALL_DOCDIR: $(ESMF_INSTALL_DOCDIR)"
340+
-@echo "ESMF_INSTALL_CMAKEDIR: $(ESMF_INSTALL_CMAKEDIR)"
340341
-@echo " "
341342
-@echo "--------------------------------------------------------------"
342343
-@echo " * ESMF Benchmark directory and parameters *"
@@ -479,6 +480,7 @@ endif
479480
-@echo "ESMF_APPSDIR=$(ESMF_APPSDIR)" >> $(MKINFO)
480481
-@echo "ESMF_LIBSDIR=$(ESMF_LIBDIR)" >> $(MKINFO)
481482
-@echo "ESMF_ESMXDIR=$(ESMF_ESMXDIR)" >> $(MKINFO)
483+
-@echo "ESMF_CMAKEDIR=$(ESMF_CMAKEDIR)" >> $(MKINFO)
482484
-@echo "" >> $(MKINFO)
483485
-@echo "" >> $(MKINFO)
484486
-@echo "ESMF_F90COMPILER=$(ESMF_F90COMPILER)" >> $(MKINFO)
@@ -772,7 +774,7 @@ envdump:
772774

773775
# Rewrite esmf.mk during installation to ensure correct installation paths are encoded
774776
install_info_mk:
775-
$(MAKE) info_mk ESMF_APPSDIR=$(ESMF_INSTALL_BINDIR_ABSPATH) ESMF_LDIR=$(ESMF_INSTALL_LIBDIR_ABSPATH) ESMF_LIBDIR=$(ESMF_INSTALL_LIBDIR_ABSPATH) ESMF_ESMXDIR=$(ESMF_INSTALL_HEADERDIR_ABSPATH)/ESMX ESMF_MODDIR=$(ESMF_INSTALL_MODDIR_ABSPATH) ESMF_INCDIR=$(ESMF_INSTALL_HEADERDIR_ABSPATH)
777+
$(MAKE) info_mk ESMF_APPSDIR=$(ESMF_INSTALL_BINDIR_ABSPATH) ESMF_LDIR=$(ESMF_INSTALL_LIBDIR_ABSPATH) ESMF_LIBDIR=$(ESMF_INSTALL_LIBDIR_ABSPATH) ESMF_ESMXDIR=$(ESMF_INSTALL_HEADERDIR_ABSPATH)/ESMX ESMF_CMAKEDIR=$(ESMF_INSTALL_CMAKEDIR_ABSPATH) ESMF_MODDIR=$(ESMF_INSTALL_MODDIR_ABSPATH) ESMF_INCDIR=$(ESMF_INSTALL_HEADERDIR_ABSPATH)
776778

777779
# Relink apps during installation to ensure correct shared library location is encoded
778780
install_apps:
@@ -811,6 +813,8 @@ install: envdump
811813
cp -f $(ESMF_BUILD)/src/include/ESMC_*.h $(ESMF_INSTALL_HEADERDIR_ABSPATH)
812814
cp -f $(ESMF_DIR)/build_config/$(ESMF_OS).$(ESMF_COMPILER).$(ESMF_SITE)/ESMC_Conf.h $(ESMF_INSTALL_HEADERDIR_ABSPATH)
813815
cp -fr $(ESMF_ESMXDIR) $(ESMF_INSTALL_HEADERDIR_ABSPATH)
816+
mkdir -p $(ESMF_INSTALL_CMAKEDIR_ABSPATH)
817+
cp -f $(ESMF_CMAKEDIR)/*.cmake $(ESMF_INSTALL_CMAKEDIR_ABSPATH)
814818
mkdir -p $(ESMF_INSTALL_MODDIR_ABSPATH)
815819
cp -f $(ESMF_MODDIR)/*.mod $(ESMF_INSTALL_MODDIR_ABSPATH)
816820
mkdir -p $(ESMF_INSTALL_LIBDIR_ABSPATH)

src/doc/ESMF_builddetail.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ \subsubsection{Customizing the {\tt build\_rules.mk} fragment}
279279
\item[ESMF\_INCDIR]
280280
\item[ESMF\_INSTALL\_BINDIR]
281281
\item[ESMF\_INSTALL\_BINDIR\_ABSPATH]
282+
\item[ESMF\_INSTALL\_CMAKEDIR]
283+
\item[ESMF\_INSTALL\_CMAKEDIR\_ABSPATH]
282284
\item[ESMF\_INSTALL\_DOCDIR]
283285
\item[ESMF\_INSTALL\_DOCDIR\_ABSPATH]
284286
\item[ESMF\_INSTALL\_HEADERDIR]

src/doc/ESMF_install.tex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,13 @@ \subsection{ESMF Environment Variables}
959959
location can be specified as absolute path (starting with "/") or relative to
960960
{\tt ESMF\_INSTALL\_PREFIX}.
961961

962+
\item[ESMF\_INSTALL\_CMAKEDIR]
963+
Possible value: {\em relative or absolute path}
964+
965+
Location into which to install the CMake module files during installation. This
966+
location can be specified as absolute path (starting with "/") or relative to
967+
{\tt ESMF\_INSTALL\_PREFIX}.
968+
962969
\item[ESMF\_INSTALL\_PREFIX]
963970
Possible value: {\em relative or absolute path}
964971

@@ -1322,6 +1329,7 @@ \subsection{Installing the ESMF}
13221329
\item {\tt ESMF\_INSTALL\_MODDIR} -- where to install Fortran module files.
13231330
\item {\tt ESMF\_INSTALL\_BINDIR} -- where to install application files.
13241331
\item {\tt ESMF\_INSTALL\_DOCDIR} -- where to install documentation files.
1332+
\item {\tt ESMF\_INSTALL\_CMAKEDIR} -- where to install cmake module files.
13251333
\end{itemize}
13261334

13271335
Section~\ref{EnvironmentVariables} describes what each of these

src/doc/ESMF_quickstart.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ \subsubsection{make info}
279279
ESMF_INSTALL_LIBDIR: lib/libg/Linux.intel.64.mpiuni.default
280280
ESMF_INSTALL_BINDIR: bin/bing/Linux.intel.64.mpiuni.default
281281
ESMF_INSTALL_DOCDIR: doc
282+
ESMF_INSTALL_CMAKEDIR: cmake
282283
283284
284285
--------------------------------------------------------------

0 commit comments

Comments
 (0)