【问题标题】:How to add a folder with a sh file to cmake to call the file via system()如何将带有 sh 文件的文件夹添加到 cmake 以通过 system() 调用文件
【发布时间】:2019-04-08 07:05:55
【问题描述】:

我有一个 Source 文件夹,其中包含一个名为 test.sh 的 .sh 文件。使用 c++ vi 可以调用带有system("Source/test.sh") 的 .sh 文件。如何将目录添加到 c++ 项目中,如果可执行文件不在根目录中,我可以调用该文件。

【问题讨论】:

  • 你的意思是要使用绝对目录system("/the/directory/to/the/test/script/test.sh" ?
  • execute_process()add_custom_target()
  • 我会将文件复制到c项目中,所以文件在可执行文件中而不是在计算机上

标签: c++ linux cmake


【解决方案1】:

您可以按如下方式使用execute_process:

execute_process (
    COMMAND bash -c " your command"
    OUTPUT_VARIABLE outVar
)

所以如果你想复制你的文件:

set(MAKECMD "cp myf/ile")
list(APPEND MAKECMD ${CMAKE_CURRENT_SOURCE_DIR})
execute_process (
    COMMAND bash -c ${MAKE_CMD}
    OUTPUT_VARIABLE CMDOUTPUT
)

更多信息:https://cmake.org/cmake/help/v3.0/command/execute_process.html

【讨论】:

    猜你喜欢
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    相关资源
    最近更新 更多