Merge branch 'add-file-includes' into 'master'

File Include Support for C/C++

See merge request ita1024/waf!2286
This commit is contained in:
swaldhoer 2020-04-26 17:49:18 +00:00
commit 25a03dcf81
12 changed files with 48 additions and 3 deletions

6
demos/c++/c.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <iostream>
int main() {
printf("%s\n", HELLO_WORLD);
return 0;
}

View File

@ -0,0 +1,4 @@
#ifndef HEADER_H
#define HEADER_H
#define HELLO_WORLD "Hello World"
#endif /* HEADER_H */

View File

@ -23,6 +23,7 @@ def build(bld):
bld.shlib(source='a.cpp', target='mylib3')
bld.program(source='main.cpp', target='app', use='mylib')
bld.stlib(target='foo', source='b.cpp')
bld.program(source='c.cpp', target='file-include', includes='file-include/inc-file/header.h')
# just a test to check if the .c is compiled as c++ when no c compiler is found
bld.program(features='cxx cxxprogram', source='main.c', target='app2')

View File

@ -0,0 +1,4 @@
#ifndef HEADER_H
#define HEADER_H
#define HELLO_WORLD "Hello World"
#endif /* HEADER_H */

View File

@ -0,0 +1,7 @@
#include<stdio.h>
int main()
{
printf("%s\n", HELLO_WORLD);
return 0;
}

View File

@ -0,0 +1 @@
bld(features='c cprogram', source='main.c', includes='inc-file/header.h', target='app')

View File

@ -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)

View File

@ -518,6 +518,22 @@ class Node(object):
else:
return self.abspath()
def isfile(self):
"""
Returns True if the Node object is a file.
:rtype: bool
"""
return os.path.isfile(self.abspath())
def isdir(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``

View File

@ -119,9 +119,12 @@ def apply_incpaths(self):
"""
lst = self.to_incnodes(self.to_list(getattr(self, 'includes', [])) + self.env.INCLUDES)
self.includes_nodes = lst
inc_files = [x for x in lst if x.isfile()]
self.includes_nodes = list(set(lst) - set(inc_files)) # diff only holds directory
cwd = self.get_cwd()
self.env.INCPATHS = [x.path_from(cwd) for x in lst]
self.env.INCPATHS = [x.path_from(cwd) for x in self.includes_nodes]
self.env.prepend_value('CFLAGS', [self.env.CPPFILES_ST % x for x in inc_files])
self.env.prepend_value('CXXFLAGS', [self.env.CPPFILES_ST % x for x in inc_files])
class link_task(Task.Task):
"""

View File

@ -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

View File

@ -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

View File

@ -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:'