Skip to content

Commit 29d0ef6

Browse files
committed
Implemented install directory structure discussed in #3
mod files are now installed along library archives/objects, under `<prefix>/lib/<project>-<version>/<compilerID>/` Some variables were refactored to, to try to simplify the CMakeLists.txt file.
1 parent 177bd53 commit 29d0ef6

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

CMakeLists.txt

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,24 @@ set ( JF_LIB_SRCS src/json_module.f90 )
5050
# Collect all the mod files into their own
5151
# directory to ease installation issues
5252
#-----------------------------------------
53-
# No standard mechanism or location for compiled .mod files
54-
# but often they are thought of as similar to precompiled
55-
# header files. Let's include the compiler ID to ease
56-
# compatibility issues for thos linking against the installed
57-
# libraries.
58-
set ( CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/include" )
53+
set ( CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/lib" )
5954

6055
#-------------------------------------
6156
# Define where our files get installed
6257
#-------------------------------------
63-
# Most of this is probably 'wrong' for Windows/Cygwin
64-
65-
#if ( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
66-
# include ( GNUInstallDirs ) # Standard CMake module
67-
if ( UNIX ) #Apple, BSD, solaris, other *NIX? Framework on Apple instead?
68-
set ( CMAKE_INSTALL_LIBDIR lib )
69-
set ( CMAKE_INSTALL_INCLUDEDIR include )
70-
set ( CMAKE_INSTALL_DATAROOTDIR share )
71-
endif ( UNIX )
72-
#endif ( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
73-
7458
# Set the package name to be specific to the compiler used, so that
7559
# versions compiled with different compilers can be installed in parallel
7660
string ( TOLOWER ${CMAKE_PROJECT_NAME}-${CMAKE_Fortran_COMPILER_ID} PACKAGE_NAME )
77-
string ( TOLOWER fortran/${CMAKE_Fortran_COMPILER_ID}-compiler FCOMPILER_DIR )
61+
string ( TOLOWER ${CMAKE_Fortran_COMPILER_ID}-compiler FCOMPILER_DIR )
62+
63+
# Most of this is probably 'wrong' for Windows/Cygwin
64+
# if ( UNIX )
65+
set ( CMAKE_INSTALL_LIBDIR lib )
66+
set ( CMAKE_INSTALL_DATAROOTDIR share )
67+
# endif ( UNIX )
68+
set ( INSTALL_MOD_DIR "${CMAKE_INSTALL_LIBDIR}/${PROJ_VERSION}/${FCOMPILER_DIR}" )
69+
set ( INSTALL_LIB_DIR "${CMAKE_INSTALL_LIBDIR}/${PROJ_VERSION}/${FCOMPILER_DIR}" )
70+
set( ABS_LIB_INSTALL_DIR "\${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}" )
7871

7972
if ( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" )
8073
set ( ENABLE_DYLIBS_USE_RPATH TRUE CACHE BOOL
@@ -86,7 +79,7 @@ if ( ENABLE_DYLIBS_USE_RPATH )
8679
set ( CMAKE_MACOSX_RPATH TRUE )
8780
else ( ENABLE_DYLIBS_USE_RPATH )
8881
set ( CMAKE_INSTALL_NAME_DIR
89-
"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${FCOMPILER_DIR}" )
82+
"${ABS_LIB_INSTALL_DIR}" )
9083
endif ( ENABLE_DYLIBS_USE_RPATH )
9184

9285
#---------------------------------------------
@@ -119,27 +112,24 @@ set_target_properties ( ${LIB_NAME}
119112

120113
install ( TARGETS ${LIB_NAME} ${LIB_NAME}-static
121114
EXPORT ${PACKAGE_NAME}-targets
122-
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${FCOMPILER_DIR}"
123-
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${FCOMPILER_DIR}" )
124-
#?ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${FCOMPILER_DIR}/${CMAKE_PROJECT_NAME}-${VERSION}"
115+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
116+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" )
117+
125118

126-
set( ABS_LIB_INSTALL_DIR "\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${FCOMPILER_DIR}" )
127119
if ( NOT ENABLE_DYLIBS_USE_RPATH )
128120
if ( CMAKE_INSTALL_NAME_TOOL ) # On Mac and have install_name_tool
129-
install ( CODE "
130-
if ( DEFINED ENV{DESTDIR} )
121+
install ( CODE
122+
"if ( DEFINED ENV{DESTDIR} )
131123
string ( REGEX REPLACE \"/$\" \"\" DESTDIR \"\$ENV{DESTDIR}\" ) # strip trailing /
132-
get_filename_component ( INSALL_LIB
124+
get_filename_component ( INSTALL_LIB
133125
\${DESTDIR}/${ABS_LIB_INSTALL_DIR}/lib${LIB_NAME}.${VERSION_MAJOR}.${VERSION_MINOR}.dylib
134126
ABSOLUTE )
135127
execute_process ( COMMAND \"${CMAKE_INSTALL_NAME_TOOL}\"
136-
-id \"\${INSALL_LIB}\" \"\${INSALL_LIB}\" )
128+
-id \"\${INSTALL_LIB}\" \"\${INSTALL_LIB}\" )
137129
endif ( DEFINED ENV{DESTDIR} )" )
138130
endif ( CMAKE_INSTALL_NAME_TOOL )
139131
endif ( NOT ENABLE_DYLIBS_USE_RPATH )
140-
141132

142-
set ( INSTALL_MOD_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${FCOMPILER_DIR}/${PROJ_VERSION}" )
143133
install ( DIRECTORY "${CMAKE_Fortran_MODULE_DIRECTORY}/" DESTINATION "${INSTALL_MOD_DIR}" )
144134

145135
#------------------------------------------

0 commit comments

Comments
 (0)