run a shell command (ctags) in cmake and make

前端 未结 3 506
我在风中等你
我在风中等你 2020-12-29 07:55

I\'m coding a c++ project in vim.

I\'d like to run a ctags command (ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .) to generate referen

3条回答
  •  醉梦人生
    2020-12-29 08:34

    The most basic way to do this is:

    set_source_files_properties( tags PROPERTIES GENERATED true)
    add_custom_command ( OUTPUT tags
        COMMAND ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . 
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} )
    add_executable ( MyProjectOutput tags )
    

    The first line tells CMake that tags will be generated. The add_custom_command is CMake will generate tags when needed, and finally, some target needs to depend on tags. The default working directory is in the build tree, so WORKING_DIRECTORY must be set to your source tree. This is equivalent a Makefile entry:

    tags:
        ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
    
    MyProjectOutput: tags
        # Whatever here...
    

提交回复
热议问题