summaryrefslogtreecommitdiffstats
path: root/source/core/windows
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/windows')
-rw-r--r--source/core/windows/slang-win-visual-studio-util.cpp148
-rw-r--r--source/core/windows/slang-win-visual-studio-util.h3
2 files changed, 15 insertions, 136 deletions
diff --git a/source/core/windows/slang-win-visual-studio-util.cpp b/source/core/windows/slang-win-visual-studio-util.cpp
index 2fdf7e400..81d77c710 100644
--- a/source/core/windows/slang-win-visual-studio-util.cpp
+++ b/source/core/windows/slang-win-visual-studio-util.cpp
@@ -40,33 +40,8 @@ struct VersionInfo
const char* name; ///< The name of the registry key
};
-
-
-class WinVisualStudioCompiler : public CPPCompiler
-{
-public:
- typedef CPPCompiler Super;
-
- Result WinVisualStudioCompiler::compile(const CompileOptions& options, ExecuteResult& outRes) SLANG_OVERRIDE
- {
- CommandLine cmdLine;
- WinVisualStudioUtil::calcArgs(options, cmdLine);
- return WinVisualStudioUtil::executeCompiler(m_versionPath, cmdLine, outRes);
- }
- /// Ctor
- WinVisualStudioCompiler(const Desc& desc, const WinVisualStudioUtil::VersionPath& versionPath) :
- Super(desc),
- m_versionPath(versionPath)
- {
- }
-
- WinVisualStudioUtil::VersionPath m_versionPath;
-};
-
} // anonymous
-
-
static SlangResult _readRegistryKey(const char* path, const char* keyName, String& outString)
{
// https://docs.microsoft.com/en-us/windows/desktop/api/winreg/nf-winreg-regopenkeyexa
@@ -313,7 +288,10 @@ static SlangResult _find(int versionIndex, WinVisualStudioUtil::VersionPath& out
VersionPath versionPath;
if (!set->getCompiler(desc) && SLANG_SUCCEEDED(_find(i, versionPath)))
{
- RefPtr<WinVisualStudioCompiler> compiler = new WinVisualStudioCompiler(desc, versionPath);
+ CommandLine cmdLine;
+ calcExecuteCompilerArgs(versionPath, cmdLine);
+
+ RefPtr<GenericCPPCompiler> compiler = new GenericCPPCompiler(desc, cmdLine, &CPPCompilerUtil::calcVisualStudioArgs);
set->addCompiler(compiler);
}
}
@@ -321,12 +299,11 @@ static SlangResult _find(int versionIndex, WinVisualStudioUtil::VersionPath& out
return SLANG_OK;
}
-/* static */SlangResult WinVisualStudioUtil::executeCompiler(const VersionPath& versionPath, const CommandLine& commandLine, ExecuteResult& outResult)
+/* static */void WinVisualStudioUtil::calcExecuteCompilerArgs(const VersionPath& versionPath, CommandLine& outCmdLine)
{
// To invoke cl we need to run the suitable vcvars. In order to run this we have to have MS CommandLine.
// So here we build up a cl command line that is run by first running vcvars, and then executing cl with the parameters as passed to commandLine
- StringBuilder builder;
CommandLine cmdLine;
cmdLine.setExecutableFilename("cmd.exe");
@@ -353,9 +330,15 @@ static SlangResult _find(int versionIndex, WinVisualStudioUtil::VersionPath& out
cmdLine.addArg("&&");
cmdLine.addArg("cl");
+ outCmdLine = cmdLine;
+}
+
+/* static */SlangResult WinVisualStudioUtil::executeCompiler(const VersionPath& versionPath, const CommandLine& commandLine, ExecuteResult& outResult)
+{
+ CommandLine cmdLine;
+ calcExecuteCompilerArgs(versionPath, cmdLine);
// Append the command line options
cmdLine.addArgs(commandLine.m_args.getBuffer(), commandLine.m_args.getCount());
-
return ProcessUtil::execute(cmdLine, outResult);
}
@@ -380,111 +363,4 @@ static SlangResult _find(int versionIndex, WinVisualStudioUtil::VersionPath& out
}
}
-/* static */void WinVisualStudioUtil::calcArgs(const CPPCompiler::CompileOptions& options, CommandLine& cmdLine)
-{
- typedef CPPCompiler::OptimizationLevel OptimizationLevel;
- typedef CPPCompiler::TargetType TargetType;
- typedef CPPCompiler::DebugInfoType DebugInfoType;
-
- // https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically?view=vs-2019
-
- cmdLine.addArg("/nologo");
- // Generate complete debugging information
- cmdLine.addArg("/Zi");
- // Display full path of source files in diagnostics
- cmdLine.addArg("/FC");
-
- switch (options.optimizationLevel)
- {
- case OptimizationLevel::Debug:
- {
- // No optimization
- cmdLine.addArg("/Od");
-
- cmdLine.addArg("/MDd");
- break;
- }
- case OptimizationLevel::Normal:
- {
- cmdLine.addArg("/O2");
- // Multithreaded DLL
- cmdLine.addArg("/MD");
- break;
- }
- default: break;
- }
-
- // /Fd - followed by name of the pdb file
- if (options.debugInfoType != DebugInfoType::None)
- {
- cmdLine.addPrefixPathArg("/Fd", options.modulePath, ".pdb");
- }
-
- switch (options.targetType)
- {
- case TargetType::SharedLibrary:
- {
- // Create dynamic link library
- if (options.optimizationLevel == OptimizationLevel::Debug)
- {
- cmdLine.addArg("/LDd");
- }
- else
- {
- cmdLine.addArg("/LD");
- }
-
- cmdLine.addPrefixPathArg("/Fe", options.modulePath, ".dll");
- break;
- }
- case TargetType::Executable:
- {
- cmdLine.addPrefixPathArg("/Fe", options.modulePath, ".exe");
- break;
- }
- default: break;
- }
-
- // Object file specify it's location - needed if we are out
- cmdLine.addPrefixPathArg("/Fo", options.modulePath, ".obj");
-
- // 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);
- }
-
- // https://docs.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=vs-2019
- // /Eha - Specifies the model of exception handling. (a, s, c, r are options)
-
- // Files to compile
- for (const auto& sourceFile : options.sourceFiles)
- {
- cmdLine.addArg(sourceFile);
- }
-
- // Link options (parameters past /link go to linker)
- cmdLine.addArg("/link");
-
- for (const auto& libPath : options.libraryPaths)
- {
- // Note that any escaping of the path is handled in the ProcessUtil::
- cmdLine.addPrefixPathArg("/LIBPATH:", libPath);
- }
-}
-
} // namespace Slang
diff --git a/source/core/windows/slang-win-visual-studio-util.h b/source/core/windows/slang-win-visual-studio-util.h
index b7e1c8a85..76e1cc710 100644
--- a/source/core/windows/slang-win-visual-studio-util.h
+++ b/source/core/windows/slang-win-visual-studio-util.h
@@ -33,6 +33,9 @@ struct WinVisualStudioUtil
/// Find and add to the set (if not already there)
static SlangResult find(CPPCompilerSet* set);
+ /// Create the cmdLine to start compiler for specified path
+ static void calcExecuteCompilerArgs(const VersionPath& versionPath, CommandLine& outCmdLine);
+
/// Run visual studio on specified path with the parameters specified on the command line. Output placed in outResult.
static SlangResult executeCompiler(const VersionPath& versionPath, const CommandLine& commandLine, ExecuteResult& outResult);