如何使用 cmake pack redhat 风格的 rpm,这是主要的和"-devel"?
How to use cmake pack redhat-style rpm, which is major and "-devel"?
我尝试使用cmake来打包redhat风格的rpm。 经典的红帽式转速由 2 rpm 组成,一个是package-version.rpm
rpm,另一个是package-devel-version.rpm
。但我失败了。
例如,项目foo
,其中包含
- bin/demo
- lib/libfoo.so.1.2.3
- lib/libfoo.so.1
- lib/libfoo.so
- include/foo.h
我希望foo-1.2.3.rpm
包含bin/demo
、lib/libfoo.so.1
、lib/libfoo.so.1.2.3
和foo-devel-1.2.3.rpm
包含lib/libfoo.so
、include/foo.h
。
但是现在,我只能得到foo-1.2.3-major.rpm
(bin/demo
,lib/libfoo.so
,lib/libfoo.so.1
,lib/libfoo.so.1.2.3
(和foo-1.2.3-devel.rpm
(include/foo.h
(。
# CMakeLists.txt
project (foo)
include (GNUInstallDirs)
set(CPACK_PACKAGE_VERSION_MAJOR 1)
set(CPACK_PACKAGE_VERSION_MINOR 2)
set(CPACK_PACKAGE_VERSION_PATCH 3)
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The CMake Demo Project")
set(CPACK_GENERATOR RPM)
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_ALL major devel)
include (CPackComponent)
include (CPack)
cpack_add_component(major DISPLAY_NAME Major)
cpack_add_component(devel DISPLAY_NAME Development)
add_executable (demo demo.cxx)
add_library (foo SHARED foo.cxx foo.h)
set_target_properties(foo PROPERTIES VERSION 1.2.3 SOVERSION 1)
install (TARGETS demo foo
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT major
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT major
)
install (FILES foo.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT devel
)
多亏了@Tsyvarev,我取得了一些进展。 在include(CPack)
之前添加行set(CPACK_RPM_MAIN_COMPONENT major)
,我得到以下结果。rpm 名称foo-1.2.3.rpm
现在是正确的。
]$ rpm -ql --qf "%{name}-%{version}n" -p foo-1.2.3-devel.rpm
foo-devel-1.2.3
/usr/include/foo.h
]$ rpm -ql --qf "%{name}-%{version}n" -p foo-1.2.3.rpm
foo-1.2.3
/usr/bin/demo
/usr/lib64/libfoo.so
/usr/lib64/libfoo.so.1
/usr/lib64/libfoo.so.1.2.3
但是foo-1.2.3-devel.rpm
的文件名仍然不正确,rpm 中的文件仍然错误。
最后,我完成了我的CMakeLists.txt
# CMakeLists.txt
cmake_minimum_required (VERSION 3.12)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "build type")
project (foo VERSION 1.2.3 HOMEPAGE_URL "http://null")
include (GNUInstallDirs)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The CMake Demo Project")
set(CPACK_COMPONENTS_ALL major devel)
set(CPACK_GENERATOR RPM)
set(CPACK_RPM_PACKAGE_RELEASE 10)
set(CPACK_RPM_PACKAGE_RELEASE_DIST ON)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_MAIN_COMPONENT major) # Which set the major package name to foo instead of foo-major
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT") # Which makes the rpm name from foo-1.2.3-devel to foo-devel-1.2.3
set(CPACK_RPM_DEBUGINFO_PACKAGE ON)
set(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE ON)
# you must include it here after set(CPACK...) and befor cpack_add_...
include (CPack)
cpack_add_component(major DESCRIPTION "Something for demo")
cpack_add_component(devel DESCRIPTION "For Development")
add_executable (demo demo.cxx)
add_library (foo SHARED foo.cxx foo.h)
set_target_properties(foo PROPERTIES VERSION 1.2.3 SOVERSION 1)
set(PUBLIC_HEADERS foo.h)
install (TARGETS demo foo
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT major
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT major
NAMELINK_COMPONENT devel # Which separate libfoo.so into foo-devel rpm, but it requires cmake-3.12, RHEL-8 takes 3.11.
)
install (FILES ${PUBLIC_HEADERS}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT devel
)
install (FILES README.md
DESTINATION ${CMAKE_INSTALL_DOCDIR}-${PROJECT_VERSION}
COMPONENT devel
)
带有 cmake-3.11 的 RHEL-8 的解决方法:
# install libfoo.so.1.2.3 and libfoo.so.1
install (TARGETS foo
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT major
NAMELINK_SKIP
)
# install libfoo.so
install (TARGETS foo
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT devel
NAMELINK_ONLY
)
感谢大家
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用CMake创建QML插件
- cmake如何在fedora工作站中找到boost静态库包
- 使用CMake检测支持的C++标准
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 如何使用CMake编译.proto文件来生成.grpcp.pb.cc和.grpc.pb.h文件
- cmake在我的项目中所需的所有静态库都不成功
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 无法链接 CMake 中的本地库
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 如何在Ubuntu中使用cmake设置qt4
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 为什么 cmake 许可证<>样式不包括?
- cmake更新缓存的变量
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 使外部项目可用于find_package CMake
- 生成MRPT库时cmake配置失败
- 如何使用 cmake pack redhat 风格的 rpm,这是主要的和"-devel"?