4 "${MAIN_LIB_DIR}/main/MAVLink"
9 __REVISION__="${GIT_REV}"
13 # Can't check for OSX yet at this point
15 set(MAIN_COMPILE_OPTIONS
21 #-Wno-unknown-warning-option
24 set(MAIN_COMPILE_OPTIONS
27 -Wunsafe-loop-optimizations
34 macro(main_sources var) # list-var src-1...src-n
36 list(TRANSFORM ${var} PREPEND "${MAIN_SRC_DIR}/")
39 function(exclude var excludes)
41 foreach(item ${${var}})
42 if (NOT ${item} IN_LIST excludes)
43 list(APPEND filtered ${item})
46 set(${var} ${filtered} PARENT_SCOPE)
49 function(exclude_basenames var excludes)
51 foreach(item ${${var}})
52 get_filename_component(basename ${item} NAME)
53 if (NOT ${basename} IN_LIST excludes)
54 list(APPEND filtered ${item})
57 set(${var} ${filtered} PARENT_SCOPE)
60 function(glob_except var pattern excludes)
61 file(GLOB results ${pattern})
62 list(LENGTH results count)
64 message(FATAL_ERROR "glob with pattern '${pattern}' returned no results")
66 exclude_basenames(results "${excludes}")
67 set(${var} ${results} PARENT_SCOPE)
70 function(get_generated_files_dir output target_name)
71 set(${output} ${CMAKE_CURRENT_BINARY_DIR}/${target_name} PARENT_SCOPE)
74 function(setup_executable exe name)
75 get_generated_files_dir(generated_dir ${name})
76 target_compile_options(${exe} PRIVATE ${MAIN_COMPILE_OPTIONS})
77 target_include_directories(${exe} PRIVATE ${generated_dir} ${MAIN_INCLUDE_DIRS})
78 target_compile_definitions(${exe} PRIVATE ${MAIN_DEFINITIONS} __TARGET__="${name}" ${name})
79 # XXX: Don't make SETTINGS_GENERATED_C part of the build,
80 # since it's compiled via #include in settings.c. This will
81 # change once we move off PGs
82 target_sources(${exe} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${name}/${SETTINGS_GENERATED_H}")
83 set_target_properties(${exe} PROPERTIES
84 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
86 if(IS_RELEASE_BUILD AND NOT (CMAKE_HOST_APPLE AND SITL))
87 set_target_properties(${exe} PROPERTIES
88 INTERPROCEDURAL_OPTIMIZATION ON
93 function(setup_firmware_target exe name)
94 setup_executable(${exe} ${name})
95 enable_settings(${exe} ${name})
96 get_property(targets GLOBAL PROPERTY VALID_TARGETS)
97 list(APPEND targets ${name})
98 set_property(GLOBAL PROPERTY VALID_TARGETS "${targets}")
100 setup_openocd(${exe} ${name})
101 setup_svd(${exe} ${name})
104 cmake_parse_arguments(args "SKIP_RELEASES" "" "" ${ARGN})
105 if(args_SKIP_RELEASES)
106 set_target_properties(${exe} ${name} PROPERTIES SKIP_RELEASES ON)
110 function(exclude_from_all target)
111 set_property(TARGET ${target} PROPERTY
114 EXCLUDE_FROM_DEFAULT_BUILD 1)
117 function(collect_targets)
118 get_property(targets GLOBAL PROPERTY VALID_TARGETS)
121 foreach(target ${targets})
122 get_target_property(skip_releases ${target} SKIP_RELEASES)
123 if(NOT skip_releases)
124 list(APPEND release_targets ${target})
128 list(JOIN targets " " target_names)
129 list(JOIN release_targets " " release_targets_names)
130 set_property(GLOBAL PROPERTY RELEASE_TARGETS ${release_targets})
132 set(list_target_name "targets")
133 add_custom_target(${list_target_name}
134 COMMAND ${CMAKE_COMMAND} -E echo "Valid targets: ${target_names}"
135 COMMAND ${CMAKE_COMMAND} -E echo "Release targets: ${release_targets_names}"
137 exclude_from_all(${list_target_name})
138 set(release_target_name "release")
139 add_custom_target(${release_target_name}
140 ${CMAKE_COMMAND} -E true
141 DEPENDS ${release_targets}
143 list(LENGTH targets target_count)
144 list(LENGTH release_targets release_target_count)
145 message("-- ${target_count} targets (${release_target_count} for release) found for toolchain ${TOOLCHAIN}")