执行cmake target的输出作为另一个的依赖

时间:2017-05-07 21:02:53

标签: c++ cmake

我有以下目录结构:

.
├── CMakeLists.txt
├── generator
│   ├── CMakeLists.txt
│   └── main.cpp
├── include
└── src
    ├── CMakeLists.txt
    └── mylib.cpp

我想构建generator,然后使用generator生成将用于构建mylib的源文件。我试过这个:

发生器/的CMakeLists.txt:

add_executable(gen main.cpp)

add_custom_command(
    OUTPUT
        ${CMAKE_BINARY_DIR}/generated.cpp
    DEPENDS
        gen
    COMMAND
        ${CMAKE_BINARY_DIR}/gen -d /tmp
    VERBATIM
)

的src /的CMakeLists.txt:

add_library(py-cppast
        ${CMAKE_BINARY_DIR}/generated.cpp
        mylib.cpp)

的CMakeLists.txt:

cmake_minimum_required(VERSION 3.1.2)
project(my-project)

add_subdirectory(generator)    
add_subdirectory(src)

但是,该命令未执行。相反,我只是得到错误:

CMake Error at src/CMakeLists.txt:2 (add_library):
  Cannot find source file:

    /home/....(the cmake binary dir)..../generated.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx

如何告诉cmake执行我用它构建的程序?这甚至可以在一次构建中实现吗?

0 个答案:

没有答案