[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    Re: [CMake] How can I prevent invalid -DCMAKE_BULD_TYPE values?
From:       Jack Morrison <JackMorrison1 () gmail ! com>
Date:       2014-06-13 18:11:49
Message-ID: CALATMoKCRsxJWkxTRZpS64gRWYPavGH638VMmH=bMUR5RQ6xAA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Miller,

You could add a check in your application's top-level CMakeLists.txt like
the following:

```
set(ACCEPTED_BUILD_TYPES Release Debug RelWithDebInfo)
list(FIND ACCEPTED_BUILD_TYPES ${CMAKE_BUILD_TYPE} IS_BUILD_TYPE_ACCEPTED)
if(${IS_BUILD_TYPE_ACCEPTED} EQUAL -1)
  message(FATAL_ERROR "CMAKE_BUILD_TYPE of ${CMAKE_BUILD_TYPE} is not
accepted.")
endif()
```

You might want to uppercase the accepted list and ${CMAKE_BUILD_TYPE} to be
flexible to different cases.

Cheers,
Jack




On Fri, Jun 13, 2014 at 11:04 AM, Miller Henry <MillerHenry@johndeere.com>
wrote:

>  One of my co-workers just did a build where they ran cmake with the
> option –DCMAKE_BUILD_TYPE=RelWithDebugInfo  Of course what was obviously
> meant was RelWithDbgInfo.  Because of this incorrect option the build was
> not as expected, but it took a while to figure out why it failed.  Of
> course once we realize the problem it is obvious that they expected to
> build with optimizations, but instead they build with no optimizations. Is
> there some way to make cmake abort when the option is not recognized?  I
> realize I could add any build type, but in this case it doesn't make sense.
>
> The reason the build failed was at some point we have a test that is
> something like this:
>         #ifdef DEBUG
>                 EXPECT_FLOAT_EQ(7.47869, value);
>         #else
>                 EXPECT_FLOAT_EQ(6.19632, value);
>         #endif
>
> The code under test was written about 10 years before we even heard of
> tests, and we have years of real world use that shows it works.  Since the
> algorithms are complex in the typical ways of legacy code: nobody has
> figured out what is going on that compiler optimizations can change a
> floating point value by this much.  This test is just a characterization of
> current behavior so we don't accidentally break it if we have to touch it.
>
> I'm also investigating if I can something different in the preprocessor to
> get the information I need, but this is outside the scope of cmake, and it
> seems that cmake should warn me if my build type option is set to something
> that isn't valid.
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>

[Attachment #5 (text/html)]

<div dir="ltr"><div>Hi Miller,</div><div><br></div>You could add a check in your \
application&#39;s top-level CMakeLists.txt like the \
following:<div><br></div><div><font face="courier new, \
monospace">```</font></div><div><font face="courier new, \
monospace">set(ACCEPTED_BUILD_TYPES Release Debug RelWithDebInfo)</font></div>

<div><font face="courier new, monospace">list(FIND ACCEPTED_BUILD_TYPES \
${CMAKE_BUILD_TYPE} IS_BUILD_TYPE_ACCEPTED)</font></div><div><font face="courier new, \
monospace">if(${IS_BUILD_TYPE_ACCEPTED} EQUAL -1)</font></div> <div>
<font face="courier new, monospace">   message(FATAL_ERROR &quot;CMAKE_BUILD_TYPE of \
${CMAKE_BUILD_TYPE} is not accepted.&quot;)</font></div><div><font face="courier new, \
monospace">endif()</font></div><div><font face="courier new, \
monospace">```</font></div>

<div><br></div><div>You might want to uppercase the accepted list and \
${CMAKE_BUILD_TYPE} to be flexible to different \
cases.</div><div><br></div><div>Cheers,<br>Jack<br><div><br></div><div><br></div></div></div><div \
class="gmail_extra">

<br><br><div class="gmail_quote">On Fri, Jun 13, 2014 at 11:04 AM, Miller Henry <span \
dir="ltr">&lt;<a href="mailto:MillerHenry@johndeere.com" \
target="_blank">MillerHenry@johndeere.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">








<div>
<font face="Calibri"><span style="font-size:11pt">
<div>One of my co-workers just did a build where they ran cmake with the option \
–DCMAKE_BUILD_TYPE=RelWithDebugInfo   Of course what was obviously meant was \
RelWithDbgInfo.   Because of this incorrect option the build was not as expected, but \
it took a while to figure out why it failed.   Of course once we realize the problem \
it is obvious that they expected to build with optimizations, but instead they build \
with no optimizations. Is there some way to make cmake abort when the option is not \
recognized?   I realize I could add any build type, but in this case it doesn't make \
sense.</div> <div>  </div>
<div>The reason the build failed was at some point we have a test that is something \
like this:</div> <div>               #ifdef DEBUG</div>
<div>                               EXPECT_FLOAT_EQ(7.47869, value);</div>
<div>               #else</div>
<div>                               EXPECT_FLOAT_EQ(6.19632, value);</div>
<div>               #endif</div>
<div>  </div>
<div>The code under test was written about 10 years before we even heard of tests, \
and we have years of real world use that shows it works.   Since the algorithms are \
complex in the typical ways of legacy code: nobody has figured out what is going on \
that compiler optimizations can change a floating point value by this much.   This \
test is just a characterization of current behavior so we don't accidentally break it \
if we have to touch it.</div> <div>  </div>
<div>I'm also investigating if I can something different in the preprocessor to get \
the information I need, but this is outside the scope of cmake, and it seems that \
cmake should warn me if my build type option is set to something that isn't \
valid.</div>


<div>  </div>
</span></font>
</div>

<br>--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a \
href="http://www.cmake.org/Wiki/CMake_FAQ" \
target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br> <br>
Kitware offers various services to support the CMake community. For more information \
on each offering, please visit:<br> <br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" \
target="_blank">http://cmake.org/cmake/help/support.html</a><br> CMake Consulting: <a \
href="http://cmake.org/cmake/help/consulting.html" \
target="_blank">http://cmake.org/cmake/help/consulting.html</a><br> CMake Training \
Courses: <a href="http://cmake.org/cmake/help/training.html" \
target="_blank">http://cmake.org/cmake/help/training.html</a><br> <br>
Visit other Kitware open-source projects at <a \
href="http://www.kitware.com/opensource/opensource.html" \
target="_blank">http://www.kitware.com/opensource/opensource.html</a><br> <br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" \
target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br></div>




-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: \
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information \
on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at \
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic