c++ - How to set different compiler warning levels for native code and external code in CMake -


suppose setting strict compiler warning level own code problem code dependent on external library wasn't written rigorously, when include header file external library sorts of warnings. there way can set different warning levels different files in cmake?

here example showing situation, suppose have main.cpp

#include "external.h"  int main(){   // code } 

and corresponding cmakelists.txt

cmake_minimum_required(version 2.8) project(test)  set(project_srcs ${project_source_dir}/main.cpp )  if(msvc)   if(cmake_cxx_flags matches "/w[0-4]")     string(regex replace "/w[0-4]" "/w4" cmake_cxx_flags "${cmake_cxx_flags}")   else()     set(cmake_cxx_flags "${cmake_cxx_flags} /w4")   endif() elseif(cmake_compiler_is_gnucc or cmake_compiler_is_gnucxx)   set(cmake_cxx_flags "${cmake_cxx_flags} -w -wall -werror -wshadow") endif()  include_directories(${external_inc})  add_executable(test ${project_srcs})  target_link_libraries(test ${external_lib}) 

suppose "external.h" causing -wshadow warnings, can take -wshadow out means -wshadow warnings won't catched native code. know can add pragma warning push , pop in main.cpp approach work windows. possible in cmake works different platform such linux , windows , keep source code clean?

no, can't cmake regarding issue. can rely on intrusive compiler-dependant method push/pop pragma warnings. seems know how msvc , here link how gcc.

but why can't cmake without modifying headers? because headers not standalone files embedded cpp ones , processed. whole units should set-up, not headers. , in general don't know units include headers. if compiler use supports per file warning levels brittle try use feature: header might included in other unit later different programmer knows nothing strategy — depends on human bad.

it easier create turnoffwarnings/turnonwarnings header files , force policy in organization wrap includes angle brackets between these custom headers.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -