@@ -61,23 +61,59 @@ class ShaderCompiler final : public system::IApplicationFramework
61
61
m_arguments.erase (builtin_flag_pos);
62
62
}
63
63
64
- auto output_flag_pos = std::find (m_arguments.begin (), m_arguments.end (), " -Fo" );
65
- if (output_flag_pos == m_arguments.end ())
66
- output_flag_pos = std::find (m_arguments.begin (), m_arguments.end (), " -Fc" );
67
-
68
- if (output_flag_pos == m_arguments.end ()) {
69
- m_logger->log (" Missing arguments. Expecting `-Fo {filename}` or `-Fc {filename}`." , ILogger::ELL_ERROR);
64
+ auto split = [&](const std::string& str, char delim)
65
+ {
66
+ std::vector<std::string> strings;
67
+ size_t start, end = 0 ;
68
+
69
+ while ((start = str.find_first_not_of (delim, end)) != std::string::npos)
70
+ {
71
+ end = str.find (delim, start);
72
+ strings.push_back (str.substr (start, end - start));
73
+ }
74
+
75
+ return strings;
76
+ };
77
+
78
+ auto findOutputFlag = [&](const std::string_view& outputFlag)
79
+ {
80
+ return std::find_if (m_arguments.begin (), m_arguments.end (), [&](const std::string& argument)
81
+ {
82
+ return argument.find (outputFlag.data ()) != std::string::npos;
83
+ });
84
+ };
85
+
86
+ auto output_flag_pos = findOutputFlag (" -Fc" );
87
+
88
+ if (output_flag_pos == m_arguments.end ())
89
+ {
90
+ m_logger->log (" Missing arguments. Expecting `-Fc {filename}`." , ILogger::ELL_ERROR);
70
91
return false ;
71
92
}
72
-
73
- if (output_flag_pos + 1 != m_arguments.end ()) {
74
- output_filepath = *(output_flag_pos + 1 );
93
+ else
94
+ {
95
+ // we need to assume -Fc may be passed with output file name quoted together with "", so we split it (DXC does it)
96
+ const auto & outpufFlag = *output_flag_pos;
97
+ auto outputFlagVector = split (outpufFlag, ' ' );
98
+
99
+ if (outpufFlag == " -Fc" )
100
+ {
101
+ if (output_flag_pos + 1 != m_arguments.end ())
102
+ {
103
+ output_filepath = *(output_flag_pos + 1 );
104
+ }
105
+ else
106
+ {
107
+ m_logger->log (" Incorrect arguments. Expecting filename after -Fc." , ILogger::ELL_ERROR);
108
+ return false ;
109
+ }
110
+ }
111
+ else
112
+ {
113
+ output_filepath = outputFlagVector[1 ];
114
+ }
115
+
75
116
m_logger->log (" Compiled shader code will be saved to " + output_filepath);
76
- m_arguments.erase (output_flag_pos, output_flag_pos+1 );
77
- }
78
- else {
79
- m_logger->log (" Incorrect arguments. Expecting filename after -Fo or -Fc." , ILogger::ELL_ERROR);
80
- return false ;
81
117
}
82
118
83
119
#ifndef NBL_EMBED_BUILTIN_RESOURCES
0 commit comments