Hello, I'm very interested in the fact that CMake could offer possibilities to portably set default warning levels.
All people, with who I work, wondered a day how to set warning flags, especially for gcc (Flag /W3 is already set for Visual Studio). Different simple solutions have been found but they are not satisfactory: - change CMAKE_C_FLAGS CMAKE_CXX_FLAGS variables when generating files, but you could forget to do it - set warnings in the root CMakeLists ( set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") ), but you can't dynamically change warning levels I have written some macros to portably and easily set default warning levels but it only works for gcc/g++ and Visual Studio (See attachment) Macros WARNINGS, FULL_WARNINGS, NO_WARNINGS and WARNINGS_AS_ERRORS are used to set default warning levels. I need a REMOVE_FLAGS macro to remove flag /W3 from Visual Studio flags (and some others if needed). Macros WARNING_AS_ERROR and SUPPRESS_WARNING are used to set specific flags for a platform. It's pretty poor but it's sufficient for our projects. I love the idea to set warning flags in platform files but I don't understand why new files must be created. Is not it possible to add warning variables to existent platform files in Modules/Platform ? I wonder if it would be possible to add a CMAKE_WARNING_LEVEL variable (like CMAKE_BUILD_TYPE) which could take values like Warning1, Warning2, Warning3, Warning4 (or All, Full, No). So we could define in platform files CMAKE_CXX_FLAGS_WARNING1_INIT, CMAKE_CXX_FLAGS_WARNING2_INIT... variables (like CMAKE_CXX_FLAGS_DEBUG_INIT, CMAKE_CXX_FLAGS_RELEASE_INIT). The final default value for CMAKE_CXX_FLAGS would be "${CMAKE_CXX_FLAGS_INIT} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}_INIT} ${CMAKE_CXX_FLAGS_${CMAKE_WARNING_LEVEL}_INIT}". I think it would be a great idea that CMake provide default and portable warning flags. If you need any help, I would be very pleased to contribute. J. Bedouet >Michael Jackson wrote: >> >> On Nov 22, 2008, at 1:13 PM, Robert Dailey wrote: >> >>> So it seems that this issue has come up before and it is an obvious >>> feature to implement. In the meantime, can someone offer me the code >>> for a macro I can use to easily and portably set warning levels? >>> >>> Thanks >> >> >> pseudo code >> >> macro(set_warning_level level) >> >> if (MSVC) >> # Set msvc type warnings >> SET (CXX_FLAGS ${CXX_FLAGS} [your warnings here]) >> >> elseif(GCC) >> # set gcc type warnings >> SET (CXX_FLAGS ${CXX_FLAGS} [your warnings here]) >> >> else() >> # we don't know this compiler >> message(STATUS "Warning levels have not been defined for this compiler") >> >> endif() >> >> endmacro(set_warning_level level) >> > >When this is done in CMake, that information will go into the >Modules/Platform files. So, it might be best to come up with something >that uses the same idea as that. > > INCLUDE(MyPlatform/${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-CXX >OPTIONAL ) > >Put MyPlatform into the CMAKE_MODULE_PATH, then create platform files in >MyPlatform/Linux-Intel-C.cmake > >set(${CMAKE_CXX_COMPILER_ID}-CXX-WARNING1 -W1) > >Then have the macro just add the specified warning variable. If someone >works out all the names, we can then move this stuff into CMake CVS. > >-Bill >
Warning.cmake
Description: Binary data
_______________________________________________ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake