On Tuesday 17 January 2012, Alexander Neundorf wrote:
> On Monday 16 January 2012, Yury G. Kudryashov wrote:
> > Alexander Neundorf wrote:
> > > On Sunday 15 January 2012, Yury G. Kudryashov wrote:
> > >> 15 January 2012 20:06:51 Alexander Neundorf written:
> > >> The only comment: there are 4 possible combinations of
> > >> cmake -DLIB_INSTALL_DIR=relative_or_absolute -
> > >> DINCLUDE_INSTALL_DIR=relative_or_absolute
> > >> It seems that your library will not be relocatable if
> > >> INCLUDE_INSTALL_DIR is set to an absolute path.
> > > 
> > > I think I can improve this a bit more, but yes, this may be a
> > > limitation, but IMO an acceptable limitation.
> > > If you want to create a relocatable package, don't set absolute paths.
> > > (I know all install dirs are absolute with kdelibs4, this will change
> > > with KDE frameworks).
> > 
> > This can be solved if you store the original prefix in Config.cmake.

I extended the set_absolute() function so that it can now also "relocate" 
absolute install dirs, it's in the ImprovedConfigDotCMakeFile branch.
But I'm actually not sure whether this is a good idea at all.
Using absolute install paths could, maybe should be interpreted as "don't 
relocate me".
I mean, this is not the only thing which has to be taken care of.
A package which contains absolute RPATHS may not be relocatable. A package 
with relative RPATHS might be relocatable.
A package may have relative install dirs but absolute RPATHs (to its own 
shared libraries). It still is not be relocatable.

Alex
function(SET_ABSOLUTE _var _dir _actualInstalledPrefix _installPrefix)
   if(IS_ABSOLUTE "${_dir}")
      # if it is an absolute path, if it was a subdir of the original CMAKE_INSTALL_PREFIX,
      # replace this original CMAKE_INSTALL_PREFIX with the actual prefix:
      string(REGEX REPLACE "^${_installPrefix}" "${_actualInstalledPrefix}" absPath "${_dir}")
      # or is this too clever and we should leave absolute install dirs simply as they are.
      # They could be interpreted as a sign that the package should not be relocated.
      #set(absPath "${_dir}")
   else()
      set(absPath "${_actualInstalledPrefix}/${_dir}" )
   endif()
   if(NOT EXISTS "${absPath}")
      message(FATAL_ERROR "File or directory \"${absPath}\" referenced by variable ${_var} does not exist !")
   endif()
   set(${_var} ${absPath} PARENT_SCOPE)
endfunction()


function(determine_installed_location _var _install_prefix  _cmakeconfig_install_dir)
  if(NOT IS_ABSOLUTE "${_cmakeconfig_install_dir}")
    set(_cmakeconfig_install_dir  "${_install_prefix}/${_cmakeconfig_install_dir}")
  endif()

  file(RELATIVE_PATH _relative_cmakeconfig_install_dir "${_cmakeconfig_install_dir}" "${_install_prefix}" )

  get_filename_component(rootDir1 ${CMAKE_CURRENT_LIST_DIR}/${_relative_cmakeconfig_install_dir} ABSOLUTE)
  #get_filename_component(rootDir2 ${CMAKE_CURRENT_LIST_DIR}/${_BAR_RELATIVE_CMAKECONFIG_INSTALL_DIR} REALPATH)


  if(NOT "${rootDir1}" STREQUAL "${_install_prefix}")
    message(STATUS "Package has been relocated during installation.")
  endif()
  set(${_var} ${rootDir1} PARENT_SCOPE)
endfunction()

########### actual Config.cmake file starts here: #############################


# set the version of myself
set(BAR_VERSION_MAJOR @BAR_VERSION_MAJOR@)
set(BAR_VERSION_MINOR @BAR_VERSION_MINOR@)
set(BAR_VERSION_PATCH @BAR_VERSION_PATCH@)
set(BAR_VERSION ${BAR_VERSION_MAJOR}.${BAR_VERSION_MINOR}.${BAR_VERSION_PATCH} )

set(BAR_CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@")

determine_installed_location(_BAR_INSTALLED_PREFIX  "${BAR_CMAKE_INSTALL_PREFIX}"  "@CMAKECONFIG_INSTALL_DIR@")

set_absolute(BAR_INCLUDE_DIR "@INCLUDE_INSTALL_DIR@" "${_BAR_INSTALLED_PREFIX}" "${BAR_CMAKE_INSTALL_PREFIX}")

set_absolute(BAR_DATA_DIR "@DATA_INSTALL_DIR@" "${_BAR_INSTALLED_PREFIX}" "${BAR_CMAKE_INSTALL_PREFIX}")

# what is my include directory
set(BAR_INCLUDES "${BAR_INCLUDE_DIR}")

# import the exported targets
include(${CMAKE_CURRENT_LIST_DIR}/BarTargets.cmake)

# set the expected library variable
set(BAR_LIBRARIES bar )
_______________________________________________
Kde-buildsystem mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-buildsystem

Reply via email to