0

I added on my CMakeLists.txt on Android:

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-unused-function -Wno-error")

but I get multiple errors like this:

 error: unused function 'createParserError' [-Werror,-Wunused-function]

There's nothing that could rewrite CMAKE_CXX_FLAGS.

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • Does this answer your question? [How can you add warning flags using cmake cross platform?](https://stackoverflow.com/questions/36255910/how-can-you-add-warning-flags-using-cmake-cross-platform) –  May 28 '21 at 17:50
  • "There's nothing that could rewrite `CMAKE_CXX_FLAGS`." - Please, do NOT **describe** what your code contains and what it doesn't contain. Instead, add your code into the question post, preferrably in form of [mcve]. The single line `SET(CMAKE_CXX_FLAGS ...)` is definitely not enough to reproduce your problem. – Tsyvarev May 28 '21 at 18:24

1 Answers1

1

With modern cmake, you can use add_compile_options and target_compile_options instead of setting the variable directly

Thus in your context you can write

add_compile_options(" -Wno-unused-variable -Wno-unused-function -Wno-error")

to add the compile options to all targets or simply

target_compile_options(LIBRARY_NAME SCOPE "-Wno-unused-variable -Wno-unused-function -Wno-error")

to set those options for one target. If you need it to be cross platform

if(${PLATFORM_1})
  add_compile_options("WARNING_FLAGS_FOR_PLATFORM1")
elseif(${PLATFORM_2})
  add_compile_options("WARNING_FLAGS_FOR_PLATFORM2")
endif()

replace the variable by your required values