Created
June 4, 2024 13:23
-
-
Save Shauren/bb87af9e0c8a1dcee9c10279afffc77e to your computer and use it in GitHub Desktop.
casclib unicode mismatch detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
index 3d66ed2..b7d8c48 100644 | |
--- a/CMakeLists.txt | |
+++ b/CMakeLists.txt | |
@@ -126,6 +126,8 @@ if(CASC_BUILD_SHARED_LIB) | |
# On Win32, build CascLib.dll | |
if(WIN32) | |
set_target_properties(casc PROPERTIES OUTPUT_NAME CascLib) | |
+ add_library(casc_check_unicode OBJECT src/CascCheckUnicode.cpp) | |
+ add_custom_command(TARGET casc POST_BUILD COMMAND "${CMAKE_AR}" $<TARGET_IMPORT_FILE:casc> $<TARGET_OBJECTS:casc_check_unicode>) | |
endif() | |
target_compile_definitions(casc PUBLIC CASCLIB_NO_AUTO_LINK_LIBRARY CASCLIB_NODEBUG) | |
endif() | |
diff --git a/src/CascCheckUnicode.cpp b/src/CascCheckUnicode.cpp | |
new file mode 100644 | |
index 0000000..a487f0c | |
--- /dev/null | |
+++ b/src/CascCheckUnicode.cpp | |
@@ -0,0 +1,4 @@ | |
+#define __CASCLIB_SELF__ | |
+#include "CascLib.h" | |
+ | |
+extern "C" int casclib_unicode_mismatch_check = 0; | |
diff --git a/src/CascLib.h b/src/CascLib.h | |
index 6936c05..30492fb 100644 | |
--- a/src/CascLib.h | |
+++ b/src/CascLib.h | |
@@ -19,6 +19,17 @@ | |
#ifdef _MSC_VER | |
#pragma warning(disable:4668) // 'XXX' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' | |
#pragma warning(disable:4820) // 'XXX' : '2' bytes padding added after data member 'XXX::yyy' | |
+ | |
+#ifdef _UNICODE | |
+#pragma detect_mismatch("CASCLIB_UNICODE", "1") | |
+#else | |
+#pragma detect_mismatch("CASCLIB_UNICODE", "0") | |
+#endif | |
+ | |
+#ifndef __CASCLIB_SELF__ | |
+#pragma comment( linker, "/INCLUDE:casclib_unicode_mismatch_check") | |
+#endif | |
+ | |
#endif | |
#include "CascPort.h" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment