CMakeMacroLibtoolFile: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
(Fixed the formatting of the code, so it's all code-formatting.)
Line 9: Line 9:


-----
-----
 
MACRO(GET_TARGET_PROPERTY_WITH_DEFAULT _variable _target _property _default_value)
 
  GET_TARGET_PROPERTY (${_variable} ${_target} ${_property})
MACRO(GET_TARGET_PROPERTY_WITH_DEFAULT _variable _target _property _default_value)
  IF (${_variable} STREQUAL NOTFOUND)
  GET_TARGET_PROPERTY (${_variable} ${_target} ${_property})
    SET (${_variable} ${_default_value})
  IF (${_variable} STREQUAL NOTFOUND)
  ENDIF (${_variable} STREQUAL NOTFOUND)
    SET (${_variable} ${_default_value})
ENDMACRO (GET_TARGET_PROPERTY_WITH_DEFAULT)
  ENDIF (${_variable} STREQUAL NOTFOUND)
ENDMACRO (GET_TARGET_PROPERTY_WITH_DEFAULT)
MACRO(CREATE_LIBTOOL_FILE _target _install_DIR)
 
  GET_TARGET_PROPERTY(_target_location ${_target} LOCATION)
MACRO(CREATE_LIBTOOL_FILE _target _install_DIR)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_static_lib ${_target} STATIC_LIB "")
  GET_TARGET_PROPERTY(_target_location ${_target} LOCATION)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dependency_libs ${_target} LT_DEPENDENCY_LIBS "")
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_static_lib ${_target} STATIC_LIB "")
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_current ${_target} LT_VERSION_CURRENT 0)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dependency_libs ${_target} LT_DEPENDENCY_LIBS "")
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_age ${_target} LT_VERSION_AGE 0)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_current ${_target} LT_VERSION_CURRENT 0)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_revision ${_target} LT_VERSION_REVISION 0)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_age ${_target} LT_VERSION_AGE 0)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_installed ${_target} LT_INSTALLED yes)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_revision ${_target} LT_VERSION_REVISION 0)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_shouldnotlink ${_target} LT_SHOULDNOTLINK yes)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_installed ${_target} LT_INSTALLED yes)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlopen ${_target} LT_DLOPEN "")
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_shouldnotlink ${_target} LT_SHOULDNOTLINK yes)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlpreopen ${_target} LT_DLPREOPEN "")
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlopen ${_target} LT_DLOPEN "")
  GET_FILENAME_COMPONENT(_laname ${_target_location} NAME_WE)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlpreopen ${_target} LT_DLPREOPEN "")
  GET_FILENAME_COMPONENT(_soname ${_target_location} NAME)
  GET_FILENAME_COMPONENT(_laname ${_target_location} NAME_WE)
  SET(_laname ${_laname}.la)
  GET_FILENAME_COMPONENT(_soname ${_target_location} NAME)
  FILE(WRITE ${_laname} "# ${_laname} - a libtool library file, generated by cmake \n")
  SET(_laname ${_laname}.la)
  FILE(APPEND ${_laname} "# The name that we can dlopen(3).\n")
  FILE(WRITE ${_laname} "# ${_laname} - a libtool library file, generated by cmake \n")
  FILE(APPEND ${_laname} "dlname='${_soname}'\n")
  FILE(APPEND ${_laname} "# The name that we can dlopen(3).\n")
  FILE(APPEND ${_laname} "# Names of this library\n")
  FILE(APPEND ${_laname} "dlname='${_soname}'\n")
  FILE(APPEND ${_laname} "library_names='${_soname}.${_target_current}.${_target_age}.${_target_revision} ${_soname}.${_target_current} ${_soname}'\n")
  FILE(APPEND ${_laname} "# Names of this library\n")
  FILE(APPEND ${_laname} "# The name of the static archive\n")
  FILE(APPEND ${_laname} "library_names='${_soname}.${_target_current}.${_target_age}.${_target_revision} ${_soname}.${_target_current} ${_soname}'\n")
  FILE(APPEND ${_laname} "old_library='${_target_static_lib}'\n")
  FILE(APPEND ${_laname} "# The name of the static archive\n")
  FILE(APPEND ${_laname} "# Libraries that this one depends upon.\n")
  FILE(APPEND ${_laname} "old_library='${_target_static_lib}'\n")
  FILE(APPEND ${_laname} "dependency_libs='${_target_dependency_libs}'\n")
  FILE(APPEND ${_laname} "# Libraries that this one depends upon.\n")
  FILE(APPEND ${_laname} "# Version information.\n")
  FILE(APPEND ${_laname} "dependency_libs='${_target_dependency_libs}'\n")
  FILE(APPEND ${_laname} "current=${_target_current}\n")
  FILE(APPEND ${_laname} "# Version information.\n")
  FILE(APPEND ${_laname} "age=${_target_age}\n")
  FILE(APPEND ${_laname} "current=${_target_current}\n")
  FILE(APPEND ${_laname} "revision=${_target_revision}\n")
  FILE(APPEND ${_laname} "age=${_target_age}\n")
  FILE(APPEND ${_laname} "# Is this an already installed library?\n")
  FILE(APPEND ${_laname} "revision=${_target_revision}\n")
  FILE(APPEND ${_laname} "installed=${_target_installed}\n")
  FILE(APPEND ${_laname} "# Is this an already installed library?\n")
  FILE(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\n")
  FILE(APPEND ${_laname} "installed=${_target_installed}\n")
  FILE(APPEND ${_laname} "shouldnotlink=${_target_shouldnotlink}\n")
  FILE(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\n")
  FILE(APPEND ${_laname} "# Files to dlopen/dlpreopen\n")
  FILE(APPEND ${_laname} "shouldnotlink=${_target_shouldnotlink}\n")
  FILE(APPEND ${_laname} "dlopen='${_target_dlopen}'\n")
  FILE(APPEND ${_laname} "# Files to dlopen/dlpreopen\n")
  FILE(APPEND ${_laname} "dlpreopen='${_target_dlpreopen}'\n")
  FILE(APPEND ${_laname} "dlopen='${_target_dlopen}'\n")
  FILE(APPEND ${_laname} "# Directory that this library needs to be installed in:\n")
  FILE(APPEND ${_laname} "dlpreopen='${_target_dlpreopen}'\n")
  FILE(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}${_install_DIR}'\n")
  FILE(APPEND ${_laname} "# Directory that this library needs to be installed in:\n")
  INSTALL( FILES ${_laname} ${_soname}
  FILE(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}${_install_DIR}'\n")
    DESTINATION ${CMAKE_INSTALL_PREFIX}${_install_DIR})
  INSTALL( FILES ${_laname} ${_soname}
ENDMACRO(CREATE_LIBTOOL_FILE)
    DESTINATION ${CMAKE_INSTALL_PREFIX}${_install_DIR})
ENDMACRO(CREATE_LIBTOOL_FILE)
-----
-----
[[CMake_User_Contributed_Macros|Back]]
[[CMake_User_Contributed_Macros|Back]]


{{CMake/Template/Footer}}
{{CMake/Template/Footer}}

Revision as of 07:07, 12 August 2007

Back

This macro creates a libtool .la file for shared libraries or plugins. The first parameter is the target name of the library, the second parameter is the directory where it will be installed to. E.g. for a KDE 3.x module named "kfoo" the usage would be as follows:

The macro GET_TARGET_PROPERTY_WITH_DEFAULT is helpful to handle properties with default values.

ADD_LIBRARY(foo SHARED kfoo1.cpp kfoo2.cpp)
CREATE_LIBTOOL_FILE(foo /lib/kde3)


MACRO(GET_TARGET_PROPERTY_WITH_DEFAULT _variable _target _property _default_value)
  GET_TARGET_PROPERTY (${_variable} ${_target} ${_property})
  IF (${_variable} STREQUAL NOTFOUND)
    SET (${_variable} ${_default_value})
  ENDIF (${_variable} STREQUAL NOTFOUND)
ENDMACRO (GET_TARGET_PROPERTY_WITH_DEFAULT)

MACRO(CREATE_LIBTOOL_FILE _target _install_DIR)
  GET_TARGET_PROPERTY(_target_location ${_target} LOCATION)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_static_lib ${_target} STATIC_LIB "")
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dependency_libs ${_target} LT_DEPENDENCY_LIBS "")
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_current ${_target} LT_VERSION_CURRENT 0)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_age ${_target} LT_VERSION_AGE 0)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_revision ${_target} LT_VERSION_REVISION 0)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_installed ${_target} LT_INSTALLED yes)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_shouldnotlink ${_target} LT_SHOULDNOTLINK yes)
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlopen ${_target} LT_DLOPEN "")
  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlpreopen ${_target} LT_DLPREOPEN "")
  GET_FILENAME_COMPONENT(_laname ${_target_location} NAME_WE)
  GET_FILENAME_COMPONENT(_soname ${_target_location} NAME)
  SET(_laname ${_laname}.la)
  FILE(WRITE ${_laname} "# ${_laname} - a libtool library file, generated by cmake \n")
  FILE(APPEND ${_laname} "# The name that we can dlopen(3).\n")
  FILE(APPEND ${_laname} "dlname='${_soname}'\n")
  FILE(APPEND ${_laname} "# Names of this library\n")
  FILE(APPEND ${_laname} "library_names='${_soname}.${_target_current}.${_target_age}.${_target_revision} ${_soname}.${_target_current} ${_soname}'\n")
  FILE(APPEND ${_laname} "# The name of the static archive\n")
  FILE(APPEND ${_laname} "old_library='${_target_static_lib}'\n")
  FILE(APPEND ${_laname} "# Libraries that this one depends upon.\n")
  FILE(APPEND ${_laname} "dependency_libs='${_target_dependency_libs}'\n")
  FILE(APPEND ${_laname} "# Version information.\n")
  FILE(APPEND ${_laname} "current=${_target_current}\n")
  FILE(APPEND ${_laname} "age=${_target_age}\n")
  FILE(APPEND ${_laname} "revision=${_target_revision}\n")
  FILE(APPEND ${_laname} "# Is this an already installed library?\n")
  FILE(APPEND ${_laname} "installed=${_target_installed}\n")
  FILE(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\n")
  FILE(APPEND ${_laname} "shouldnotlink=${_target_shouldnotlink}\n")
  FILE(APPEND ${_laname} "# Files to dlopen/dlpreopen\n")
  FILE(APPEND ${_laname} "dlopen='${_target_dlopen}'\n")
  FILE(APPEND ${_laname} "dlpreopen='${_target_dlpreopen}'\n")
  FILE(APPEND ${_laname} "# Directory that this library needs to be installed in:\n")
  FILE(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}${_install_DIR}'\n")
  INSTALL( FILES ${_laname} ${_soname}
    DESTINATION ${CMAKE_INSTALL_PREFIX}${_install_DIR})
ENDMACRO(CREATE_LIBTOOL_FILE)

Back



CMake: [Welcome | Site Map]