问题如下:
项目结构:
ProjectDir
- CMakeLists.txt
- src
-- CMakeLists.txt
-- FirstApp
--- CMakeLists.txt
--- ... sources ...
-- SecondApp
--- CMakeLists.txt
--- ... sources ...
- tools
-- CMakeLists.txt
-- SomeTool
--- CMakeLists.txt
--- ... sources ...
-- SomeOtherTool
--- CMakeLists.txt
--- ... sources ...
我想要实现的是:
- 带有SomeTool二进制文件的包(让它成为rpm或deb) ;
- 包含FirstApp、SecondApp和SomeOtherTool二进制文件;
我所知道的:
- CPack 将安装命令中定义的内容放入包内容中;
- CPack 不能
include(CPack)
在同一棵树中被调用 ( ) 两次(例如,它不能在 CMakeLists.txtsrc
级别 ANDSecondApp
级别调用);
我有什么
在ProjectDir/tools/SomeTool/CMakeLists.txt
我(这是伪代码)中:
PROJECT( SomeTool )
SET(TARGET SomeTool)
SET(CPACK_GENERATOR "RPM")
SET(CPACK_PACKAGE_NAME "SomeTool")
# ...
# all the other CPACK_* stuff
# ...
include(CPack)
add_custom_target(${TARGET}-package
COMMAND cpack --config "${CMAKE_CURRENT_BINARY_DIR}/CPack${PROJECT_NAME}Config.cmake")
SET(SOURCES ...)
SET(HEADERS ...)
add_executable(${TARGET} ${SOURCES} ${HEADERS})
install(TARGETS ${TARGET}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/bin)
这样我就可以调用它,它会创建带有 content的make SomeTool-package
package ( ) 。伟大的!SomeTool.rpm
/usr/bin/SomeTool
我可以CMakeLists.txt
在ProjectDir/src/
目录中有非常相似的:
# src/CMakeLists.txt
PROJECT( MainProject )
SET(CPACK_GENERATOR "RPM")
SET(CPACK_PACKAGE_NAME "MainProject")
# ...
# all the other CPACK_* stuff
# ...
include(CPack)
add_custom_target(MainProject-package
COMMAND cpack --config "${CMAKE_CURRENT_BINARY_DIR}/CPack${PROJECT_NAME}Config.cmake")
add_subdirectory(FirstApp)
add_subdirectory(SecondApp)
# src/FirstApp/CMakeLists.txt
SET(TARGET FirstApp)
SET(SOURCES ...)
SET(HEADERS ...)
add_executable(${TARGET} ${SOURCES} ${HEADERS})
install(TARGETS ${TARGET}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/bin)
# src/SecondApp/CMakeLists.txt
SET(TARGET SecondApp)
SET(SOURCES ...)
SET(HEADERS ...)
add_executable(${TARGET} ${SOURCES} ${HEADERS})
install(TARGETS ${TARGET}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/bin)
这样我可以调用make MainProject-package
,它会创建MainProject.rpm
包含内容的包 ()/usr/bin/FirstApp
和/usr/bin/SecondApp
. 伟大的!
SomeOtherTool也有一个CMakeLists.txt
看起来与FirstApp和SecondApp CMakeLists.txt
相同的东西,我可以调用make SomeOtherTool
它,它会生成SomeOtherTool
二进制文件。
问题
由于 CPack 正在将连接到install
命令的东西放入包中,我如何将SomeOtherTool与我的MainProject-package连接?
我的解决方案是(是)install
在末尾添加另一个子句,src/CMakeLists.txt
如下所示:
add_dependency(MainProject SomeOtherTool)
install(FILES ${CMAKE_BINARY_DIR}/SomeOtherTool DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/bin )
还有其他方法吗?这个解决方案看起来不干净。如果我更改SomeOtherTool可执行文件名称,我也必须在这里更改它。安装路径也是如此。