我有以下的目录结构:执行cmake的目标的输出作为依赖于另一
.
├── CMakeLists.txt
├── generator
│ ├── CMakeLists.txt
│ └── main.cpp
├── include
└── src
├── CMakeLists.txt
└── mylib.cpp
我想建立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的执行,我用它开发程序?这是甚至可能在一个单一的构建?