14

I'm using GLAD on my project, and building everything with cmake.

Since this is an external library and not my code, I'd like to completely suppress its warnings during build time, because I get a ton of these:

warning: ISO C forbids conversion of object pointer to function pointer type [-Wpedantic]
 glad_glCullFace = ( PFNGLCULLFACEPROC ) load ( "glCullFace" );
                   ^

How can I do it? I can either just include it in my sources, or do an add_library with GLAD's sources, don't mind either way.

Thanks

Joao Pincho
  • 939
  • 2
  • 11
  • 26
  • If you build the library as separate one, adjust compiler flags (variable `CMAKE_C_FLAGS`). If you build the library's source with your ones, adjust property [COMPILE_FLAGS](https://cmake.org/cmake/help/v3.7/prop_sf/COMPILE_FLAGS.html) for library's sources. Both of these approaches are easily googled. – Tsyvarev Mar 10 '17 at 22:43
  • 1
    Possible duplicate of [How to suppress GCC warnings from library headers?](http://stackoverflow.com/questions/1867065/how-to-suppress-gcc-warnings-from-library-headers) especially the answer http://stackoverflow.com/a/26297802/2799037 which explains adding SYSTEM to include_libraries – usr1234567 Mar 10 '17 at 22:43
  • 2
    @usr1234567: The warning actually is in the [source file](https://github.com/ephja/nim-glfw/blob/master/src/glfw/deps/glad.c), not in the header. – Tsyvarev Mar 10 '17 at 22:45
  • @Tsyvarev: I see, thanks for the hint. Probably this is no CMake question. Once the question is answered for C, it is trivially applied to CMake as stated in your comment. – usr1234567 Mar 10 '17 at 23:50
  • @usr1234567 . not a duplicate. I know about the SYSTEM option to include_directory ( not include_libraries ). This is not about building the main project with those headers, it's about building that library itself. – Joao Pincho Mar 13 '17 at 08:29
  • @Tsyvarev I've been avoiding specifying COMPILE_FLAGS because that's platform/compiler dependent, which kinda breaks the entire idea behind cmake, does it not? In a last resort, I'll have to do that, no doubt... – Joao Pincho Mar 13 '17 at 08:30
  • Your last comment should be incorporated **into the question post**: it describes **an actual problem**. Yes, you are rigth that CMake tends to provide common interface for platform-dependent things. But as far as I know, there is no such interface for warnings suppressing. Probably, this is because different compilers have [different set of warnings types](https://github.com/ruslo/leathers/wiki/List). (The link is taken from that [answer](http://stackoverflow.com/a/24379666/3440745)) – Tsyvarev Mar 13 '17 at 08:52

1 Answers1

5

Use the SYSTEM keyword to avoid warnings from system libraries like so:

target_include_directories(target SYSTEM GLAD)
jaques-sam
  • 2,578
  • 1
  • 26
  • 24