<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Hi all,<br><br>I am setting CMAKE_CXX_FLAGS to "-Wall -ansi -pedantic" but would like to remove these flags for compilation<br>of UnitTest++.&nbsp; I tried three methods of doing this with some issue with each:<br><br>1.&nbsp;&nbsp; string (REPLACE "-Wall" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})<br><font style="" color="#00b050">&nbsp;&nbsp; &nbsp; # And likewise for -ansi and -pedantic</font><br><br>2.&nbsp;&nbsp; set (CMAKE_CXX_FLAGS "")<br><br>3.&nbsp;&nbsp; unset (CMAKE_CXX_FLAGS CACHE)<br><br>I am doing the above for both CMAKE_CXX_FLAGS and CMAKE_C_FLAGS.<br><br>The problem with 1 and 2 is that they are not working.&nbsp; GCC (MinGW-W32) still gives the concerned warnings.&nbsp; I do not get these warnings if I do not set these flags at all to begin with.<br><br>Method 3 does work.&nbsp; The problem however is that it removes CMAKE_CXX_FLAGS globally, not just from CMakeList.txt for UnitTest++.&nbsp; I could in principle recreate CMAKE_CXX_FLAGS but would like to understand what's going on first.<br><br>Method 1 worked well for MSVC (using different flags than for GCC).<br><br>Here are all my files with relevant lines (shown only for CMAKE_CXX_FLAGS but done also for CMAKE_C_FLAGS):<br><br><u>CXX_Flag_Overrides.cmake</u>:<br><font style="" color="#00b050">&nbsp;&nbsp; &nbsp;# ...</font><br>&nbsp;&nbsp; &nbsp;if (CMAKE_COMPILER_IS_GNUCXX)<br><font style="" color="#00b050">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# message ("CMAKE_COMPILER_IS_GNUCXX")</font><br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -Wall -ansi -pedantic")<br>&nbsp;&nbsp; &nbsp;endif()<br><font style="" color="#00b050">&nbsp;&nbsp;&nbsp; # ...</font><br><br><u>CMakeLists.txt (top-level)</u><br><font style="" color="#00b050">&nbsp;&nbsp;&nbsp; # ...</font><br>&nbsp;&nbsp; &nbsp;set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/CXX_Flag_Overrides.cmake)<br>&nbsp;&nbsp; &nbsp;project (projectname)<br><font style="" color="#00b050">&nbsp;&nbsp;&nbsp; # ...</font><br>&nbsp;&nbsp; &nbsp;add_subdirectory (UnitTest++)<br><font style="" color="#00b050">&nbsp;&nbsp;&nbsp; # ...</font><br><br><u>CMakeLists.txt (UnitTest++)</u><br><font style="" color="#00b050">&nbsp;&nbsp;&nbsp; # ...</font><br>&nbsp;&nbsp; &nbsp;if (CMAKE_COMPILER_IS_GNUCXX) # http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_COMPILER_IS_GNULANG<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;message ("CMAKE_COMPILER_IS_GNUCXX")<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<font style="" color="#00b050">#string (REPLACE "-Wall" ""&nbsp;&nbsp;&nbsp;&nbsp; CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})</font><font style="" color="#00b050"><br></font><font style="" color="#00b050">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#string (REPLACE "-ansi" ""&nbsp;&nbsp;&nbsp;&nbsp; CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})</font><font style="" color="#00b050"><br></font><font style="" color="#00b050">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#string (REPLACE "-pedantic" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})</font><font style="" color="#00b050"><br></font><font style="" color="#00b050">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#unset (CMAKE_CXX_FLAGS CACHE)</font><br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;set (CMAKE_CXX_FLAGS "")<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;message ("${CMAKE_CXX_FLAGS}")<br>&nbsp;&nbsp; &nbsp;endif()<br><font style="" color="#00b050">&nbsp;&nbsp;&nbsp; # ...</font><br>&nbsp;&nbsp; &nbsp;add_library (UnitTest++ ${Sources})<br><br>Thanks,<br><br>Alok<br>                                               <br /><hr />The New Busy is not the old busy. Search, chat and e-mail from your inbox. <a href='http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3' target='_new'>Get started.</a></body>
</html>