Cmake cannot run shell command

二次信任 提交于 2020-01-25 08:53:08

问题


Let's assume we have a project with some subdirectories and we need to generate .cpp and .h files in one of its subdirectories. True fact: if we run a command (without < and >) in that directory, it generates valid files.

So how to do the same using cmake?

Cmake has add_custom_command, but it does nothing, so we cannot use it. execute_process is better because it runs something, but in a wrong way.

execute_process(COMMAND "protoc -I=\".\" --cpp_out=\".\" protocol.proto"
                WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

Unfortunately the result is nothing because cmake cannot run the command properly, so "protoc" prints "No such file or directory".

ADD/EDIT: this execute_process call is located in CMakeLists.txt which is located in the same directory with protocol.proto file

Why it cannot just simply run this command?


回答1:


You shouldn't need to wrap the COMMAND arguments in quotations:

execute_process(COMMAND protoc -I=. --cpp_out=. protocol.proto
                WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})


来源:https://stackoverflow.com/questions/14297840/cmake-cannot-run-shell-command

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