Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
78 views
in Technique[技术] by (71.8m points)

c++ - Is it possible to compile recently changed files first?

The following scenario happens a lot:

  • I change a header which is included in a lot of places, e.g. to add a function declaration.
  • I add a function definition to the corresponding source file, which has an error because I'm dumb.
  • I compile, and wait a long time for a bunch of irrelevant stuff to be compiled before I see the error in the code I'm working on.

If cmake would prioritize compiling recently modified files first, it would reduce my test cycle time in these cases by several minutes. Is this possible?

question from:https://stackoverflow.com/questions/65837237/is-it-possible-to-compile-recently-changed-files-first

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I couldn't find anything general in CMake that allows you to specify build order, but you may be able to do this with specific build system generators that allow you to compile individual .o or .obj files. For example, using the Ninja generator:

add_executable(mytarget the-suspect-src.cpp)

The generated Ninja build system lets me build the corresponding .o file by specifying it explicitly:

ninja CMakeFiles/mytarget.dir/the-suspect-src.cpp.o

So you could achieve your desired behavior with:

ninja CMakeFiles/mytarget.dir/the-suspect-src.cpp.o && ninja

Note that I don't memorize these paths to the .o files, but instead tab-complete in the terminal.


I happen to know that the Makefile generators also have a similar ability to build individual .o files, but I'm not aware of any other generators which have this ability.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...