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}")
102 string(TOLOWER ${PROJECT_NAME} lowercase_project_name)
103 set(binary_name ${lowercase_project_name}_${FIRMWARE_VERSION}_${name})
104 if(DEFINED BUILD_SUFFIX AND NOT "" STREQUAL "${BUILD_SUFFIX}")
105 set(binary_name "${binary_name}_${BUILD_SUFFIX}")
108 list(APPEND target_definitions ${SITL_DEFINITIONS})
109 set(exe_target ${name}.elf)
110 add_executable(${exe_target})
111 target_sources(${exe_target} PRIVATE ${target_sources} ${COMMON_SRC})
112 target_include_directories(${exe_target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
113 target_compile_definitions(${exe_target} PRIVATE ${target_definitions})
116 if(WARNINGS_AS_ERRORS)
117 target_compile_options(${exe_target} PRIVATE -Werror)
120 target_compile_options(${exe_target} PRIVATE ${SITL_COMPILE_OPTIONS})
122 target_link_libraries(${exe_target} PRIVATE ${SITL_LINK_LIBRARIS})
123 target_link_options(${exe_target} PRIVATE ${SITL_LINK_OPTIONS})
125 set(script_path ${MAIN_SRC_DIR}/target/link/sitl.ld)
126 if(NOT EXISTS ${script_path})
127 message(FATAL_ERROR "linker script ${script_path} doesn't exist")
129 set_target_properties(${exe_target} PROPERTIES LINK_DEPENDS ${script_path})
131 target_link_options(${exe_target} PRIVATE -T${script_path})
135 set(exe_filename ${CMAKE_BINARY_DIR}/${binary_name}.exe)
137 set(exe_filename ${CMAKE_BINARY_DIR}/${binary_name})
140 add_custom_target(${name} ALL
141 cmake -E copy $<TARGET_FILE:${exe_target}> ${exe_filename}
144 setup_firmware_target(${exe_target} ${name} ${ARGN})
146 set(generator_cmd "")
147 if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
148 set(generator_cmd "make")
149 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
150 set(generator_cmd "ninja")
152 if (NOT generator_cmd STREQUAL "")
153 set(clean_target "clean_${name}")
154 add_custom_target(${clean_target}
155 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
156 COMMAND ${generator_cmd} clean
157 COMMENT "Removing intermediate files for ${name}")
158 set_property(TARGET ${clean_target} PROPERTY
160 EXCLUDE_FROM_DEFAULT_BUILD 1)