From 07f98f173725395720f48360e21f6a0d1e7b0fc8 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 23 Jun 2023 15:23:14 +0200 Subject: [PATCH] (Windows) Made es-pdf-convert build with MinGW --- es-pdf-converter/CMakeLists.txt | 11 ++++++++--- es-pdf-converter/src/main.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/es-pdf-converter/CMakeLists.txt b/es-pdf-converter/CMakeLists.txt index ce0b6425a..87556008d 100644 --- a/es-pdf-converter/CMakeLists.txt +++ b/es-pdf-converter/CMakeLists.txt @@ -9,9 +9,14 @@ project(es-pdf-convert) if(WIN32) - set(POPPLER_CPP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../external/poppler-23.05.0/Library/include/poppler/cpp) - set(POPPLER_CPP_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/poppler-cpp.lib) - else() + set(POPPLER_CPP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../external/poppler/Library/include/poppler/cpp) + if(CMAKE_CXX_COMPILER_ID MATCHES MSVC) + set(POPPLER_CPP_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/poppler-cpp.lib) + else() + set(POPPLER_CPP_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/libpoppler-cpp-0.dll) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -municode") + endif() +else() find_package(Poppler REQUIRED COMPONENTS cpp) endif() diff --git a/es-pdf-converter/src/main.cpp b/es-pdf-converter/src/main.cpp index e6fcec3cd..f171933b6 100644 --- a/es-pdf-converter/src/main.cpp +++ b/es-pdf-converter/src/main.cpp @@ -25,8 +25,15 @@ #include #include +#if defined(_MSC_VER) // MSVC compiler. int wmain(int argc, wchar_t* argv[]) { +#else +int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) +{ + wchar_t** argv {__wargv}; + int argc = __argc; +#endif HANDLE stdoutHandle {GetStdHandle(STD_OUTPUT_HANDLE)}; if (stdoutHandle == INVALID_HANDLE_VALUE) { @@ -111,7 +118,7 @@ int main(int argc, char* argv[]) std::ifstream file; - file.open(path, std::ifstream::binary); + file.open(path.c_str(), std::ifstream::binary); if (file.fail()) { std::cerr << "Error: Couldn't open PDF file, permission problems?" << std::endl; exit(-1);