CMake add_custom_command fails with bin/sh:1 : … not found

人盡茶涼 提交于 2019-12-13 03:45:24

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/55711749/cmake-add-custom-command-fails-with-bin-sh1-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!