From fd268cd831f39138be9a4497751c8004675a6a3f Mon Sep 17 00:00:00 2001 From: stevenknight Date: Mon, 21 Oct 2002 23:40:24 +0000 Subject: [PATCH] Add MSVC .res builder. (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@486 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/scons.1 | 22 +++++++++++-- src/CHANGES.txt | 4 +-- src/engine/SCons/Scanner/__init__.py | 4 +++ src/engine/SCons/Tool/msvc.py | 7 +++++ test/msvc.py | 46 ++++++++++++++++++++++++++-- 5 files changed, 77 insertions(+), 6 deletions(-) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 6b3aabd0..6307f34f 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -977,6 +977,17 @@ Example: env.Program(target = 'foo', source = ['foo.o', 'bar.c', 'baz.f']) .EE +.IP RES +Builds a Microsoft Visual C++ resource file. This builder is only +provided when Microsoft Visual C++ is being used as the compiler. The +.I .res +suffix is added to the target name if no other suffix is given. The source +file is scanned for implicit dependencies as though it were a C file. Example: + +.ES +env.RES('resource.rc') +.EE + .IP StaticLibrary Builds a static library given one or more object files or C, C++ or Fortran source files. @@ -1884,8 +1895,6 @@ the empty string if the "#pragma hrdstop" construct is being used: env['PCHSTOP'] = 'StdAfx.h' .EE - - .IP PDB The Microsoft Visual C++ PDB file that will store debugging information for object files, shared libraries, and programs. This variable is ignored by @@ -1929,6 +1938,15 @@ The archive indexer. .IP RANLIBFLAGS General options passed to the archive indexer. +.IP RC +The resource compiler used by the RES builder. + +.IP RCCOM +The command line used by the RES builder. + +.IP RCFLAGS +The flags passed to the resource compiler by the RES builder. + .IP RDirs A function that converts a file name into a list of Dir instances by searching the repositories. diff --git a/src/CHANGES.txt b/src/CHANGES.txt index d542c0d4..0b1b027e 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -81,8 +81,8 @@ RELEASE 0.09 - - Add an Options() object for friendlier accomodation of command- line arguments. - - Add support for Microsoft VC++ precompiled header (.pch) - and debugger (.pdb) files. + - Add support for Microsoft VC++ precompiled header (.pch) files, + debugger (.pdb) files, and resource (.rc) files. - Don't compute the $_CPPINCFLAGS, $_F77INCFLAGS, $_LIBFLAGS and $_LIBDIRFLAGS variables each time a command is executed, define diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index dc106480..aef5d728 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -127,6 +127,10 @@ class Base: def __hash__(self): return hash(None) + def add_skey(self, skey): + """Add a skey to the list of skeys""" + self.skeys.append(skey) + class RExists(Base): """ Scan a node only if it exists (locally or in a Repository). diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py index f71c074c..94f1e4dc 100644 --- a/src/engine/SCons/Tool/msvc.py +++ b/src/engine/SCons/Tool/msvc.py @@ -238,6 +238,7 @@ def object_emitter(target, source, env): return (target, source) pch_builder = SCons.Builder.Builder(action='$PCHCOM', suffix='.pch', emitter=pch_emitter) +res_builder = SCons.Builder.Builder(action='$RCCOM', suffix='.res') def generate(env, platform): """Add Builders and construction variables for MSVC++ to an Environment.""" @@ -270,6 +271,12 @@ def generate(env, platform): env['INCSUFFIX'] = '' env['OBJEMITTER'] = object_emitter + env['RC'] = 'rc' + env['RCFLAGS'] = '' + env['RCCOM'] = '$RC $_CPPINCFLAGS $RCFLAGS /fo$TARGET $SOURCES' + env.CScan.add_skey('.rc') + env['BUILDERS']['RES'] = res_builder + include_path, lib_path, exe_path = get_msdev_paths() env['ENV']['INCLUDE'] = include_path env['ENV']['PATH'] = exe_path diff --git a/test/msvc.py b/test/msvc.py index ed434210..7d771d30 100644 --- a/test/msvc.py +++ b/test/msvc.py @@ -44,7 +44,7 @@ env=Environment() env['PCH'] = env.PCH('StdAfx.cpp')[0] env['PDB'] = File('test.pdb') env['PCHSTOP'] = 'StdAfx.h' -env.Program('test', 'test.cpp') +env.Program('test', ['test.cpp', env.RES('test.rc')], LIBS=['user32']) env.Object('fast', 'foo.cpp') env.Object('slow', 'foo.cpp', PCH=0) @@ -52,19 +52,38 @@ env.Object('slow', 'foo.cpp', PCH=0) test.write('test.cpp', ''' #include "StdAfx.h" +#include "resource.h" int main(void) { - return 1; + char test[1024]; + LoadString(GetModuleHandle(NULL), IDS_TEST, test, sizeof(test)); + printf("%d %s\\n", IDS_TEST, test); + return 0; } ''') +test.write('test.rc', ''' +#include "resource.h" + +STRINGTABLE DISCARDABLE +BEGIN + IDS_TEST "test 1" +END +''') + +test.write('resource.h', ''' +#define IDS_TEST 2001 +''') + + test.write('foo.cpp', ''' #include "StdAfx.h" ''') test.write('StdAfx.h', ''' #include +#include ''') test.write('StdAfx.cpp', ''' @@ -73,13 +92,36 @@ test.write('StdAfx.cpp', ''' test.run(arguments='test.exe') +test.fail_test(not os.path.exists(test.workpath('test.exe'))) +test.fail_test(not os.path.exists(test.workpath('test.res'))) test.fail_test(not os.path.exists(test.workpath('test.pdb'))) test.fail_test(not os.path.exists(test.workpath('StdAfx.pch'))) test.fail_test(not os.path.exists(test.workpath('StdAfx.obj'))) +test.run(program=test.workpath('test.exe'), stdout='2001 test 1\n') + +test.write('resource.h', ''' +#define IDS_TEST 2002 +''') +test.run(arguments='test.exe') +test.run(program=test.workpath('test.exe'), stdout='2002 test 1\n') + +test.write('test.rc', ''' +#include "resource.h" + +STRINGTABLE DISCARDABLE +BEGIN + IDS_TEST "test 2" +END +''') +test.run(arguments='test.exe') +test.run(program=test.workpath('test.exe'), stdout='2002 test 2\n') + test.run(arguments='-c .') +test.fail_test(os.path.exists(test.workpath('test.exe'))) test.fail_test(os.path.exists(test.workpath('test.pdb'))) +test.fail_test(os.path.exists(test.workpath('test.res'))) test.fail_test(os.path.exists(test.workpath('StdAfx.pch'))) test.fail_test(os.path.exists(test.workpath('StdAfx.obj'))) -- 2.26.2