Skip to content

Commit

Permalink
Fix Windows Store build
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslo committed Mar 26, 2018
1 parent 840cb86 commit 5dcec59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
19 changes: 11 additions & 8 deletions libtiff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
13 changes: 10 additions & 3 deletions libtiff/tif_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "tiffiop.h"

#include <windows.h>
#include <stdlib.h> // abort

static tmsize_t
_tiffReadProc(thandle_t fd, void* buf, tmsize_t size)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 5dcec59

Please sign in to comment.