0

Windows 10 VS2019 Cmake 3.20.5

https://github.com/ftexchange/ftx/tree/master/cpp

Whenever I try to run the cpp files (rest_test.cc), I would receive command line error D8021: invalid numeric argument '/Werror' etc. for many of the flags here

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_FLAGS "-Wall -Werror -Wfatal-errors -Wpedantic -Wextra -Wmissing-include-dirs -Wconversion -Wsign-conversion -pthread")
add_compile_options(-Wall -Werror -Wfatal-errors -Wpedantic -Wextra -Wmissing-include-dirs -Wconversion -Wsign-conversion -pthread)

I'm not sure how to proceed

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153

1 Answers1

0

Those flags are for a GCC-compatible compiler, not MSVC. You'll have to remove them from the build you've encountered (or authored).

The reason for the "invalid numeric argument" is because MSVC numbers its warning levels. For example, to enable all (too many) warnings, you could pass /W4. MSVC tries to parse error as a number because it is expecting to find a flag like /W1 or /W3.

Such flags do not belong in the CMakeLists.txt file to begin with. Setting CMAKE_CXX_FLAGS is bad practice for exactly the reason you just experienced. Keep this in mind as you learn CMake: only things that are absolutely required to build your project belong in the CMakeLists.txt. Warning flags are not absolutely required.

Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
  • 1
    "Setting `CMAKE_CXX_FLAGS` is a bad practice for exactly the reason you just experienced." - The only reason OP is experienced is that the project isn't prepared for MSVC, as it has no check for the compiler when adding the *compiler-specific* options. By itself, there is nothing bad in setting `CMAKE_CXX_FLAGS`. See e.g. [that question](https://stackoverflow.com/questions/45955272/modern-way-to-set-compiler-flags-in-cross-platform-cmake-project) about the proper ways for doing that in multiplatform manner. – Tsyvarev Jun 23 '21 at 06:04
  • @Tsyvarev - I completely disagree. I would love to buy you a coffee and talk about it sometime. – Alex Reinking Jun 23 '21 at 06:05
  • @Tsyvarev - I have commented on the answer you linked me to. The notion of a "compiler-specific" option goes down to the compiler _version_, not just its command-line syntax. Putting warnings (and especially warnings-as-errors) in the CMakeLists.txt (as opposed to a toolchain or preset) is a recipe for headaches. – Alex Reinking Jun 23 '21 at 06:10