2 main_sources(SITL_COMMON_SRC_EXCLUDES
9 drivers/accgyro/accgyro_mpu.c
10 drivers/display_ug2864hsweg01.c
15 config/config_streamer_file.c
18 target/SITL/sim/realFlight.c
19 target/SITL/sim/realFlight.h
20 target/SITL/sim/simHelper.c
21 target/SITL/sim/simHelper.h
22 target/SITL/sim/simple_soap_client.c
23 target/SITL/sim/simple_soap_client.h
24 target/SITL/sim/xplane.c
25 target/SITL/sim/xplane.h
34 -Wl,-L${STM32_LINKER_DIR}
38 set(SITL_LINK_OPTIONS ${SITL_LINK_OPTIONS} "-static-libgcc")
41 set(SITL_LINK_LIBRARIS
48 set(SITL_LINK_LIBRARIS ${SITL_LINK_LIBRARIS} -lrt)
51 set(SITL_COMPILE_OPTIONS
52 -Wno-format #Fixme: Compile for 32bit, but settings.rb has to be adjusted
57 message(STATUS "Debug mode enabled. Adding -g to SITL_COMPILE_OPTIONS.")
58 list(APPEND SITL_COMPILE_OPTIONS -g)
62 set(SITL_COMPILE_OPTIONS ${SITL_COMPILE_OPTIONS}
63 -Wno-return-local-addr
64 -Wno-error=maybe-uninitialized
65 -fsingle-precision-constant
67 if (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.0)
68 set(SITL_LINK_OPTIONS ${SITL_LINK_OPTIONS} "-Wl,--no-warn-rwx-segments")
71 set(SITL_COMPILE_OPTIONS ${SITL_COMPILE_OPTIONS}
79 function (target_sitl name)
80 if(CMAKE_VERSION VERSION_GREATER 3.22)
81 set(CMAKE_C_STANDARD 17)
84 if(NOT host STREQUAL TOOLCHAIN)
88 exclude(COMMON_SRC "${SITL_COMMON_SRC_EXCLUDES}")
91 list(APPEND target_sources ${SITL_SRC})
92 file(GLOB target_c_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
93 file(GLOB target_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
94 list(APPEND target_sources ${target_c_sources} ${target_h_sources})
96 set(target_definitions ${COMMON_COMPILE_DEFINITIONS})
98 set(hse_mhz ${STM32_DEFAULT_HSE_MHZ})
99 math(EXPR hse_value "${hse_mhz} * 1000000")
100 list(APPEND target_definitions "HSE_VALUE=${hse_value}")
103 list(APPEND target_definitions "MSP_UART=${MSP_UART}")
106 string(TOLOWER ${PROJECT_NAME} lowercase_project_name)
107 set(binary_name ${lowercase_project_name}_${FIRMWARE_VERSION}_${name})
108 if(DEFINED BUILD_SUFFIX AND NOT "" STREQUAL "${BUILD_SUFFIX}")
109 set(binary_name "${binary_name}_${BUILD_SUFFIX}")
112 list(APPEND target_definitions ${SITL_DEFINITIONS})
113 set(exe_target ${name}.elf)
114 add_executable(${exe_target})
115 target_sources(${exe_target} PRIVATE ${target_sources} ${COMMON_SRC})
116 target_include_directories(${exe_target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
117 target_compile_definitions(${exe_target} PRIVATE ${target_definitions})
120 if(WARNINGS_AS_ERRORS)
121 target_compile_options(${exe_target} PRIVATE -Werror)
124 target_compile_options(${exe_target} PRIVATE ${SITL_COMPILE_OPTIONS})
126 target_link_libraries(${exe_target} PRIVATE ${SITL_LINK_LIBRARIS})
127 target_link_options(${exe_target} PRIVATE ${SITL_LINK_OPTIONS})
129 set(script_path ${MAIN_SRC_DIR}/target/link/sitl.ld)
130 if(NOT EXISTS ${script_path})
131 message(FATAL_ERROR "linker script ${script_path} doesn't exist")
133 set_target_properties(${exe_target} PROPERTIES LINK_DEPENDS ${script_path})
135 target_link_options(${exe_target} PRIVATE -T${script_path})
139 set(exe_filename ${CMAKE_BINARY_DIR}/${binary_name}.exe)
141 set(exe_filename ${CMAKE_BINARY_DIR}/${binary_name})
144 add_custom_target(${name} ALL
145 cmake -E copy $<TARGET_FILE:${exe_target}> ${exe_filename}
148 setup_firmware_target(${exe_target} ${name} ${ARGN})
150 set(generator_cmd "")
151 if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
152 set(generator_cmd "make")
153 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
154 set(generator_cmd "ninja")
156 if (NOT generator_cmd STREQUAL "")
157 set(clean_target "clean_${name}")
158 add_custom_target(${clean_target}
159 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
160 COMMAND ${generator_cmd} clean
161 COMMENT "Removing intermediate files for ${name}")
162 set_property(TARGET ${clean_target} PROPERTY
164 EXCLUDE_FROM_DEFAULT_BUILD 1)