Dave Flogeras writes: > On Fri, Dec 18, 2015 at 9:55 AM, Magnus Therning <mag...@therning.org> wrote: >> >> I'm sure I'm not the first one to run into the conflict between a >> desire to test the code shipped to customers and the desire to at the >> same time define NDEBUG to make sure tests don't have their `assert` >> turned into NOOPs. >> >> Is there some nice way of handling this? > > I've also wondered this. My solution of choice has always been to keep > my tests in a subdirectory with a test header like you described: > > .... > #fidef NDEBUG > #undef NDEBUG > #include <cassert> // or assert.h for C > #define NDEBUG > #else > #include <cassert> > #endif > .... > > And include this in each of the unit tests. However, I have found > sometimes this is not foolproof. In particular I recall on one version > of OSX one of the system headers would undo this and make assert() > disappear again, requiring me to play the #include shell game. I > usually place my "test_assert.hpp" include after all others in the > unit test, but this is brittle. > > I have always just left it as a "good enough" solution, but I too > would love to hear if someone has a more robust solution.
I did a bit of testing and found that 1. CMAKE_C_FLAGS_* is, very irritatingly, *not* a list, so it's not easy to remove '-DNDEBUG' from them in the CMakeLists.txt for the tests. 2. Compile options added by target_compile_options() are added *after* CMAKE_C_FLAGS_* so I settled on using it to pass -UNDEBUG to gcc. Far from nice, but it works for now (which feels quite typical for CMake). /M -- Magnus Therning OpenPGP: 0x927912051716CE39 email: mag...@therning.org jabber: mag...@therning.org twitter: magthe http://therning.org/magnus If you can explain how you do something, then you're very very bad at it. -- John Hopfield
signature.asc
Description: PGP signature
-- 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