# get_all_targets(OUTVAR var [DIRECTORY dir]) # will produce a list (in var) containing # all the targets defined in the directory # hierarchy starting at dir (if not given # dir defaults to $CMAKE_CURRENT_SOURCE_DIR) # function(get_all_targets) cmake_parse_arguments(PARSE_ARGV 0 A "SORTED" "OUTVAR;DIRECTORY" "") if(A_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Got trailing arguments ${A_UNPARSED_ARGUMENTS}") endif() if(NOT A_DIRECTORY) set(A_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endif() set(targets) get_all_targets_recursive(targets ${A_DIRECTORY}) if(A_SORTED) # sort by output_name set(sorted_targets) set(onames) foreach(item IN LISTS targets) get_property(is_example TARGET ${item} PROPERTY KM3NET_JPP_EXAMPLE) get_property(oname TARGET ${item} PROPERTY RUNTIME_OUTPUT_NAME) # if case of examples, add a prefix to avoid possible duplicated # names (with non-example applications or scripts) set(oname "${is_example}${oname}") set(map_${oname} ${item}) list(APPEND onames ${oname}) endforeach() list(SORT onames) foreach(name IN LISTS onames) list(APPEND sorted_targets ${map_${name}}) endforeach() set(${A_OUTVAR} ${sorted_targets} PARENT_SCOPE) else() set(${A_OUTVAR} ${targets} PARENT_SCOPE) endif() endfunction() macro(get_all_targets_recursive targets dir) get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES) foreach(subdir ${subdirectories}) get_all_targets_recursive(${targets} ${subdir}) endforeach() get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS) list(APPEND ${targets} ${current_targets}) endmacro()