<commit_before>diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..3eb6f89
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+include(flags OPTIONAL)
+add_subdirectory(cmake)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 33e069f..255443c 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -44,7 +44,21 @@ if (CMAKE_USE_PTHREADS_INIT)
   add_definitions(-DHAVE_PTHREAD)
 endif (CMAKE_USE_PTHREADS_INIT)
 
-if (MSVC)
+include(CheckLibraryExists)
+check_library_exists(rt sched_yield "${CMAKE_LIBRARY_PATH}" HAVE_LIBRT)
+if (HAVE_LIBRT)
+  set(SYSTEM_LIBRARIES rt)
+endif ()
+
+option(ZLIB_MODULE_PATH "Find zlib in CMAKE_MODULE_PATH" OFF)
+mark_as_advanced(ZLIB_MODULE_PATH)
+if (ZLIB_MODULE_PATH)
+  find_package(usexp-ZLIB REQUIRED PATHS ${CMAKE_MODULE_PATH} NO_DEFAULT_PATH)
+  if (ZLIB_FOUND)
+    set(HAVE_ZLIB 1)
+    set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRS})
+  endif (ZLIB_FOUND)
+elseif (MSVC)
   if (ZLIB)
     set(HAVE_ZLIB 1)
     find_path(ZLIB_INCLUDE_DIRECTORIES zlib.h ${protobuf_SOURCE_DIR})
@@ -52,7 +66,7 @@ if (MSVC)
   else (ZLIB)
     set(HAVE_ZLIB 0)
   endif (ZLIB)
-else (MSVC)
+else ()
   find_package(ZLIB)
   if (ZLIB_FOUND)
     set(HAVE_ZLIB 1)
@@ -63,7 +77,7 @@ else (MSVC)
     set(ZLIB_INCLUDE_DIRECTORIES)
     set(ZLIB_LIBRARIES)
   endif (ZLIB_FOUND)
-endif (MSVC)
+endif ()
 
 if (HAVE_ZLIB)
   add_definitions(-DHAVE_ZLIB)
diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake
index 9fafc31..c9aec56 100644
--- a/cmake/libprotobuf-lite.cmake
+++ b/cmake/libprotobuf-lite.cmake
@@ -25,7 +25,7 @@ set(libprotobuf_lite_files
 )
 
 add_library(libprotobuf-lite ${libprotobuf_lite_files})
-target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT} ${SYSTEM_LIBRARIES})
 target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src)
 set_target_properties(libprotobuf-lite PROPERTIES
     COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS
diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake
index 64a9cae..9d35a1b 100644
--- a/cmake/libprotobuf.cmake
+++ b/cmake/libprotobuf.cmake
@@ -54,7 +54,7 @@ set(libprotobuf_files
 )
 
 add_library(libprotobuf ${libprotobuf_lite_files} ${libprotobuf_files})
-target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES})
+target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${SYSTEM_LIBRARIES})
 target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src)
 set_target_properties(libprotobuf PROPERTIES
     COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS
diff --git a/cmake/protobuf-module.cmake.in b/cmake/protobuf-module.cmake.in
index d81dc45..5627d1f 100644
--- a/cmake/protobuf-module.cmake.in
+++ b/cmake/protobuf-module.cmake.in
@@ -25,7 +25,7 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
 
   # Add well-known type protos include path
   list(APPEND _protobuf_include_path
-    -I "${_PROTOBUF_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@")
+    -I "${PROTOBUF_INCLUDE_DIR}")
 
   if(DEFINED PROTOBUF_IMPORT_DIRS)
     foreach(DIR ${PROTOBUF_IMPORT_DIRS})
diff --git a/cmake/protoc.cmake b/cmake/protoc.cmake
index 4f07c38..2be9c39 100644
--- a/cmake/protoc.cmake
+++ b/cmake/protoc.cmake
@@ -4,3 +4,6 @@ set(protoc_files
 
 add_executable(protoc ${protoc_files})
 target_link_libraries(protoc libprotobuf libprotoc)
+set_target_properties(protoc PROPERTIES
+  DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}"
+)
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index 26a4f0b..175a398 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -47,6 +47,9 @@
 #include <errno.h>
 #include <iostream>
 #include <ctype.h>
+#ifdef __sun
+#include <limits.h>
+#endif
 
 #include <memory>
 #ifndef _SHARED_PTR_H
diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc
index 2f6416d..9a58678 100644
--- a/src/google/protobuf/message.cc
+++ b/src/google/protobuf/message.cc
@@ -495,11 +495,19 @@ Message* GenericTypeHandler<Message>::NewFromPrototype(
   return prototype->New(arena);
 }
 template<>
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
+GOOGLE_ATTRIBUTE_NOINLINE
+#endif
 google::protobuf::Arena* GenericTypeHandler<Message>::GetArena(
     Message* value) {
   return value->GetArena();
 }
 template<>
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
+GOOGLE_ATTRIBUTE_NOINLINE
+#endif
 void* GenericTypeHandler<Message>::GetMaybeArenaPointer(
     Message* value) {
   return value->GetMaybeArenaPointer();<commit_msg>protobuf patch: remove #define __BYTE_ORDER<commit_after>diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..3eb6f89
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+include(flags OPTIONAL)
+add_subdirectory(cmake)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 33e069f..255443c 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -44,7 +44,21 @@ if (CMAKE_USE_PTHREADS_INIT)
   add_definitions(-DHAVE_PTHREAD)
 endif (CMAKE_USE_PTHREADS_INIT)
 
-if (MSVC)
+include(CheckLibraryExists)
+check_library_exists(rt sched_yield "${CMAKE_LIBRARY_PATH}" HAVE_LIBRT)
+if (HAVE_LIBRT)
+  set(SYSTEM_LIBRARIES rt)
+endif ()
+
+option(ZLIB_MODULE_PATH "Find zlib in CMAKE_MODULE_PATH" OFF)
+mark_as_advanced(ZLIB_MODULE_PATH)
+if (ZLIB_MODULE_PATH)
+  find_package(usexp-ZLIB REQUIRED PATHS ${CMAKE_MODULE_PATH} NO_DEFAULT_PATH)
+  if (ZLIB_FOUND)
+    set(HAVE_ZLIB 1)
+    set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRS})
+  endif (ZLIB_FOUND)
+elseif (MSVC)
   if (ZLIB)
     set(HAVE_ZLIB 1)
     find_path(ZLIB_INCLUDE_DIRECTORIES zlib.h ${protobuf_SOURCE_DIR})
@@ -52,7 +66,7 @@ if (MSVC)
   else (ZLIB)
     set(HAVE_ZLIB 0)
   endif (ZLIB)
-else (MSVC)
+else ()
   find_package(ZLIB)
   if (ZLIB_FOUND)
     set(HAVE_ZLIB 1)
@@ -63,7 +77,7 @@ else (MSVC)
     set(ZLIB_INCLUDE_DIRECTORIES)
     set(ZLIB_LIBRARIES)
   endif (ZLIB_FOUND)
-endif (MSVC)
+endif ()
 
 if (HAVE_ZLIB)
   add_definitions(-DHAVE_ZLIB)
diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake
index 9fafc31..c9aec56 100644
--- a/cmake/libprotobuf-lite.cmake
+++ b/cmake/libprotobuf-lite.cmake
@@ -25,7 +25,7 @@ set(libprotobuf_lite_files
 )
 
 add_library(libprotobuf-lite ${libprotobuf_lite_files})
-target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT} ${SYSTEM_LIBRARIES})
 target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src)
 set_target_properties(libprotobuf-lite PROPERTIES
     COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS
diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake
index 64a9cae..9d35a1b 100644
--- a/cmake/libprotobuf.cmake
+++ b/cmake/libprotobuf.cmake
@@ -54,7 +54,7 @@ set(libprotobuf_files
 )
 
 add_library(libprotobuf ${libprotobuf_lite_files} ${libprotobuf_files})
-target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES})
+target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${SYSTEM_LIBRARIES})
 target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src)
 set_target_properties(libprotobuf PROPERTIES
     COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS
diff --git a/cmake/protobuf-module.cmake.in b/cmake/protobuf-module.cmake.in
index d81dc45..5627d1f 100644
--- a/cmake/protobuf-module.cmake.in
+++ b/cmake/protobuf-module.cmake.in
@@ -25,7 +25,7 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
 
   # Add well-known type protos include path
   list(APPEND _protobuf_include_path
-    -I "${_PROTOBUF_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@")
+    -I "${PROTOBUF_INCLUDE_DIR}")
 
   if(DEFINED PROTOBUF_IMPORT_DIRS)
     foreach(DIR ${PROTOBUF_IMPORT_DIRS})
diff --git a/cmake/protoc.cmake b/cmake/protoc.cmake
index 4f07c38..2be9c39 100644
--- a/cmake/protoc.cmake
+++ b/cmake/protoc.cmake
@@ -4,3 +4,6 @@ set(protoc_files
 
 add_executable(protoc ${protoc_files})
 target_link_libraries(protoc libprotobuf libprotoc)
+set_target_properties(protoc PROPERTIES
+  DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}"
+)
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index 26a4f0b..175a398 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -47,6 +47,9 @@
 #include <errno.h>
 #include <iostream>
 #include <ctype.h>
+#ifdef __sun
+#include <limits.h>
+#endif
 
 #include <memory>
 #ifndef _SHARED_PTR_H
diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc
index 2f6416d..9a58678 100644
--- a/src/google/protobuf/message.cc
+++ b/src/google/protobuf/message.cc
@@ -495,11 +495,19 @@ Message* GenericTypeHandler<Message>::NewFromPrototype(
   return prototype->New(arena);
 }
 template<>
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
+GOOGLE_ATTRIBUTE_NOINLINE
+#endif
 google::protobuf::Arena* GenericTypeHandler<Message>::GetArena(
     Message* value) {
   return value->GetArena();
 }
 template<>
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
+GOOGLE_ATTRIBUTE_NOINLINE
+#endif
 void* GenericTypeHandler<Message>::GetMaybeArenaPointer(
     Message* value) {
   return value->GetMaybeArenaPointer();
diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h
index 9ea34cd..eebe9d7 100644
--- a/src/google/protobuf/stubs/port.h
+++ b/src/google/protobuf/stubs/port.h
@@ -267,11 +267,9 @@ inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) {
 #define GOOGLE_THREAD_LOCAL __thread
 #endif
 
-// The following guarantees declaration of the byte swap functions, and
-// defines __BYTE_ORDER for MSVC
+// The following guarantees declaration of the byte swap functions.
 #ifdef _MSC_VER
 #include <stdlib.h>  // NOLINT(build/include)
-#define __BYTE_ORDER __LITTLE_ENDIAN
 #define bswap_16(x) _byteswap_ushort(x)
 #define bswap_32(x) _byteswap_ulong(x)
 #define bswap_64(x) _byteswap_uint64(x)
{'fraction_non_alphanumeric': 0.13155886281244036, 'fraction_numerical': 0.04331234497233352, 'mean_word_length': 5.491021671826625, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1965400', 'n_tokens_mistral': 4457, 'n_tokens_neox': 3970, 'n_words': 674}