Skip to content

Commit 4a2925e

Browse files
committed
Bug in install name dir when using DESTDIR fixed
More quoting of file names and directories to be defensive. @rpath seems to work all the time now, except when using DESTDIR to install. Also, the contents of <proj>-targets.cmake seem to be pointing to incorrect places to find targets, but this doesn't seem to cause any issues. (other than, perhaps, the @rpath issue)
1 parent e7cfb2e commit 4a2925e

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

CMakeLists.txt

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# CMake Configuration and build added by Izaak Beekman -- May, 2014
2-
#
2+
33
# Copy right (c) 2014, Izaak Beekman
44
# All rights reserved.
5-
#
5+
66
# This file is contributed to the json-fortran project, and
77
# is licensed under the terms of json-fortran license. The json-fortran
88
# license is located in the LICENSE file which must be distributed with
@@ -82,11 +82,9 @@ if ( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" )
8282
endif ( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" )
8383

8484
if ( ENABLE_DYLIBS_USE_RPATH )
85-
if ( "${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel" )
86-
message ( WARNING
87-
"CMake bug may cause problems linking against dylibs compiled with ifort and installed using @rpath" )
88-
endif ( "${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel" )
89-
set ( CMAKE_MACOSX_RPATH FALSE )
85+
message ( WARNING
86+
"NOTICE: Currently CMake does not support installing @rpath install name dylibs using DESTDIR. If you would like to be able to install using 'DESTDIR=/install/path/root' set ENABLE_DYLIBS_USE_RPATH to FALSE." )
87+
set ( CMAKE_MACOSX_RPATH TRUE )
9088
else ( ENABLE_DYLIBS_USE_RPATH )
9189
set ( CMAKE_INSTALL_NAME_DIR
9290
"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${FCOMPILER_DIR}" )
@@ -114,6 +112,7 @@ set_target_properties ( ${LIB_NAME}
114112
#---------------------------------------------------------------------
115113
# Add some tests to ensure that the software is performing as expected
116114
#---------------------------------------------------------------------
115+
# Not implemented yet
117116

118117
#-------------------------
119118
# Perform the installation
@@ -125,27 +124,24 @@ install ( TARGETS ${LIB_NAME} ${LIB_NAME}-static
125124
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${FCOMPILER_DIR}" )
126125
#?ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${FCOMPILER_DIR}/${CMAKE_PROJECT_NAME}-${VERSION}"
127126

128-
# The following is some serious hackery and there's likely a better way
129-
# That better way is RPATH but bugs in CMake when using the Intel compiler persist
130-
# (-Wl,-rpath,/path/to/dylib does not get passed when compiling against imported dylib)
131127
set( ABS_LIB_INSTALL_DIR "\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${FCOMPILER_DIR}" )
132128
if ( NOT ENABLE_DYLIBS_USE_RPATH )
133129
if ( CMAKE_INSTALL_NAME_TOOL ) # On Mac and have install_name_tool
134130
install ( CODE "
135131
if ( DEFINED ENV{DESTDIR} )
136132
string ( REGEX REPLACE \"/$\" \"\" DESTDIR \"\$ENV{DESTDIR}\" ) # strip trailing /
137-
get_filename_component ( _install_path \${DESTDIR}/${ABS_LIB_INSTALL_DIR}
133+
get_filename_component ( INSALL_LIB
134+
\${DESTDIR}/${ABS_LIB_INSTALL_DIR}/lib${LIB_NAME}.${VERSION_MAJOR}.${VERSION_MINOR}.dylib
138135
ABSOLUTE )
139-
execute_process ( COMMAND
140-
${CMAKE_INSTALL_NAME_TOOL} -id \${_install_path} \${_install_path}/lib${LIB_NAME}.${VERSION}.dylib)
136+
execute_process ( COMMAND \"${CMAKE_INSTALL_NAME_TOOL}\"
137+
-id \"\${INSALL_LIB}\" \"\${INSALL_LIB}\" )
141138
endif ( DEFINED ENV{DESTDIR} )" )
142139
endif ( CMAKE_INSTALL_NAME_TOOL )
143140
endif ( NOT ENABLE_DYLIBS_USE_RPATH )
144141

145-
146142

147143
set ( INSTALL_MOD_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${FCOMPILER_DIR}/${PROJ_VERSION}" )
148-
install ( DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ DESTINATION "${INSTALL_MOD_DIR}" )
144+
install ( DIRECTORY "${CMAKE_Fortran_MODULE_DIRECTORY}/" DESTINATION "${INSTALL_MOD_DIR}" )
149145

150146
#------------------------------------------
151147
# Add portable unistall command to makefile
@@ -155,17 +151,17 @@ configure_file ( "${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in" "${CMAKE_BINARY_
155151
@ONLY)
156152

157153
add_custom_target ( uninstall
158-
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/uninstall.cmake )
154+
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/uninstall.cmake" )
159155

160156
#-----------------------------------------------------
161157
# Publicize installed location to other CMake projects
162158
#-----------------------------------------------------
163159
set ( EXPORT_INSTALL_DIR
164-
${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PACKAGE_NAME}-${VERSION} )
165-
install ( EXPORT ${PACKAGE_NAME}-targets DESTINATION ${EXPORT_INSTALL_DIR} )
160+
"${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PACKAGE_NAME}-${VERSION}" )
161+
install ( EXPORT ${PACKAGE_NAME}-targets DESTINATION "${EXPORT_INSTALL_DIR}" )
166162

167163
include ( CMakePackageConfigHelpers ) # Standard CMake module
168-
write_basic_package_version_file( ${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake
164+
write_basic_package_version_file( "${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
169165
VERSION ${VERSION}
170166
COMPATIBILITY SameMajorVersion )
171167

@@ -183,16 +179,16 @@ endif ( NOT (\"${CMAKE_Fortran_COMPILER_ID}\" MATCHES \"\${CMAKE_Fortran_COMPILE
183179

184180
# install package config file
185181
configure_package_config_file (
186-
${CMAKE_SOURCE_DIR}/cmake/pkg/${CMAKE_PROJECT_NAME}-config.cmake.in
187-
${CMAKE_BINARY_DIR}/pkg/${PACKAGE_NAME}-config.cmake
188-
INSTALL_DESTINATION ${EXPORT_INSTALL_DIR}
182+
"${CMAKE_SOURCE_DIR}/cmake/pkg/${CMAKE_PROJECT_NAME}-config.cmake.in"
183+
"${CMAKE_BINARY_DIR}/pkg/${PACKAGE_NAME}-config.cmake"
184+
INSTALL_DESTINATION "${EXPORT_INSTALL_DIR}"
189185
PATH_VARS EXPORT_INSTALL_DIR INSTALL_MOD_DIR )
190186

191187
# Install the config and version files so that we can find this project with others
192188
install ( FILES
193-
${CMAKE_BINARY_DIR}/pkg/${PACKAGE_NAME}-config.cmake
194-
${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake
195-
DESTINATION ${EXPORT_INSTALL_DIR} )
189+
"${CMAKE_BINARY_DIR}/pkg/${PACKAGE_NAME}-config.cmake"
190+
"${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
191+
DESTINATION "${EXPORT_INSTALL_DIR}" )
196192

197193
#----------------------------------------------
198194
# Make build tree targets accessible for import
@@ -201,12 +197,12 @@ export ( TARGETS ${LIB_NAME} ${LIB_NAME}-static FILE ${PACKAGE_NAME}-targets.cma
201197

202198
# build tree package config file, NOT installed
203199
configure_file (
204-
${CMAKE_SOURCE_DIR}/cmake/${CMAKE_PROJECT_NAME}-config.cmake.in
205-
${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-config.cmake
200+
"${CMAKE_SOURCE_DIR}/cmake/${CMAKE_PROJECT_NAME}-config.cmake.in"
201+
"${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-config.cmake"
206202
@ONLY )
207203

208-
set ( ENABLE_BUILD_TREE_IN_REGISTRY FALSE CACHE BOOL
204+
set ( ENABLE_BUILD_TREE_EXPORT FALSE CACHE BOOL
209205
"Add the ${PACKAGE_NAME} build tree to the CMake package registry?" )
210-
if ( ENABLE_BUILD_TREE_IN_REGISTRY )
206+
if ( ENABLE_BUILD_TREE_EXPORT )
211207
export ( PACKAGE ${PACKAGE_NAME} )
212-
endif ( ENABLE_BUILD_TREE_IN_REGISTRY )
208+
endif ( ENABLE_BUILD_TREE_EXPORT )

0 commit comments

Comments
 (0)