0
votes

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

1 Answers

4
votes

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})