Update pwm_mapping.h
[inav.git] / cmake / settings.cmake
blob979b5e17220bdd7dec8f2f8ced171b41843ae6be
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     find_program(RUBY_EXECUTABLE ruby)
33     if (NOT RUBY_EXECUTABLE)
34         message(FATAL_ERROR "Could not find ruby")
35     endif()
37     if(host STREQUAL TOOLCHAIN)
38         set(USE_HOST_GCC "-g")
39     endif()
40     set(output ${dir}/${SETTINGS_GENERATED_H} ${dir}/${SETTINGS_GENERATED_C})
41     add_custom_command(
42         OUTPUT ${output}
43         COMMAND
44             ${CMAKE_COMMAND} -E env CFLAGS="${cflags}" TARGET=${name} PATH="$ENV{PATH}" SETTINGS_CXX=${args_SETTINGS_CXX}
45             ${RUBY_EXECUTABLE} ${SETTINGS_GENERATOR} ${MAIN_DIR} ${SETTINGS_FILE} -o "${dir}" ${USE_HOST_GCC} 
46         DEPENDS ${SETTINGS_GENERATOR} ${SETTINGS_FILE}
47     )
48     set(${args_OUTPUTS} ${output} PARENT_SCOPE)
49 endfunction()