diff --git a/Src/libCZI/CMakeLists.txt b/Src/libCZI/CMakeLists.txt index 46c33ab0..64ddf9a2 100644 --- a/Src/libCZI/CMakeLists.txt +++ b/Src/libCZI/CMakeLists.txt @@ -259,6 +259,14 @@ else() endif() endif() +if (WIN32 OR CYGWIN OR MSYS OR MINGW) + set(libCZI_WINDOWSAPIAVAILABLE 1) + message(STATUS "*********** Windows-API available WIN32 is true ***********") +else() + set(libCZI_WINDOWSAPIAVAILABLE 0) + message(STATUS "*********** Windows-API NOT available WIN32 is false ***********") +endif() + configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/libCZI_Config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/libCZI_Config.h" @@ -304,6 +312,9 @@ if (LIBCZI_BUILD_DYNLIB) IF(UNIX) target_compile_options(libCZI PRIVATE -D_FILE_OFFSET_BITS=64) ENDIF(UNIX) + if( libCZI_WINDOWSAPIAVAILABLE) + target_link_libraries(libCZI PRIVATE ole32 Windowscodecs) + endif() endif(LIBCZI_BUILD_DYNLIB) # @@ -342,7 +353,9 @@ IF(UNIX) target_compile_options(libCZIStatic PRIVATE -D_FILE_OFFSET_BITS=64) set_property(TARGET libCZIStatic PROPERTY POSITION_INDEPENDENT_CODE ON) ENDIF(UNIX) - +if( libCZI_WINDOWSAPIAVAILABLE) + target_link_libraries(libCZIStatic PUBLIC ole32 Windowscodecs) +endif() # # Notes: - the variables CMAKE_INSTALL_<...> have been defined in the module "GNUInstallDirs" diff --git a/Src/libCZI/StreamImpl.cpp b/Src/libCZI/StreamImpl.cpp index f99e4d92..df2ae07e 100644 --- a/Src/libCZI/StreamImpl.cpp +++ b/Src/libCZI/StreamImpl.cpp @@ -72,7 +72,7 @@ COutputStreamImplPwrite::~COutputStreamImplPwrite() //---------------------------------------------------------------------------- -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE CSimpleOutputStreamImplWindows::CSimpleOutputStreamImplWindows(const wchar_t* filename, bool overwriteExisting) : handle(INVALID_HANDLE_VALUE) @@ -316,7 +316,7 @@ CInputOutputStreamImplPreadPwrite::~CInputOutputStreamImplPreadPwrite() //----------------------------------------------------------------------------- -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE CSimpleInputOutputStreamImplWindows::CSimpleInputOutputStreamImplWindows(const wchar_t* filename) : handle(INVALID_HANDLE_VALUE) { diff --git a/Src/libCZI/StreamImpl.h b/Src/libCZI/StreamImpl.h index 6bce2b82..1ce6edff 100644 --- a/Src/libCZI/StreamImpl.h +++ b/Src/libCZI/StreamImpl.h @@ -4,11 +4,11 @@ #pragma once -#include #include "libCZI.h" #include "inc_libCZI_Config.h" -#if defined(_WIN32) - #include +#include +#if LIBCZI_WINDOWSAPI_AVAILABLE +#include #endif /// A simplistic output-stream implementation (based on C-runtime fopen). Note that this implementation is NOT thread-safe. @@ -40,7 +40,7 @@ class COutputStreamImplPwrite : public libCZI::IOutputStream }; #endif -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE class CSimpleOutputStreamImplWindows : public libCZI::IOutputStream { @@ -84,7 +84,7 @@ class CInputOutputStreamImplPreadPwrite : public libCZI::IInputOutputStream }; #endif -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE class CSimpleInputOutputStreamImplWindows : public libCZI::IInputOutputStream { private: diff --git a/Src/libCZI/StreamsLib/windowsfileinputstream.cpp b/Src/libCZI/StreamsLib/windowsfileinputstream.cpp index 167c7ba3..059af9e8 100644 --- a/Src/libCZI/StreamsLib/windowsfileinputstream.cpp +++ b/Src/libCZI/StreamsLib/windowsfileinputstream.cpp @@ -4,7 +4,7 @@ #include "windowsfileinputstream.h" -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE #include #include #include "../utilities.h" diff --git a/Src/libCZI/StreamsLib/windowsfileinputstream.h b/Src/libCZI/StreamsLib/windowsfileinputstream.h index c01022b3..dc0da30f 100644 --- a/Src/libCZI/StreamsLib/windowsfileinputstream.h +++ b/Src/libCZI/StreamsLib/windowsfileinputstream.h @@ -5,7 +5,7 @@ #pragma once #include -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE #include #include "../libCZI.h" #include diff --git a/Src/libCZI/decoder_wic.cpp b/Src/libCZI/decoder_wic.cpp index 720343de..2d6d15b6 100644 --- a/Src/libCZI/decoder_wic.cpp +++ b/Src/libCZI/decoder_wic.cpp @@ -2,14 +2,15 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#if defined(_WIN32) #include "decoder_wic.h" + +#if LIBCZI_WINDOWSAPI_AVAILABLE #include "BitmapOperations.h" #include #include "Site.h" - -#pragma comment(lib, "Windowscodecs.lib") +// +//#pragma comment(lib, "Windowscodecs.lib") using namespace std; using namespace libCZI; diff --git a/Src/libCZI/decoder_wic.h b/Src/libCZI/decoder_wic.h index 11b0c62f..b18cd811 100644 --- a/Src/libCZI/decoder_wic.h +++ b/Src/libCZI/decoder_wic.h @@ -4,7 +4,9 @@ #pragma once -#if defined(_WIN32) +#include + +#if LIBCZI_WINDOWSAPI_AVAILABLE #include #include "libCZI_Pixels.h" diff --git a/Src/libCZI/libCZI.h b/Src/libCZI/libCZI.h index aa474830..48bca598 100644 --- a/Src/libCZI/libCZI.h +++ b/Src/libCZI/libCZI.h @@ -35,10 +35,8 @@ namespace libCZI enum class SiteObjectType { Default, ///< An enum constant representing the default option (which is JXRLib) - WithJxrDecoder ///< An enum constant representing a Site-object using the internal JXRLib. -#if defined(_WIN32) - , WithWICDecoder///< An enum constant representing a Site-object using the Windows WIC-codec. -#endif + WithJxrDecoder, ///< An enum constant representing a Site-object using the internal JXRLib. + WithWICDecoder, ///< An enum constant representing a Site-object using the Windows WIC-codec. }; class ISite; diff --git a/Src/libCZI/libCZI_Config.h.in b/Src/libCZI/libCZI_Config.h.in index dcc52aa2..e490e60a 100644 --- a/Src/libCZI/libCZI_Config.h.in +++ b/Src/libCZI/libCZI_Config.h.in @@ -10,6 +10,9 @@ #define LIBCZI_VERSION_PATCH "@libCZI_VERSION_PATCH@" #define LIBCZI_VERSION_TWEAK "@libCZI_VERSION_TWEAK@" +// whether the libCZI library is built with support for the Windows-API, i.e. whether it is being built for a Windows-environment +#define LIBCZI_WINDOWSAPI_AVAILABLE @libCZI_WINDOWSAPIAVAILABLE@ + // if the host system is a big-endian system, this is "1", otherwise 0 #define LIBCZI_ISBIGENDIANHOST @libCZI_ISBIGENDIANHOST@ diff --git a/Src/libCZI/libCZI_Site.cpp b/Src/libCZI/libCZI_Site.cpp index 5aa84264..de77a4c4 100644 --- a/Src/libCZI/libCZI_Site.cpp +++ b/Src/libCZI/libCZI_Site.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "libCZI.h" +#include "inc_libCZI_Config.h" #include "decoder.h" #include "decoder_zstd.h" #include @@ -37,7 +38,7 @@ class CSiteImpBase : public ISite } }; -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE class CSiteImpWic : public CSiteImpBase { private: @@ -139,7 +140,7 @@ class CSiteImpJxrLib : public CSiteImpBase } }; -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE static CSiteImpWic theWicSite; #endif static CSiteImpJxrLib theJxrLibSite; @@ -168,7 +169,7 @@ libCZI::ISite* libCZI::GetDefaultSiteObject(SiteObjectType type) { switch (type) { -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE case SiteObjectType::WithWICDecoder: return &theWicSite; #endif diff --git a/Src/libCZI/utilities.cpp b/Src/libCZI/utilities.cpp index fbb7c3e2..28d9538a 100644 --- a/Src/libCZI/utilities.cpp +++ b/Src/libCZI/utilities.cpp @@ -3,18 +3,17 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "utilities.h" +#include "inc_libCZI_Config.h" #include #include #include #include #include -#if !defined(_WIN32) -#include -#endif -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE #include +#else +#include #endif -#include "inc_libCZI_Config.h" #if LIBCZI_HAVE_ENDIAN_H #include "endian.h" #endif @@ -124,7 +123,7 @@ tString trimImpl(const tString& str, const tString& whitespace) /*static*/libCZI::GUID Utilities::GenerateNewGuid() { -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE ::GUID guid; CoCreateGuid(&guid); libCZI::GUID guid_value