How to change build flag for just a few source files in a project for debugging

If I already have a project set up with a standard set of compile/link options for that build type and need to debug by changing the compile and or link options for just one or two source files and leave the existing compile/link options for the rest of the project without having to rebuild the entire project with the modified compile/link options, is there a recommended way to do this? In standard Make I would just create a special rule for those source files that I want to impact and rebuild.

Have a look at source file property COMPILE_OPTIONS.

For link options, there is no source file property for that because this step is related to the target is so is the same for all sources. See LINK_OPTIONS.

But keep in mind that changing a CMakeLists.txt will trigger a new generation step before compilation step.

Due to a limitation with the way CMake’s Makefiles generator works, if you change a source file property for one source in a target, all sources for that target will be recompiled. This limitation does not apply to other generators, so switching to Ninja may be a better choice for this workflow.

Thanks Craig and Marc. I will try Ninja and see but in my current build using plain old GNU Makefile, I do what I mentioned above all the time w/o triggering any massive rebuild. If I have a library already build with say -O3 optimization level and want to debug a specific module with -O0, all I doin my current Makefile is to define a new rule for that module and only that one got recompile and replaced the previous version in the library, no massive recompilation for the rest of the unaffected codes.