Run the below script from the top level project directory.

Setup Script

[code langusage=”cpp”]
#!/bin/bash
find -type f -iname ‘*.c’ -o -iname ‘*.cpp’ -o -iname ‘*.h’ -o -iname ‘*.hpp’ -o -iname ‘*.cc’ -o -iname ‘*.hh’  -type f  > ~/cscope.files
cscope -q -R -b -i ~/cscope.files -f ~/cscope.out
export CSCOPE_DB=~/cscope.out
ctags -R .
[/code]

The path of the cscope database file can be customized according to your environment.

Working with Multiple directory
You can specify multiple directory to find command above. See below:

[code langusage=”cpp”]
$find misc/xxxx/abc/ net/wireless/xyz/ ../../../kernel/topic/include/ -type f -iname ‘*.c’ -o -iname ‘*.cpp’ -o -iname ‘*.h’ -o -iname ‘*.hpp’ -o -iname ‘*.cc’ -o -iname ‘*.hh’ -type f > ~/cscope.files
[/code]

Error tag not found
By default ctrl-] doesn’t look into the cscope database rather it looks into the ctag database. So to search in cscope database add the following in your .vimrc file:

[code langusage=”cpp”]
set cscopetag
[/code]

After opening a vim session do the below:

[code langusage=”cpp”]
:cs add $CSCOPE_DB
[/code]

Alternatively you may add it in your ~/.vimrc file as below:

[code langusage=”cpp”]
:cs add $CSCOPE_DB
:set cscopetag
[/code]

Remember in this configuration the CSCOPE_DB will always point to ~/cscope.out. So if you were to start working with a different code base at a later point of time, you have to regenerate your cscope.out file as described above. You can place the cscope.out file anywhere you like but you have to keep in mind the CSCOPE_DB should be pointing to that location. For example if you decide to place it under /home/xyz/abc instead of ~/ then in your environment the CSCOPE_DB should be set as:

[code langusage=”cpp”]
export CSCOPE_DB=/home/xyz/abc/cscope.out
[/code]
For re-generating the cscope.out you can to do:

[code langusage=”cpp”]
$find -type f -iname ‘*.c’ -o -iname ‘*.cpp’ -o -iname ‘*.h’ -o -iname ‘*.hpp’ -o -iname ‘*.cc’ -o -iname ‘*.hh’ -type f > /home//xyz/abc/cscope.files
$cscope -q -R -b -i /home/xyz/abc/cscope.files -f /home//xyz/abc/cscope.out
[/code]

Exit Cscope
Hit CTRL-D to exit Cscope.

Leave a Reply