Use NDEBUG to control the debug code compilation

CMake provides NDEBUG macro in Release build type, so if we have any
codes that need to be compiled in Debug type, check if NDEBUG is not
defined.