[CMake] How can I prevent invalid -DCMAKE_BULD_TYPE values?
Jack Morrison
JackMorrison1 at gmail.com
Fri Jun 13 14:11:49 EDT 2014
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 at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140613/fa75f22a/attachment-0001.html>
More information about the CMake
mailing list