Fix switch build

This commit is contained in:
Benau 2022-03-17 13:52:46 +08:00
parent f01959de8b
commit 38a553513c
4 changed files with 16 additions and 6 deletions

View File

@ -1465,7 +1465,7 @@ void CompileAndLinkShaderFiles(glslang::TWorklist& Worklist)
ShaderCompUnit compUnit(FindLanguage("stdin")); ShaderCompUnit compUnit(FindLanguage("stdin"));
std::istreambuf_iterator<char> begin(std::cin), end; std::istreambuf_iterator<char> begin(std::cin), end;
std::string tempString(begin, end); std::string tempString(begin, end);
char* fileText = strdup(tempString.c_str()); char* fileText = __Strdup(tempString.c_str());
std::string fileName = "stdin"; std::string fileName = "stdin";
compUnit.addString(fileName, fileText); compUnit.addString(fileName, fileText);
compUnits.push_back(compUnit); compUnits.push_back(compUnit);
@ -1721,7 +1721,7 @@ void CompileFile(const char* fileName, ShHandle compiler)
if ((Options & EOptionStdin) != 0) { if ((Options & EOptionStdin) != 0) {
std::istreambuf_iterator<char> begin(std::cin), end; std::istreambuf_iterator<char> begin(std::cin), end;
std::string tempString(begin, end); std::string tempString(begin, end);
shaderString = strdup(tempString.c_str()); shaderString = __Strdup(tempString.c_str());
} else { } else {
shaderString = ReadFileData(fileName); shaderString = ReadFileData(fileName);
} }

View File

@ -33,7 +33,7 @@
if(WIN32) if(WIN32)
add_subdirectory(OSDependent/Windows) add_subdirectory(OSDependent/Windows)
elseif(UNIX OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia") elseif(UNIX OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoSwitch")
add_subdirectory(OSDependent/Unix) add_subdirectory(OSDependent/Unix)
else() else()
message("unknown platform") message("unknown platform")

View File

@ -46,6 +46,7 @@
#endif #endif
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring>
#include <list> #include <list>
#include <map> #include <map>
#include <set> #include <set>
@ -98,9 +99,15 @@ std::string to_string(const T& val) {
} }
#endif #endif
#if defined(_MSC_VER) inline char* __Strdup(const char* s)
#define strdup _strdup {
#endif size_t slen = strlen(s);
char* result = (char*)malloc(slen + 1);
if (result == NULL)
return NULL;
memcpy(result, s, slen + 1);
return result;
}
/* windows only pragma */ /* windows only pragma */
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@ -39,6 +39,9 @@ option(SPIRV_ALLOW_TIMERS "Allow timers via clock_gettime on supported platforms
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
add_definitions(-DSPIRV_LINUX) add_definitions(-DSPIRV_LINUX)
set(SPIRV_TIMER_ENABLED ${SPIRV_ALLOW_TIMERS}) set(SPIRV_TIMER_ENABLED ${SPIRV_ALLOW_TIMERS})
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoSwitch")
# STK addition treat it as linux, SPIRV_LINUX is used in source/print.cpp:17 only
add_definitions(-DSPIRV_LINUX)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten") elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
add_definitions(-DSPIRV_EMSCRIPTEN) add_definitions(-DSPIRV_EMSCRIPTEN)
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Windows") elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")