Skip to content

Commit

Permalink
Refactor: Remove precompiled headers and update CMake
Browse files Browse the repository at this point in the history
Removed `stdafx.h` includes from multiple source files and deleted `stdafx.cpp`, `stdafx.h`, `targetver.h`, and `platform_defines.h`. Updated `CMakeLists.txt` to replace platform-specific checks with `LIBCZI_HAVE_WIN32_API` and set `CZICMD_WINDOWSAPIAVAILABLE` accordingly. Adjusted `CMakeLists.txt` to conditionally link Windows libraries and updated the `RapidJSON` Git tag. Replaced platform-specific macros with `CZICMD_WINDOWSAPI_AVAILABLE` in various source files. Added necessary includes to `consoleio.h`. Removed `#pragma once` and other preprocessor directives from multiple files.
  • Loading branch information
ptahmose committed Sep 20, 2024
1 parent d3cba5d commit ca5c619
Show file tree
Hide file tree
Showing 25 changed files with 38 additions and 120 deletions.
2 changes: 0 additions & 2 deletions Src/CZICmd/BitmapGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"

#include "IBitmapGen.h"
#include "BitmapGenGdiplus.h"
#include "BitmapGenNull.h"
Expand Down
1 change: 0 additions & 1 deletion Src/CZICmd/BitmapGenFreeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include "inc_CZIcmd_Config.h"

#if CZICMD_USE_FREETYPE == 1
Expand Down
1 change: 0 additions & 1 deletion Src/CZICmd/BitmapGenGdiplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include "BitmapGenGdiplus.h"
#include "BitmapGenNull.h"
#include "utils.h"
Expand Down
1 change: 0 additions & 1 deletion Src/CZICmd/BitmapGenNull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include "BitmapGenNull.h"
#include "utils.h"
#include "inc_libCZI.h"
Expand Down
22 changes: 10 additions & 12 deletions Src/CZICmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: LGPL-3.0-or-later

IF(UNIX)
IF(NOT LIBCZI_HAVE_WIN32_API)
find_package(ZLIB QUIET)
if (NOT ZLIB_FOUND)
message(FATAL_ERROR [=[
Expand All @@ -24,7 +24,7 @@ IF(UNIX)
message("** FreeType was not found, CZICmd with the option \"CreateCZI\" will create only empty images.")
message(" (consider installing FreeType with e.g. 'sudo apt-get install libfreetype6-dev')")
ENDIF()
ENDIF(UNIX)
ENDIF()

include(FetchContent)

Expand All @@ -43,7 +43,7 @@ else()
FetchContent_Declare(
RapidJSON
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
GIT_TAG "v1.1.0"
GIT_TAG 7c73dd7de7c4f14379b781418c6e947ad464c818 # master as of 2024-08-16
GIT_SHALLOW TRUE
PREFIX "${CMAKE_BINARY_DIR}/vendor/rapidjson"
)
Expand All @@ -68,7 +68,6 @@ endif()
set (CZICMDSRCFILES
BitmapGen.cpp
DisplaySettingsHelper.h
targetver.h
BitmapGenFreeType.cpp
cmdlineoptions.cpp
execute.cpp
Expand All @@ -84,17 +83,14 @@ set (CZICMDSRCFILES
consoleio.cpp
executeCreateCzi.h
inc_CZIcmd_Config.h
stdafx.cpp
BitmapGenGdiplus.h
consoleio.h
execute.h
inc_libCZI.h
stdafx.h
BitmapGenNull.cpp
inc_rapidjson.h
BitmapGenNull.h
CZIcmd.cpp
platform_defines.h
executePlaneScan.h
executePlaneScan.cpp
executeBase.h
Expand All @@ -108,8 +104,8 @@ 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})

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

IF (FREETYPE_FOUND)
Expand All @@ -118,16 +114,17 @@ IF (FREETYPE_FOUND)
target_link_libraries(CZIcmd PRIVATE ${FREETYPE_LIBRARIES})
ENDIF()

IF(UNIX)
IF(NOT LIBCZI_HAVE_WIN32_API)
target_include_directories(CZIcmd PRIVATE ${ZLIB_INCLUDE_DIR} ${PNG_INCLUDE_DIR})
# seems to be problem with glibc I'd reckon -> https://stackoverflow.com/questions/51584960/stdcall-once-throws-stdsystem-error-unknown-error-1
target_link_libraries(CZIcmd PUBLIC pthread)
ENDIF(UNIX)
ENDIF()

set(CZICMD_USE_FREETYPE 0)
set(CZICMD_USE_WIC 0)
set(CZICMD_USE_GDIPLUS 0)
set(CZICMD_USE_LIBPNG 0)
set(CZICMD_WINDOWSAPIAVAILABLE 0)

IF (FREETYPE_FOUND)
set(CZICMD_USE_FREETYPE 1)
Expand All @@ -139,7 +136,8 @@ IF(PNG_FOUND)
set(CZICMD_LIBPNG_VERSION_STRING "${PNG_VERSION_STRING}")
ENDIF()

IF(WIN32)
IF(LIBCZI_HAVE_WIN32_API)
set(CZICMD_WINDOWSAPIAVAILABLE 1)
set(CZICMD_USE_WIC 1)
set(CZICMD_USE_GDIPLUS 1)
ENDIF()
Expand Down
20 changes: 7 additions & 13 deletions Src/CZICmd/CZIcmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include "inc_CZIcmd_Config.h"
#include "consoleio.h"
#include "cmdlineoptions.h"
#include "execute.h"
#include "inc_libCZI.h"

#if defined(LINUXENV)
#include <clocale>
#endif

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

Expand All @@ -24,7 +19,7 @@ class CLibCZISite : public libCZI::ISite
public:
explicit CLibCZISite(const CCmdLineOptions& opts) : options(opts)
{
#if defined(WIN32ENV)
#if CZICMD_WINDOWSAPI_AVAILABLE
if (options.GetUseWICJxrDecoder())
{
this->pSite = libCZI::GetDefaultSiteObject(libCZI::SiteObjectType::WithWICDecoder);
Expand Down Expand Up @@ -61,11 +56,10 @@ class CLibCZISite : public libCZI::ISite

int main(int argc, char** _argv)
{
#if defined(WIN32ENV)
#if CZICMD_WINDOWSAPI_AVAILABLE
CoInitialize(NULL);
CommandlineArgsWindowsHelper args_helper;
#endif
#if defined(LINUXENV)
#else
setlocale(LC_CTYPE, "");
#endif

Expand All @@ -74,7 +68,7 @@ int main(int argc, char** _argv)
try
{
CCmdLineOptions options(log);
#if defined(WIN32ENV)
#if CZICMD_WINDOWSAPI_AVAILABLE
auto cmdLineParseResult = options.Parse(args_helper.GetArgc(), args_helper.GetArgv());
#else
auto cmdLineParseResult = options.Parse(argc, _argv);
Expand Down Expand Up @@ -110,7 +104,7 @@ int main(int argc, char** _argv)
retVal = 1;
}

#if defined(WIN32ENV)
#if CZICMD_WINDOWSAPI_AVAILABLE
CoUninitialize();
#endif

Expand Down
3 changes: 3 additions & 0 deletions Src/CZICmd/CZIcmd_Config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#pragma once

// whether Win32-API can be used
#define CZICMD_WINDOWSAPI_AVAILABLE @CZICMD_WINDOWSAPIAVAILABLE@

#define CZICMD_USE_WIC @CZICMD_USE_WIC@

#define CZICMD_USE_LIBPNG @CZICMD_USE_LIBPNG@
Expand Down
1 change: 0 additions & 1 deletion Src/CZICmd/SaveBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include "SaveBitmap.h"
#include <fstream>
#include <stdexcept>
Expand Down
1 change: 0 additions & 1 deletion Src/CZICmd/cmdlineoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include "cmdlineoptions.h"
#include "inc_libCZI.h"
#include <clocale>
Expand Down
1 change: 0 additions & 1 deletion Src/CZICmd/consoleio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include <cstdarg>
#include "consoleio.h"
#include <iostream>
Expand Down
3 changes: 3 additions & 0 deletions Src/CZICmd/consoleio.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#pragma once

#include <string>
#include <memory>

class ILog
{
public:
Expand Down
1 change: 0 additions & 1 deletion Src/CZICmd/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include "execute.h"
#include "executeBase.h"
#include "executeCreateCzi.h"
Expand Down
1 change: 0 additions & 1 deletion Src/CZICmd/executeCreateCzi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include "executeCreateCzi.h"
#include "IBitmapGen.h"
#include "inc_libCZI.h"
Expand Down
1 change: 0 additions & 1 deletion Src/CZICmd/executePlaneScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include "executePlaneScan.h"
#include "executeBase.h"
#include "SaveBitmap.h"
Expand Down
2 changes: 1 addition & 1 deletion Src/CZICmd/inc_rapidjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#define RAPIDJSON_HAS_STDSTRING (1)
#define RAPIDJSON_HAS_STDSTRING 1

#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>
Expand Down
13 changes: 0 additions & 13 deletions Src/CZICmd/platform_defines.h

This file was deleted.

11 changes: 0 additions & 11 deletions Src/CZICmd/stdafx.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions Src/CZICmd/stdafx.h

This file was deleted.

14 changes: 0 additions & 14 deletions Src/CZICmd/targetver.h

This file was deleted.

6 changes: 3 additions & 3 deletions Src/CZICmd/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "stdafx.h"
#include "inc_CZIcmd_Config.h"
#include "utils.h"
#include <cwctype>
#include <iomanip>
#include <regex>

#if defined(WIN32ENV)
#if CZICMD_WINDOWSAPI_AVAILABLE
#define HAS_CODECVT
#include <Windows.h>
#endif
Expand Down Expand Up @@ -434,7 +434,7 @@ bool TryParseGuid(const std::wstring& str, libCZI::GUID* outGuid)
return false;
}

#if defined(WIN32ENV)
#if CZICMD_WINDOWSAPI_AVAILABLE
CommandlineArgsWindowsHelper::CommandlineArgsWindowsHelper()
{
int number_arguments;
Expand Down
3 changes: 2 additions & 1 deletion Src/CZICmd/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include "inc_CZIcmd_Config.h"
#include <string>
#include <vector>
#include "inc_libCZI.h"
Expand Down Expand Up @@ -78,7 +79,7 @@ inline final_act<F> finally(F&& f) noexcept
return final_act<F>(std::forward<F>(f));
}

#if defined(WIN32ENV)
#if CZICMD_WINDOWSAPI_AVAILABLE
/// A utility which is providing the command-line arguments (on Windows) as UTF8-encoded strings.
class CommandlineArgsWindowsHelper
{
Expand Down
Loading

0 comments on commit ca5c619

Please sign in to comment.