[CMake] win32 problem with export_library_dependencies

Ralf Habacker ralf.habacker at freenet.de
Thu Jan 3 13:36:40 EST 2008


Hi,

the cmake function "export_library_dependencies" creates - as the name
indicates - library dependency informations.

At least for kdelibs and kdepimlibs these dependencies are placed into a
file which is installed and released along with all the other installed
files of the related package. Other source packages use this dependency
file at configure time to determine to which libraries local
libraries/application have to link to. Below is an example of the file
KDELibsDependencies.cmake created for the kdelibs package on a german
win32 system.

SET(kdecore_LIB_DEPENDS
"C:/Programme/kdewin/lib/QtCore4.lib;C:/Programme/kdewin/lib/QtCored4.lib;C:/Programme/kdewin/lib/QtNetwork4.lib;C:/Programme/kdewin/lib/QtNetworkd4.lib;C:/Programme/kdewin/lib/QtDBus4.lib;C:/Programme/kdewin/lib/QtDBusd4.lib;C:/Programme/kdewin/lib/QtXml4.lib;C:/Programme/kdewin/lib/QtXmld4.lib;C:/Programme/kdewin/lib/zlib.lib;C:/Programme/kdewin/lib/kdewin32.lib
;user32;shell32;ws2_32;netapi32;userenv;C:/Programme/kdewin/lib/bzip2.lib;C:/Programme/kdewin/lib/libintl.lib;")
SET(C:/Programme/kdewin/lib/QtCore4.lib_LINK_TYPE "optimized")
SET(C:/Programme/kdewin/lib/QtCored4.lib_LINK_TYPE "debug")
SET(C:/Programme/kdewin/lib/QtNetwork4.lib_LINK_TYPE "optimized")
SET(C:/Programme/kdewin/lib/QtNetworkd4.lib_LINK_TYPE "debug")
SET(C:/Programme/kdewin/lib/QtDBus4.lib_LINK_TYPE "optimized")
SET(C:/Programme/kdewin/lib/QtDBusd4.lib_LINK_TYPE "debug")

The problem now is that the hardcoded pathes are valid on kdelibs
compile time on a specific computer but may not be valid on other
computers (for example on an english installed pc which uses c:/Program
Files/ by default) or if the installation uses different pathes or drives.

To solve this problem it is required that export_library_dependencies
do not print out hardcoded pathes instead it should print out the
related variable names from the CMakeCache.txt file.

Let me explain this with an example for some dependencies. In the 
kdelibs build CMakeCache.txt file there are the following definitions:

//Path to a library.
QT_QTCORE_LIBRARY:FILEPATH=C:/Programme/kdewin/lib/QtCore4.lib

//Path to a library.
QT_QTCORE_LIBRARY_DEBUG:FILEPATH=C:/Programme/kdewin/lib/QtCored4.lib

export_library_dependencies should create the following definitions

SET(kdecore_LIB_DEPENDS
"${QT_QTCORE_LIBRARY};${QT_QTCORE_LIBRARY_DEBUG};...")
SET(${QT_QTCORE_LIBRARY}_LINK_TYPE "optimized")
SET(${QT_QTCORE_LIBRARY_DEBUG}_LINK_TYPE "debug")
....

(only a subset of the real required dependencies are listed)

To provide a complete patch it would need more time to dig into the
cmake internals (I haven't found a short way to get the cmake cache
variable name of a related dependency) so at now I can only give some
hints for the required implementation.
The related part is located in the method void
cmExportLibraryDependenciesCommand::ConstFinalPass()  line 100 and
following.
To enable this mode of operation  there should be an additional optional
parameter for export_library_dependencies  as mentioned below in the
related help page.

--help-command output ----------------------------------------------------
      Write out the dependency information for all targets of a project.

        export_library_dependencies(<file> [SYMBOLIC] [APPEND])

      Create a file named <file> that can be included into a CMake listfile
      with the INCLUDE command.  The file will contain a number of SET
      commands that will set all the variables needed for library dependency
      information.  This should be the last command in the top level
      CMakeLists.txt file of the project.
      If the SYMBOLIC option is  specified, the SET commands will use
      variable names instead of hardcoded library pathes.
      If the APPEND option is specified, the SET commands will be appended
      to the given file instead of replacing it.
-------------------------------------------------------------------------

BTW: This type of operation may also help to support non standard
dependency path locations on unix too.

Would it be possible to implement such a feature in cmake ?

Ralf





More information about the CMake mailing list