<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 5/11/2010 9:52 AM, Alok Govil wrote:
<blockquote cite="mid:COL101-W544D31E5195A3E6803E114BDFA0@phx.gbl"
 type="cite">
  <style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>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) #
<a class="moz-txt-link-freetext" href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_COMPILER_IS_GNULANG">http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_COMPILER_IS_GNULANG</a><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>
</blockquote>
<br>
<br>
You might consider using the target property COMPILE_FLAGS as a more
fine-grained way to control the flags, instead of the build-wide
variable.&nbsp; See the help for more info.<br>
<br>
Ryan<br>
</body>
</html>