Blob Blame History Raw
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 74e7e24..b3770be 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -88,6 +88,9 @@ ENDIF()
 # For CMAKE_INSTALL_LIBDIR
 INCLUDE(GNUInstallDirs)
 
+# By default install Fortran modules into include directory
+OPTION(Fortran_INSTALL_MODDIR "Fortran module install directory" "${CMAKE_INSTALL_INCLUDEDIR}")
+
 IF(MSVC)
   SET(GLOBAL PROPERTY USE_FOLDERS ON)
 ENDIF()
diff --git a/configure.ac b/configure.ac
index f613828..9e9960b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -323,6 +323,13 @@ TEMP_LARGE=${TEMP_LARGE-.}
 AC_MSG_RESULT($TEMP_LARGE)
 AC_DEFINE_UNQUOTED([TEMP_LARGE], ["$TEMP_LARGE"], [Place to put very large netCDF test files.])
 
+# Allow setting the fortran module install dir
+AC_ARG_WITH([fmoddir],
+  [AS_HELP_STRING([--with-fmoddir=DIR], [Fortran module install directory])],
+  [fmoddir=$withval],
+  [fmoddir="\${includedir}"])
+AC_SUBST([fmoddir], [$fmoddir])
+
 # Set up libtool.
 AC_MSG_NOTICE([setting up libtool])
 LT_PREREQ([2.2])
diff --git a/fortran/CMakeLists.txt b/fortran/CMakeLists.txt
index 4a269ca..252b389 100644
--- a/fortran/CMakeLists.txt
+++ b/fortran/CMakeLists.txt
@@ -176,6 +176,6 @@ INSTALL(TARGETS netcdff
     ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
     )
 INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/
-        DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+        DESTINATION "${Fortran_INSTALL_MODDIR}"
         FILES_MATCHING PATTERN "*.mod" PATTERN "netcdf.inc"
         )
diff --git a/fortran/Makefile.am b/fortran/Makefile.am
index e1a6f14..8b03b64 100644
--- a/fortran/Makefile.am
+++ b/fortran/Makefile.am
@@ -146,13 +146,13 @@ MODFILES += netcdf.mod
 # Mod files are build sources.
 BUILT_SOURCES = $(MODFILES)
 
-# Mod files are installed as headers, but not distrubuted.
-nodist_include_HEADERS = $(MODFILES)
+# Mod files are installed, but not distrubuted.
+nodist_fmod_DATA = $(MODFILES)
 
 # The netcdf.inc file is built on the user machine, and installed as
 # a header.
 BUILT_SOURCES += netcdf.inc
-nodist_include_HEADERS += netcdf.inc
+nodist_include_HEADERS = netcdf.inc
 
 # Build netcdf.inc file from netcdf2, netcdf3 and netcdf4 files
 netcdf.inc: netcdf2.inc netcdf3.inc netcdf4.inc
diff --git a/netcdf-fortran.pc.in b/netcdf-fortran.pc.in
index fb48a42..f6bded2 100644
--- a/netcdf-fortran.pc.in
+++ b/netcdf-fortran.pc.in
@@ -2,6 +2,7 @@ prefix=@prefix@
 exec_prefix=@exec_prefix@
 libdir=@libdir@
 includedir=@includedir@
+fmoddir=@fmoddir@
 ccompiler=@CC@
 fcompiler=@FC@
 
@@ -12,4 +13,4 @@ Version: @PACKAGE_VERSION@
 Requires.private: netcdf > 4.1.1
 Libs: -L${libdir} -lnetcdff
 Libs.private: -L${libdir} -lnetcdff -lnetcdf
-Cflags: -I${includedir}
+Cflags: -I${includedir} -I${fmoddir}
diff --git a/nf-config.cmake.in b/nf-config.cmake.in
index cc5dc96..f8e51cb 100644
--- a/nf-config.cmake.in
+++ b/nf-config.cmake.in
@@ -8,11 +8,12 @@ prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=@CMAKE_INSTALL_PREFIX@
 libdir=@CMAKE_INSTALL_PREFIX@/lib
 includedir=@CMAKE_INSTALL_PREFIX@/include
+fmoddir=@CMAKE_INSTALL_PREFIX@/@Fortran_INSTALL_MODDIR@
 #
 cc="@CMAKE_C_COMPILER@"
 fc="@CMAKE_Fortran_COMPILER@"
 cflags="-I@CMAKE_INSTALL_PREFIX@/include @CMAKE_C_FLAGS@ @CMAKE_CPP_FLAGS@"
-fflags="@MOD_FLAG@${includedir}"
+fflags="-I${includedir} @MOD_FLAG@${fmoddir}"
 #
 has_dap="@HAS_DAP@"
 has_nc2="@HAS_NC2@"
diff --git a/nf-config.in b/nf-config.in
index 31a0f3a..db18c83 100644
--- a/nf-config.in
+++ b/nf-config.in
@@ -7,11 +7,12 @@ prefix=@prefix@
 exec_prefix=@exec_prefix@
 libdir=@libdir@
 includedir=@includedir@
+fmoddir=@fmoddir@
 
 cc="@CC@"
 fc="@FC@"
-cflags=" -I${includedir} @CPPFLAGS@" 
-fflags="@MOD_FLAG@${includedir}"
+cflags="-I${includedir} @CPPFLAGS@" 
+fflags="-I${includedir} @MOD_FLAG@${fmoddir}"
 has_dap="@HAS_DAP@"
 has_nc2="@HAS_NC2@"
 has_nc4="@HAS_NC4@"