Drop MSP_PID and MSP_SET_PID frames
[inav.git] / cmake / settings.cmake
blob065f3a87dbbb1f68b7dfbf213b9a0cb9b0c7f7e0
1 set(SETTINGS_GENERATED "settings_generated")
2 set(SETTINGS_GENERATED_C "${SETTINGS_GENERATED}.c")
3 set(SETTINGS_GENERATED_H "${SETTINGS_GENERATED}.h")
4 set(SETTINGS_FILE "${MAIN_SRC_DIR}/fc/settings.yaml")
5 set(SETTINGS_GENERATOR "${MAIN_UTILS_DIR}/settings.rb")
7 include(CMakeParseArguments)
9 function(enable_settings exe name)
10     get_generated_files_dir(dir ${name})
11     get_target_property(options ${exe} COMPILE_OPTIONS)
12     get_target_property(includes ${exe} INCLUDE_DIRECTORIES)
13     list(TRANSFORM includes PREPEND "-I")
14     get_target_property(defs ${exe} COMPILE_DEFINITIONS)
15     list(TRANSFORM defs PREPEND "-D")
16     list(APPEND cflags ${options})
17     list(APPEND cflags ${includes})
18     list(APPEND cflags ${defs})
20     cmake_parse_arguments(
21         args
22         # Boolean arguments
23         ""
24         # Single value arguments
25         "OUTPUTS;SETTINGS_CXX"
26         # Multi-value arguments
27         ""
28         # Start parsing after the known arguments
29         ${ARGN}
30     )
32     set(output ${dir}/${SETTINGS_GENERATED_H} ${dir}/${SETTINGS_GENERATED_C})
33     add_custom_command(
34         OUTPUT ${output}
35         COMMAND
36             ${CMAKE_COMMAND} -E env CFLAGS="${cflags}" TARGET=${name} PATH="$ENV{PATH}" SETTINGS_CXX=${args_SETTINGS_CXX}
37             ${RUBY_EXECUTABLE} ${SETTINGS_GENERATOR} ${MAIN_DIR} ${SETTINGS_FILE} -o "${dir}"
38         DEPENDS ${SETTINGS_GENERATOR} ${SETTINGS_FILE}
39     )
40     set(${args_OUTPUTS} ${output} PARENT_SCOPE)
41 endfunction()