summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-01-07 16:46:20 (GMT)
committerBrad King <brad.king@kitware.com>2014-02-14 20:48:43 (GMT)
commited9c866490f5799ea0a4cf6fb88b1e705d594b61 (patch)
treef9806396bf6a69bf28609b47e48863b8e3dd9797
parent16cc24ee9f6a7f66763bea4a3cd4d0cf0e1e884f (diff)
downloadCastXML-ed9c866490f5799ea0a4cf6fb88b1e705d594b61.zip
CastXML-ed9c866490f5799ea0a4cf6fb88b1e705d594b61.tar.gz
CastXML-ed9c866490f5799ea0a4cf6fb88b1e705d594b61.tar.bz2
Add --castxml-cc-<id> option to specify compiler command
Add members to the Options struct to hold the preprocessor and target settings detected from a given compiler command. Add an API to fill in the members.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Detect.cxx34
-rw-r--r--src/Detect.h28
-rw-r--r--src/Options.h10
-rw-r--r--src/castxml.cxx44
5 files changed, 115 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 484f209..b0320e1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -25,6 +25,7 @@ llvm_map_components_to_libraries(llvm_libs native option bitreader)
add_executable(castxml
castxml.cxx
+ Detect.cxx Detect.h
Options.h
Utils.cxx Utils.h
)
diff --git a/src/Detect.cxx b/src/Detect.cxx
new file mode 100644
index 0000000..16692b4
--- /dev/null
+++ b/src/Detect.cxx
@@ -0,0 +1,34 @@
+/*
+ Copyright Kitware, Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "Detect.h"
+#include "Options.h"
+#include "Utils.h"
+
+#include <string.h>
+
+//----------------------------------------------------------------------------
+bool detectCC(const char* id,
+ const char* const* argBeg,
+ const char* const* argEnd,
+ Options& opts)
+{
+ (void)id;
+ (void)argBeg;
+ (void)argEnd;
+ (void)opts;
+ return false;
+}
diff --git a/src/Detect.h b/src/Detect.h
new file mode 100644
index 0000000..1877433
--- /dev/null
+++ b/src/Detect.h
@@ -0,0 +1,28 @@
+/*
+ Copyright Kitware, Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+#ifndef CASTXML_DETECT_H
+#define CASTXML_DETECT_H
+
+struct Options;
+
+/// detectCC - Detect settings from given compiler command.
+
+bool detectCC(const char* id,
+ const char* const* argBeg,
+ const char* const* argEnd,
+ Options& opts);
+
+#endif // CASTXML_DETECT_H
diff --git a/src/Options.h b/src/Options.h
index 95311d3..84c1fa6 100644
--- a/src/Options.h
+++ b/src/Options.h
@@ -16,10 +16,18 @@
#ifndef CASTXML_OPTIONS_H
#define CASTXML_OPTIONS_H
+#include <cxsys/Configure.hxx>
+#include <string>
+#include <vector>
+
struct Options
{
- Options(): GccXml(false) {}
+ Options(): GccXml(false), HaveCC(false) {}
bool GccXml;
+ bool HaveCC;
+ std::vector<std::string> Includes;
+ std::string Predefines;
+ std::string Triple;
};
#endif // CASTXML_OPTIONS_H
diff --git a/src/castxml.cxx b/src/castxml.cxx
index 2b10a4b..983a508 100644
--- a/src/castxml.cxx
+++ b/src/castxml.cxx
@@ -14,6 +14,7 @@
limitations under the License.
*/
+#include "Detect.h"
#include "Options.h"
#include "Utils.h"
@@ -37,11 +38,14 @@ int main(int argc, const char* const * argv)
}
const char* usage =
- "Usage: castxml [--castxml-gccxml] [<clang-args>...]\n"
+ "Usage: castxml [--castxml-gccxml] [<clang-args>...] \\\n"
+ " [--castxml-cc-<id> <cc> [<cc-args>...]]\n"
;
Options opts;
llvm::SmallVector<const char *, 16> clang_args;
+ llvm::SmallVector<const char *, 16> cc_args;
+ const char* cc_id = 0;
for(int i=1; i < argc; ++i) {
if(strcmp(argv[i], "--castxml-gccxml") == 0) {
@@ -55,10 +59,48 @@ int main(int argc, const char* const * argv)
;
return 1;
}
+ } else if(strncmp(argv[i], "--castxml-cc-", 13) == 0) {
+ if(!cc_id) {
+ cc_id = argv[i] + 13;
+ for(++i;i < argc && strncmp(argv[i], "--castxml-", 10) != 0; ++i) {
+ cc_args.push_back(argv[i]);
+ }
+ --i;
+ } else {
+ std::cerr <<
+ "error: '--castxml-cc-<id>' may be given at most once!\n"
+ "\n" <<
+ usage
+ ;
+ return 1;
+ }
} else {
clang_args.push_back(argv[i]);
}
}
+ if(cc_id) {
+ opts.HaveCC = true;
+ if(cc_args.empty()) {
+ std::cerr <<
+ "error: '--castxml-cc-" << cc_id <<
+ "' must be followed by a compiler command!\n"
+ "\n" <<
+ usage
+ ;
+ return 1;
+ }
+ if(!detectCC(cc_id, cc_args.data(), cc_args.data() + cc_args.size(),
+ opts)) {
+ return 1;
+ }
+ }
+
+ std::cerr << opts.Predefines;
+ for(std::vector<std::string>::iterator i = opts.Includes.begin(),
+ e = opts.Includes.end(); i != e; ++i) {
+ std::cerr << *i << "\n";
+ }
+
return 0;
}