From 88af828724c77ef5624bd8d10ed4bd3c023536cd Mon Sep 17 00:00:00 2001 From: Nuno Marques Date: Tue, 5 May 2026 20:56:00 -0700 Subject: [PATCH] build(windows): harden native SITL toolchains Add compiler-specific CMake helpers and use them across Windows-sensitive targets so MSVC and MinGW can share the native SITL build without leaking unsupported flags between compilers. Signed-off-by: Nuno Marques --- .github/workflows/compile_windows.yml | 6 +- .vscode/cmake-kits.json | 8 +- CMakeLists.txt | 7 +- boards/beaglebone/blue/cmake/init.cmake | 2 +- boards/modalai/voxl2/src/CMakeLists.txt | 4 +- cmake/kconfig.cmake | 4 +- cmake/px4_add_common_flags.cmake | 154 ++++++++++++++++++ cmake/px4_add_module.cmake | 24 ++- cmake/px4_git.cmake | 44 +++-- msg/CMakeLists.txt | 6 +- msg/px4_msgs_old/CMakeLists.txt | 2 + msg/translation_node/CMakeLists.txt | 8 +- platforms/common/work_queue/CMakeLists.txt | 4 +- platforms/posix/CMakeLists.txt | 5 +- .../cmake/Toolchain-mingw-w64-x86_64.cmake | 91 +++++++++-- platforms/posix/cmake/px4_impl_os.cmake | 14 +- platforms/posix/cmake/windows.cmake | 18 ++ platforms/posix/src/px4/common/CMakeLists.txt | 4 +- platforms/ros2/CMakeLists.txt | 7 +- platforms/ros2/src/px4/common/CMakeLists.txt | 4 +- src/drivers/cyphal/CMakeLists.txt | 4 +- src/drivers/ins/ilabs/libilabs/CMakeLists.txt | 5 +- src/drivers/ins/microstrain/CMakeLists.txt | 11 ++ src/drivers/ins/sbgecom/CMakeLists.txt | 20 +-- .../ins/vectornav/libvnc/CMakeLists.txt | 30 ++-- .../osd/msp_osd/MessageDisplay/CMakeLists.txt | 6 +- src/drivers/uavcan/CMakeLists.txt | 9 +- .../kinetis/driver/CMakeLists.txt | 2 +- .../socketcan/driver/CMakeLists.txt | 2 +- src/lib/cdrstream/CMakeLists.txt | 16 +- src/lib/collision_prevention/CMakeLists.txt | 4 +- .../controllib/controllib_test/CMakeLists.txt | 10 +- src/lib/crypto/CMakeLists.txt | 8 +- src/lib/events/CMakeLists.txt | 10 +- src/lib/led/CMakeLists.txt | 4 +- src/lib/matrix/test/CMakeLists.txt | 7 +- src/lib/parameters/CMakeLists.txt | 8 +- src/lib/rc/CMakeLists.txt | 5 +- src/lib/rc/rc_tests/CMakeLists.txt | 10 +- src/lib/rl_tools/CMakeLists.txt | 9 +- src/lib/tensorflow_lite_micro/CMakeLists.txt | 13 +- src/lib/tinybson/CMakeLists.txt | 5 +- src/lib/version/CMakeLists.txt | 2 +- src/lib/world_magnetic_model/CMakeLists.txt | 5 +- src/modules/dataman/CMakeLists.txt | 9 +- src/modules/ekf2/CMakeLists.txt | 11 +- src/modules/ekf2/EKF/CMakeLists.txt | 5 +- .../flight_mode_manager/CMakeLists.txt | 4 +- src/modules/gyro_fft/CMakeLists.txt | 8 +- src/modules/logger/CMakeLists.txt | 9 +- src/modules/mavlink/CMakeLists.txt | 16 +- src/modules/mc_nn_control/CMakeLists.txt | 10 +- src/modules/mc_raptor/CMakeLists.txt | 4 +- src/modules/simulation/gz_msgs/CMakeLists.txt | 8 +- .../simulator_mavlink/CMakeLists.txt | 14 +- src/modules/zenoh/CMakeLists.txt | 51 +++--- src/systemcmds/gpio/CMakeLists.txt | 6 +- src/systemcmds/microbench/CMakeLists.txt | 12 +- src/systemcmds/param/CMakeLists.txt | 6 +- src/systemcmds/tests/CMakeLists.txt | 22 +-- 60 files changed, 637 insertions(+), 179 deletions(-) diff --git a/.github/workflows/compile_windows.yml b/.github/workflows/compile_windows.yml index 4a7c034ba6..d81c076344 100644 --- a/.github/workflows/compile_windows.yml +++ b/.github/workflows/compile_windows.yml @@ -90,7 +90,11 @@ jobs: shell: pwsh run: | python -m pip install --upgrade pip - python -m pip install jinja2 pyyaml toml numpy packaging jsonschema future empy pyros-genmsg + # empy pinned <4: PX4's msg/uxrce_dds/flight_tasks/zenoh generators + # use the empy 3.x Interpreter(...options={em.RAW_OPT: True, + # em.BUFFERED_OPT: True}) API removed in empy 4.x. Matches the pin + # in Tools/setup/requirements.txt and Tools/setup/windows.ps1. + python -m pip install jinja2 pyyaml toml numpy packaging jsonschema future "empy>=3.3,<4" pyros-genmsg kconfiglib - name: Install Ninja (MSVC) if: matrix.toolchain == 'MSVC' diff --git a/.vscode/cmake-kits.json b/.vscode/cmake-kits.json index 517c8c6d52..6fffb9f6a7 100644 --- a/.vscode/cmake-kits.json +++ b/.vscode/cmake-kits.json @@ -1,5 +1,5 @@ [ - { - "name": "PX4 detect" - } -] + { + "name": "PX4 detect" + } +] \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index cfbe893ead..339ab9c6c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -318,7 +318,12 @@ endif() set(package-contact "px4users@googlegroups.com") -set(CMAKE_CXX_STANDARD 17) +if(MSVC) + set(CMAKE_CXX_STANDARD 20) +else() + set(CMAKE_CXX_STANDARD 17) +endif() + set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) diff --git a/boards/beaglebone/blue/cmake/init.cmake b/boards/beaglebone/blue/cmake/init.cmake index aa1b69bb2f..06f82f94dc 100644 --- a/boards/beaglebone/blue/cmake/init.cmake +++ b/boards/beaglebone/blue/cmake/init.cmake @@ -31,7 +31,7 @@ # ############################################################################ -add_compile_options(-Wno-cast-align) +px4_add_compile_options_for_compiler(GNU_LIKE -Wno-cast-align) include(ExternalProject) ExternalProject_Add(librobotcontrol diff --git a/boards/modalai/voxl2/src/CMakeLists.txt b/boards/modalai/voxl2/src/CMakeLists.txt index ed492407d2..87837ef30b 100644 --- a/boards/modalai/voxl2/src/CMakeLists.txt +++ b/boards/modalai/voxl2/src/CMakeLists.txt @@ -81,7 +81,9 @@ if("${PX4_PLATFORM}" STREQUAL "qurt") add_library(mavlink_common_headers INTERFACE) add_dependencies(mavlink_common_headers mavlink_common_generate) - target_compile_options(mavlink_common_headers INTERFACE -Wno-address-of-packed-member -Wno-cast-align) + px4_target_compile_options_for_compiler(mavlink_common_headers INTERFACE + GNU_LIKE -Wno-address-of-packed-member -Wno-cast-align + ) target_include_directories(mavlink_common_headers INTERFACE ${MAVLINK_LIBRARY_DIR} ${MAVLINK_LIBRARY_DIR}/common diff --git a/cmake/kconfig.cmake b/cmake/kconfig.cmake index e483ee6f0e..898f17c0b5 100644 --- a/cmake/kconfig.cmake +++ b/cmake/kconfig.cmake @@ -356,7 +356,7 @@ if(EXISTS ${BOARD_DEFCONFIG}) if(CONSTRAINED_FLASH) set(px4_constrained_flash_build "1" CACHE INTERNAL "constrained flash build" FORCE) - add_definitions(-DCONSTRAINED_FLASH) + add_definitions(-DCONSTRAINED_FLASH=1) endif() if(NO_HELP) @@ -378,7 +378,7 @@ if(EXISTS ${BOARD_DEFCONFIG}) if(CRYPTO) set(PX4_CRYPTO "1" CACHE INTERNAL "PX4 crypto implementation" FORCE) - add_definitions(-DPX4_CRYPTO) + add_definitions(-DPX4_CRYPTO=1) endif() if(LINKER_PREFIX) diff --git a/cmake/px4_add_common_flags.cmake b/cmake/px4_add_common_flags.cmake index 0272b96feb..907bff2ae2 100644 --- a/cmake/px4_add_common_flags.cmake +++ b/cmake/px4_add_common_flags.cmake @@ -40,6 +40,159 @@ # Usage: # px4_add_common_flags() # + +function(px4_msvc_compile_options_from_gnu out_var) + set(msvc_flags) + + # Keep GNU-like warning names as the common policy vocabulary and translate + # the MSVC equivalents here when the mapping is exact enough to be useful. + foreach(flag IN LISTS ARGN) + if("${flag}" STREQUAL "-Werror") + list(APPEND msvc_flags /WX) + elseif("${flag}" STREQUAL "-Wno-error") + list(APPEND msvc_flags /WX-) + elseif("${flag}" STREQUAL "-Wall" OR "${flag}" STREQUAL "-Wextra") + list(APPEND msvc_flags /W4) + elseif("${flag}" STREQUAL "-Wno-array-bounds") + list(APPEND msvc_flags /wd4789) + elseif("${flag}" STREQUAL "-Wno-deprecated-copy") + list(APPEND msvc_flags /wd5267) + elseif("${flag}" STREQUAL "-Wno-deprecated-declarations") + list(APPEND msvc_flags /wd4996) + elseif("${flag}" STREQUAL "-Wno-empty-body") + list(APPEND msvc_flags /wd4390) + elseif("${flag}" STREQUAL "-Wno-implicit-function-declaration") + list(APPEND msvc_flags /wd4013) + elseif("${flag}" STREQUAL "-Wno-implicit-fallthrough") + list(APPEND msvc_flags /wd5262) + elseif("${flag}" STREQUAL "-Wno-incompatible-pointer-types") + list(APPEND msvc_flags /wd4133) + elseif("${flag}" STREQUAL "-Wno-maybe-uninitialized" OR "${flag}" STREQUAL "-Wno-uninitialized") + list(APPEND msvc_flags /wd4701 /wd4703) + elseif("${flag}" STREQUAL "-Wno-overloaded-virtual") + list(APPEND msvc_flags /wd4263 /wd4264) + elseif("${flag}" STREQUAL "-Wno-shadow") + list(APPEND msvc_flags /wd4456 /wd4457 /wd4458 /wd4459) + elseif("${flag}" STREQUAL "-Wno-sign-compare") + list(APPEND msvc_flags /wd4018 /wd4389) + elseif("${flag}" STREQUAL "-Wno-strict-prototypes") + list(APPEND msvc_flags /wd4255) + elseif("${flag}" STREQUAL "-Wno-switch") + list(APPEND msvc_flags /wd4061 /wd4062) + elseif("${flag}" STREQUAL "-Wno-type-limits") + list(APPEND msvc_flags /wd4296) + elseif("${flag}" STREQUAL "-Wno-unknown-pragmas") + list(APPEND msvc_flags /wd4068) + elseif("${flag}" STREQUAL "-Wno-unused") + list(APPEND msvc_flags /wd4100 /wd4101 /wd4189 /wd4505) + elseif("${flag}" STREQUAL "-Wno-unused-but-set-parameter") + list(APPEND msvc_flags /wd4100) + elseif("${flag}" STREQUAL "-Wno-unused-but-set-variable") + list(APPEND msvc_flags /wd4189) + elseif("${flag}" STREQUAL "-Wno-unused-function") + list(APPEND msvc_flags /wd4505) + elseif("${flag}" STREQUAL "-Wno-unused-parameter") + list(APPEND msvc_flags /wd4100) + elseif("${flag}" STREQUAL "-Wno-unused-variable") + list(APPEND msvc_flags /wd4101 /wd4189) + elseif("${flag}" STREQUAL "-Wno-write-strings") + list(APPEND msvc_flags /wd4090) + endif() + endforeach() + + if(msvc_flags) + list(REMOVE_DUPLICATES msvc_flags) + endif() + + set(${out_var} ${msvc_flags} PARENT_SCOPE) +endfunction() + +function(px4_add_compile_options_for_compiler) + cmake_parse_arguments(arg "" "" "GNU_LIKE;MSVC" ${ARGN}) + set(is_gnu_like_compiler FALSE) + + if((CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang") OR (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")) + set(is_gnu_like_compiler TRUE) + endif() + + if(MSVC) + if(arg_MSVC) + add_compile_options(${arg_MSVC}) + else() + px4_msvc_compile_options_from_gnu(msvc_flags ${arg_GNU_LIKE}) + + if(msvc_flags) + add_compile_options(${msvc_flags}) + endif() + endif() + elseif(is_gnu_like_compiler AND arg_GNU_LIKE) + add_compile_options(${arg_GNU_LIKE}) + endif() +endfunction() + +function(px4_add_c_compile_options_for_compiler) + cmake_parse_arguments(arg "" "" "GNU_LIKE;MSVC" ${ARGN}) + + if(MSVC) + if(arg_MSVC) + set(msvc_flags ${arg_MSVC}) + else() + px4_msvc_compile_options_from_gnu(msvc_flags ${arg_GNU_LIKE}) + endif() + + foreach(flag ${msvc_flags}) + add_compile_options($<$:${flag}>) + endforeach() + elseif(arg_GNU_LIKE AND (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang")) + foreach(flag ${arg_GNU_LIKE}) + add_compile_options($<$:${flag}>) + endforeach() + endif() +endfunction() + +function(px4_target_compile_options_for_compiler target scope) + cmake_parse_arguments(arg "" "" "GNU_LIKE;MSVC" ${ARGN}) + set(is_gnu_like_compiler FALSE) + + if((CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang") OR (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")) + set(is_gnu_like_compiler TRUE) + endif() + + if(MSVC) + if(arg_MSVC) + target_compile_options(${target} ${scope} ${arg_MSVC}) + else() + px4_msvc_compile_options_from_gnu(msvc_flags ${arg_GNU_LIKE}) + + if(msvc_flags) + target_compile_options(${target} ${scope} ${msvc_flags}) + endif() + endif() + elseif(is_gnu_like_compiler AND arg_GNU_LIKE) + target_compile_options(${target} ${scope} ${arg_GNU_LIKE}) + endif() +endfunction() + +function(px4_target_c_compile_options_for_compiler target scope) + cmake_parse_arguments(arg "" "" "GNU_LIKE;MSVC" ${ARGN}) + + if(MSVC) + if(arg_MSVC) + set(msvc_flags ${arg_MSVC}) + else() + px4_msvc_compile_options_from_gnu(msvc_flags ${arg_GNU_LIKE}) + endif() + + foreach(flag ${msvc_flags}) + target_compile_options(${target} ${scope} $<$:${flag}>) + endforeach() + elseif(arg_GNU_LIKE AND (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang")) + foreach(flag ${arg_GNU_LIKE}) + target_compile_options(${target} ${scope} $<$:${flag}>) + endforeach() + endif() +endfunction() + function(px4_add_common_flags) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") @@ -49,6 +202,7 @@ function(px4_add_common_flags) /EHsc /bigobj /permissive- + /Zc:preprocessor /utf-8 /FIvisibility.h /W3 diff --git a/cmake/px4_add_module.cmake b/cmake/px4_add_module.cmake index 0b5b757516..4b14318a8b 100644 --- a/cmake/px4_add_module.cmake +++ b/cmake/px4_add_module.cmake @@ -91,6 +91,22 @@ function(px4_add_module) REQUIRED MODULE MAIN ARGN ${ARGN}) + set(MODULE_COMPILE_FLAGS ${COMPILE_FLAGS}) + + if(MSVC AND MODULE_COMPILE_FLAGS) + set(MODULE_COMPILE_FLAGS_FILTERED) + px4_msvc_compile_options_from_gnu(MODULE_COMPILE_FLAGS_MSVC ${MODULE_COMPILE_FLAGS}) + + foreach(flag IN LISTS MODULE_COMPILE_FLAGS) + if(NOT flag MATCHES "^-W") + list(APPEND MODULE_COMPILE_FLAGS_FILTERED "${flag}") + endif() + endforeach() + + list(APPEND MODULE_COMPILE_FLAGS_FILTERED ${MODULE_COMPILE_FLAGS_MSVC}) + set(MODULE_COMPILE_FLAGS ${MODULE_COMPILE_FLAGS_FILTERED}) + endif() + if(UNITY_BUILD AND (${PX4_PLATFORM} STREQUAL "nuttx")) # build standalone test library to catch compilation errors and provide sane output add_library(${MODULE}_original STATIC EXCLUDE_FROM_ALL ${SRCS}) @@ -117,8 +133,8 @@ function(px4_add_module) target_include_directories(${MODULE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) add_dependencies(${MODULE} ${MODULE}_original) # build standalone module first to get clean compile errors - if(COMPILE_FLAGS) - target_compile_options(${MODULE}_original PRIVATE ${COMPILE_FLAGS}) + if(MODULE_COMPILE_FLAGS) + target_compile_options(${MODULE}_original PRIVATE ${MODULE_COMPILE_FLAGS}) endif() if(DEPENDS) @@ -229,8 +245,8 @@ function(px4_add_module) message(FATAL_ERROR "MAIN required") endif() - if(COMPILE_FLAGS) - target_compile_options(${MODULE} PRIVATE ${COMPILE_FLAGS}) + if(MODULE_COMPILE_FLAGS) + target_compile_options(${MODULE} PRIVATE ${MODULE_COMPILE_FLAGS}) endif() if (KERNEL) diff --git a/cmake/px4_git.cmake b/cmake/px4_git.cmake index 22fb7d358b..32d79c6784 100644 --- a/cmake/px4_git.cmake +++ b/cmake/px4_git.cmake @@ -64,24 +64,48 @@ function(px4_add_git_submodule) set(REL_PATH) - if(IS_ABSOLUTE ${PATH}) + if(IS_ABSOLUTE "${PATH}") + set(ABS_PATH ${PATH}) file(RELATIVE_PATH REL_PATH ${PX4_SOURCE_DIR} ${PATH}) else() - file(RELATIVE_PATH REL_PATH ${PX4_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}) + get_filename_component(ABS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${PATH}" ABSOLUTE) + file(RELATIVE_PATH REL_PATH ${PX4_SOURCE_DIR} ${ABS_PATH}) endif() - execute_process( - COMMAND Tools/check_submodules.sh ${REL_PATH} - WORKING_DIRECTORY ${PX4_SOURCE_DIR} - ) + set(GIT_SUBMODULE_DEPS ${PX4_SOURCE_DIR}/.gitmodules ${ABS_PATH}/.git) - string(REPLACE "/" "_" NAME ${PATH}) - string(REPLACE "." "_" NAME ${NAME}) + if(CMAKE_GENERATOR STREQUAL "MinGW Makefiles") + set(GIT_SUBMODULE_DEPS) + endif() + + if(CMAKE_HOST_WIN32) + if(NOT EXISTS "${ABS_PATH}/.git") + execute_process( + COMMAND git submodule sync --recursive -- ${REL_PATH} + WORKING_DIRECTORY ${PX4_SOURCE_DIR} + ) + execute_process( + COMMAND git submodule update --init --recursive -- ${REL_PATH} + WORKING_DIRECTORY ${PX4_SOURCE_DIR} + ) + endif() + + set(CHECK_SUBMODULE_COMMAND ${CMAKE_COMMAND} -E true) + else() + execute_process( + COMMAND Tools/check_submodules.sh ${REL_PATH} + WORKING_DIRECTORY ${PX4_SOURCE_DIR} + ) + + set(CHECK_SUBMODULE_COMMAND Tools/check_submodules.sh ${REL_PATH}) + endif() + + string(MAKE_C_IDENTIFIER "${REL_PATH}" NAME) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/git_init_${NAME}.stamp - COMMAND Tools/check_submodules.sh ${REL_PATH} + COMMAND ${CHECK_SUBMODULE_COMMAND} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/git_init_${NAME}.stamp - DEPENDS ${PX4_SOURCE_DIR}/.gitmodules ${PATH}/.git + DEPENDS ${GIT_SUBMODULE_DEPS} COMMENT "git submodule ${REL_PATH}" WORKING_DIRECTORY ${PX4_SOURCE_DIR} USES_TERMINAL diff --git a/msg/CMakeLists.txt b/msg/CMakeLists.txt index 1d7dae1bd7..fe2da241fc 100644 --- a/msg/CMakeLists.txt +++ b/msg/CMakeLists.txt @@ -430,7 +430,11 @@ add_custom_command( ) add_library(uorb_msgs ${uorb_headers} ${msg_out_path}/uORBTopics.hpp ${uorb_sources} ${msg_source_out_path}/uORBTopics.cpp ${uorb_message_fields_cpp_file}) -target_link_libraries(uorb_msgs PRIVATE m) + +if(NOT MSVC) + target_link_libraries(uorb_msgs PRIVATE m) +endif() + add_dependencies(uorb_msgs prebuild_targets uorb_headers) if(CONFIG_LIB_CDRSTREAM) diff --git a/msg/px4_msgs_old/CMakeLists.txt b/msg/px4_msgs_old/CMakeLists.txt index add08bc670..1a19a55521 100644 --- a/msg/px4_msgs_old/CMakeLists.txt +++ b/msg/px4_msgs_old/CMakeLists.txt @@ -6,6 +6,8 @@ list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake") if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra) +elseif(MSVC) + add_compile_options(/W4) endif() find_package(ament_cmake REQUIRED) diff --git a/msg/translation_node/CMakeLists.txt b/msg/translation_node/CMakeLists.txt index 4880709ce2..793eec4eb3 100644 --- a/msg/translation_node/CMakeLists.txt +++ b/msg/translation_node/CMakeLists.txt @@ -3,6 +3,8 @@ project(translation_node) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-parameter -Werror) +elseif(MSVC) + add_compile_options(/W4 /WX /wd4100) endif() # find dependencies @@ -69,7 +71,11 @@ if(BUILD_TESTING) ${TEST_SRC} ) target_include_directories(${PROJECT_NAME}_unit_tests PRIVATE ${CMAKE_CURRENT_LIST_DIR}) - target_compile_options(${PROJECT_NAME}_unit_tests PRIVATE -Wno-error=sign-compare) # There is a warning from gtest internal + if(MSVC) + target_compile_options(${PROJECT_NAME}_unit_tests PRIVATE /WX- /wd4018 /wd4389) # There is a warning from gtest internal + else() + target_compile_options(${PROJECT_NAME}_unit_tests PRIVATE -Wno-error=sign-compare) # There is a warning from gtest internal + endif() target_link_libraries(${PROJECT_NAME}_unit_tests ${PROJECT_NAME}_lib) rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} "rosidl_typesupport_cpp") target_link_libraries(${PROJECT_NAME}_unit_tests "${cpp_typesupport_target}") diff --git a/platforms/common/work_queue/CMakeLists.txt b/platforms/common/work_queue/CMakeLists.txt index 75ec99a057..20a3ebd405 100644 --- a/platforms/common/work_queue/CMakeLists.txt +++ b/platforms/common/work_queue/CMakeLists.txt @@ -51,7 +51,9 @@ if(NOT "${PX4_PLATFORM}" MATCHES "nuttx") work_thread.c ) target_compile_definitions(work_queue PRIVATE MODULE_NAME="work_queue") - target_compile_options(work_queue PRIVATE -Wno-cast-align) # TODO: fix and enable + px4_target_compile_options_for_compiler(work_queue PRIVATE + GNU_LIKE -Wno-cast-align + ) add_dependencies(work_queue prebuild_targets) endif() diff --git a/platforms/posix/CMakeLists.txt b/platforms/posix/CMakeLists.txt index d05e180c15..a9f3a66526 100644 --- a/platforms/posix/CMakeLists.txt +++ b/platforms/posix/CMakeLists.txt @@ -72,9 +72,10 @@ if (BUILD_TESTING) ${_px4_posix_math_libraries} parameters ) - target_compile_options(mavlink_fuzz_tests + px4_target_compile_options_for_compiler(mavlink_fuzz_tests PRIVATE - # There warnings come from within fuzztest + GNU_LIKE + # These warnings come from within fuzztest -Wno-float-equal -Wno-sign-compare -Wno-shadow diff --git a/platforms/posix/cmake/Toolchain-mingw-w64-x86_64.cmake b/platforms/posix/cmake/Toolchain-mingw-w64-x86_64.cmake index 37cdee80db..eef7297333 100644 --- a/platforms/posix/cmake/Toolchain-mingw-w64-x86_64.cmake +++ b/platforms/posix/cmake/Toolchain-mingw-w64-x86_64.cmake @@ -20,16 +20,66 @@ set(CMAKE_SYSTEM_PROCESSOR x86_64) set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) -find_program(MINGW_C_COMPILER NAMES ${TOOLCHAIN_PREFIX}-gcc-posix ${TOOLCHAIN_PREFIX}-gcc) -find_program(MINGW_CXX_COMPILER NAMES ${TOOLCHAIN_PREFIX}-g++-posix ${TOOLCHAIN_PREFIX}-g++) -find_program(MINGW_RC_COMPILER NAMES ${TOOLCHAIN_PREFIX}-windres) -find_program(MINGW_AR NAMES ${TOOLCHAIN_PREFIX}-ar) -find_program(MINGW_RANLIB NAMES ${TOOLCHAIN_PREFIX}-ranlib) +set(MINGW_SEARCH_PATHS) -if(NOT MINGW_C_COMPILER OR NOT MINGW_CXX_COMPILER) - message(FATAL_ERROR - "MinGW-w64 (${TOOLCHAIN_PREFIX}) not found. " - "Install with: apt-get install mingw-w64 g++-mingw-w64-x86-64-posix gcc-mingw-w64-x86-64-posix") +if(CMAKE_HOST_WIN32) + list(APPEND MINGW_SEARCH_PATHS + "$ENV{MINGW_PREFIX}/bin" + "C:/msys64/mingw64/bin") +endif() + +find_program(MINGW_REAL_C_COMPILER NAMES ${TOOLCHAIN_PREFIX}-gcc-posix ${TOOLCHAIN_PREFIX}-gcc HINTS ${MINGW_SEARCH_PATHS}) +find_program(MINGW_REAL_CXX_COMPILER NAMES ${TOOLCHAIN_PREFIX}-g++-posix ${TOOLCHAIN_PREFIX}-g++ HINTS ${MINGW_SEARCH_PATHS}) +find_program(MINGW_REAL_RC_COMPILER NAMES ${TOOLCHAIN_PREFIX}-windres HINTS ${MINGW_SEARCH_PATHS}) +find_program(MINGW_AR NAMES ${TOOLCHAIN_PREFIX}-ar HINTS ${MINGW_SEARCH_PATHS}) +find_program(MINGW_RANLIB NAMES ${TOOLCHAIN_PREFIX}-ranlib HINTS ${MINGW_SEARCH_PATHS}) + +if(NOT MINGW_REAL_C_COMPILER OR NOT MINGW_REAL_CXX_COMPILER) + if(CMAKE_HOST_WIN32) + message(FATAL_ERROR + "MinGW-w64 (${TOOLCHAIN_PREFIX}) not found. " + "Install the MSYS2 mingw-w64-x86_64 toolchain and add the MinGW bin directory " + "(for example C:/msys64/mingw64/bin) to PATH.") + else() + message(FATAL_ERROR + "MinGW-w64 (${TOOLCHAIN_PREFIX}) not found. " + "Install with: apt-get install mingw-w64 g++-mingw-w64-x86-64-posix gcc-mingw-w64-x86-64-posix") + endif() +endif() + +get_filename_component(MINGW_BIN_DIR "${MINGW_REAL_C_COMPILER}" DIRECTORY) + +if(CMAKE_HOST_WIN32) + # The GCC driver is enough to locate cc1/ld, but child tools still need + # the MinGW DLLs from the same bin directory. + set(ENV{PATH} "${MINGW_BIN_DIR};$ENV{PATH}") + + set(MINGW_WRAPPER_DIR "${CMAKE_BINARY_DIR}/mingw_toolchain") + set(MINGW_WRAPPER_PATH "${MINGW_BIN_DIR};%SystemRoot%/system32;%SystemRoot%;%SystemRoot%/System32/Wbem") + file(MAKE_DIRECTORY "${MINGW_WRAPPER_DIR}") + file(WRITE "${MINGW_WRAPPER_DIR}/gcc.cmd" + "@echo off\r\n" + "set \"PATH=${MINGW_WRAPPER_PATH}\"\r\n" + "\"${MINGW_REAL_C_COMPILER}\" %*\r\n" + "exit /b %ERRORLEVEL%\r\n") + file(WRITE "${MINGW_WRAPPER_DIR}/gxx.cmd" + "@echo off\r\n" + "set \"PATH=${MINGW_WRAPPER_PATH}\"\r\n" + "\"${MINGW_REAL_CXX_COMPILER}\" %*\r\n" + "exit /b %ERRORLEVEL%\r\n") + file(WRITE "${MINGW_WRAPPER_DIR}/windres.cmd" + "@echo off\r\n" + "set \"PATH=${MINGW_WRAPPER_PATH}\"\r\n" + "\"${MINGW_REAL_RC_COMPILER}\" %*\r\n" + "exit /b %ERRORLEVEL%\r\n") + + set(MINGW_C_COMPILER "${MINGW_WRAPPER_DIR}/gcc.cmd") + set(MINGW_CXX_COMPILER "${MINGW_WRAPPER_DIR}/gxx.cmd") + set(MINGW_RC_COMPILER "${MINGW_WRAPPER_DIR}/windres.cmd") +else() + set(MINGW_C_COMPILER "${MINGW_REAL_C_COMPILER}") + set(MINGW_CXX_COMPILER "${MINGW_REAL_CXX_COMPILER}") + set(MINGW_RC_COMPILER "${MINGW_REAL_RC_COMPILER}") endif() set(CMAKE_C_COMPILER ${MINGW_C_COMPILER}) @@ -43,7 +93,14 @@ set(CMAKE_RANLIB ${MINGW_RANLIB}) # PACKAGE uses BOTH so find_package() can locate packages installed by # nested ExternalProject builds (microcdr under the PX4 build tree) as # well as packages living in the MinGW sysroot. -set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) +if(CMAKE_HOST_WIN32) + get_filename_component(MINGW_PREFIX "${MINGW_BIN_DIR}" DIRECTORY) + set(CMAKE_FIND_ROOT_PATH + "${MINGW_PREFIX}" + "${MINGW_PREFIX}/${TOOLCHAIN_PREFIX}") +else() + set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) +endif() set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) @@ -58,6 +115,20 @@ get_filename_component(_px4_windows_shim_dir "${CMAKE_CURRENT_LIST_DIR}/../include/windows_shim" ABSOLUTE) include_directories(BEFORE SYSTEM "${_px4_windows_shim_dir}") +# Vendored upstream code (Micro-XRCE-DDS-Client, CycloneDDS, libvnc) writes +# `#include `. MinGW only ships the lowercase header, so on +# case-sensitive hosts (Linux, macOS) we need an uppercase alias. On +# case-insensitive hosts (Windows itself) the alias must NOT exist on the +# include path: a shim `Windows.h` would match `#include ` first +# and `#pragma once`-recurse to itself, hiding the real header. Generate +# the alias under the build tree only when we actually need it. +if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(_px4_windows_case_alias_dir ${CMAKE_BINARY_DIR}/windows_case_alias) + file(WRITE ${_px4_windows_case_alias_dir}/Windows.h + "#pragma once\n#include \n") + include_directories(BEFORE SYSTEM ${_px4_windows_case_alias_dir}) +endif() + # Target Windows 10 (1803+) so AF_UNIX is available in WinSock2. add_compile_definitions( _WIN32_WINNT=0x0A00 # Windows 10 diff --git a/platforms/posix/cmake/px4_impl_os.cmake b/platforms/posix/cmake/px4_impl_os.cmake index b1b8e5cc84..5eb87fdaca 100644 --- a/platforms/posix/cmake/px4_impl_os.cmake +++ b/platforms/posix/cmake/px4_impl_os.cmake @@ -211,13 +211,17 @@ function(px4_posix_generate_symlinks) if (MAIN) set(ln_name "${PREFIX}${MAIN}") if(WIN32 OR MINGW) - # Windows symlinks require admin; copy the exe instead so that - # px4-.exe can be invoked the same way as on POSIX. + set(alias_executable "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${ln_name}.exe") + + # Windows symlinks require extra privileges. Hard links keep the + # px4-.exe entry points without duplicating the MSVC exe. add_custom_command(TARGET ${TARGET} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy + COMMAND ${CMAKE_COMMAND} -E remove -f + ${alias_executable} + COMMAND ${CMAKE_COMMAND} -E create_hardlink $ - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${ln_name}.exe + ${alias_executable} ) else() add_custom_command(TARGET ${TARGET} @@ -245,7 +249,7 @@ function(px4_os_add_flags) add_definitions(-D__PX4_POSIX) if(MSVC) - add_definitions(-Dnoreturn_function=__declspec\(noreturn\)) + add_definitions(-Dnoreturn_function=) else() add_definitions(-Dnoreturn_function=__attribute__\(\(noreturn\)\)) endif() diff --git a/platforms/posix/cmake/windows.cmake b/platforms/posix/cmake/windows.cmake index 8452dfe4c7..acf9ec0733 100644 --- a/platforms/posix/cmake/windows.cmake +++ b/platforms/posix/cmake/windows.cmake @@ -38,6 +38,9 @@ set(PX4_POSIX_WINDOWS_ROOT "${PX4_SOURCE_DIR}/platforms/posix/src/px4/windows") set(PX4_POSIX_WINDOWS_PRIVATE_INCLUDE_DIR "${PX4_POSIX_WINDOWS_ROOT}/include") +set(PX4_POSIX_WINDOWS_DYNAMIC_MODULE_HOST_EXPORTS + px4_log_modulename +) function(px4_posix_windows_append_sources out_var) list(APPEND ${out_var} @@ -109,6 +112,20 @@ function(px4_posix_windows_configure_target target_name) if(MSVC) set_target_properties(${target_name} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) target_compile_options(${target_name} PRIVATE /bigobj) + + # Reproducible builds: zero out the PE COFF TimeDateStamp and the debug + # directory timestamp so byte-identical sources produce a byte-identical + # px4.exe. Without /Brepro every link embeds time(NULL), making CI + # artifact diffing and supply-chain hashing meaningless. + target_compile_options(${target_name} PRIVATE /Brepro) + target_link_options(${target_name} PRIVATE /Brepro) + + # WINDOWS_EXPORT_ALL_SYMBOLS only scans objects owned directly by + # px4.exe. Dynamic .px4mod modules also need host APIs that come from + # PX4 static libraries, so export those entry points explicitly. + foreach(host_export IN LISTS PX4_POSIX_WINDOWS_DYNAMIC_MODULE_HOST_EXPORTS) + target_link_options(${target_name} PRIVATE "/EXPORT:${host_export}") + endforeach() else() # Force an import library (`libpx4.dll.a`) to be generated alongside # px4.exe so DYNAMIC `.px4mod` modules can link against it. @@ -149,6 +166,7 @@ function(px4_posix_windows_link_libraries target_name) iphlpapi dbghelp psapi + winmm # timeBeginPeriod / timeEndPeriod for 1 ms timer resolution ) if(NOT MSVC) diff --git a/platforms/posix/src/px4/common/CMakeLists.txt b/platforms/posix/src/px4/common/CMakeLists.txt index e99ac9ca90..d8e8638bcb 100644 --- a/platforms/posix/src/px4/common/CMakeLists.txt +++ b/platforms/posix/src/px4/common/CMakeLists.txt @@ -51,7 +51,9 @@ add_library(px4_layer SerialImpl.cpp ) target_compile_definitions(px4_layer PRIVATE MODULE_NAME="px4") -target_compile_options(px4_layer PRIVATE -Wno-cast-align) # TODO: fix and enable +px4_target_compile_options_for_compiler(px4_layer PRIVATE + GNU_LIKE -Wno-cast-align # TODO: fix and enable +) target_link_libraries(px4_layer PRIVATE work_queue px4_work_queue) target_link_libraries(px4_layer PRIVATE px4_daemon drivers_board) diff --git a/platforms/ros2/CMakeLists.txt b/platforms/ros2/CMakeLists.txt index 7411aa6f80..44d2de906e 100644 --- a/platforms/ros2/CMakeLists.txt +++ b/platforms/ros2/CMakeLists.txt @@ -46,9 +46,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin) # src/px4/common/main.cpp # ) -add_compile_options( - -Wno-error - -Wno-float-equal # msg generated equality operator +px4_add_compile_options_for_compiler( + GNU_LIKE + -Wno-error + -Wno-float-equal # msg generated equality operator ) include_directories(${PX4_BINARY_DIR}) diff --git a/platforms/ros2/src/px4/common/CMakeLists.txt b/platforms/ros2/src/px4/common/CMakeLists.txt index ed06198c26..f174deecec 100644 --- a/platforms/ros2/src/px4/common/CMakeLists.txt +++ b/platforms/ros2/src/px4/common/CMakeLists.txt @@ -37,4 +37,6 @@ add_library(px4_layer STATIC ${PX4_SOURCE_DIR}/platforms/common/module_base.cpp ) target_compile_definitions(px4_layer PRIVATE MODULE_NAME="px4") -target_compile_options(px4_layer PRIVATE -Wno-cast-align) # TODO: fix and enable +px4_target_compile_options_for_compiler(px4_layer PRIVATE + GNU_LIKE -Wno-cast-align # TODO: fix and enable +) diff --git a/src/drivers/cyphal/CMakeLists.txt b/src/drivers/cyphal/CMakeLists.txt index 1e6d8a9ece..3d4862082e 100644 --- a/src/drivers/cyphal/CMakeLists.txt +++ b/src/drivers/cyphal/CMakeLists.txt @@ -143,4 +143,6 @@ px4_add_module( ) # libcanard 3.0 introduces this warning, for now no intention to fix it thus we ignore this warning -set_source_files_properties(${LIBCANARD_DIR}/libcanard/canard.c PROPERTIES COMPILE_FLAGS -Wno-cast-align) +if(NOT MSVC) + set_source_files_properties(${LIBCANARD_DIR}/libcanard/canard.c PROPERTIES COMPILE_FLAGS -Wno-cast-align) +endif() diff --git a/src/drivers/ins/ilabs/libilabs/CMakeLists.txt b/src/drivers/ins/ilabs/libilabs/CMakeLists.txt index 3879c1a7f0..076a82eef7 100644 --- a/src/drivers/ins/ilabs/libilabs/CMakeLists.txt +++ b/src/drivers/ins/ilabs/libilabs/CMakeLists.txt @@ -38,9 +38,8 @@ set(SOURCES ) add_library(${LIBRARY_NAME} ${SOURCES}) -target_compile_options(${LIBRARY_NAME} - PRIVATE - -Wno-unused-function +px4_target_compile_options_for_compiler(${LIBRARY_NAME} PRIVATE + GNU_LIKE -Wno-unused-function ) target_include_directories(${LIBRARY_NAME} PUBLIC diff --git a/src/drivers/ins/microstrain/CMakeLists.txt b/src/drivers/ins/microstrain/CMakeLists.txt index 9848bd09fd..4dbcc00529 100644 --- a/src/drivers/ins/microstrain/CMakeLists.txt +++ b/src/drivers/ins/microstrain/CMakeLists.txt @@ -42,6 +42,17 @@ set(BUILD_EXAMPLES "OFF" CACHE BOOL "" FORCE) set(BUILD_TESTING "OFF" CACHE BOOL "" FORCE) add_subdirectory(mip_sdk) +# The mip target lives in a vendored submodule; apply PX4's compiler-specific +# warning suppressions from the parent so the submodule tree stays clean. +if(TARGET mip) + px4_target_compile_options_for_compiler(mip PRIVATE + GNU_LIKE + -Wno-shadow + -Wno-strict-prototypes + -Wno-incompatible-pointer-types + ) +endif() + px4_add_module( MODULE drivers__ins__microstrain MAIN microstrain diff --git a/src/drivers/ins/sbgecom/CMakeLists.txt b/src/drivers/ins/sbgecom/CMakeLists.txt index b9778b59b3..b1acc30d8b 100644 --- a/src/drivers/ins/sbgecom/CMakeLists.txt +++ b/src/drivers/ins/sbgecom/CMakeLists.txt @@ -51,16 +51,16 @@ add_dependencies(sbgECom prebuild_targets) # If you add a flag here, it should address a warning emitted by vendor # code only. Warnings triggered in PX4-authored code must be fixed at # the source, not silenced here. -target_compile_options(sbgECom - PRIVATE - -Wno-format - -Wno-format-security - -Wno-bad-function-cast - -Wno-double-promotion - -Wno-type-limits - -Wno-maybe-uninitialized - -Wno-float-equal - -Wno-logical-op +px4_target_compile_options_for_compiler(sbgECom PRIVATE + GNU_LIKE + -Wno-format + -Wno-format-security + -Wno-bad-function-cast + -Wno-double-promotion + -Wno-type-limits + -Wno-maybe-uninitialized + -Wno-float-equal + -Wno-logical-op ) # -Wno-typedef-redefinition is Clang-only. GCC rejects unrecognized diff --git a/src/drivers/ins/vectornav/libvnc/CMakeLists.txt b/src/drivers/ins/vectornav/libvnc/CMakeLists.txt index 804256c820..07fbb5db8c 100644 --- a/src/drivers/ins/vectornav/libvnc/CMakeLists.txt +++ b/src/drivers/ins/vectornav/libvnc/CMakeLists.txt @@ -56,17 +56,25 @@ add_library(libvnc ${SOURCES}) add_dependencies(libvnc prebuild_targets) target_compile_options(libvnc PRIVATE - -Wno-double-promotion - -Wno-pointer-sign - -Wno-cast-align - -Wno-unused-but-set-parameter - -Wno-sign-compare - -Wno-bad-function-cast - -Wno-empty-body - -Wno-switch - -Wno-unused-variable - -Wno-format - -Wno-format-security + $<$:/wd4018> + $<$:/wd4061> + $<$:/wd4062> + $<$:/wd4100> + $<$:/wd4101> + $<$:/wd4189> + $<$:/wd4389> + $<$:/wd4390> + $<$>:-Wno-double-promotion> + $<$>:-Wno-pointer-sign> + $<$>:-Wno-cast-align> + $<$>:-Wno-unused-but-set-parameter> + $<$>:-Wno-sign-compare> + $<$>:-Wno-bad-function-cast> + $<$>:-Wno-empty-body> + $<$>:-Wno-switch> + $<$>:-Wno-unused-variable> + $<$>:-Wno-format> + $<$>:-Wno-format-security> ) if("${PX4_PLATFORM}" MATCHES "nuttx") diff --git a/src/drivers/osd/msp_osd/MessageDisplay/CMakeLists.txt b/src/drivers/osd/msp_osd/MessageDisplay/CMakeLists.txt index 032027dc03..0fc561bf9e 100644 --- a/src/drivers/osd/msp_osd/MessageDisplay/CMakeLists.txt +++ b/src/drivers/osd/msp_osd/MessageDisplay/CMakeLists.txt @@ -31,12 +31,14 @@ # ############################################################################ -add_compile_options(-Wno-stringop-truncation) # full message intentional string truncation - px4_add_library(message_display MessageDisplay.cpp MessageDisplay.hpp ) +px4_target_compile_options_for_compiler(message_display PRIVATE + GNU_LIKE -Wno-stringop-truncation # full message intentional string truncation +) + # unit testing px4_add_unit_gtest(SRC MessageDisplayTest.cpp LINKLIBS message_display) diff --git a/src/drivers/uavcan/CMakeLists.txt b/src/drivers/uavcan/CMakeLists.txt index 70512233cf..152494f8fe 100644 --- a/src/drivers/uavcan/CMakeLists.txt +++ b/src/drivers/uavcan/CMakeLists.txt @@ -86,10 +86,11 @@ add_definitions( -DUAVCAN_PLATFORM=${UAVCAN_PLATFORM} ) -add_compile_options( - -Wno-cast-align # TODO: fix and enable - -Wno-deprecated-copy # TODO: fix - -Wno-address-of-packed-member +px4_add_compile_options_for_compiler( + GNU_LIKE + -Wno-cast-align # TODO: fix and enable + -Wno-deprecated-copy # TODO: fix + -Wno-address-of-packed-member ) set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE) # silence libuavcan deprecation warning for now (TODO: fix and remove) add_subdirectory(${LIBDRONECAN_DIR} libdronecan EXCLUDE_FROM_ALL) diff --git a/src/drivers/uavcan/uavcan_drivers/kinetis/driver/CMakeLists.txt b/src/drivers/uavcan/uavcan_drivers/kinetis/driver/CMakeLists.txt index dc88509ae5..2839192188 100644 --- a/src/drivers/uavcan/uavcan_drivers/kinetis/driver/CMakeLists.txt +++ b/src/drivers/uavcan/uavcan_drivers/kinetis/driver/CMakeLists.txt @@ -2,7 +2,7 @@ include_directories( ./include ) -add_compile_options(-Wno-unused-variable) +px4_add_compile_options_for_compiler(GNU_LIKE -Wno-unused-variable) add_library(uavcan_kinetis_driver STATIC ./src/uc_kinetis_flexcan.cpp ./src/uc_kinetis_clock.cpp diff --git a/src/drivers/uavcan/uavcan_drivers/socketcan/driver/CMakeLists.txt b/src/drivers/uavcan/uavcan_drivers/socketcan/driver/CMakeLists.txt index 0b7b785b86..5152082b18 100644 --- a/src/drivers/uavcan/uavcan_drivers/socketcan/driver/CMakeLists.txt +++ b/src/drivers/uavcan/uavcan_drivers/socketcan/driver/CMakeLists.txt @@ -2,7 +2,7 @@ include_directories( ./include ) -add_compile_options(-Wno-unused-variable) +px4_add_compile_options_for_compiler(GNU_LIKE -Wno-unused-variable) add_library(uavcan_socketcan_driver STATIC src/socketcan.cpp src/thread.cpp diff --git a/src/lib/cdrstream/CMakeLists.txt b/src/lib/cdrstream/CMakeLists.txt index cfdb6ab090..7209c059af 100644 --- a/src/lib/cdrstream/CMakeLists.txt +++ b/src/lib/cdrstream/CMakeLists.txt @@ -36,11 +36,17 @@ if(CONFIG_LIB_CDRSTREAM) # CycloneDDS CDR serializer include(${CMAKE_CURRENT_LIST_DIR}/cyclonedds/src/core/cdr/CMakeLists.txt) - target_compile_options(cdr PUBLIC - -Wno-cast-align - -Wno-double-promotion - $<$:-Wno-implicit-function-declaration -Wno-nested-externs> - -DNDEBUG) + target_compile_options(cdr PUBLIC -DNDEBUG) + px4_target_compile_options_for_compiler(cdr PUBLIC + GNU_LIKE + -Wno-cast-align + -Wno-double-promotion + ) + px4_target_c_compile_options_for_compiler(cdr PUBLIC + GNU_LIKE + -Wno-implicit-function-declaration + -Wno-nested-externs + ) px4_add_git_submodule(TARGET git_cyclonedds PATH "cyclonedds") px4_add_git_submodule(TARGET git_rosidl PATH "rosidl") add_dependencies(cdr git_cyclonedds git_rosidl uorb_headers parameters px4_platform) diff --git a/src/lib/collision_prevention/CMakeLists.txt b/src/lib/collision_prevention/CMakeLists.txt index c0c6e06210..ba2ff5c0c2 100644 --- a/src/lib/collision_prevention/CMakeLists.txt +++ b/src/lib/collision_prevention/CMakeLists.txt @@ -36,7 +36,9 @@ px4_add_library(CollisionPrevention ObstacleMath.cpp ) set_property(GLOBAL APPEND PROPERTY PX4_MODULE_CONFIG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/collisionprevention_params.yaml) -target_compile_options(CollisionPrevention PRIVATE -Wno-cast-align) # TODO: fix and enable +px4_target_compile_options_for_compiler(CollisionPrevention PRIVATE + GNU_LIKE -Wno-cast-align # TODO: fix and enable +) target_include_directories(CollisionPrevention PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(CollisionPrevention PRIVATE mathlib) diff --git a/src/lib/controllib/controllib_test/CMakeLists.txt b/src/lib/controllib/controllib_test/CMakeLists.txt index 87333294b6..d4275469fd 100644 --- a/src/lib/controllib/controllib_test/CMakeLists.txt +++ b/src/lib/controllib/controllib_test/CMakeLists.txt @@ -31,11 +31,19 @@ # ############################################################################ +set(controllib_test_compile_flags) + +if(NOT MSVC) + list(APPEND controllib_test_compile_flags + -Wno-double-promotion # TODO: fix in Matrix library Vector::pow() + ) +endif() + px4_add_module( MODULE lib__controllib__controllib_test MAIN controllib_test COMPILE_FLAGS - -Wno-double-promotion # TODO: fix in Matrix library Vector::pow() + ${controllib_test_compile_flags} SRCS controllib_test_main.cpp MODULE_CONFIG diff --git a/src/lib/crypto/CMakeLists.txt b/src/lib/crypto/CMakeLists.txt index 90936d29b4..1d56379876 100644 --- a/src/lib/crypto/CMakeLists.txt +++ b/src/lib/crypto/CMakeLists.txt @@ -48,7 +48,9 @@ target_include_directories(monocypher ) # There is a one shadow warning in monocypher 3.1.2, ignore it -target_compile_options(monocypher PRIVATE -Wno-shadow) +px4_target_compile_options_for_compiler(monocypher PRIVATE + GNU_LIKE -Wno-shadow +) @@ -97,7 +99,9 @@ target_link_libraries(libtomcrypt # Fix for erroneous warning on some compilers: # "der_encode_asn1_identifier.c:39:18: error: comparison is always false due to limited range of data type" -target_compile_options(libtomcrypt PRIVATE -Wno-type-limits) +px4_target_compile_options_for_compiler(libtomcrypt PRIVATE + GNU_LIKE -Wno-type-limits +) # Re-define memory allocation macros if we are building for # memory protected build in nuttx. All allocations happen in diff --git a/src/lib/events/CMakeLists.txt b/src/lib/events/CMakeLists.txt index fcdb971f64..9d81727abe 100644 --- a/src/lib/events/CMakeLists.txt +++ b/src/lib/events/CMakeLists.txt @@ -42,6 +42,14 @@ foreach(f ${all_px4_src_files}) list(APPEND all_px4_src_files_relative "${relative_path}") endforeach(f) +# The relative list still blows past Windows' 8191-char cmd.exe line limit +# (~50 KB worth of paths). Write it to a response file and pass it through +# argparse's @file expansion so the python invocation stays a few hundred +# bytes regardless of source count. +set(events_srcs_response ${CMAKE_CURRENT_BINARY_DIR}/px4_event_srcs.rsp) +string(REPLACE ";" "\n" _events_srcs_lines "${all_px4_src_files_relative}") +file(WRITE ${events_srcs_response} "${_events_srcs_lines}\n") + set(generated_events_dir ${PX4_BINARY_DIR}/events) set(generated_events_px4_file ${generated_events_dir}/px4.json) set(generated_events_common_enums_file ${generated_events_dir}/common_with_enums.json) @@ -49,7 +57,7 @@ add_custom_command(OUTPUT ${generated_events_px4_file} COMMAND ${CMAKE_COMMAND} -E make_directory ${generated_events_dir} COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_process_events.py --base-path ${PX4_SOURCE_DIR}/src - --src-path ${all_px4_src_files_relative} + --src-path @${events_srcs_response} --json ${generated_events_px4_file} #--verbose DEPENDS ${all_px4_src_files} diff --git a/src/lib/led/CMakeLists.txt b/src/lib/led/CMakeLists.txt index 4ec9d49a48..707776737e 100644 --- a/src/lib/led/CMakeLists.txt +++ b/src/lib/led/CMakeLists.txt @@ -33,6 +33,6 @@ px4_add_library(led led.cpp) set_property(GLOBAL APPEND PROPERTY PX4_MODULE_CONFIG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/led_params.yaml) -target_compile_options(led - PRIVATE -Wno-implicit-fallthrough # TODO: fix and remove +px4_target_compile_options_for_compiler(led PRIVATE + GNU_LIKE -Wno-implicit-fallthrough # TODO: fix and remove ) diff --git a/src/lib/matrix/test/CMakeLists.txt b/src/lib/matrix/test/CMakeLists.txt index dbdf1d4c22..9b630717cd 100644 --- a/src/lib/matrix/test/CMakeLists.txt +++ b/src/lib/matrix/test/CMakeLists.txt @@ -1,6 +1,7 @@ -add_compile_options( - -Wno-double-promotion - -Wno-float-equal +px4_add_compile_options_for_compiler( + GNU_LIKE + -Wno-double-promotion + -Wno-float-equal ) px4_add_unit_gtest(SRC MatrixAssignmentTest.cpp) diff --git a/src/lib/parameters/CMakeLists.txt b/src/lib/parameters/CMakeLists.txt index 9cb776e0df..19c0d01507 100644 --- a/src/lib/parameters/CMakeLists.txt +++ b/src/lib/parameters/CMakeLists.txt @@ -201,11 +201,13 @@ if(NOT "${PX4_BOARD}" MATCHES "px4_io") target_link_libraries(parameters PRIVATE perf tinybson px4_platform) target_compile_definitions(parameters PRIVATE -DMODULE_NAME="parameters" -D__KERNEL__) - target_compile_options(parameters - PRIVATE - #-DDEBUG_BUILD + #target_compile_options(parameters PRIVATE -DDEBUG_BUILD) + px4_target_compile_options_for_compiler(parameters PRIVATE + GNU_LIKE -Wno-cast-align # TODO: fix and enable -Wno-sign-compare # TODO: fix and enable + MSVC + /wd4389 ) else() add_library(parameters STATIC EXCLUDE_FROM_ALL ${PX4_SOURCE_DIR}/platforms/common/empty.c) diff --git a/src/lib/rc/CMakeLists.txt b/src/lib/rc/CMakeLists.txt index e24cc0dcc9..7dd6fc8821 100644 --- a/src/lib/rc/CMakeLists.txt +++ b/src/lib/rc/CMakeLists.txt @@ -40,9 +40,8 @@ add_library(rc dsm.cpp common_rc.cpp ) -target_compile_options(rc - PRIVATE - #-DDEBUG_BUILD +px4_target_compile_options_for_compiler(rc PRIVATE + GNU_LIKE -Wno-unused-result ) target_link_libraries(rc PRIVATE prebuild_targets) diff --git a/src/lib/rc/rc_tests/CMakeLists.txt b/src/lib/rc/rc_tests/CMakeLists.txt index 61cf326748..18fe832446 100644 --- a/src/lib/rc/rc_tests/CMakeLists.txt +++ b/src/lib/rc/rc_tests/CMakeLists.txt @@ -31,11 +31,19 @@ # ############################################################################ +set(rc_tests_compile_flags) + +if(NOT MSVC) + list(APPEND rc_tests_compile_flags + -Wno-unused-result + ) +endif() + px4_add_module( MODULE lib__rc__rc_tests MAIN rc_tests COMPILE_FLAGS - -Wno-unused-result + ${rc_tests_compile_flags} SRCS RCTest.cpp DEPENDS diff --git a/src/lib/rl_tools/CMakeLists.txt b/src/lib/rl_tools/CMakeLists.txt index 83402f2c45..df025a0478 100644 --- a/src/lib/rl_tools/CMakeLists.txt +++ b/src/lib/rl_tools/CMakeLists.txt @@ -7,9 +7,10 @@ if(CONFIG_LIB_RL_TOOLS) target_compile_features(rl_tools INTERFACE cxx_std_17) - target_compile_options(rl_tools INTERFACE - -Wno-unused-parameter - -Wno-unused-variable - -Wno-unused-local-typedefs + px4_target_compile_options_for_compiler(rl_tools INTERFACE + GNU_LIKE + -Wno-unused-parameter + -Wno-unused-variable + -Wno-unused-local-typedefs ) endif() diff --git a/src/lib/tensorflow_lite_micro/CMakeLists.txt b/src/lib/tensorflow_lite_micro/CMakeLists.txt index 575bb663c3..a91afce5eb 100644 --- a/src/lib/tensorflow_lite_micro/CMakeLists.txt +++ b/src/lib/tensorflow_lite_micro/CMakeLists.txt @@ -36,11 +36,6 @@ if(CONFIG_LIB_TFLM) set(TFLITE_DOWNLOADS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tflite_micro/tensorflow/lite/micro/tools/make/downloads) - get_directory_property(FLAGS COMPILE_OPTIONS) - list(REMOVE_ITEM FLAGS "-Wcast-align") - set_directory_properties(PROPERTIES COMPILE_OPTIONS "${FLAGS}") - - file(GLOB TFLITE_MICRO_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tflite_micro/tensorflow/lite/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/tflite_micro/tensorflow/lite/micro/*.cc @@ -85,9 +80,11 @@ if(CONFIG_LIB_TFLM) add_dependencies(tensorflow_lite_micro git_tflite-micro) target_compile_features(tensorflow_lite_micro PRIVATE cxx_std_17) - target_compile_options(tensorflow_lite_micro PUBLIC - -Wno-float-equal - -Wno-shadow + px4_target_compile_options_for_compiler(tensorflow_lite_micro PUBLIC + GNU_LIKE + -Wno-cast-align + -Wno-float-equal + -Wno-shadow ) diff --git a/src/lib/tinybson/CMakeLists.txt b/src/lib/tinybson/CMakeLists.txt index 88febcd4f1..3ed2fd219e 100644 --- a/src/lib/tinybson/CMakeLists.txt +++ b/src/lib/tinybson/CMakeLists.txt @@ -38,8 +38,11 @@ add_library(tinybson target_compile_definitions(tinybson PRIVATE -DMODULE_NAME="tinybson") target_compile_options(tinybson PRIVATE - -Wno-sign-compare # TODO: fix this ${MAX_CUSTOM_OPT_LEVEL} ) +px4_target_compile_options_for_compiler(tinybson PRIVATE + GNU_LIKE -Wno-sign-compare + MSVC /wd4018 /wd4389 +) add_dependencies(tinybson prebuild_targets) diff --git a/src/lib/version/CMakeLists.txt b/src/lib/version/CMakeLists.txt index ad2e516b4f..5bb121744a 100644 --- a/src/lib/version/CMakeLists.txt +++ b/src/lib/version/CMakeLists.txt @@ -54,7 +54,7 @@ endif() set(px4_git_ver_header ${CMAKE_CURRENT_BINARY_DIR}/build_git_version.h) add_custom_command(OUTPUT ${px4_git_ver_header} COMMAND - ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/px_update_git_header.py ${px4_git_ver_header} --validate --git_tag '${PX4_GIT_TAG}' + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/px_update_git_header.py ${px4_git_ver_header} --validate --git_tag ${PX4_GIT_TAG} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/px_update_git_header.py ${git_dir_path}/HEAD diff --git a/src/lib/world_magnetic_model/CMakeLists.txt b/src/lib/world_magnetic_model/CMakeLists.txt index 523fec7f97..ae006e159d 100644 --- a/src/lib/world_magnetic_model/CMakeLists.txt +++ b/src/lib/world_magnetic_model/CMakeLists.txt @@ -57,5 +57,8 @@ target_compile_options(world_magnetic_model PRIVATE ${MAX_CUSTOM_OPT_LEVEL}) if(BUILD_TESTING) px4_add_unit_gtest(SRC test_geo_lookup.cpp LINKLIBS world_magnetic_model) - target_compile_options(unit-test_geo_lookup PRIVATE ${PX4_DEBUG_OPT_LEVEL} -Wno-double-promotion) + target_compile_options(unit-test_geo_lookup PRIVATE ${PX4_DEBUG_OPT_LEVEL}) + px4_target_compile_options_for_compiler(unit-test_geo_lookup PRIVATE + GNU_LIKE -Wno-double-promotion + ) endif() diff --git a/src/modules/dataman/CMakeLists.txt b/src/modules/dataman/CMakeLists.txt index a3ca6c3602..496e45e248 100644 --- a/src/modules/dataman/CMakeLists.txt +++ b/src/modules/dataman/CMakeLists.txt @@ -30,11 +30,18 @@ # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ + +set(dataman_compile_flags) + +if(NOT MSVC) + list(APPEND dataman_compile_flags -Wno-cast-align) # TODO: fix and enable +endif() + px4_add_module( MODULE modules__dataman MAIN dataman COMPILE_FLAGS - -Wno-cast-align # TODO: fix and enable + ${dataman_compile_flags} SRCS dataman.cpp MODULE_CONFIG diff --git a/src/modules/ekf2/CMakeLists.txt b/src/modules/ekf2/CMakeLists.txt index 1f05add4fc..11816353a2 100644 --- a/src/modules/ekf2/CMakeLists.txt +++ b/src/modules/ekf2/CMakeLists.txt @@ -244,12 +244,19 @@ endif () add_subdirectory(EKF) +set(ekf2_compile_flags ${MAX_CUSTOM_OPT_LEVEL}) + +if(MSVC) + list(APPEND ekf2_compile_flags /fp:precise) +else() + list(APPEND ekf2_compile_flags -fno-associative-math) +endif() + px4_add_module( MODULE modules__ekf2 MAIN ekf2 COMPILE_FLAGS - ${MAX_CUSTOM_OPT_LEVEL} - -fno-associative-math + ${ekf2_compile_flags} #-DDEBUG_BUILD #-O0 INCLUDES diff --git a/src/modules/ekf2/EKF/CMakeLists.txt b/src/modules/ekf2/EKF/CMakeLists.txt index 38dc2718ea..9050a9528d 100644 --- a/src/modules/ekf2/EKF/CMakeLists.txt +++ b/src/modules/ekf2/EKF/CMakeLists.txt @@ -161,4 +161,7 @@ target_link_libraries(ecl_EKF ${EKF_LIBS} ) -target_compile_options(ecl_EKF PRIVATE -fno-associative-math) +px4_target_compile_options_for_compiler(ecl_EKF PRIVATE + GNU_LIKE -fno-associative-math + MSVC /fp:precise +) diff --git a/src/modules/flight_mode_manager/CMakeLists.txt b/src/modules/flight_mode_manager/CMakeLists.txt index efd7d9a261..0ffc596393 100644 --- a/src/modules/flight_mode_manager/CMakeLists.txt +++ b/src/modules/flight_mode_manager/CMakeLists.txt @@ -89,8 +89,8 @@ add_custom_target(flighttasks_generated DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/FlightTasks_generated.cpp) add_dependencies(prebuild_targets flighttasks_generated) -add_compile_options( - -Wno-cast-align +px4_add_compile_options_for_compiler( + GNU_LIKE -Wno-cast-align ) # TODO: fix and enable # add subdirectory containing all tasks diff --git a/src/modules/gyro_fft/CMakeLists.txt b/src/modules/gyro_fft/CMakeLists.txt index 231db5d54d..1869ce1d7a 100644 --- a/src/modules/gyro_fft/CMakeLists.txt +++ b/src/modules/gyro_fft/CMakeLists.txt @@ -42,10 +42,14 @@ endif() # CMSIS DSP contains ARM Cortex-M assembly that triggers clang warnings on 64-bit ARM. # This code is unused on POSIX platforms - only the C fallback implementations run. if(${PX4_PLATFORM} MATCHES "posix" AND ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "arm64|aarch64") - add_compile_options(-Wno-asm-operand-widths) + px4_add_compile_options_for_compiler( + GNU_LIKE -Wno-asm-operand-widths + ) endif() -add_compile_options($<$:-Wno-nested-externs>) +px4_add_c_compile_options_for_compiler( + GNU_LIKE -Wno-nested-externs +) px4_add_module( MODULE modules__gyro_fft diff --git a/src/modules/logger/CMakeLists.txt b/src/modules/logger/CMakeLists.txt index 995ce88524..2969c29d8e 100644 --- a/src/modules/logger/CMakeLists.txt +++ b/src/modules/logger/CMakeLists.txt @@ -37,6 +37,12 @@ if(PX4_CRYPTO) list(APPEND LOGGER_MODULE_PARAMS module_params_crypto.yaml) endif() +set(logger_compile_flags ${MAX_CUSTOM_OPT_LEVEL}) + +if(NOT MSVC) + list(APPEND logger_compile_flags -Wno-cast-align) # TODO: fix and enable +endif() + px4_add_module( MODULE modules__logger MAIN logger @@ -46,8 +52,7 @@ px4_add_module( module.yaml ${LOGGER_MODULE_PARAMS} COMPILE_FLAGS - ${MAX_CUSTOM_OPT_LEVEL} - -Wno-cast-align # TODO: fix and enable + ${logger_compile_flags} SRCS logged_topics.cpp logger.cpp diff --git a/src/modules/mavlink/CMakeLists.txt b/src/modules/mavlink/CMakeLists.txt index 9c2540686d..8a41036d91 100644 --- a/src/modules/mavlink/CMakeLists.txt +++ b/src/modules/mavlink/CMakeLists.txt @@ -83,7 +83,9 @@ set_source_files_properties(${MAVLINK_LIBRARY_DIR}/${CONFIG_MAVLINK_DIALECT}/${C # mavlink header only library add_library(mavlink_c INTERFACE) -target_compile_options(mavlink_c INTERFACE -Wno-address-of-packed-member -Wno-cast-align) +px4_target_compile_options_for_compiler(mavlink_c INTERFACE + GNU_LIKE -Wno-address-of-packed-member -Wno-cast-align +) target_sources(mavlink_c INTERFACE ${MAVLINK_LIBRARY_DIR}/${CONFIG_MAVLINK_DIALECT}/${CONFIG_MAVLINK_DIALECT}.h @@ -95,13 +97,21 @@ target_include_directories(mavlink_c ${MAVLINK_LIBRARY_DIR}/../ ${MAVLINK_LIBRARY_DIR}/${CONFIG_MAVLINK_DIALECT} ${MAVLINK_LIBRARY_DIR}/${MAVLINK_DIALECT_UAVIONIX} -) + ) + +set(mavlink_compile_flags) + +if(NOT MSVC) + list(APPEND mavlink_compile_flags + -Wno-enum-compare # ROTATION <-> MAV_SENSOR_ROTATION + ) +endif() px4_add_module( MODULE modules__mavlink MAIN mavlink COMPILE_FLAGS - -Wno-enum-compare # ROTATION <-> MAV_SENSOR_ROTATION + ${mavlink_compile_flags} #-DDEBUG_BUILD SRCS mavlink.c diff --git a/src/modules/mc_nn_control/CMakeLists.txt b/src/modules/mc_nn_control/CMakeLists.txt index ce28324bcf..a58efe2e1c 100644 --- a/src/modules/mc_nn_control/CMakeLists.txt +++ b/src/modules/mc_nn_control/CMakeLists.txt @@ -30,11 +30,6 @@ # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ -add_compile_options(-Wno-float-equal) -get_directory_property(FLAGS COMPILE_OPTIONS) -list(REMOVE_ITEM FLAGS "-Wcast-align") -set_directory_properties(PROPERTIES COMPILE_OPTIONS "${FLAGS}") - px4_add_module( MODULE mc_nn_control MAIN mc_nn_control @@ -51,6 +46,11 @@ px4_add_module( px4_work_queue mathlib ) +px4_target_compile_options_for_compiler(mc_nn_control PRIVATE + GNU_LIKE + -Wno-cast-align + -Wno-float-equal +) target_link_libraries(mc_nn_control PRIVATE tensorflow_lite_micro) target_include_directories(mc_nn_control PRIVATE ${CMAKE_SOURCE_DIR}/src/lib/tensorflow_lite_micro) diff --git a/src/modules/mc_raptor/CMakeLists.txt b/src/modules/mc_raptor/CMakeLists.txt index 5cde791827..7e7c2bb472 100644 --- a/src/modules/mc_raptor/CMakeLists.txt +++ b/src/modules/mc_raptor/CMakeLists.txt @@ -18,4 +18,6 @@ px4_add_module( ) target_compile_features(modules__mc_raptor PRIVATE cxx_std_17) -target_compile_options(modules__mc_raptor PRIVATE -Wno-unused-result) +px4_target_compile_options_for_compiler(modules__mc_raptor PRIVATE + GNU_LIKE -Wno-unused-result +) diff --git a/src/modules/simulation/gz_msgs/CMakeLists.txt b/src/modules/simulation/gz_msgs/CMakeLists.txt index 568bd7874a..4f8ac231dd 100644 --- a/src/modules/simulation/gz_msgs/CMakeLists.txt +++ b/src/modules/simulation/gz_msgs/CMakeLists.txt @@ -19,7 +19,9 @@ if (Protobuf_FOUND) ) # Disable double-promotion warning for protobuf-generated code - target_compile_options(px4_gz_msgs PRIVATE -Wno-double-promotion) + px4_target_compile_options_for_compiler(px4_gz_msgs PRIVATE + GNU_LIKE -Wno-double-promotion + ) target_include_directories(px4_gz_msgs PUBLIC @@ -28,7 +30,9 @@ if (Protobuf_FOUND) ) target_link_libraries(px4_gz_msgs PUBLIC ${PROTOBUF_LIBRARIES}) if (Protobuf_VERSION VERSION_LESS "3.8") - target_compile_options(px4_gz_msgs PRIVATE -Wno-error=float-equal) + px4_target_compile_options_for_compiler(px4_gz_msgs PRIVATE + GNU_LIKE -Wno-error=float-equal + ) endif() # Export the binary dir for other modules diff --git a/src/modules/simulation/simulator_mavlink/CMakeLists.txt b/src/modules/simulation/simulator_mavlink/CMakeLists.txt index f5f39d7106..62b57a5448 100644 --- a/src/modules/simulation/simulator_mavlink/CMakeLists.txt +++ b/src/modules/simulation/simulator_mavlink/CMakeLists.txt @@ -31,13 +31,21 @@ # ############################################################################ +set(simulator_mavlink_compile_flags) + +if(NOT MSVC) + list(APPEND simulator_mavlink_compile_flags + -Wno-double-promotion + -Wno-cast-align + -Wno-address-of-packed-member # TODO: fix in c_library_v2 + ) +endif() + px4_add_module( MODULE modules__simulation__simulator_mavlink MAIN simulator_mavlink COMPILE_FLAGS - -Wno-double-promotion - -Wno-cast-align - -Wno-address-of-packed-member # TODO: fix in c_library_v2 + ${simulator_mavlink_compile_flags} INCLUDES ${CMAKE_BINARY_DIR}/mavlink ${CMAKE_BINARY_DIR}/mavlink/${CONFIG_MAVLINK_DIALECT} diff --git a/src/modules/zenoh/CMakeLists.txt b/src/modules/zenoh/CMakeLists.txt index cb6908d977..08f7f0127e 100644 --- a/src/modules/zenoh/CMakeLists.txt +++ b/src/modules/zenoh/CMakeLists.txt @@ -66,24 +66,29 @@ px4_add_git_submodule(TARGET git_zenoh-pico PATH "zenoh-pico") add_subdirectory(zenoh-pico) unset(MESSAGE_QUIET) add_dependencies(zenohpico_static git_zenoh-pico px4_platform) -target_compile_options(zenohpico_static PUBLIC -Wno-cast-align - -Wno-narrowing - -Wno-stringop-overflow - -Wno-stringop-truncation - -Wno-unused-result - -Wno-type-limits - -Wno-unused-variable - -Wno-maybe-uninitialized - -Wno-conversion - -Wno-float-equal) +px4_target_compile_options_for_compiler(zenohpico_static PUBLIC + GNU_LIKE + -Wno-cast-align + -Wno-narrowing + -Wno-stringop-overflow + -Wno-stringop-truncation + -Wno-unused-result + -Wno-type-limits + -Wno-unused-variable + -Wno-maybe-uninitialized + -Wno-conversion + -Wno-float-equal +) -target_compile_options(zenohpico_static PRIVATE -Wno-missing-prototypes) +px4_target_c_compile_options_for_compiler(zenohpico_static PRIVATE + GNU_LIKE -Wno-missing-prototypes +) if(CONFIG_PLATFORM_NUTTX) - target_compile_options(zenohpico_static PRIVATE -DUNIX_NO_MULTICAST_IF) + target_compile_definitions(zenohpico_static PRIVATE UNIX_NO_MULTICAST_IF) endif() if(CONFIG_ZENOH_SERIAL) - target_compile_options(zenohpico_static PRIVATE -DZ_LINK_SERIAL) + target_compile_definitions(zenohpico_static PRIVATE Z_LINK_SERIAL) endif() add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/default_topics.c @@ -99,6 +104,13 @@ COMMENT "Generating Default config" ) add_custom_target(default_topics_config DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/default_topics.c) +set(zenoh_compile_flags + -Wno-pointer-compare + -Wno-cast-align + -Wno-address-of-packed-member + -Wno-double-promotion + -Wno-unused +) px4_add_module( MODULE modules__zenoh @@ -126,11 +138,10 @@ px4_add_module( ${CMAKE_CURRENT_LIST_DIR} ${PX4_BINARY_DIR}/src/modules/zenoh/ COMPILE_FLAGS - -Wno-pointer-compare - -Wno-cast-align - -Wno-address-of-packed-member - -Wno-double-promotion - -Wno-unused - -DZENOH_LINUX - -D_Bool=int8_t + ${zenoh_compile_flags} +) + +target_compile_definitions(modules__zenoh PRIVATE + ZENOH_LINUX + _Bool=int8_t ) diff --git a/src/systemcmds/gpio/CMakeLists.txt b/src/systemcmds/gpio/CMakeLists.txt index 2a52fd3838..944581132d 100644 --- a/src/systemcmds/gpio/CMakeLists.txt +++ b/src/systemcmds/gpio/CMakeLists.txt @@ -30,11 +30,15 @@ # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ +set(gpio_compile_flags + -Wno-array-bounds +) + px4_add_module( MODULE systemcmds__gpio MAIN gpio COMPILE_FLAGS - -Wno-array-bounds + ${gpio_compile_flags} SRCS gpio.cpp DEPENDS diff --git a/src/systemcmds/microbench/CMakeLists.txt b/src/systemcmds/microbench/CMakeLists.txt index 2b123ca389..2e9fe2e389 100644 --- a/src/systemcmds/microbench/CMakeLists.txt +++ b/src/systemcmds/microbench/CMakeLists.txt @@ -31,15 +31,19 @@ # ############################################################################ +set(microbench_compile_flags + -Wno-double-promotion + -Wno-unused-but-set-variable + -Wno-unused-variable + -Wno-write-strings +) + px4_add_module( MODULE systemcmds__microbench MAIN microbench STACK_MAIN 4096 COMPILE_FLAGS - -Wno-double-promotion - -Wno-unused-but-set-variable - -Wno-unused-variable - -Wno-write-strings + ${microbench_compile_flags} SRCS microbench_main.cpp diff --git a/src/systemcmds/param/CMakeLists.txt b/src/systemcmds/param/CMakeLists.txt index 056401daf7..22dc82e204 100644 --- a/src/systemcmds/param/CMakeLists.txt +++ b/src/systemcmds/param/CMakeLists.txt @@ -30,11 +30,15 @@ # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ +set(param_compile_flags + -Wno-array-bounds +) + px4_add_module( MODULE systemcmds__param MAIN param COMPILE_FLAGS - -Wno-array-bounds + ${param_compile_flags} STACK_MAIN 4096 SRCS param.cpp diff --git a/src/systemcmds/tests/CMakeLists.txt b/src/systemcmds/tests/CMakeLists.txt index 2fdec3c070..e5fb5b530c 100644 --- a/src/systemcmds/tests/CMakeLists.txt +++ b/src/systemcmds/tests/CMakeLists.txt @@ -77,7 +77,17 @@ px4_add_module( MODULE systemcmds__tests MAIN tests STACK_MAIN 10000 - COMPILE_FLAGS + SRCS + ${srcs} + MODULE_CONFIG + params.yaml + DEPENDS + dataman_client + version + ) +px4_target_compile_options_for_compiler(systemcmds__tests PRIVATE + GNU_LIKE + -O2 # optimization needed to keep matrix code size reasonable -Wno-double-promotion -Wno-float-equal -Wno-missing-declarations @@ -88,14 +98,6 @@ px4_add_module( -Wno-unused-variable -Wno-vla-larger-than -Wno-unused-but-set-parameter - -O2 # optimization needed to keep matrix code size reasonable - SRCS - ${srcs} - MODULE_CONFIG - params.yaml - DEPENDS - dataman_client - version - ) +) add_subdirectory(hrt_test)