diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-06-14 12:20:12 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-14 12:20:12 -0400 |
| commit | 8c56d83506ef92b15b15bdb5969008dd69c8d2a6 (patch) | |
| tree | b58218a85c108b49c2ce74f77e1f3de8c668ef21 /source/core/unix | |
| parent | 7461e95210e7420d0ddf681279813f394a6fd0d8 (diff) | |
CPPCompiler improvements (#984)
* 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.
Diffstat (limited to 'source/core/unix')
| -rw-r--r-- | source/core/unix/slang-unix-cpp-compiler-util.cpp | 163 | ||||
| -rw-r--r-- | source/core/unix/slang-unix-cpp-compiler-util.h | 24 |
2 files changed, 0 insertions, 187 deletions
diff --git a/source/core/unix/slang-unix-cpp-compiler-util.cpp b/source/core/unix/slang-unix-cpp-compiler-util.cpp deleted file mode 100644 index 9217c6d52..000000000 --- a/source/core/unix/slang-unix-cpp-compiler-util.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "slang-unix-cpp-compiler-util.h" - -#include "../slang-common.h" -#include "../slang-process-util.h" -#include "../slang-string-util.h" - -#include "../slang-shared-library.h" - -#include "../slang-io.h" - -// The method used to invoke VS was originally inspired by some ideas in -// https://github.com/RuntimeCompiledCPlusPlus/RuntimeCompiledCPlusPlus/ - -namespace Slang { - - -/* static */void UnixCPPCompilerUtil::calcArgs(const CPPCompiler::CompileOptions& options, CommandLine& cmdLine) -{ - typedef CPPCompiler::OptimizationLevel OptimizationLevel; - typedef CPPCompiler::TargetType TargetType; - typedef CPPCompiler::DebugInfoType DebugInfoType; - - cmdLine.addArg("-fvisibility=hidden"); - // Use shared libraries - //cmdLine.addArg("-shared"); - - switch (options.optimizationLevel) - { - case OptimizationLevel::Debug: - { - // No optimization - cmdLine.addArg("-O0"); - break; - } - case OptimizationLevel::Normal: - { - cmdLine.addArg("-Os"); - break; - } - default: break; - } - - if (options.debugInfoType != DebugInfoType::None) - { - cmdLine.addArg("-g"); - } - - switch (options.targetType) - { - case TargetType::SharedLibrary: - { - // 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; - } - } - - cmdLine.addArg("-o"); - cmdLine.addArg(sharedLibraryPath); - break; - } - case TargetType::Executable: - { - cmdLine.addArg("-o"); - - StringBuilder builder; - builder << options.modulePath; - builder << ProcessUtil::getExecutableSuffix(); - - cmdLine.addArg(options.modulePath); - break; - } - case TargetType::Object: - { - // Don't link, just produce object file - cmdLine.addArg("-c"); - break; - } - default: break; - } - - // Add defines - for (const auto& define : options.defines) - { - StringBuilder builder; - builder << define.nameWithSig; - if (define.value.getLength()) - { - builder << "=" << define.value; - } - - cmdLine.addArg(builder); - } - - // Add includes - for (const auto& include : options.includePaths) - { - cmdLine.addArg("-I"); - cmdLine.addArg(include); - } - - // Link options - if (0) - { - StringBuilder linkOptions; - linkOptions << "Wl,"; - cmdLine.addArg(linkOptions); - } - - // Files to compile - for (const auto& sourceFile : options.sourceFiles) - { - cmdLine.addArg(sourceFile); - } - - for (const auto& libPath : options.libraryPaths) - { - // Note that any escaping of the path is handled in the ProcessUtil:: - cmdLine.addArg("-L"); - cmdLine.addArg(libPath); - cmdLine.addArg("-F"); - cmdLine.addArg(libPath); - } -} - -/* static */SlangResult UnixCPPCompilerUtil::executeCompiler(const CommandLine& commandLine, ExecuteResult& outResult) -{ - CommandLine cmdLine; - // We'll assume g++ for now - cmdLine.setExecutableFilename("g++"); - - // Append the command line options - cmdLine.addArgs(commandLine.m_args.getBuffer(), commandLine.m_args.getCount()); - -#if 0 - // Test - { - String line = ProcessUtil::getCommandLineString(cmdLine); - printf("%s", line.getBuffer()); - } -#endif - - return ProcessUtil::execute(cmdLine, outResult); -} - -} // namespace Slang diff --git a/source/core/unix/slang-unix-cpp-compiler-util.h b/source/core/unix/slang-unix-cpp-compiler-util.h deleted file mode 100644 index 42886e5eb..000000000 --- a/source/core/unix/slang-unix-cpp-compiler-util.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SLANG_UNIX_CPP_COMPILER_UTIL_H -#define SLANG_UNIX_CPP_COMPILER_UTIL_H - -#include "../slang-list.h" -#include "../slang-string.h" - -#include "../slang-process-util.h" - -#include "../slang-cpp-compiler.h" - -namespace Slang { - -struct UnixCPPCompilerUtil -{ - /// Run compiler with command line (typically generated by calcArgs). Output placed in outResult. - static SlangResult executeCompiler(const CommandLine& commandLine, ExecuteResult& outResult); - - /// Calculate the command line args - static void calcArgs(const CPPCompiler::CompileOptions& options, CommandLine& cmdLine); -}; - -} // namespace Slang - -#endif |
