From 8c56d83506ef92b15b15bdb5969008dd69c8d2a6 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 14 Jun 2019 12:20:12 -0400 Subject: 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. --- source/core/unix/slang-unix-cpp-compiler-util.cpp | 163 ---------------------- 1 file changed, 163 deletions(-) delete mode 100644 source/core/unix/slang-unix-cpp-compiler-util.cpp (limited to 'source/core/unix/slang-unix-cpp-compiler-util.cpp') 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 -- cgit v1.2.3