简体   繁体   中英

Can I compile different parts of my project with different warning levels with CMake?

I'm working on a project that depends on a few other libraries (specifically, SFML and Box2D and a few others). I like to run with my warnings turned way up, but the projects I depend on aren't so strict.

Is there a way that I can compile the libraries with their default warning settings and compile my code with the warning flags I want? I have the following list of flags in my CMakeLists.txt. The commented out lines are things I can't turn on right now because they break my dependencies.

set(CUSTOM_CFLAGS ${CUSTON_CFLAGS}
    -std=c++0x 
    #-ansi 
    -pedantic
    -Werror 
    -Wall 
    -Wextra 
    #-Weffc++
    -Wshadow 
    -Winit-self 
    -Wsign-promo 
    -Wcast-align
    #-Wlogical-op 
    -Woverloaded-virtual 
    -Wno-unused-parameter 
    #-Wstrict-null-sentinel 
    -Wmissing-include-dirs 
    -Wframe-larger-than=8192 
    #-Wmissing-format-attribute
    -g 
    #Would like this but Box2D hsa a ridiculous amount of it...
    #-Wfloat-equal -Wno-error=float-equal
   )

Yes you can compile the external libraries once. Then you can include and link them into your project without recompiling the external stuff. The only remaining external code to recompile is in the library header files. Write something like

#pragma warning(push)
#pragma warning(disable:2892,2893,2894,4096)
#include <external_header.h>
#pragma warning(pop)

in order to disable warnings popping up in the external header files. This pragma stuff is different from compiler to compiler, but most compilers have something along these lines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM