我尝试了这个虚拟示例:
CMakeLists.txt
cmake_minimum_required( VERSION 2.8 )
project( testcmake )
add_custom_command(
OUTPUT testcmake.h
COMMAND xxd -i testcmake.txt testcmake.h
DEPENDS testcmake.txt
)
add_executable( testcmake testcmake.c testcmake.h )
测试cmake.c
#include <stdio.h>
#include "testcmake.h"
int main()
{
int i;
for ( i = 0 ; i < testcmake_txt_len ; i++ )
{
fputc( testcmake_txt[ i ] , stdout );
}
}
测试cmake.txt
foo
bar
baz
问题
它失败了:
[...]
xxd: testcmake.txt: No such file or directory
[...]
添加WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
使一切正常,但我不希望我的自定义命令的输出出现在我的源目录中,我希望所有中间文件都保留在 CMake 构建目录中,就像任何非自定义规则一样。