From 7b9b7d1f3d08cd9af15a7375a09a6dd5c67ad326 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Fri, 12 Jul 2024 03:57:57 -0400 Subject: [PATCH 1/5] [build] CMake: add some flags from native-utils --- CMakeLists.txt | 1 + apriltag/CMakeLists.txt | 6 +++++- cmake/modules/CompileWarnings.cmake | 11 ++--------- wpiutil/CMakeLists.txt | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4010ef9eb27..90a4896f548 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ include(CPack) include(OptionValidation) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib) diff --git a/apriltag/CMakeLists.txt b/apriltag/CMakeLists.txt index 28a2751d577..9be0eaa2675 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 5de103201e2..12f86ae152c 100644 --- a/cmake/modules/CompileWarnings.cmake +++ b/cmake/modules/CompileWarnings.cmake @@ -5,7 +5,7 @@ macro(wpilib_target_warnings target) -pedantic -Wextra -Wno-unused-parameter - ${WPILIB_TARGET_WARNINGS} + -Wformat=2 ) if(NOT NO_WERROR) set(WARNING_FLAGS ${WARNING_FLAGS} -Werror) @@ -15,14 +15,7 @@ macro(wpilib_target_warnings target) else() target_compile_options( ${target} - PRIVATE - /wd4146 - /wd4244 - /wd4251 - /wd4267 - /WX - /D_CRT_SECURE_NO_WARNINGS - ${WPILIB_TARGET_WARNINGS} + PRIVATE /wd4146 /wd4244 /wd4251 /wd4267 /WX /D_CRT_SECURE_NO_WARNINGS ) endif() diff --git a/wpiutil/CMakeLists.txt b/wpiutil/CMakeLists.txt index e20754db214..c231295d454 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:throwingNew /MP /bigobj /utf-8 ) target_compile_definitions(wpiutil PRIVATE -D_CRT_SECURE_NO_WARNINGS) endif() From b4fea11732c162fc8d99afdc3d996f6064877826 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Fri, 12 Jul 2024 05:16:18 -0400 Subject: [PATCH 2/5] Add /Zc:__cplusplus Trying to build tests will fail if it's only added to wpiutil's list --- CMakeLists.txt | 3 +++ wpiutil/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90a4896f548..957114d2805 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,9 @@ 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/wpiutil/CMakeLists.txt b/wpiutil/CMakeLists.txt index c231295d454..3b26931b182 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 /utf-8 + PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8 ) target_compile_definitions(wpiutil PRIVATE -D_CRT_SECURE_NO_WARNINGS) endif() From 9551273758a39edb2625e475e0b2d3a07510f509 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:52:46 -0400 Subject: [PATCH 3/5] Add option to customize target warnings --- cmake/modules/CompileWarnings.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/modules/CompileWarnings.cmake b/cmake/modules/CompileWarnings.cmake index 12f86ae152c..d57090917c9 100644 --- a/cmake/modules/CompileWarnings.cmake +++ b/cmake/modules/CompileWarnings.cmake @@ -6,6 +6,7 @@ macro(wpilib_target_warnings target) -Wextra -Wno-unused-parameter -Wformat=2 + ${ARGN} ) if(NOT NO_WERROR) set(WARNING_FLAGS ${WARNING_FLAGS} -Werror) @@ -15,7 +16,7 @@ macro(wpilib_target_warnings target) else() target_compile_options( ${target} - PRIVATE /wd4146 /wd4244 /wd4251 /wd4267 /WX /D_CRT_SECURE_NO_WARNINGS + PRIVATE /wd4146 /wd4244 /wd4251 /wd4267 /WX /D_CRT_SECURE_NO_WARNINGS ${ARGN} ) endif() From cd7b7702407e257e6ae005ac8d99c2db4b95500e Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:30:59 -0400 Subject: [PATCH 4/5] Add back in user custom warnings --- README-CMAKE.md | 2 ++ cmake/modules/CompileWarnings.cmake | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README-CMAKE.md b/README-CMAKE.md index e52d77ec2ef..9f011efddbc 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/cmake/modules/CompileWarnings.cmake b/cmake/modules/CompileWarnings.cmake index d57090917c9..4d6567ab586 100644 --- a/cmake/modules/CompileWarnings.cmake +++ b/cmake/modules/CompileWarnings.cmake @@ -7,6 +7,7 @@ macro(wpilib_target_warnings target) -Wno-unused-parameter -Wformat=2 ${ARGN} + ${WPILIB_TARGET_WARNINGS} ) if(NOT NO_WERROR) set(WARNING_FLAGS ${WARNING_FLAGS} -Werror) @@ -16,7 +17,15 @@ macro(wpilib_target_warnings target) else() target_compile_options( ${target} - PRIVATE /wd4146 /wd4244 /wd4251 /wd4267 /WX /D_CRT_SECURE_NO_WARNINGS ${ARGN} + PRIVATE + /wd4146 + /wd4244 + /wd4251 + /wd4267 + /WX + /D_CRT_SECURE_NO_WARNINGS + ${ARGN} + ${WPILIB_TARGET_WARNINGS} ) endif() From 4161a5b2e3d0b8fff6d041fcfb4fbbdf58afcd00 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:34:47 -0400 Subject: [PATCH 5/5] Undo ARGN inclusion --- README-CMAKE.md | 2 +- cmake/modules/CompileWarnings.cmake | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/README-CMAKE.md b/README-CMAKE.md index 9f011efddbc..3dde6d05114 100644 --- a/README-CMAKE.md +++ b/README-CMAKE.md @@ -72,7 +72,7 @@ The following build options are available: * `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 + * Add compiler flags to this option to customize compiler options like warnings. ## Build Setup diff --git a/cmake/modules/CompileWarnings.cmake b/cmake/modules/CompileWarnings.cmake index 4d6567ab586..94d952ce5d7 100644 --- a/cmake/modules/CompileWarnings.cmake +++ b/cmake/modules/CompileWarnings.cmake @@ -6,7 +6,6 @@ macro(wpilib_target_warnings target) -Wextra -Wno-unused-parameter -Wformat=2 - ${ARGN} ${WPILIB_TARGET_WARNINGS} ) if(NOT NO_WERROR) @@ -24,7 +23,6 @@ macro(wpilib_target_warnings target) /wd4267 /WX /D_CRT_SECURE_NO_WARNINGS - ${ARGN} ${WPILIB_TARGET_WARNINGS} ) endif()