4 "${MAIN_LIB_DIR}/main/MAVLink"
9 __REVISION__="${GIT_REV}"
12 set(MAIN_COMPILE_OPTIONS
15 -Wunsafe-loop-optimizations
21 macro(main_sources var) # list-var src-1...src-n
23 list(TRANSFORM ${var} PREPEND "${MAIN_SRC_DIR}/")
26 function(exclude_basenames var excludes)
28 foreach(item ${${var}})
29 get_filename_component(basename ${item} NAME)
30 if (NOT ${basename} IN_LIST excludes)
31 list(APPEND filtered ${item})
34 set(${var} ${filtered} PARENT_SCOPE)
37 function(glob_except var pattern excludes)
38 file(GLOB results ${pattern})
39 list(LENGTH results count)
41 message(FATAL_ERROR "glob with pattern '${pattern}' returned no results")
43 exclude_basenames(results "${excludes}")
44 set(${var} ${results} PARENT_SCOPE)
47 function(get_generated_files_dir output target_name)
48 set(${output} ${CMAKE_CURRENT_BINARY_DIR}/${target_name} PARENT_SCOPE)
51 function(setup_executable exe name)
52 get_generated_files_dir(generated_dir ${name})
53 target_compile_options(${exe} PRIVATE ${MAIN_COMPILE_OPTIONS})
54 target_include_directories(${exe} PRIVATE ${generated_dir} ${MAIN_INCLUDE_DIRS})
55 target_compile_definitions(${exe} PRIVATE ${MAIN_DEFINITIONS} __TARGET__="${name}" ${name})
56 # XXX: Don't make SETTINGS_GENERATED_C part of the build,
57 # since it's compiled via #include in settings.c. This will
58 # change once we move off PGs
59 target_sources(${exe} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${name}/${SETTINGS_GENERATED_H}")
60 set_target_properties(${exe} PROPERTIES
61 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
64 set_target_properties(${exe} PROPERTIES
65 INTERPROCEDURAL_OPTIMIZATION ON
70 function(setup_firmware_target exe name)
71 setup_executable(${exe} ${name})
72 enable_settings(${exe} ${name})
73 get_property(targets GLOBAL PROPERTY VALID_TARGETS)
74 list(APPEND targets ${name})
75 set_property(GLOBAL PROPERTY VALID_TARGETS "${targets}")
76 setup_openocd(${exe} ${name})
77 setup_svd(${exe} ${name})
79 cmake_parse_arguments(args "SKIP_RELEASES" "" "" ${ARGN})
80 if(args_SKIP_RELEASES)
81 set_target_properties(${exe} ${name} PROPERTIES SKIP_RELEASES ON)
85 function(exclude_from_all target)
86 set_property(TARGET ${target} PROPERTY
89 EXCLUDE_FROM_DEFAULT_BUILD 1)
92 function(collect_targets)
93 get_property(targets GLOBAL PROPERTY VALID_TARGETS)
96 foreach(target ${targets})
97 get_target_property(skip_releases ${target} SKIP_RELEASES)
99 list(APPEND release_targets ${target})
103 list(JOIN targets " " target_names)
104 list(JOIN release_targets " " release_targets_names)
105 set_property(GLOBAL PROPERTY RELEASE_TARGETS ${release_targets})
107 set(list_target_name "targets")
108 add_custom_target(${list_target_name}
109 COMMAND ${CMAKE_COMMAND} -E echo "Valid targets: ${target_names}"
110 COMMAND ${CMAKE_COMMAND} -E echo "Release targets: ${release_targets_names}"
112 exclude_from_all(${list_target_name})
113 set(release_target_name "release")
114 add_custom_target(${release_target_name}
115 ${CMAKE_COMMAND} -E true
116 DEPENDS ${release_targets}
118 list(LENGTH targets target_count)
119 list(LENGTH release_targets release_target_count)
120 message("-- ${target_count} targets (${release_target_count} for release) found for toolchain ${TOOLCHAIN}")