How to generate cscope.files from CMakeLists.txt
Asked Answered
W

2

2

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?

Whelp answered 2/3, 2013 at 15:10 Comment(0)
P
3

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.

Pelagi answered 7/3, 2013 at 16:44 Comment(1)
Nice one - I didn't know that! I would (should) have used execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ...).Overdevelop
O
2

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}")
Overdevelop answered 2/3, 2013 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.