From bab462bb4b525118c34f5d80c3bf272d1fdde339 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 31 Jul 2021 19:52:40 -0400 Subject: [PATCH] Build standalone adapter directly from .cpp file instead of via .o files. Add unicode wmain() wrapper for main() function on Windows. --- Makefile | 9 ++++----- adapters/standalone.cpp | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index eab75137..db224cf1 100644 --- a/Makefile +++ b/Makefile @@ -84,12 +84,11 @@ include compile.mk ifdef ARCH_MAC STANDALONE_LDFLAGS += $(MAC_SDK_FLAGS) endif -STANDALONE_OBJECTS += $(patsubst %, build/%.o, $(STANDALONE_SOURCES)) -STANDALONE_DEPENDENCIES := $(patsubst %, build/%.d, $(STANDALONE_SOURCES)) +STANDALONE_OBJECTS += $(TARGET) -include $(STANDALONE_DEPENDENCIES) -$(STANDALONE_TARGET): $(STANDALONE_OBJECTS) $(TARGET) - $(CXX) -o $@ $^ $(STANDALONE_LDFLAGS) +$(STANDALONE_TARGET): $(STANDALONE_OBJECTS) $(STANDALONE_SOURCES) + $(CXX) $(CXXFLAGS) -o $@ $^ $(STANDALONE_LDFLAGS) # Convenience targets @@ -131,7 +130,7 @@ valgrind: $(STANDALONE_TARGET) valgrind --suppressions=valgrind.supp ./$< -d clean: - rm -rfv $(TARGET) $(STANDALONE_TARGET) libRack.dll.a Rack.res build dist + rm -rfv $(TARGET) $(STANDALONE_TARGET) libRack.dll.a Rack.res build dist *.d # For Windows resources diff --git a/adapters/standalone.cpp b/adapters/standalone.cpp index 277e09e3..cc67b057 100644 --- a/adapters/standalone.cpp +++ b/adapters/standalone.cpp @@ -56,7 +56,6 @@ static void fatalSignalHandler(int sig) { } -// TODO Use -municode on Windows and change this to wmain. Convert argv to UTF-8. int main(int argc, char* argv[]) { #if defined ARCH_WIN // Windows global mutex to prevent multiple instances @@ -258,3 +257,18 @@ int main(int argc, char* argv[]) { return 0; } + + +#ifdef UNICODE +/** UTF-16 to UTF-8 wrapper for Windows with unicode */ +int wmain(int argc, wchar_t* argvU16[]) { + // Initialize char* array with string-owned buffers + std::string argvStr[argc]; + const char* argvU8[argc]; + for (int i = 0; i < argc; i++) { + argvStr[i] = string::UTF16toUTF8(argvU16[i]); + argvU8[i] = argvStr[i].c_str(); + } + return main(argc, (char**) argvU8); +} +#endif