Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SITL] sitl specific cmake cleanup (Windows only linker option) #8995

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions cmake/sitl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ set(SITL_LINK_OPTIONS
-lrt
-Wl,-L${STM32_LINKER_DIR}
-Wl,--cref
-static-libgcc # Required for windows build under cygwin
)

if(${WIN32} OR ${CYGWIN})
set(SITL_LINK_OPTIONS ${SITL_LINK_OPTIONS} "-static-libgcc")
endif()

set(SITL_LINK_LIBRARIS
-lpthread
-lm
Expand Down Expand Up @@ -60,21 +63,24 @@ function(generate_map_file target)
endfunction()

function (target_sitl name)
if(CMAKE_VERSION VERSION_GREATER 3.22)
set(CMAKE_C_STANDARD 17)
endif()

if(NOT host STREQUAL TOOLCHAIN)
return()
endif()

exclude(COMMON_SRC "${SITL_COMMON_SRC_EXCLUDES}")

set(target_sources)
list(APPEND target_sources ${SITL_SRC})
file(GLOB target_c_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
file(GLOB target_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
list(APPEND target_sources ${target_c_sources} ${target_h_sources})

set(target_definitions ${COMMON_COMPILE_DEFINITIONS})

set(hse_mhz ${STM32_DEFAULT_HSE_MHZ})
math(EXPR hse_value "${hse_mhz} * 1000000")
list(APPEND target_definitions "HSE_VALUE=${hse_value}")
Expand All @@ -92,18 +98,18 @@ function (target_sitl name)
target_include_directories(${exe_target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(${exe_target} PRIVATE ${target_definitions})


if(WARNINGS_AS_ERRORS)
target_compile_options(${exe_target} PRIVATE -Werror)
endif()

target_compile_options(${exe_target} PRIVATE ${SITL_COMPILE_OPTIONS})

target_link_libraries(${exe_target} PRIVATE ${SITL_LINK_LIBRARIS})
target_link_options(${exe_target} PRIVATE ${SITL_LINK_OPTIONS})

generate_map_file(${exe_target})

set(script_path ${MAIN_SRC_DIR}/target/link/sitl.ld)
if(NOT EXISTS ${script_path})
message(FATAL_ERROR "linker script ${script_path} doesn't exist")
Expand All @@ -116,7 +122,7 @@ function (target_sitl name)
else()
set(exe_filename ${CMAKE_BINARY_DIR}/${binary_name})
endif()

add_custom_target(${name} ALL
cmake -E env PATH="$ENV{PATH}"
${CMAKE_OBJCOPY} $<TARGET_FILE:${exe_target}> ${exe_filename}
Expand Down