From 5dcec596c186c7689bcb901c4ed983f9520c639e Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Mon, 26 Mar 2018 19:05:17 +0300 Subject: [PATCH] Fix Windows Store build --- libtiff/CMakeLists.txt | 19 +++++++++++-------- libtiff/tif_win32.c | 13 ++++++++++--- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/libtiff/CMakeLists.txt b/libtiff/CMakeLists.txt index 91c9cb5..a74f66b 100755 --- a/libtiff/CMakeLists.txt +++ b/libtiff/CMakeLists.txt @@ -106,6 +106,17 @@ endif() add_library(libtiff ${lib_srcs}) target_link_libraries(libtiff PUBLIC ZLIB::zlib) +if("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore") + # Can't use MessageBoxA, GetFocus, GetFileSize, CreateFileA, CreateFileW + target_compile_definitions(libtiff PRIVATE TIFF_WINDOWS_STORE) +elseif(MSVC) + # MessageBoxA, GetFocus + target_link_libraries(libtiff PUBLIC User32) + + # GetFileSize, CreateFileA, CreateFileW + target_link_libraries(libtiff PUBLIC Kernel32) +endif() + # Some platforms (e.g. Linux) need separate math library check_library_exists(m pow "" LIB_M_REQUIRED) if(LIB_M_REQUIRED) @@ -120,14 +131,6 @@ if(ENABLE_SOLUTION_FOLDERS) set_target_properties(libtiff PROPERTIES FOLDER "3rdparty") endif() -if(MSVC) - # MessageBoxA, GetFocus - target_link_libraries(libtiff PUBLIC User32) - - # GetFileSize, CreateFileA, CreateFileW - target_link_libraries(libtiff PUBLIC Kernel32) -endif() - #### # Installation (https://github.com/forexample/package-example) diff --git a/libtiff/tif_win32.c b/libtiff/tif_win32.c index 73b8175..f855c9f 100755 --- a/libtiff/tif_win32.c +++ b/libtiff/tif_win32.c @@ -31,6 +31,7 @@ #include "tiffiop.h" #include +#include // abort static tmsize_t _tiffReadProc(thandle_t fd, void* buf, tmsize_t size) @@ -128,9 +129,15 @@ _tiffCloseProc(thandle_t fd) static uint64 _tiffSizeProc(thandle_t fd) { +#if defined(TIFF_WINDOWS_STORE) + // GetFileSize is not available, + // user should inject his own version of tiffSizeProc + abort(); +#else ULARGE_INTEGER m; m.LowPart=GetFileSize(fd,&m.HighPart); return(m.QuadPart); +#endif } static int @@ -224,7 +231,7 @@ TIFFFdOpen(int ifd, const char* name, const char* mode) return (tif); } -#ifndef _WIN32_WCE +#if !defined(_WIN32_WCE) && !defined(TIFF_WINDOWS_STORE) /* * Open a TIFF file for read/writing. @@ -371,7 +378,7 @@ _TIFFmemcmp(const void* p1, const void* p2, tmsize_t c) static void Win32WarningHandler(const char* module, const char* fmt, va_list ap) { -#ifndef TIF_PLATFORM_CONSOLE +#if !defined(TIF_PLATFORM_CONSOLE) && !defined(TIFF_WINDOWS_STORE) LPTSTR szTitle; LPTSTR szTmp; LPCTSTR szTitleText = "%s Warning"; @@ -402,7 +409,7 @@ TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler; static void Win32ErrorHandler(const char* module, const char* fmt, va_list ap) { -#ifndef TIF_PLATFORM_CONSOLE +#if !defined(TIF_PLATFORM_CONSOLE) && !defined(TIFF_WINDOWS_STORE) LPTSTR szTitle; LPTSTR szTmp; LPCTSTR szTitleText = "%s Error";