0
votes

My project structure:

/external-source-generating-tool
/external-source-generating-tool/CMakeLists.txt
/external-source-generating-tool/*.cpp
/src
/src/CMakeLists.txt
/src/*.cpp
/CMakeLists.txt

CMakeLists.txt:

add_subdirectory(external-source-generating-tool)
add_subdirectory(src)

/src/CMakeLists.txt:

add_custom_command(OUTPUT generated-source.cpp
    COMMAND external-source-generating-tool -o generated-source.cpp
    MAIN_DEPENDENCY external-source-generating-tool
    COMMENT "Generating...")

add_executable(my-app source1.cpp generated-source.cpp)

The problems is /src/CMakeLists.txt cannot find external-source-generating-tool:

Error:Cannot find source file:
external-source-generating-tool
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx

How correctly call external-source-generating-tool from /src/CMakeLists.txt?

1
According to error message it seems that you are trying to add external-source-generating-tool as source file for add_executable(). It has nothing common with inability to find external-source-generating-tool executable for run it.Tsyvarev
Really, it was visible. The problem was with the MAIN_DEPENDENCY external-source-generating-tool parameter. I removed it and now all works fine.york.beta

1 Answers

1
votes

The problem was with the MAIN_DEPENDENCY external-source-generating-tool parameter of add_custom_command. I replaced it by DEPENDS external-source-generating-tool:

add_custom_command(OUTPUT generated-source.cpp
    COMMAND external-source-generating-tool -o generated-source.cpp
    DEPENDS external-source-generating-tool
    COMMENT "Generating...")

And now all works fine.