function(define_filename targetname) get_target_property(source_files "${targetname}" SOURCES) foreach(sourcefile ${source_files}) get_filename_component(basename "${sourcefile}" NAME) set_property( SOURCE "${sourcefile}" APPEND PROPERTY COMPILE_DEFINITIONS "__FILENAME__=\"${basename}\"") endforeach() endfunction()