如何从CMake的另一个目录中引用可执行文件?

时间:2016-07-26 11:35:33

标签: build cmake code-generation

我的项目结构:

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

问题是/src/CMakeLists.txt找不到external-source-generating-tool

  

错误:找不到源文件:
  外部源产生的工具
  尝试扩展.c .C .c ++ .cc .cpp .cxx .m .M .mm .h .hh .h ++ .hm .hpp   .hxx .in .txx

如何从external-source-generating-tool正确拨打/src/CMakeLists.txt

1 个答案:

答案 0 :(得分:1)

问题在于MAIN_DEPENDENCY external-source-generating-tool的{​​{1}}参数。我将其替换为add_custom_command

DEPENDS external-source-generating-tool

现在一切正常。