CMake project in Visual Studio gives flag override warnings (Command line warning D9025: overriding '/W4' with '/w') - visual-c++

I have a CMake project, which I am building with Microsoft Visual Studio 2019. I am trying to fix and remove all warnings, but there is one type which I can't disable or fix.
All of them are of the type:
Command line warning D9025: overriding '/W4' with '/w'
Command line warning D9025: overriding '/W3' with '/W4'
I tried fixing them, but I can't find out what's causing all of them.
My question is:
How can I disable the warnings using CMake? Or is there a surefire way to find the underlying cause of them and fix them?

This issue has been raised (here and here), and depending on your CMake version there are a couple solutions.
When building for MSVC with CMake, the compiler warning flags (like /W3) are added by default. In CMake 3.15, CMake introduced a fix for this, and the compiler warning flags are no longer automatically added so the warning should no longer appear. From the docs:
CMake 3.15 and above prefer to leave out warning flags from the value of CMAKE_<LANG>_FLAGS by default.
Along with this fix, CMake introduced policy CMP0092, which allows you to switch back to the OLD behavior (adding the warning flags by default) if necessary.
If you are tied to a CMake version older than 3.15, you can manually manipulate the CMAKE_<LANG>_FLAGS variable to replace the warnings yourself using CMake's regular expressions. You can try something like this:
string(REGEX REPLACE "/W[3|4]" "/w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

I had this problem even though I was using CMake 3.19. It was caused by having the project command before the cmake_minimum_required command.

Related

Set Wno-dev in particular CMakeLists

I have a project when I use cmake. I also use cmake to create a deb and an rpm package.
When building RPM we have many warnings like this:
CMake Warning (dev) at /usr/share/cmake-3.13/Modules/Internal/CPack/CPackRPM.cmake:135 (message):
CPackRPM:Warning: Path /etc/apache2/sites-available/mux.conf is not on one
of the relocatable paths! Package will be partially relocatable.
Call Stack (most recent call first):
/usr/share/cmake-3.13/Modules/Internal/CPack/CPackRPM.cmake:1001 (cpack_rpm_prepare_relocation_paths)
/usr/share/cmake-3.13/Modules/Internal/CPack/CPackRPM.cmake:1870 (cpack_rpm_generate_package)
This warning is for project developers. Use -Wno-dev to suppress it.
We have many sub CmakeLists files and even when we use "-Wno-dev" at the top of the project we still have this warning.
How can I force the Wno-dev in the CMakeLists that cause this warning?
Cmake-gui: Options|Warning Messages: Suppress Warnings - check "Developer Warnings"
From man cmake: cmake -Wno-dev ...

CMake: suppress developer warnings

Description:
I am using cmake-gui on Ubuntu to compile programs.
I often encountered warning messages for developpers ending by:
This warning is for project developers. Use -Wno-dev to suppress it.
I tried to insert this -Wno-dev flag in the CMAKE_CXX_FLAGS box but it doesn't suppress the warnings.
Questions:
I have now two very simple questions:
1) Where exactly should I insert this flag?
2) How to separate it from other existing flags (if any) ?
Probably does not solve your problem with the gui but adding the -Wno-dev from command line works.
The flag does not belong to the CMAKE_CXX_FLAGS that are specific for compiler not for CMAKE.
Instead you can suppress the message setting the cmake_policy

Using `-Wno-implicit-fallthrough` on older versions of gcc

I have a project which builds fine under gcc 4.8.4. I tried building using gcc 7, and noticed a lot of -Wimplicit-fallthrough= warnings. As far as I'm aware, this was indeed added in gcc version 7. I'm now using -Wno-implicit-fallthrough when building to suppress these warnings. Moving back to the older version of gcc, keeping the -Wno-implicit-fallthrough compiler flag does not lead to any error, even though I do not believe that gcc 4 recognizes this option. How come? Are specifically the -Wno- options allowed to not be recognized?
From man gcc:
When an unrecognized warning option is requested (e.g.,
-Wunknown-warning), GCC emits a diagnostic stating that the option is
not recognized. However, if the -Wno- form is used, the behavior is
slightly different: no diagnostic is produced for -Wno-unknown-warning
unless other diagnostics are being produced. This allows the use of
new -Wno- options with old compilers, but if something goes wrong, the
compiler warns that an unrecognized option is present.
To sum it up: if all goes well, unknown -Wno-* switches are ignored to preserve compatibility.

HHVM CMake error

I am trying to install HHVM on an Ubunut 14.04 machine using this guide:
https://docs.hhvm.com/hhvm/installation/building-from-source#ubuntu-15.04-vivid
However, when running the cmake -DMYSQL_UNIX_SOCK_ADDR=/var/run/mysqld/mysqld.sock . step i am retuned an error like this:
CMake Error in third-party/CMakeLists.txt:
Cannot find source file:
INTERFACE
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Warning (dev) in third-party/CMakeLists.txt:
Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
interface. Run "cmake --help-policy CMP0022" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
Target "boost" has an INTERFACE_LINK_LIBRARIES property. This should be
preferred as the source of the link interface for this library but because
CMP0022 is not set CMake is ignoring the property and using the link
implementation as the link interface instead.
INTERFACE_LINK_LIBRARIES:
/usr/lib/x86_64-linux-gnu/libboost_context.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/usr/lib/x86_64-linux-gnu/libboost_program_options.so;/usr/lib/x86_64-linux-gnu/libboost_regex.so;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/x86_64-linux-gnu/libboost_thread.so;/usr/lib/x86_64-linux-gnu/libpthread.so
Link implementation:
(empty)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring incomplete, errors occurred!
See also "/home/mihai/hhvm/CMakeFiles/CMakeOutput.log".
See also "/home/mihai/hhvm/CMakeFiles/CMakeError.log".
This issue is not happening on an Ubuntu 16.04 machine. I have searched up and down for a solution and found nothing.
Thank you,
Mihai
I suspect that you need a newer version of cmake. It looks like the add_library(name INTERFACE ...) command was added some time after v2.8.12 (which is what ships with ubuntu 14.04).

Compiling alsa-lib with Buildroot: C preprocessor fails sanity check

Trying to compile a Linux image for LPC3250 ARM using Buildroot.
Stock settings, it compiles fine.
I'm getting this error when I try to add alsa-lib and alsa-utils:
configure: error: in `/home/user/projects/buildroot/output/build/alsa-lib-1.0.26 ':
configure: error: C preprocessor "/home/user/projects/buildroot/output/host/usr/ bin/arm-buildroot-linux-uclibcgnueabi-cpp" fails sanity check
See `config.log' for more details
Excerpt of alsa-lib's config.log. It kinda sucks because half the error messages have been cut off for some reason:
/home/user/projects/buildroot/output/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/features.h:219:5: error: #error It appears you have defined _FILE_OF$
In file included from /home/user/projects/buildroot/output/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/stdio.h:72,
from conftest.c:12:
/home/user/projects/buildroot/output/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/bits/uClibc_stdio.h:61:2: error: #error Sorry... uClibc was built wi$
In file included from conftest.c:12:
/home/user/projects/buildroot/output/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/stdio.h:83: error: expected '=', ',', ';', 'asm' or '__attribute__' $
In file included from conftest.c:12:
/home/user/projects/buildroot/output/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/stdio.h:721: error: expected declaration specifiers or '...' before $
/home/user/projects/buildroot/output/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/stdio.h:723: error: expected ';', ',' or ')' before '*' token
Similar question here says something about "unsetting" CPP and CPPFlags.
Not sure where I would do this or check for it within the Buildroot environment. I'm not sure if this is even the same issue. I'm guessing its not related since in that other question it's talking about compiling GCC, which I'm not doing.
My #1 hunch right now is that I have to edit the configure file for lib-alsa. I'm just not sure what edits to make.
Edit: Did some aggressive Googling and came up with what I think is the full version of one of my errors: ...features.h:329:2: #error It appears you have defined _FILE_OFFSET_BITS=64. Unfortunately, uClibc was built without large file support enabled.
Checked my uClibc config file and UCLIBC_HAS_LFS=y is present. ???
The root of the issue here is Buildroot is using the uClibc config file located at: output/toolchain/uClibc-0.9.33.2/.config
rather than toolchain/uClibc/uClibc-0.9.33.config as specified in the Buildroot configuration menu.
I ran make uclibc-menuconfig (which defaults to saving the configuration in .config) and selected General Library Settings->Large File Support and everything compiled just fine.
Well, output/toolchain/uClibc-0.9.33.2/.config is generated from toolchain/uClibc/uClibc-0.9.33.config when Buildroot configures and builds uClibc. So it doesn't make any sense to use output/toolchain/uClibc-0.9.33.2/.config as the uClibc configuration. You should leave the default of toolchain/uClibc/uClibc-0.9.33.config.
Regarding Large File Support, normally all the packages have a proper dependency on it. So if a package needs large file support, the package cannot be selected until you enable large file support in Buildroot. If it is not the case, then it is a bug, and the Buildroot community would be interested in having a bug report about this (which details the Buildroot version being, the Buildroot configuration file being used, and the build error that you get).
Now, if Large File support is indeed needed, you should enable it at the Buildroot level rather than at the uClibc level. If you enable it only at the uClibc level, then Buildroot will not now about this, and will not show you all the packages that have a dependency on large file support.
So, what you should do is enable the BR2_TOOLCHAIN_BUILDROOT_LARGEFILE configuration option in Buildroot, and then do a complete rebuild: make clean all.

Resources