cpp-include
v1.1.1
Published
Collect path of #include directive on C/C++ source code.
Downloads
44
Maintainers
Readme
cpp-include
Collect path of #include
directive on C/C++ source code.
const cppInclude = require('cpp-include');
cppInclude.getIncludeFiles("myapp.cpp");
/* [
{ path: "myapp.h", local: true },
]*/
cppInclude.getIncludeFiles("myapp.h");
/* [
{ path: "iostream", local: false },
{ path: "mylib.h", local: true },
]*/
local
represents whether include directive is quoted-form (local: true
) or
angle-bracket form (local: false
)
If want to input source code string rather than path, use
getIncludeFilesFromString
var src = "#include <iostream>\n#include \"mylib.h\"";
cppInclude.getIncludeFilesFromString(src);
/* [
{ path: "iostream", local: false },
{ path: "mylib.h", local: true },
]*/
Find the actual full path of include file
Return items of getIncludeFiles
and getIncludeFilesFromString
respectively
has two additional members: find
and origin
.
origin
represents the path of the C/C++ source code that was passed togetIncludeFiles
.- This value can be changed at any time, changing it affects the
find
method. - NOTE: Semantically this value MUST be file path rather than
directory path. But
find
method can work fine as long as specified directory exist. SeeensureDirname
internal function to learn why.
- This value can be changed at any time, changing it affects the
find
is the method to accuire the actual location on the machine.- When
local
istrue
, this method try to find from the following directories:origin
- 1st argument of this method (string, or Array of string)
CPATH
(Linux/Mac) orINCLUDE
(Windows)
- Otherwise (
local
isfalse
)- 1st argument of this method (string, or Array of string)
CPATH
(Linux/Mac) orINCLUDE
(Windows)
- When
cppInclude.getIncludeFile("myapp.cpp")
.filter(f => { return f.path == "iostream" })[0]
.find();
// C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\iostream
cppInclude.getIncludeFile("myapp.cpp")
.filer(f => { return f.path == "mylib.h" })[0]
.find("C:\\Users\\retorillo\\include");
// C:\Users\retorillo\include\mylib.h
License
Distirubted under the MIT license
Copyright (C) 2017 Retorillo