[CMake] How can I prevent invalid -DCMAKE_BULD_TYPE values?

Miller Henry MillerHenry at JohnDeere.com
Fri Jun 13 11:04:34 EDT 2014


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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140613/117fb524/attachment.html>


More information about the CMake mailing list