0

As part of the configuration step of my CMake-based program, I download a program into a subfolder of CMAKE_BINARY_DIR, which is then invoked as part of an add_custom_command() to generate some source files at build time.

However, when running make to build the project, I always get this error message when getting to the custom build step:

: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable

re-running make with the VERBOSE=1 flag to make it print build commands, I get the following output:

cd (directory) && (cmake_binary_dir)/path/to/tool (arguments...)
: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable

where the path to the tool is an absolute path under the CMAKE_BINARY_DIR

Copying the full absolute path to the tool and pasting it directly into my terminal makes the program start up without issue.

I'm at a loss at this point as to how to get CMake to run my custom build stage. Any advice?

EDIT: My actual add_custom_command invocation is the following:

# at this point, PROTOC_COMPILER holds the path to protoc (inside the cmake build directory)
# PROTOBUF_FILES is the collection of .proto files I want to generate

message(STATUS "protoc path: ${PROTOC_COMPILER}")

foreach(PROTOFILE ${PROTOBUF_FILES})
    get_filename_component(PROTOFILE_DIR ${PROTOFILE} DIRECTORY)
    get_filename_component(PROTOFILE_NAME ${PROTOFILE} NAME_WE) # name without extension
    get_filename_component(PROTOFILE_ABSOLUTE_PATH ${PROTOFILE} ABSOLUTE)

    set(PROTOFILE_OUTPUT_HEADER_NAME "${FULL_OUTPUT_DIR}/${PROTOFILE_DIR}/${PROTOFILE_NAME}.pb.h")
    set(PROTOFILE_OUTPUT_SRC_NAME "${FULL_OUTPUT_DIR}/${PROTOFILE_DIR}/${PROTOFILE_NAME}.pb.cc")

    add_custom_command(
        OUTPUT "${PROTOFILE_OUTPUT_HEADER_NAME}" "${PROTOFILE_OUTPUT_SRC_NAME}"
        COMMENT "Compiling Protobuf file: ${PROTOFILE}"

        # make sure the output directory exists.
        COMMAND ${CMAKE_COMMAND} -E make_directory "${FULL_OUTPUT_DIR}/${PROTOFILE_DIR}"

        # actually generate the files. This is the command that fails.
        COMMAND ${PROTOC_COMPILER}
            --cpp_out="${FULL_OUTPUT_DIR}"  # where to put the output files.
            # make sure we can reference includes.
            # directory the $PROTOFILE is in. Otherwise protoc complains about it.
            -I${CMAKE_CURRENT_SOURCE_DIR}
            --grpc_out="${FULL_OUTPUT_DIR}"
            --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}"
            "${PROTOFILE_ABSOLUTE_PATH}" # the file to build

        DEPENDS "${PROTOFILE_ABSOLUTE_PATH}"
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    )

    list(APPEND GENERATED_HEADERS ${PROTOFILE_OUTPUT_HEADER_NAME})
    list(APPEND GENERATED_SOURCES ${PROTOFILE_OUTPUT_SRC_NAME})
endforeach()


add_library(my-project-protomessages STATIC ${GENERATED_SOURCES} ${GENERATED_HEADERS})
target_include_directories(my-project-protomessages PUBLIC ${FULL_OUTPUT_DIR})
Paul Belanger
  • 2,354
  • 14
  • 23
  • Please see my edit. – Paul Belanger Jun 04 '20 at 16:28
  • 1
    `I get the following` Could you post the actual paths and the actual text as it is printed by cmake? – KamilCuk Jun 04 '20 at 16:31
  • According to the googling, the error message is output by `protoc` utility. So the path to the utility is OK, it is some of its **parameter** which is wrong. – Tsyvarev Jun 04 '20 at 16:31
  • I think that's the issue! I was searching for `cmake "program not found or is not executable"` and was coming up blank. I was passing an empty string to the "grpc plugin" argument when I did a second pass to generate the GRPC stubs. – Paul Belanger Jun 04 '20 at 16:38
  • ie, in the above example, ${GRPC_CPP_PLUGIN} was the empty string. – Paul Belanger Jun 04 '20 at 16:49

0 Answers0