Skip to content

Commit ce47718

Browse files
committed
Improved readability in top level CMakeLists.txt
Pushed some CMake ugliness to included files
1 parent 29d0ef6 commit ce47718

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

CMakeLists.txt

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,8 @@ install ( TARGETS ${LIB_NAME} ${LIB_NAME}-static
115115
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
116116
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" )
117117

118-
119-
if ( NOT ENABLE_DYLIBS_USE_RPATH )
120-
if ( CMAKE_INSTALL_NAME_TOOL ) # On Mac and have install_name_tool
121-
install ( CODE
122-
"if ( DEFINED ENV{DESTDIR} )
123-
string ( REGEX REPLACE \"/$\" \"\" DESTDIR \"\$ENV{DESTDIR}\" ) # strip trailing /
124-
get_filename_component ( INSTALL_LIB
125-
\${DESTDIR}/${ABS_LIB_INSTALL_DIR}/lib${LIB_NAME}.${VERSION_MAJOR}.${VERSION_MINOR}.dylib
126-
ABSOLUTE )
127-
execute_process ( COMMAND \"${CMAKE_INSTALL_NAME_TOOL}\"
128-
-id \"\${INSTALL_LIB}\" \"\${INSTALL_LIB}\" )
129-
endif ( DEFINED ENV{DESTDIR} )" )
130-
endif ( CMAKE_INSTALL_NAME_TOOL )
131-
endif ( NOT ENABLE_DYLIBS_USE_RPATH )
118+
# Code to fix the install name.
119+
include ( cmake/fixupInstallNameDir.cmake )
132120

133121
install ( DIRECTORY "${CMAKE_Fortran_MODULE_DIRECTORY}/" DESTINATION "${INSTALL_MOD_DIR}" )
134122

@@ -154,17 +142,8 @@ write_basic_package_version_file( "${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-config-ve
154142
VERSION ${VERSION}
155143
COMPATIBILITY SameMajorVersion )
156144

157-
# Put common compiler compatibility check in a variable to be written out, rather than
158-
# duplicating it across the build and install package-config files
159-
set ( COMPILER_CONSISTENCY_CHECK
160-
"# Check that the correct compiler is in use. Mod files and object files/archives
161-
# are NOT compatible across different Fortran compilers when modules are present
162-
set ( ${PACKAGE_NAME}_Fortran_COMPILER_ID ${CMAKE_Fortran_COMPILER_ID} )
163-
set ( ${PACKAGE_NAME}_COMPATIBLE_COMPILER TRUE )
164-
if ( NOT (\"${CMAKE_Fortran_COMPILER_ID}\" MATCHES \"\${CMAKE_Fortran_COMPILER_ID}\") )
165-
message ( SEND_ERROR \"Incompatible Fortran compilers detected! ${PACKAGE_NAME} was compiled with the ${CMAKE_Fortran_COMPILER_ID} Fortran compiler, but the current project is trying to use the \${CMAKE_Fortran_COMPILER_ID} Fortran compiler! In general, Fortran modules and libraries can only link against other projects built using the same compiler.\" )
166-
set ( ${PACKAGE_NAME}_COMPATIBLE_COMPILER FALSE )
167-
endif ( NOT (\"${CMAKE_Fortran_COMPILER_ID}\" MATCHES \"\${CMAKE_Fortran_COMPILER_ID}\") )" )
145+
# provides COMPILER_CONSISTENCY_CHECK
146+
include ( cmake/FCompilerConsistencyCheck.cmake )
168147

169148
# install package config file
170149
configure_package_config_file (

cmake/FCompilerConsistencyCheck.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Put common compiler compatibility check in a variable to be written out, rather than
2+
# duplicating it across the build and install package-config files
3+
4+
set ( COMPILER_CONSISTENCY_CHECK
5+
"# Check that the correct compiler is in use. Mod files and object files/archives
6+
# are NOT compatible across different Fortran compilers when modules are present
7+
set ( ${PACKAGE_NAME}_Fortran_COMPILER_ID ${CMAKE_Fortran_COMPILER_ID} )
8+
set ( ${PACKAGE_NAME}_COMPATIBLE_COMPILER TRUE )
9+
if ( NOT (\"${CMAKE_Fortran_COMPILER_ID}\" MATCHES \"\${CMAKE_Fortran_COMPILER_ID}\") )
10+
message ( SEND_ERROR \"Incompatible Fortran compilers detected! ${PACKAGE_NAME} was compiled with the ${CMAKE_Fortran_COMPILER_ID} Fortran compiler, but the current project is trying to use the \${CMAKE_Fortran_COMPILER_ID} Fortran compiler! In general, Fortran modules and libraries can only link against other projects built using the same compiler.\" )
11+
set ( ${PACKAGE_NAME}_COMPATIBLE_COMPILER FALSE )
12+
endif ( NOT (\"${CMAKE_Fortran_COMPILER_ID}\" MATCHES \"\${CMAKE_Fortran_COMPILER_ID}\") )" )

cmake/fixupInstallNameDir.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Code to fixup install names when dylibs not using @rpath are installed using DESTDIR
2+
# I think this could be considered a CMake Bug. This is a work around.
3+
if ( NOT ENABLE_DYLIBS_USE_RPATH )
4+
if ( CMAKE_INSTALL_NAME_TOOL ) # On Mac and have install_name_tool
5+
install ( CODE
6+
"if ( DEFINED ENV{DESTDIR} )
7+
string ( REGEX REPLACE \"/$\" \"\" DESTDIR \"\$ENV{DESTDIR}\" ) # strip trailing /
8+
get_filename_component ( INSTALL_LIB
9+
\${DESTDIR}/${ABS_LIB_INSTALL_DIR}/lib${LIB_NAME}.${VERSION_MAJOR}.${VERSION_MINOR}.dylib
10+
ABSOLUTE )
11+
execute_process ( COMMAND \"${CMAKE_INSTALL_NAME_TOOL}\"
12+
-id \"\${INSTALL_LIB}\" \"\${INSTALL_LIB}\" )
13+
endif ( DEFINED ENV{DESTDIR} )" )
14+
endif ( CMAKE_INSTALL_NAME_TOOL )
15+
endif ( NOT ENABLE_DYLIBS_USE_RPATH )

0 commit comments

Comments
 (0)