CMake add_custom_command失败,并出现bin / sh:1:...找不到 [英] CMake add_custom_command fails with bin/sh:1 : ... not found

查看:175
本文介绍了CMake add_custom_command失败,并出现bin / sh:1:...找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现的目标



我尝试建立一个工具链来编译适用于Intel FPGA的OpenCL应用程序。因此,在构建基于C ++的主机应用程序下面,我需要为OpenCL内核调用Intel OpenCL脱机编译器。



仅当cl源文件已被编辑或结果二进制文件丢失。我的方法是添加一个自定义命令以调用CL编译器并创建一个依赖于此命令生成的输出的自定义目标。离线Open CL编译器称为 aoc ,由于系统上可能存在多个SDK版本,因此我使用存储在<$ c $中的绝对路径来调用它c> aocExecutable 。这是我的CMakeLists.txt的相关部分。

  set(CLKernelName vector_add)
set(CLKernelSourceFile $ {PROJECT_SOURCE_DIR} / $ {CLKernelName} .cl)
set(CLKernelBinary $ {PROJECT_BINARY_DIR} / $ {CLKernelName} .aocx)

add_executable(HostApplication main.cpp)

#------这里有很多不必要的详细信息------

add_custom_command(OUTPUT $ {CLKernelBinary}
COMMAND $ { aocExecutable} -march = emulator $ {CLKernelSourceFile} -o $ {CLKernelBinary}
DEPENDS $ {CLKernelSourceFile}



add_custom_target(CompileCLSources DEPENDS $ {CLKernelBinary})
add_dependencies(HostApplication CompileCLSources)

是什么? t work
在Linux下的CLion IDE中运行此命令会导致此错误:

  / bin / sh:1:/home/me/SDKsAndFrameworks/intelFPGA/18.1/hld/bin/aoc -march = emulator / home / me / CL ionProjects / cltest / vector_add.cl -o /home/me/CLionProjects/cltest/cmake-build-debug-openclintelfpgasimulation/vector_add.aocx:找不到

整个命令可以正确展开,将其复制并粘贴到终端中可以正常工作,所以我不确定找不到什么错误的意思。



其他问题



假设上述问题将是解决后,如何才能不仅在构建目录中不存在输出文件时,而且在编辑CL源文件时调用自定义命令?

解决方案

正如您在错误消息中看到的那样,bash会解释整个命令行

  /home/me/SDKsAndFrameworks/intelFPGA/18.1/hld/bin/aoc -march = emulator /home/me/CLionProjects/cltest/vector_add.cl -o / home / me / CLionProjects / cltest / cmake-build-debug-openclintelfpgasimulation / vector_add.aocx 

作为单个可执行文件



这是因为您将COMMAND包装在脚本中并使用双引号



删除这些双引号,以便一切正常。






与许多其他脚本语言一样,在CMake中,双引号使带引号的字符串被解释为函数或宏的单个参数。 / p>

但在 add_custom_command / add_custom_target 中,关键字 COMMAND 开始一个参数列表,第一个表示可执行文件,其他表示该可执行文件的单独参数。


What I want to achieve

I try to set up a toolchain to compile OpenCL applications for Intel FPGAs. Therefore beneath building the C++ based host application I need to invoke the Intel OpenCL offline compiler for OpenCL kernels.

This step should only take place if the cl source file was edited or the resulting binaries are missing. My approach is to add a custom command to invoke the CL compiler and create a custom target that depends on the output generated by this command. The offline Open CL compiler is called aoc and due to the possibility of multiple SDK-Versions present on the system I invoke it with an absolute path that is stored in aocExecutable. This is the relevant part of my CMakeLists.txt

set (CLKernelName "vector_add")
set (CLKernelSourceFile "${PROJECT_SOURCE_DIR}/${CLKernelName}.cl")
set (CLKernelBinary     "${PROJECT_BINARY_DIR}/${CLKernelName}.aocx")

add_executable (HostApplication main.cpp)

# ------ a lot of unneccessary details here ------ 

add_custom_command (OUTPUT  "${CLKernelBinary}"
                    COMMAND "${aocExecutable} -march=emulator ${CLKernelSourceFile} -o ${CLKernelBinary}"
                    DEPENDS "${CLKernelSourceFile}"
)


add_custom_target (CompileCLSources DEPENDS "${CLKernelBinary}")
add_dependencies (HostApplication CompileCLSources)

What doesn't work Running this in the CLion IDE under Linux leads to this error:

/bin/sh: 1: /home/me/SDKsAndFrameworks/intelFPGA/18.1/hld/bin/aoc -march=emulator /home/me/CLionProjects/cltest/vector_add.cl -o /home/me/CLionProjects/cltest/cmake-build-debug-openclintelfpgasimulation/vector_add.aocx: not found

The whole command expands correctly, copying it and pasting it into a terminal works without problems, so I'm not sure what the not found error means.

Further Question

Assumed the above problem will be solved, how can I achieve that the custom command is not only invoked if the output file is not present in the build directory but also if the CL source file was edited?

解决方案

As you can see in the error message, the bash interprets the whole command line

/home/me/SDKsAndFrameworks/intelFPGA/18.1/hld/bin/aoc -march=emulator /home/me/CLionProjects/cltest/vector_add.cl -o /home/me/CLionProjects/cltest/cmake-build-debug-openclintelfpgasimulation/vector_add.aocx

as a single executable.

This is because you wrap COMMAND in your script with double quotes.

Remove these double quotes, so everything will work.


As in many other scripting languages, in CMake double quotes makes the quoted string to be interpreted as a single argument for a function or for a macro.

But in add_custom_command/add_custom_target functions a keyword COMMAND starts a list of arguments, first of which denotes an executable and others - separated parameters for that executable.

这篇关于CMake add_custom_command失败,并出现bin / sh:1:...找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆