Skip to content

Commit

Permalink
enable private RapidJSON-download & improvements to CMake (#72)
Browse files Browse the repository at this point in the history
* clang-tidy fixes

* cosmetic

* add option "LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_RAPIDJSON", fix libCURL configuration

* update

* this seems to work ok - Mingw build is now fine

* update

* cosmetic

* cosmetic

* bump version

* Update Src/CZICmd/CMakeLists.txt

Co-authored-by: DaveyJonesBitPail <[email protected]>

* Update Src/CZICmd/CMakeLists.txt

Co-authored-by: DaveyJonesBitPail <[email protected]>

* language

---------

Co-authored-by: DaveyJonesBitPail <[email protected]>
  • Loading branch information
ptahmose and DaveyJonesBitPail authored Nov 3, 2023
1 parent 069e621 commit 8cb7ac3
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 36 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW) # enable new "MSVC runtime library selection" (https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html)

project(libCZI
VERSION 0.54.0
VERSION 0.54.1
HOMEPAGE_URL "https://github.com/ZEISS/libczi"
DESCRIPTION "libCZI is an Open Source Cross-Platform C++ library to read and write CZI")

Expand Down Expand Up @@ -105,6 +105,10 @@ option(LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_EIGEN3 "Prefer an Eigen3-package pres
# See here: https://discourse.cmake.org/t/findzstd/3506
option(LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_ZSTD "Prefer a ZSTD-package present on the system" OFF)

# When this option is ON, we try to use an existing RapidJSON-library. Otherwise, we download a private
# copy of RapidJSON during the CMake-run. This option is only relevant if building CZICmd.
option(LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_RAPIDJSON "Prefer an RapidJSON-package present on the system" ON)

if (LIBCZI_BUILD_UNITTESTS)
include (CTest)
enable_testing()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ libCZI is an Open Source Cross-Platform C++ library to read and write [CZI](http
libCZI is a library intended for providing read and write access to [CZI](https://www.zeiss.com/microscopy/en/products/software/zeiss-zen/czi-image-file-format.html) featuring:

* reading subblocks and get the content as a bitmap
* reading subblocks which are compressed with JPEG-XR
* reading subblocks which are compressed with JPEG-XR or zstd
* works with tiled images and pyramid images
* composing multi-channel images with tinting and applying a gradation curve
* access metadata
Expand Down
13 changes: 6 additions & 7 deletions Src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ if (LIBCZI_BUILD_CURL_BASED_STREAM)
GIT_TAG "curl-8_4_0"
# Set the prefix to control where it's installed
PREFIX "${CMAKE_BINARY_DIR}/vendor/curl"
# Pass CMake arguments to build curl as a static library
# for possible options -> c.f https://github.com/curl/curl/blob/master/CMakeLists.txt
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF
-DBUILD_STATIC_LIBS=ON
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/curl
-DENABLE_UNICODE=ON
)

# configure libcurl-build as a static library, for possible options -> c.f. https://github.com/curl/curl/blob/master/CMakeLists.txt
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "" FORCE)
set(ENABLE_UNICODE ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(libcurl)
endif(LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_LIBCURL)
endif(LIBCZI_BUILD_CURL_BASED_STREAM)
Expand Down
4 changes: 2 additions & 2 deletions Src/CZICmd/BitmapGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ using namespace libCZI;
{
{ "null", "creating just black images" },
#if CZICMD_USE_GDIPLUS == 1
{ "gdi", "based on GDI+, providing text-rendering" },
{ "gdi", "based on GDI+, provides text-rendering" },
#endif
#if CZICMD_USE_FREETYPE == 1
{ "freetype", "based on the Freetype-library providing text-rendering" },
{ "freetype", "based on the Freetype-library, provides text-rendering" },
#endif
};

Expand Down
4 changes: 1 addition & 3 deletions Src/CZICmd/BitmapGenGdiplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <gdiplus.h>

using namespace Gdiplus;
#pragma comment (lib, "gdiplus.lib")

using namespace std;
using namespace libCZI;

Expand Down Expand Up @@ -116,7 +114,7 @@ CBitmapGenGdiplus::CBitmapGenGdiplus(const IBitmapGenParameters* params) : fonth
pxlFmt = PixelFormat24bppRGB;
break;
default:
throw std::exception("unsupported pixelformat");
throw std::runtime_error("unsupported pixelformat");
}

shared_ptr<Bitmap> bitmap = make_shared<Bitmap>(width, height, pxlFmt);
Expand Down
45 changes: 35 additions & 10 deletions Src/CZICmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,44 @@ IF(UNIX)
ENDIF()
ENDIF(UNIX)

find_package(RapidJSON QUIET)
IF (NOT RapidJSON_FOUND)
message(FATAL_ERROR [=[
RapidJSON library was not found, which is required for building. Consider installing
like 'sudo apt-get install rapidjson-dev'.
]=])
ENDIF()

include(FetchContent)

if (LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_RAPIDJSON)
find_package(RapidJSON QUIET)
if (NOT RapidJSON_FOUND)
message(FATAL_ERROR [=[
RapidJSON library was not found, which is required for building. Consider installing
like 'sudo apt-get install rapidjson-dev'. Alternatively, consider setting the option
LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_RAPIDJSON to OFF in order to download and build RapidJSON
automatically as part of the build process.
]=])
endif()
else()
# since "RapidJSON" is a header-only library, we just have to download it and point to the include directory
FetchContent_Declare(
RapidJSON
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
GIT_TAG "v1.1.0"
GIT_SHALLOW TRUE
PREFIX "${CMAKE_BINARY_DIR}/vendor/rapidjson"
)

if (NOT rapidjson_POPULATED)
FetchContent_Populate(RapidJSON)
set(RAPIDJSON_INCLUDE_DIRS ${rapidjson_SOURCE_DIR}/include)
endif()
endif()

# make "CLI11" available
FetchContent_Declare(
cli11
GIT_REPOSITORY https://github.com/CLIUtils/CLI11
GIT_TAG v2.2.0
)
FetchContent_MakeAvailable(cli11)

if (NOT cli11_POPULATED)
FetchContent_MakeAvailable(cli11)
endif()

set (CZICMDSRCFILES
BitmapGen.cpp
Expand Down Expand Up @@ -81,7 +102,11 @@ set_target_properties(CZIcmd PROPERTIES CXX_STANDARD 11)
target_compile_definitions(CZIcmd PRIVATE _LIBCZISTATICLIB)

target_link_libraries(CZIcmd PRIVATE ${ZLIB_LIBRARIES} ${PNG_LIBRARIES} CLI11::CLI11 libCZIStatic)
target_include_directories(CZIcmd PRIVATE ${CMAKE_CURRENT_BINARY_DIR} "${RAPIDJSON_INCLUDE_DIRS}")
target_include_directories(CZIcmd PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${RAPIDJSON_INCLUDE_DIRS})

IF(WIN32)
target_link_libraries(CZIcmd PRIVATE gdiplus Windowscodecs)
ENDIF()

IF (FREETYPE_FOUND)
target_compile_definitions(CZIcmd PRIVATE _USE_FREETYPE)
Expand Down
2 changes: 0 additions & 2 deletions Src/CZICmd/SaveBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <memory>
#include <wincodec.h>

#pragma comment(lib, "Windowscodecs.lib")

using namespace std;

struct COMDeleter
Expand Down
2 changes: 1 addition & 1 deletion Src/CZICmd/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ class CExecuteExtractAttachment : CExecuteBase
std::ofstream output;
output.exceptions(std::ifstream::badbit | std::ifstream::failbit);
#if defined(WIN32ENV)
output.open(filename, ios::out | ios::binary);
output.open(filename.c_str(), ios::out | ios::binary);
#endif
#if defined(LINUXENV)
output.open(convertToUtf8(filename), ios::out | ios::binary);
Expand Down
11 changes: 5 additions & 6 deletions Src/CZICmd/platform_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#pragma once

#if defined(_WIN32)
// this means that the Win32-API is available, and the Windows-SDK is available
#define WIN32ENV (1)
#endif

#if defined(__GNUC__)
#define LINUXENV (1)
// this means that the Win32-API is available, and the Windows-SDK is available
#define WIN32ENV (1)
#else
// otherwise, we assume that we are on Linux
#define LINUXENV (1)
#endif
1 change: 0 additions & 1 deletion Src/CZICmd/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#if defined(WIN32ENV)
#define HAS_CODECVT
#define NOMINMAX
#include <Windows.h>
#endif

Expand Down
4 changes: 2 additions & 2 deletions Src/libCZI/StreamsLib/windowsfileinputstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "windowsfileinputstream.h"

#if defined(_WIN32)
#include <intsafe.h>
#include <limits>
#include <iomanip>
#include "../utilities.h"

Expand Down Expand Up @@ -38,7 +38,7 @@ WindowsFileInputStream::~WindowsFileInputStream()

void WindowsFileInputStream::Read(std::uint64_t offset, void* pv, std::uint64_t size, std::uint64_t* ptrBytesRead)
{
if (size > DWORD_MAX)
if (size > (std::numeric_limits<DWORD>::max)())
{
throw std::runtime_error("size is too large");
}
Expand Down

0 comments on commit 8cb7ac3

Please sign in to comment.