[CMake] Eliminating spurious dependencies

Michael Hertling mhertling at online.de
Fri Jun 25 21:09:30 EDT 2010


On 06/26/2010 01:09 AM, Tom Birch wrote:
> I'm using add_excecutable to generate a .s file which I then parse to generate a header file. This all works fine and all the dependencies seem to be working, but it gets built every time, even if nothing has changed.
> 
> I have a function to generate the asm file:
> 
> function (make_asm_file source dest defs flags)
> set_source_files_properties(
> 	${source}
> 	PROPERTIES
> 	COMPILE_DEFINITIONS "${${defs}}"
> 	COMPILE_FLAGS "${${flags}} -S"
> 	)
> add_executable (
> 	${dest}
> 	EXCLUDE_FROM_ALL
> 	${source}
> 	)
> set_target_properties(
> 	${dest}
> 	PROPERTIES
> 	OUTPUT_NAME ${dest}
> 	RULE_LAUNCH_LINK "sh build_tools/copier.sh ${CMAKE_BINARY_DIR} <OBJECTS> --"
> 	)
> endfunction(make_asm_file)
> 
> and I invoke that, and then add a custom command to convert the .s into a .h like this:
> 
> make_asm_file(${input_c} ${output_s} c_defs c_flags)
> 
> add_custom_command (
> 	OUTPUT ${header_path}
> 	COMMAND ./make_header ${header_path} ${dest}
> 	DEPENDS ${output_s}
> 	)
> 
> and then I use set_source_file_properties(OBJECT_DEPENDS) to make the sources depend on this generated header.
> 
> Every time I get type make (even on incremental builds) I get
> 
> [  0%] Built target genassym.c.s
> 
> but I only see the custom command on a build when the header hasn't previously been generated, i.e.
> 
> [  1%] Generating assym.h
> 
> So my question is, what is it about this invocation of add_excecutable that makes it always run? Shouldn't EXCLUDE_FROM_ALL get rid of that?

Are you really sure that the targets in question get rebuilt each time
you run make? The message "Built target ..." appears if the target is
found to be up to date regardless if it has been rebuilt afore or not
whereas the "Generating ..." message for custom commands appears only
if the command's output is actually regenerated. So, could you check
with "make VERBOSE=1" for lines like "Building ...", "Compiling ..."
or "Linking ..."? These are the ones indicating the expensive
operations.

BTW, setting COMPILE_FLAGS "-S" as a source file property is somewhat
risky: If you ever need the concerned files for a usual compilation
they will be just translated to assembler code at that time, too,
making the subsequent link operation fail. Perhaps, you should
prefer to impose the "-S" as a COMPILE_FLAGS target property.

Regards,

Michael


More information about the CMake mailing list