0

我想为我正在使用 CMake 3 构建的库生成一个 libtool 文件。我发现了这个宏,它对旧版本的 CMake 有帮助:https ://gitlab.kitware.com/cmake/community/- /wikis/contrib/macros/LibtoolFile

这是适用于 CMake 2.8 的代码:

 MACRO(GET_TARGET_PROPERTY_WITH_DEFAULT _variable _target _property _default_value)
   GET_TARGET_PROPERTY (${_variable} ${_target} ${_property})
   IF (${_variable} MATCHES NOTFOUND)
     SET (${_variable} ${_default_value})
   ENDIF (${_variable} MATCHES 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 ${PROJECT_BINARY_DIR}/${_laname}.la)
   FILE(WRITE ${_laname} "# ${_laname} - a libtool library file\n")
   FILE(WRITE ${_laname} "# Generated by CMake ${CMAKE_VERSION} (like GNU libtool)\n")
   FILE(WRITE ${_laname} "\n# Please DO NOT delete this file!\n# It is necessary for linking the library with libtool.\n\n" )
   FILE(APPEND ${_laname} "# The name that we can dlopen(3).\n")
   FILE(APPEND ${_laname} "dlname='${_soname}'\n\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\n")
   FILE(APPEND ${_laname} "# The name of the static archive.\n")
   FILE(APPEND ${_laname} "old_library='${_target_static_lib}'\n\n")
   FILE(APPEND ${_laname} "# Libraries that this one depends upon.\n")
   FILE(APPEND ${_laname} "dependency_libs='${_target_dependency_libs}'\n\n")
   FILE(APPEND ${_laname} "# Names of additional weak libraries provided by this library\n")
   FILE(APPEND ${_laname} "weak_library_names=''\n\n")
   FILE(APPEND ${_laname} "# Version information for ${_laname}.\n")
   FILE(APPEND ${_laname} "current=${_target_current}\n")
   FILE(APPEND ${_laname} "age=${_target_age}\n")
   FILE(APPEND ${_laname} "revision=${_target_revision}\n\n")
   FILE(APPEND ${_laname} "# Is this an already installed library?\n")
   FILE(APPEND ${_laname} "installed=${_target_installed}\n\n")
   FILE(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\n")
   FILE(APPEND ${_laname} "shouldnotlink=${_target_shouldnotlink}\n\n")
   FILE(APPEND ${_laname} "# Files to dlopen/dlpreopen\n")
   FILE(APPEND ${_laname} "dlopen='${_target_dlopen}'\n")
   FILE(APPEND ${_laname} "dlpreopen='${_target_dlpreopen}'\n\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} DESTINATION ${CMAKE_INSTALL_PREFIX}${_install_DIR})
 ENDMACRO(CREATE_LIBTOOL_FILE)

不幸的是,这对我现在不起作用,因为最新版本的 cmake 不再支持 GET_TARGET_PROPERTY(... LOCATION)。我看到有一个生成器表达式你可以使用 ($<TARGET_FILE_NAME:target_name>) 代替它,但是你可以使用生成器表达式的规则是不同的,而且我对 CMake 的经验仍然非常有限。

谁能给我提示我如何将上述宏调整为最新版本的 CMake,或者如果已经存在一个替代解决方案,可能会给我指出一个替代解决方案?

编辑:此问题已关闭,因为它与此“相同”:如何删除 CMake 中的“可能无法从目标读取位置属性”错误?

内容相似,但不一样。上面的链接问题解释了如何替换特定的代码行,而我的问题是寻求有关如何为此处找到的代码提供替代解决方案的指导:https ://gitlab.kitware.com/cmake/community/ -/wikis/contrib/macros/LibtoolFile

4

0 回答 0