How to get the list of files that will be installed when installing a CMake component
有没有办法以编程方式(在 CMake 中)知道如果安装了
目前,我正在将
1 2 3 | cmake -DCOMPONENT=my_test_component -DCMAKE_INSTALL_PREFIX=${TMP_PACKAGING_ROOT} -P ${CMAKE_BINARY_DIR}/cmake_install.cmake |
我想知道是否可以获取文件列表以便我只能将这些文件明确包含在包中?或者可能将它们作为输出添加到自定义命令?
知道它的唯一方法似乎是阅读
CMake 没有
关联的文件
通常,
For certain kinds of binary installers (including the graphical installers on macOS and Windows), CPack generates installers that allow users to select individual application components to install. The contents of each of the components are identified by the
COMPONENT argument of CMakea€?sINSTALL command.
但是,如果您不使用 CPack,CMake 仍然支持
进行过滤
1 2 3 4 5 6 7 8 9 10 11 12 13 | # Define install rule for MyExecutable target (grouping it in MyComponent). install(TARGETS MyExecutable DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/installation CONFIGURATIONS Release COMPONENT MyComponent ) # Add custom target to filter and install MyComponent files. add_custom_target(MyInstallTarget COMMAND"${CMAKE_COMMAND}" -DCOMPONENT=MyComponent -P cmake_install.cmake DEPENDS MyExecutable WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) |
在构建此自定义目标(例如
但是,这个清单文件本身并不是很有用。要以编程方式使用它,我们可以扩展自定义目标以将这些特定于组件的文件读入 CMake 变量。
1 2 3 4 5 6 | add_custom_target(MyInstallTarget COMMAND"${CMAKE_COMMAND}" -DCOMPONENT=MyComponent -P cmake_install.cmake COMMAND"${CMAKE_COMMAND}" -DCOMPONENT=MyComponent -P ../my_install_script.cmake DEPENDS MyExecutable WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) |
在
将它们复制到安装目标
1 2 3 4 5 6 7 8 9 10 11 12 13 | # Check if an install COMPONENT was provided. if(COMPONENT) # Read the manifest file. file(READ"install_manifest_${COMPONENT}.txt" MY_INSTALL_FILES) # Create a list from the component files. string(REPLACE"\ "";" MY_INSTALL_FILES ${MY_INSTALL_FILES}) # Loop through each file, placing it in the installation directory. foreach(curFile ${MY_INSTALL_FILES}) message("Installing file:" ${curFile}) configure_file(${curFile} /your/final/install/folder COPYONLY) endforeach() endif(COMPONENT) |