[CMake] set_property on sources causing extra files to be rebuilt

Daniel Nelson torham at connect2.com
Thu Mar 19 20:46:29 EDT 2009


I am using set_property to add extra compile flags to source files that are 
built using a precompiled header, but whenever a source file is added or 
removed it causes every file in the executable to be rebuilt.  I have come up 
with a CMakeList that shows the issue.

#####
cmake_minimum_required(VERSION 2.6) 
project(prop_test)
set(sources foo.cpp bar.cpp main.cpp) 
add_executable(prop_test ${sources})
set_property(SOURCE foo.cpp main.cpp APPEND PROPERTY COMPILE_FLAGS -Wall)
#####

If you compile the project using a Makefile generator, then remove foo.cpp from 
the sources variable and recompile, it will also recompile main.cpp and 
bar.cpp even though no compile flags have changed.  If you then put foo.cpp 
back and build it will again rebuild main.cpp and bar.cpp.  It seems that you 
will need to rebuild every source file that is used in the executable, even 
though nothing has changed.

Is there a way around doing all this rebuilding?


More information about the CMake mailing list