From e00bb2f07b8fc346d883ee0d208afc68b8660b28 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Sat, 13 Jul 2024 00:51:55 -0400 Subject: [PATCH] [build] CMake: add some compiler flags from native-utils (#6825) --- CMakeLists.txt | 4 ++++ README-CMAKE.md | 2 ++ apriltag/CMakeLists.txt | 6 +++++- cmake/modules/CompileWarnings.cmake | 1 + wpiutil/CMakeLists.txt | 2 +- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4010ef9eb2..957114d280 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,10 @@ include(CPack) include(OptionValidation) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) +if(MSVC) + add_compile_options(/Zc:__cplusplus) +endif() set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib) diff --git a/README-CMAKE.md b/README-CMAKE.md index e52d77ec2e..3dde6d0511 100644 --- a/README-CMAKE.md +++ b/README-CMAKE.md @@ -71,6 +71,8 @@ The following build options are available: * Set this option to the location of the archive of the OpenCV Java bindings (it should be called opencv-xxx.jar, with the x'es being version numbers). NOTE: set it to the LOCATION of the file, not the file itself! * `NO_WERROR` (OFF Default) * This option will disable the `-Werror` compilation flag for non-MSVC builds. +* `WPILIB_TARGET_WARNINGS` + * Add compiler flags to this option to customize compiler options like warnings. ## Build Setup diff --git a/apriltag/CMakeLists.txt b/apriltag/CMakeLists.txt index 28a2751d57..9be0eaa267 100644 --- a/apriltag/CMakeLists.txt +++ b/apriltag/CMakeLists.txt @@ -134,7 +134,11 @@ if(MSVC) else() target_compile_options( apriltag - PRIVATE -Wno-sign-compare -Wno-gnu-zero-variadic-macro-arguments -Wno-type-limits + PRIVATE + -Wno-sign-compare + -Wno-gnu-zero-variadic-macro-arguments + -Wno-type-limits + -Wno-format-nonliteral ) endif() diff --git a/cmake/modules/CompileWarnings.cmake b/cmake/modules/CompileWarnings.cmake index 5de103201e..94d952ce5d 100644 --- a/cmake/modules/CompileWarnings.cmake +++ b/cmake/modules/CompileWarnings.cmake @@ -5,6 +5,7 @@ macro(wpilib_target_warnings target) -pedantic -Wextra -Wno-unused-parameter + -Wformat=2 ${WPILIB_TARGET_WARNINGS} ) if(NOT NO_WERROR) diff --git a/wpiutil/CMakeLists.txt b/wpiutil/CMakeLists.txt index e20754db21..3b26931b18 100644 --- a/wpiutil/CMakeLists.txt +++ b/wpiutil/CMakeLists.txt @@ -151,7 +151,7 @@ target_compile_features(wpiutil PUBLIC cxx_std_20) if(MSVC) target_compile_options( wpiutil - PUBLIC /permissive- /Zc:preprocessor /Zc:throwingNew /MP /bigobj + PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8 ) target_compile_definitions(wpiutil PRIVATE -D_CRT_SECURE_NO_WARNINGS) endif()