How to generate cscope.files from CMakeLists.txt

风格不统一 提交于 2019-12-10 11:01:48

问题


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?


回答1:


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.




回答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}")


来源:https://stackoverflow.com/questions/15175955/how-to-generate-cscope-files-from-cmakelists-txt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!