add_custom_command无法正常工作

时间:2015-10-13 20:28:51

标签: cmake

我试图了解add_custom_command的用法,我写了一个最小的make文件(CMakeLists.txt) 如下图所示 当我使用

运行make文件时

$ cmake的。

$化妆 我没有看到perfecthash.cpp被创建并且构建中断了

cmake_minimum_required(VERSION 2.8)
# Call add_custom_command() with appropriate arguments for generate output file
# Note, that *gperf* will work in the build tree,
# so for file in the source tree full path should be used.
function(gperf_generate_new input output)
    MESSAGE("debugging function")
    add_custom_command(
        OUTPUT ${output}
        COMMAND gperf -L c++ ${input} > ${output}
        DEPENDS ${input}
        COMMENT "printing ${output}" # Just for nice message during build
    )
endfunction()

# Generate *example.hpp* file ...
gperf_generate_new(command_options.new.gperf pefecthash.hpp)

# ... for use it in executable
add_custom_target(my_target
    ALL # Force target to be built with default build target.
    DEPENDS perfecthash.hpp

)

$ cmake。

$使

给出以下错误

-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
debugging function
-- Configuring done
-- Generating done
-- Build files have been written to: /home/srinivas
Scanning dependencies of target my_target
make[2]: *** No rule to make target `perfecthash.hpp', needed by `CMakeFiles/my_target'.  Stop.
make[1]: *** [CMakeFiles/my_target.dir/all] Error 2
make: *** [all] Error 2

1 个答案:

答案 0 :(得分:0)

只是一个错字:
    gperf_generate_new(command_options.new.gperf pefecthash .hpp)
    ...
    DEPENDS perfecthash .hpp