Re: Creating/using precompiled headers and static libraries

Bram Moolenaar <[email protected]> Sun, 25 Apr 2004 16:10:58 +0200
Newsgroups gmane.comp.tools.aap.user
Message-ID <[email protected]>
Thore Karlsen wrote:

> I'm trying to use AAP for the first time, and I'm trying to guess how
> things work. I've made some headway, but my project seems to be more
> complex than I thought it was!
> 
> I'm using MSVC to compile static libraries, DLLs, and executables. I've
> modified msvc.py to create static libraries, but I'm not sure how to use
> the resulting static library as a dependency for another project.
> 
> I have this to build two static libraries, Common.lib and IPP.lib.
> Common.lib links with IPP.lib.
> 
> COMMON_PROJECT_FILES =
> :tree Common { filename = .*\.cp?p? } { reject = Test_.*|stdafx\.cpp }
> 	COMMON_PROJECT_FILES += $name
> 
> # All common project files should use precompiled headers.
> :attr { add_CPPFLAGS = /Yu"stdafx.h" } $COMMON_PROJECT_FILES
> 
> # All stdafx.cpp should create precompiled headers.
> :tree . { filename = stdafx\.cpp }
> 	:attr { add_CPPFLAGS = /Yc"stdafx.h" } $name
> 
> :lib $BDIR/IPP.lib : IPP/*.cpp
> 
> :lib $BDIR/Common.lib
> 	{ add_LIBS = $BDIR/IPP.lib } :
> 	Common/stdafx.cpp
> 	$COMMON_PROJECT_FILES
> 
> There are a couple of problems with this:
> 
> 1. IPP.lib is linked correctly with Common.lib, but IPP.lib is not a
> dependency, so it's not automatically created. How do I fix this?

There is currently no automatic dependency for used libraries.  You can
add it explicitly:

	$BDIR/Common.lib : $BDIR/IPP.lib

> 2. When I attribute the files using :attr, the C++-flags are added three
> times. In other words, I'm getting "/Ycstdafx.h /Ycstdafx.h /Ycstdafx.h"
> on the command line. This happens for the :attr in the :tree, and the
> :attr not in the tree. Not a big deal in this case, but it certainly
> doesn't seem right.

This looks like a bug.  I think this happens because the add_CPPFLAGS is
added by the dependency and by the action.  The third time probably
happens when an action invokes another action.

Part of the solution could be that $source and $target don't inherit the
add_* and var_ attributes.  I implemented that and it avoids adding the
attribute twice for a simple example.  Problem remains that the
attribute may be added by an action twice.  That's because it uses the
attributes of the node.  That is difficult to avoid without breaking
something else...

Would it be acceptable that the string from "add_VAR" is not added when
it's already present?  Thus always avoid duplicates?  I can't think of a
situation where it would be desired to have the value twice.

Try this patch:

--- Action.py   25 Sep 2003 19:09:46 -0000  1.34
+++ Action.py   25 Apr 2004 13:49:20 -0000
@@ -225,7 +225,11 @@
             if k[0] == 'a':
                 oldval = get_var_val(0, todict, "_no", varname)
                 if oldval:
-                    val = oldval + ' ' + val
+                    # If the value already appears, don't append it again.
+                    if string.find(' ' + oldval + ' ', ' ' + val + ' ') >= 0:
+                        val = oldval
+                    else:
+                        val = oldval + ' ' + val
             if savedict:
                 savedict[varname] = todict.get(varname)
             todict[varname] = val


> 3. How can I print a message before starting a build? I'd like to print
> "Creating Common.lib" or something to separate the various subprojects I
> need to build.

I can't think of a simple way to do this.  Would require defining your
ownd dependency or action.

> Also, is there a better/easier/cleaner way to do the above precompiled
> header stuff? Basically what I need to do is:
> 
> - Compile all the .c/.cpp files in a recursive directory structure
> - Compile stdafx.cpp _first_ with an extra flag /Yc"stdafx.h" to create 
>   the PCH
> - Compile all other files with an extra flag /Yu"stdafx.h" to use PCH

I would think you are doing it the right way.  Could only be simplified
when the tool supports it somehow.

> Thanks for any help you can give me. This looks very promising, and
> looks like just what I need for my project, but the learning threshold
> is very high and the documentation and simple examples hasn't gotten me
> far.

I'm glad you appear to understand Aap quite well.  It does take a bit of
time to learn, since it offers so many features.

Your changes to support static libraries could be useful for others.
Can the changes to msvc.py be included in the distribution?

-- 
Far back in the mists of ancient time, in the great and glorious days of the
former Galactic Empire, life was wild, rich and largely tax free.
Mighty starships plied their way between exotic suns, seeking adventure and
reward among the furthest reaches of Galactic space.  In those days, spirits
were brave, the stakes were high, men were real men, women were real women
and small furry creatures from Alpha Centauri were real small furry creatures
from Alpha Centauri.  And all dared to brave unknown terrors, to do mighty
deeds, to boldly split infinitives that no man had split before -- and thus
was the Empire forged.
		-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\  Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///


-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
For a limited time only, get FREE Ground shipping on all orders of $35
or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297