2015-10-13 48 views
-1

我想了解add_custom_command使用,我寫了像下面所示 當我運行使用add_custom_command不工作

$ C進行make文件最小的make文件(的CMakeLists.txt) 。

$使 我沒有看到正在創建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 

回答

0

只是一個錯字:
gperf_generate_new(command_options.new.gperf pefecthash .HPP)
...
DEPENDS perfecthash .hpp