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
30 -Wl,-L${STM32_LINKER_DIR}
32 -static-libgcc # Required for windows build under cygwin
35 set(SITL_LINK_LIBRARIS
41 set(SITL_COMPILE_OPTIONS
42 -Wno-format #Fixme: Compile for 32bit, but settings.rb has to be adjusted
43 -Wno-return-local-addr
44 -fsingle-precision-constant
52 function(generate_map_file target)
53 if(CMAKE_VERSION VERSION_LESS 3.15)
54 set(map "$<TARGET_FILE:${target}>.map")
56 set(map "$<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.map")
58 target_link_options(${target} PRIVATE "-Wl,-gc-sections,-Map,${map}")
61 function (target_sitl name)
63 if(NOT host STREQUAL TOOLCHAIN)
67 exclude(COMMON_SRC "${SITL_COMMON_SRC_EXCLUDES}")
70 list(APPEND target_sources ${SITL_SRC})
71 file(GLOB target_c_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
72 file(GLOB target_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
73 list(APPEND target_sources ${target_c_sources} ${target_h_sources})
75 set(target_definitions ${COMMON_COMPILE_DEFINITIONS})
77 set(hse_mhz ${STM32_DEFAULT_HSE_MHZ})
78 math(EXPR hse_value "${hse_mhz} * 1000000")
79 list(APPEND target_definitions "HSE_VALUE=${hse_value}")
81 string(TOLOWER ${PROJECT_NAME} lowercase_project_name)
82 set(binary_name ${lowercase_project_name}_${FIRMWARE_VERSION}_${name})
83 if(DEFINED BUILD_SUFFIX AND NOT "" STREQUAL "${BUILD_SUFFIX}")
84 set(binary_name "${binary_name}_${BUILD_SUFFIX}")
87 list(APPEND target_definitions ${SITL_DEFINITIONS})
88 set(exe_target ${name}.elf)
89 add_executable(${exe_target})
90 target_sources(${exe_target} PRIVATE ${target_sources} ${COMMON_SRC})
91 target_include_directories(${exe_target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
92 target_compile_definitions(${exe_target} PRIVATE ${target_definitions})
95 if(WARNINGS_AS_ERRORS)
96 target_compile_options(${exe_target} PRIVATE -Werror)
99 target_compile_options(${exe_target} PRIVATE ${SITL_COMPILE_OPTIONS})
101 target_link_libraries(${exe_target} PRIVATE ${SITL_LINK_LIBRARIS})
102 target_link_options(${exe_target} PRIVATE ${SITL_LINK_OPTIONS})
104 generate_map_file(${exe_target})
106 set(script_path ${MAIN_SRC_DIR}/target/link/sitl.ld)
107 if(NOT EXISTS ${script_path})
108 message(FATAL_ERROR "linker script ${script_path} doesn't exist")
110 set_target_properties(${exe_target} PROPERTIES LINK_DEPENDS ${script_path})
111 target_link_options(${exe_target} PRIVATE -T${script_path})
113 if(${WIN32} OR ${CYGWIN})
114 set(exe_filename ${CMAKE_BINARY_DIR}/${binary_name}.exe)
116 set(exe_filename ${CMAKE_BINARY_DIR}/${binary_name})
119 add_custom_target(${name} ALL
120 cmake -E env PATH="$ENV{PATH}"
121 ${CMAKE_OBJCOPY} $<TARGET_FILE:${exe_target}> ${exe_filename}
125 setup_firmware_target(${exe_target} ${name} ${ARGN})
127 set(generator_cmd "")
128 if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
129 set(generator_cmd "make")
130 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
131 set(generator_cmd "ninja")
133 if (NOT generator_cmd STREQUAL "")
134 set(clean_target "clean_${name}")
135 add_custom_target(${clean_target}
136 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
137 COMMAND ${generator_cmd} clean
138 COMMENT "Removing intermediate files for ${name}")
139 set_property(TARGET ${clean_target} PROPERTY
141 EXCLUDE_FROM_DEFAULT_BUILD 1)