mirror of https://gitlab.com/ita1024/waf.git
add file includes
This commit is contained in:
parent
816f466e32
commit
c7b2a5628e
|
@ -0,0 +1,4 @@
|
|||
#ifndef HEADER_H
|
||||
#define HEADER_H
|
||||
#define HELLO_WORLD "Hello World"
|
||||
#endif /* HEADER_H */
|
|
@ -4,5 +4,6 @@ extern void foo();
|
|||
|
||||
int main() {
|
||||
foo();
|
||||
printf("%s", HELLO_WORLD);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ def build(bld):
|
|||
bld.shlib(source='a.cpp', target='mylib', vnum='9.8.7')
|
||||
bld.shlib(source='a.cpp', target='mylib2', vnum='9.8.7', cnum='9.8')
|
||||
bld.shlib(source='a.cpp', target='mylib3')
|
||||
bld.program(source='main.cpp', target='app', use='mylib')
|
||||
bld.program(source='main.cpp', target='app', include_files='file-include/inc-file/header.h', use='mylib')
|
||||
bld.stlib(target='foo', source='b.cpp')
|
||||
|
||||
# just a test to check if the .c is compiled as c++ when no c compiler is found
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef HEADER_H
|
||||
#define HEADER_H
|
||||
#define HELLO_WORLD "Hello World"
|
||||
#endif /* HEADER_H */
|
|
@ -0,0 +1,7 @@
|
|||
#include<stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("%s", HELLO_WORLD);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
bld(features='c cprogram', source='main.c', include_files='inc-file/header.h', target='app')
|
|
@ -78,7 +78,7 @@ def configure(conf):
|
|||
def build(bld):
|
||||
bld.env.DEFINES=['WAF=1']
|
||||
|
||||
bld.recurse('program stlib stlib-deps shlib')
|
||||
bld.recurse('program stlib stlib-deps shlib file-include')
|
||||
#bld.install_files('/tmp/foo', 'wscript')
|
||||
#bld.env.PREFIX='/tmp/foo'
|
||||
bld.install_files('${PREFIX}/', 'program/a.h program/main.c', relative_trick=False)
|
||||
|
|
|
@ -518,6 +518,22 @@ class Node(object):
|
|||
else:
|
||||
return self.abspath()
|
||||
|
||||
def is_file(self):
|
||||
"""
|
||||
Returns True if the Node object is a file.
|
||||
|
||||
:rtype: bool
|
||||
"""
|
||||
return os.path.isfile(self.abspath())
|
||||
|
||||
def is_directory(self):
|
||||
"""
|
||||
Returns True if the Node object is a directory.
|
||||
|
||||
:rtype: bool
|
||||
"""
|
||||
return os.path.isdir(self.abspath())
|
||||
|
||||
def abspath(self):
|
||||
"""
|
||||
Returns the absolute path. A cache is kept in the context as ``cache_node_abspath``
|
||||
|
|
|
@ -17,7 +17,7 @@ def c_hook(self, node):
|
|||
|
||||
class c(Task.Task):
|
||||
"Compiles C files into object files"
|
||||
run_str = '${CC} ${ARCH_ST:ARCH} ${CFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT[0].abspath()} ${CPPFLAGS}'
|
||||
run_str = '${CC} ${ARCH_ST:ARCH} ${CFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${CPPFILES_ST:INCFILES} ${DEFINES_ST:DEFINES} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT[0].abspath()} ${CPPFLAGS}'
|
||||
vars = ['CCDEPS'] # unused variable to depend on, just in case
|
||||
ext_in = ['.h'] # set the build order easily by using ext_out=['.h']
|
||||
scan = c_preproc.scan
|
||||
|
|
|
@ -123,6 +123,32 @@ def apply_incpaths(self):
|
|||
cwd = self.get_cwd()
|
||||
self.env.INCPATHS = [x.path_from(cwd) for x in lst]
|
||||
|
||||
@feature('c', 'cxx', 'include_files')
|
||||
@after_method('propagate_uselib_vars', 'process_source')
|
||||
def apply_incfiles(self):
|
||||
"""
|
||||
Task generator method that processes the attribute *include_files*::
|
||||
|
||||
tg = bld(features='include_files', include_files='my-header.h')
|
||||
|
||||
The files need to be given relative to the current directory.
|
||||
This method will add a list of header file nodes to ``tg.env.INCFILES``.
|
||||
"""
|
||||
node_lst = []
|
||||
for x in self.to_list(getattr(self, 'include_files', [])) + self.env.INCLUDE_FILES:
|
||||
if isinstance(x, Node.Node):
|
||||
node_lst.append(x)
|
||||
else:
|
||||
node_lst.append(self.path.find_node(x))
|
||||
cwd = self.get_cwd()
|
||||
if self.env.CXX_NAME == "msvc":
|
||||
# This is necessary as CL.exe running in CPP-mode can not handle relative includes.
|
||||
# In C-mode however it can, but handling C and CPP sources different makes things more
|
||||
# complicated, and like this way it works fine.
|
||||
self.env.INCFILES = [x.abspath() for x in node_lst if x.is_file()]
|
||||
else:
|
||||
self.env.INCFILES = [x.path_from(cwd) for x in node_lst if x.is_file()]
|
||||
|
||||
class link_task(Task.Task):
|
||||
"""
|
||||
Base class for all link tasks. A task generator is supposed to have at most one link task bound in the attribute *link_task*. See :py:func:`waflib.Tools.ccroot.apply_link`.
|
||||
|
|
|
@ -18,7 +18,7 @@ if not '.c' in TaskGen.task_gen.mappings:
|
|||
|
||||
class cxx(Task.Task):
|
||||
"Compiles C++ files into object files"
|
||||
run_str = '${CXX} ${ARCH_ST:ARCH} ${CXXFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXX_SRC_F}${SRC} ${CXX_TGT_F}${TGT[0].abspath()} ${CPPFLAGS}'
|
||||
run_str = '${CXX} ${ARCH_ST:ARCH} ${CXXFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${CPPFILES_ST:INCFILES} ${DEFINES_ST:DEFINES} ${CXX_SRC_F}${SRC} ${CXX_TGT_F}${TGT[0].abspath()} ${CPPFLAGS}'
|
||||
vars = ['CXXDEPS'] # unused variable to depend on, just in case
|
||||
ext_in = ['.h'] # set the build order easily by using ext_out=['.h']
|
||||
scan = c_preproc.scan
|
||||
|
|
|
@ -36,6 +36,7 @@ def gcc_common_flags(conf):
|
|||
v.CCLNK_SRC_F = []
|
||||
v.CCLNK_TGT_F = ['-o']
|
||||
v.CPPPATH_ST = '-I%s'
|
||||
v.CPPFILES_ST = '-include%s'
|
||||
v.DEFINES_ST = '-D%s'
|
||||
|
||||
v.LIB_ST = '-l%s' # template for adding libs
|
||||
|
|
|
@ -36,6 +36,7 @@ def gxx_common_flags(conf):
|
|||
v.CXXLNK_SRC_F = []
|
||||
v.CXXLNK_TGT_F = ['-o']
|
||||
v.CPPPATH_ST = '-I%s'
|
||||
v.CPPFILES_ST = '-include%s'
|
||||
v.DEFINES_ST = '-D%s'
|
||||
|
||||
v.LIB_ST = '-l%s' # template for adding libs
|
||||
|
|
|
@ -910,6 +910,7 @@ def msvc_common_flags(conf):
|
|||
v.CXX_TGT_F = ['/FC'] + v.CXX_TGT_F
|
||||
|
||||
v.CPPPATH_ST = '/I%s' # template for adding include paths
|
||||
v.CPPFILES_ST = '/FI%s'
|
||||
|
||||
v.AR_TGT_F = v.CCLNK_TGT_F = v.CXXLNK_TGT_F = '/OUT:'
|
||||
|
||||
|
|
Loading…
Reference in New Issue