开发者

programatically install headers and dependent headers using scons

开发者 https://www.devze.com 2023-04-09 10:02 出处:网络
I\'m using scons as my build system and I\'d like to install my project\'s development headers using scons as well. I\'d like to avoid maintaining a list of all the needed headers and their include de

I'm using scons as my build system and I'd like to install my project's development headers using scons as well. I'd like to avoid maintaining a list of all the needed headers and their include dependencies and instead use the built-in dependency parsing magic of scons to provide this list for me.

As an example I have 2 headers I want to install, explicitly, Foo1.h and Foo2.h:

/* Foo1.h */
#ifndef FOO1_H_
#define FOO1_H_开发者_Go百科

#include "Bar.h"
#include <somelibrary.h>

/* header contents */

#endif /* FOO1_H_ */

and

/* Foo2.h */
#ifndef FOO2_H_
#define FOO2_H_

/* header contents */

#endif /* FOO2_H_ */

Since Bar.h is required by Foo1.h, I want it to be installed too, automagically. somelibrary.h shouldn't be part of the installed headers. There has to be some way to accomplish this or there has to be some reason what I'm trying to do isn't advisable.

Thanks for any help!


Well, I figured out the answer. Here's the code snippet that'll do exactly what I was talking about:

def getDependentIncludes(environ, explicit_includes, search_path, depincludes):
    for inc in explicit_includes:
        if inc not in depincludes:
            depincludes.add(inc)
            incs = SCons.Defaults.CScan(inc, environ, search_path)
            getDependentIncludes(environ, incs, search_path, depincludes)
# create a set of all the headers
development_headers = set()
# call function, with development_headers storing the result
getDependentIncludes(env, 
                 external_facing_headers, 
                 include_dirs, development_headers)
# print the glorious results
names = map(lambda x : '"./' + os.path.relpath(str(x), Dir("#").abspath) + '"', development_headers)
names.sort()
print " ".join(names)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号