ruben2020
ruben2020

Reputation: 1549

How to generate cscope.files from CMakeLists.txt

I'm using CMake to build my code. CMakeLists.txt contains the list of all the .C or .CPP files and all the include directories.

How can I implement CMakeLists.txt so that I can have a make option that generates cscope.files for me containing the list of all the .C and .CPP (or .CXX) files and also all the .h files from the include directories in it?

For e.g. I should be able to run make cscopefiles and it will generate cscope.files for me.

Or is there already such an option?

Upvotes: 2

Views: 1402

Answers (2)

DLRdave
DLRdave

Reputation: 14280

You could also extend Fraser's answer with a configure_file call, so the final file only changes when its content has changed.

file(WRITE
  ${CMAKE_BINARY_DIR}/cscope.files.in
  "${AllFiles}")
configure_file(
  ${CMAKE_BINARY_DIR}/cscope.files.in
  ${CMAKE_BINARY_DIR}/cscope.files
  COPYONLY)

That could help minimize incremental rebuilds if something else (a custom command) depends on the cscope.files output file. The configure_file call will only update the output file if the result is different from its current contents.

Upvotes: 3

Fraser
Fraser

Reputation: 78418

You could generate the file every time CMake runs by adding something like the following: (this assumes your current list of files are in 2 variables called SourceFiles and HeaderFiles)

set(AllFiles ${SourceFiles} ${HeaderFiles})
string(REPLACE ";" "\n" AllFiles "${AllFiles}")
file(WRITE ${CMAKE_BINARY_DIR}/cscope.files "${AllFiles}")

Upvotes: 2

Related Questions