简体   繁体   English

使用cmake将源文件放入INSTALL目标中

[英]put source files in INSTALL target with cmake

I asked a question How to add files to a non-executable or non-library target with CMake a few days ago, and the best solution to this problem is to use add_custom_target command. 我几天前问了一个问题, 如何使用CMake将文件添加到不可执行或非库目标中,对此问题的最佳解决方案是使用add_custom_target命令。

However, this solution may not work if the target is created by CMAKE itself. 但是,如果目标是由CMAKE本身创建的,则此解决方案可能不起作用。 For example, the INSTALL target that is created automatically when running CMAKE. 例如,运行CMAKE时自动创建的INSTALL目标。 Suppose, I also put some additional files under the INSTALL project, what should I do? 假设我还在INSTALL项目下放置了一些其他文件,该怎么办? I have tried the following command, but failed: 我尝试了以下命令,但失败了:

add_custom_target( INSTALL  
  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/file_to_be_added.h
)

CMake's default INSTALL target cannot be modified. CMake的默认INSTALL目标无法修改。 You can however add a custom target, which does the same thing as the INSTALL target and has additional files added, eg: 但是,您可以添加一个自定义目标,该目标与INSTALL目标具有相同的功能,并添加了其他文件,例如:

add_custom_target(myinstall
    COMMAND "${CMAKE_COMMAND}" "-DBUILD_TYPE=$<CONFIGURATION>"
        "-P" "${CMAKE_BINARY_DIR}/cmake_install.cmake"
    SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/file_to_be_added.h"
    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM