diff --git a/ciolib/CMakeLists.txt b/ciolib/CMakeLists.txt
index ede224bb545d662964cf9f41d849a56008f7c0af..69153878d55ba8a8440c4b2562e10064f15e0b36 100644
--- a/ciolib/CMakeLists.txt
+++ b/ciolib/CMakeLists.txt
@@ -53,14 +53,16 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
 endif()
 
 if(X11_FOUND)
-	list(APPEND SOURCE x_events.c x_cio.c scale.c)
+	list(APPEND SOURCE x_events.c x_cio.c)
 	set(NEED_BITMAP TRUE)
 	set(NEED_DLOPEN TRUE)
+	set(NEED_SCALE TRUE)
 endif()
 
-if(SDL2_FOUND)
+if(SDL2_INCLUDE_DIRS)
 	list(APPEND SOURCE sdl_con.c)
 	list(APPEND SOURCE sdlfuncs.c)
+	set(NEED_SCALE TRUE)
 	if(WIN32)
 		list(APPEND SOURCE SDL_win32_main.c)
 	endif()
@@ -75,6 +77,10 @@ if(NEED_BITMAP)
 	list(APPEND SOURCE bitmap_con.c)
 endif()
 
+if(NEED_SCALE)
+	list(APPEND SOURCE scale.c)
+endif()
+
 add_library(ciolib OBJECT ${SOURCE})
 target_include_directories(ciolib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
 
@@ -84,8 +90,8 @@ else()
 	target_compile_definitions(ciolib PRIVATE NO_X)
 endif()
 
-if(SDL2_FOUND)
-	target_include_directories(ciolib PRIVATE ${SDL2_INCLUDE_DIRS})
+if(SDL2_INCLUDE_DIRS)
+	target_include_directories(ciolib PUBLIC ${SDL2_INCLUDE_DIRS})
 	set(WITH_SDL TRUE PARENT_SCOPE)
 endif()
 
diff --git a/xpdev/datewrap.c b/xpdev/datewrap.c
index 3c2e9168e366bacd34537a0a2f555296bd6307c7..5f3759e676c353a193e3e1f97b90a82884a4c06b 100644
--- a/xpdev/datewrap.c
+++ b/xpdev/datewrap.c
@@ -114,6 +114,7 @@ struct tm* localtime32(const time32_t* t32, struct tm* tm)
 
 #if defined(_WIN32)
 	#include <windows.h>	/* SYSTEMTIME and GetLocalTime() */
+	#include <time.h>	/* _mkgmtime */
 #else
 	#include <sys/time.h>	/* stuct timeval, gettimeofday() */
 #endif
diff --git a/xpdev/datewrap.h b/xpdev/datewrap.h
index c57cd9447f357a5cb0ff3cae2f564b353970bebd..843de233ce0894272f0bb0e4603d9d2ae78bf437 100644
--- a/xpdev/datewrap.h
+++ b/xpdev/datewrap.h
@@ -57,7 +57,7 @@ DLLEXPORT struct tm*	localtime32(const time32_t* t, struct tm* tm);
 
 /* Microsoft's equivalent of GLIBC/BSD timegm() */
 #if defined(_MSC_VER) || defined(__MINGW32__)
-	#define timegm _mkgmtime
+	#define timegm _mkgmtime32
 #endif
 
 /***********************************/