Skip to content

Commit b277d20

Browse files
committed
Add CMake option for GNU-like install dirs
- Option to install into a more traditional GNU layout - Should allow homebrew to successfully link symlinks in /usr/local - Option should not be used when installing for use with multiple Fortran compilers
1 parent 8ee77e2 commit b277d20

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

CMakeLists.txt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,40 @@ set ( JF_TEST_UCS4_SUPPORT_SRC "${CMAKE_SOURCE_DIR}/src/tests/introspection/test
4949
# Collect all the mod files into their own
5050
# directory to ease installation issues
5151
#-----------------------------------------
52-
set ( MODULE_DIR "${CMAKE_BINARY_DIR}/lib" )
52+
set ( MODULE_DIR "${CMAKE_BINARY_DIR}/include" )
5353

5454
#-------------------------------------
5555
# Define where our files get installed
5656
#-------------------------------------
57+
set ( USE_GNU_INSTALL_CONVENTION FALSE
58+
CACHE BOOL
59+
"Install library, module file and documentation to standard GNU locations. Do not use this if supporting multiple Fortran compilers" )
60+
5761
# Set the package name to be specific to the compiler used, so that
5862
# versions compiled with different compilers can be installed in parallel
5963
string ( TOLOWER ${CMAKE_PROJECT_NAME}-${CMAKE_Fortran_COMPILER_ID} PACKAGE_NAME )
60-
string ( TOLOWER ${CMAKE_Fortran_COMPILER_ID}-compiler FCOMPILER_DIR )
6164
set ( PACKAGE_VERSION "${PACKAGE_NAME}-${VERSION}" )
6265

66+
if (USE_GNU_INSTALL_CONVENTION)
67+
include(GNUInstallDirs)
68+
set ( INSTALL_MOD_DIR "${CMAKE_INSTALL_INCLUDEDIR}" )
69+
set ( INSTALL_LIB_DIR "${CMAKE_INSTALL_LIBDIR}")
70+
set( ABS_LIB_INSTALL_DIR "\${CMAKE_INSTALL_FULL_LIBDIR}" )
71+
else ()
72+
# Most of this could be 'wrong' for Windows/Cygwin
73+
set ( INSTALL_MOD_DIR "${PACKAGE_VERSION}/lib" )
74+
set ( INSTALL_LIB_DIR "${INSTALL_MOD_DIR}" )
75+
set( ABS_LIB_INSTALL_DIR "\${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}" )
76+
endif ()
6377

64-
# Most of this could be 'wrong' for Windows/Cygwin
65-
66-
set ( INSTALL_MOD_DIR "${PACKAGE_VERSION}/lib" )
67-
set ( INSTALL_LIB_DIR "${INSTALL_MOD_DIR}" )
68-
set( ABS_LIB_INSTALL_DIR "\${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}" )
6978

7079
# Put package export CMake files where they can be found
7180
# use `find_package ( jsonfortran-${CMAKE_Fortran_COMPILER_ID} <version> REQUIRED )`
72-
set ( EXPORT_INSTALL_DIR "${PACKAGE_VERSION}/cmake" )
81+
if (USE_GNU_INSTALL_CONVENTION)
82+
set ( EXPORT_INSTALL_DIR "${INSTALL_LIB_DIR}/cmake/${PACKAGE_VERSION}" )
83+
else ()
84+
set ( EXPORT_INSTALL_DIR "${PACKAGE_VERSION}/cmake" )
85+
endif ()
7386

7487
if ( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" )
7588
set ( ENABLE_DYLIBS_USE_RPATH TRUE CACHE BOOL

0 commit comments

Comments
 (0)