summaryrefslogtreecommitdiffstats
path: root/source/core/slang-cpp-compiler.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-06-14 18:05:12 -0400
committerTim Foley <tfoleyNV@users.noreply.github.com>2019-06-14 15:05:12 -0700
commit1fe24d3a74a9cd51c4a025cd0e78642f3e29df79 (patch)
treea52d2b1e05f0d22accbb70eb4bea69d7c67455a4 /source/core/slang-cpp-compiler.cpp
parent8c56d83506ef92b15b15bdb5969008dd69c8d2a6 (diff)
Runtime Shared Library compilation and testing (#985)
* Removed the need for VisualStudio specific CPPCompiler Improved the version parsing for gcc/clang Removed need for slang-unix-cpp-compiler-util.cpp/.h Remove binary before compiling in the compile c tests * Moved VisualStudio calcArgs into CPPCompilerUtil - as code is not windows specific. * Set up compile time version for gcc and clang * Fix compilation on OSX - use remove instead of unlink for file deletion. * On OSX - clang uses different string format. * Removed /bin/sh invoking as not required for OSX. * First pass working testing with shared libraries.
Diffstat (limited to 'source/core/slang-cpp-compiler.cpp')
-rw-r--r--source/core/slang-cpp-compiler.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/source/core/slang-cpp-compiler.cpp b/source/core/slang-cpp-compiler.cpp
index 4bcdd068c..18cb9cdae 100644
--- a/source/core/slang-cpp-compiler.cpp
+++ b/source/core/slang-cpp-compiler.cpp
@@ -33,7 +33,15 @@ SlangResult GenericCPPCompiler::compile(const CompileOptions& options, ExecuteRe
}
#endif
- return ProcessUtil::execute(cmdLine, outResult);
+ SlangResult res = ProcessUtil::execute(cmdLine, outResult);
+
+#if 0
+ {
+ printf("stdout=\"%s\"\nstderr=\"%s\"\nret=%d\n", outResult.standardOutput.getBuffer(), outResult.standardError.getBuffer(), int(outResult.resultCode));
+ }
+#endif
+
+ return res;
}
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CPPCompilerUtil !!!!!!!!!!!!!!!!!!!!!!*/
@@ -153,6 +161,16 @@ SlangResult CPPCompilerUtil::calcGCCFamilyVersion(const String& exeName, CPPComp
// Display full path of source files in diagnostics
cmdLine.addArg("/FC");
+ if (options.flags & CompileOptions::Flag::EnableExceptionHandling)
+ {
+ if (options.sourceType == SourceType::CPP)
+ {
+ // https://docs.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=vs-2019
+ // Assumes c functions cannot throw
+ cmdLine.addArg("/EHsc");
+ }
+ }
+
switch (options.optimizationLevel)
{
case OptimizationLevel::Debug:
@@ -277,28 +295,12 @@ SlangResult CPPCompilerUtil::calcGCCFamilyVersion(const String& exeName, CPPComp
{
case TargetType::SharedLibrary:
{
+ // Shared library
+ cmdLine.addArg("-shared");
// Position independent
cmdLine.addArg("-fPIC");
- String sharedLibraryPath;
-
- // Work out the shared library name
- {
- String moduleDir = Path::getParentDirectory(options.modulePath);
- String moduleFilename = Path::getFileName(options.modulePath);
-
- StringBuilder sharedLibraryFilename;
- SharedLibrary::appendPlatformFileName(moduleFilename.getUnownedSlice(), sharedLibraryFilename);
-
- if (moduleDir.getLength() > 0)
- {
- sharedLibraryPath = Path::combine(moduleDir, sharedLibraryFilename);
- }
- else
- {
- sharedLibraryPath = sharedLibraryFilename;
- }
- }
+ String sharedLibraryPath = SharedLibrary::calcPlatformPath(options.modulePath.getUnownedSlice());
cmdLine.addArg("-o");
cmdLine.addArg(sharedLibraryPath);
@@ -366,6 +368,12 @@ SlangResult CPPCompilerUtil::calcGCCFamilyVersion(const String& exeName, CPPComp
cmdLine.addArg("-F");
cmdLine.addArg(libPath);
}
+
+ if (options.sourceType == SourceType::CPP)
+ {
+ // Make STD libs available
+ cmdLine.addArg("-lstdc++");
+ }
}
static CPPCompiler::Desc _calcCompiledWithDesc()