parent_emitter(target, source, env)
- if env.has_key('PCH') and env['PCH']:
- env.Depends(target, env['PCH'])
+ # Add a dependency, but only if the target (e.g. 'Source1.obj')
+ # doesn't correspond to the pre-compiled header ('Source1.pch').
+ # If the basenames match, then this was most likely caused by
+ # someone adding the source file to both the env.PCH() and the
+ # env.Program() calls, and adding the explicit dependency would
+ # cause a cycle on the .pch file itself.
+ #
+ # See issue #2505 for a discussion of what to do if it turns
+ # out this assumption causes trouble in the wild:
+ # http://scons.tigris.org/issues/show_bug.cgi?id=2505
+ if env.has_key('PCH'):
+ pch = env['PCH']
+ if str(target[0]) != SCons.Util.splitext(str(pch))[0] + '.obj':
+ env.Depends(target, pch)
return (target, source)
--- /dev/null
+#!/usr/bin/env python\r
+#\r
+# __COPYRIGHT__\r
+#\r
+# Permission is hereby granted, free of charge, to any person obtaining\r
+# a copy of this software and associated documentation files (the\r
+# "Software"), to deal in the Software without restriction, including\r
+# without limitation the rights to use, copy, modify, merge, publish,\r
+# distribute, sublicense, and/or sell copies of the Software, and to\r
+# permit persons to whom the Software is furnished to do so, subject to\r
+# the following conditions:\r
+#\r
+# The above copyright notice and this permission notice shall be included\r
+# in all copies or substantial portions of the Software.\r
+#\r
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY\r
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\r
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+#\r
+\r
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"\r
+\r
+"""\r
+Test use of pre-compiled headers when the source .cpp file shows\r
+up in both the env.PCH() and the env.Program() source list.\r
+\r
+Issue 2505: http://scons.tigris.org/issues/show_bug.cgi?id=2505\r
+"""\r
+\r
+import sys\r
+\r
+import TestSCons\r
+\r
+test = TestSCons.TestSCons()\r
+\r
+if sys.platform != 'win32':\r
+ msg = "Skipping Visual C/C++ test on non-Windows platform '%s'\n" % sys.platform\r
+ test.skip_test(msg)\r
+\r
+\r
+test.write('SConstruct', """\\r
+env = Environment(tools=['msvc', 'mslink'])\r
+env['PCH'] = env.PCH('Source1.cpp')[0]\r
+env['PCHSTOP'] = 'Header1.hpp'\r
+env.Program('foo', ['foo.cpp', 'Source2.cpp', 'Source1.cpp'])\r
+""" % locals())\r
+\r
+test.write('Header1.hpp', r"""\r
+""")\r
+\r
+test.write('Source1.cpp', r"""\r
+#include <stdio.h>\r
+\r
+#include "Header1.hpp"\r
+\r
+void\r
+Source1(void) {\r
+ printf("Source1.cpp\n");\r
+}\r
+""")\r
+\r
+test.write('Source2.cpp', r"""\r
+#include <stdio.h>\r
+\r
+#include "Header1.hpp"\r
+\r
+void\r
+Source2(void) {\r
+ printf("Source2.cpp\n");\r
+}\r
+""")\r
+\r
+test.write('foo.cpp', r"""\r
+#include <stdio.h>\r
+\r
+#include "Header1.hpp"\r
+\r
+void Source1(void);\r
+void Source2(void);\r
+\r
+int\r
+main(int argc, char *argv[])\r
+{\r
+ Source1();\r
+ Source2();\r
+ printf("foo.cpp\n");\r
+}\r
+""")\r
+\r
+test.run(arguments = ".")\r
+\r
+test.run(program=test.workpath('foo'+TestSCons._exe),\r
+ stdout="Source1.cpp\nSource2.cpp\nfoo.cpp\n")\r
+\r
+\r
+\r
+test.pass_test()\r
+\r
+# Local Variables:\r
+# tab-width:4\r
+# indent-tabs-mode:nil\r
+# End:\r
+# vim: set expandtab tabstop=4 shiftwidth=4:\r