From b040c8b42e5a19a4e2a2dc8a6180a465862a7384 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Mon, 14 Apr 2003 11:02:34 +0000 Subject: [PATCH] Bugfix: set NDEBUG for release builds. * new/builtin.jam: Make speed active property and add NDEBUG for it. * test/ndebug.py: New test. [SVN r18250] --- src/tools/builtin.jam | 13 ++++++++++++ test/ndebug.py | 47 +++++++++++++++++++++++++++++++++++++++++++ test/project_test4.py | 2 +- test/test_all.py | 1 + 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/ndebug.py diff --git a/src/tools/builtin.jam b/src/tools/builtin.jam index af484d295..fb03e6035 100644 --- a/src/tools/builtin.jam +++ b/src/tools/builtin.jam @@ -141,6 +141,19 @@ IMPORT $(__name__) : variant : : variant ; variant debug : off on off ; variant release : speed off full ; +# When speed is specified, we need to add NDEBUG +# It is done via 'active' features, because it should be done for +# all targets built with speed. Since is free, it is +# not propagated, we can't just add it to 'release'. And we cannot make +# propagated, because (i) free features cannot be propagated and +# (ii) this is dangerous. +rule builtin.handle-ndebug ( property : properties * ) +{ + return NDEBUG ; +} +feature.action speed : builtin.handle-ndebug ; + + rule searched-lib-target ( name : project : shared ? diff --git a/test/ndebug.py b/test/ndebug.py new file mode 100644 index 000000000..a7448134a --- /dev/null +++ b/test/ndebug.py @@ -0,0 +1,47 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +# Test that building with optimization brings NDEBUG define, and, more +# importantly, that dependency targets are built with NDEBUG as well, +# even if they are not directly requested. + + +from BoostBuild import Tester, List + + +t = Tester() + +t.write("project-root.jam", "") +t.write("Jamfile", """ +exe hello : hello.cpp lib/lib1 ; +""") +t.write("hello.cpp", """ +#ifdef NDEBUG +void foo(); +int main() +{ + foo(); + return 0; +} +#endif +""") +t.write("lib/Jamfile", """ +lib lib1 : lib1.cpp ; +""") +t.write("lib/lib1.cpp", """ +#ifdef NDEBUG +void foo() {} +#endif +""") + +# 'release' builds should get NDEBUG define +# use static linking to avoid messing with +# imports/exports on windows. +t.run_build_system("link=static release") + + +t.cleanup() diff --git a/test/project_test4.py b/test/project_test4.py index 6ffc0ae51..245e51348 100644 --- a/test/project_test4.py +++ b/test/project_test4.py @@ -25,7 +25,7 @@ t.expect_content("bin/$toolset/debug/a.exe", t.expect_addition("lib/bin/$toolset/debug/optimization-speed/b.obj") t.expect_content("lib/bin/$toolset/debug/optimization-speed/b.obj", -"""$toolset/debug/include-everything/optimization-speed +"""$toolset/debug/define-NDEBUG/include-everything/optimization-speed lib/b.cpp """) diff --git a/test/test_all.py b/test/test_all.py index 7f249f37d..b37ea44e3 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -86,6 +86,7 @@ tests = [ "project_test1", "unused", "default_features", "print", + "ndebug", ] if os.name == 'posix':