Skip to content

Commit

Permalink
allow to build without spdlog
Browse files Browse the repository at this point in the history
  • Loading branch information
unxed committed Jul 23, 2023
1 parent 53ba7d9 commit d6821bf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
7 changes: 6 additions & 1 deletion colorer/CMakeLists.txt
Expand Up @@ -29,7 +29,12 @@ set(SOURCES

add_library(colorer MODULE ${SOURCES})

FIND_PACKAGE(Spdlog REQUIRED)
FIND_PACKAGE(Spdlog)
if(NOT Spdlog_FOUND)
message(STATUS "${ColorRed}Building Colorer without logging as SpdLog library is not found${ColorNormal}")
add_compile_definitions(NOSPDLOG)
endif()

FIND_PACKAGE(XercesC REQUIRED)

# sometimes libstd requires linking to libfmt, sometimes not
Expand Down
5 changes: 5 additions & 0 deletions colorer/src/Colorer-library/src/CMakeLists.txt
Expand Up @@ -174,6 +174,11 @@ endif ()
add_library(colorer_lib STATIC ${SRC_COLORER} ${SRC_MALLOC})

FIND_PACKAGE(Spdlog REQUIRED)
if(NOT Spdlog_FOUND)
message(STATUS "${ColorRed}Building Colorer without logging as SpdLog library is not found${ColorNormal}")
add_compile_definitions(NOSPDLOG)
endif()

FIND_PACKAGE(XercesC REQUIRED)


Expand Down
31 changes: 31 additions & 0 deletions colorer/src/Colorer-library/src/colorer/Common.h
Expand Up @@ -5,7 +5,9 @@
typedef unsigned char byte;

#include <memory>
#ifndef NOSPDLOG
#include <spdlog/spdlog.h>
#endif
#include <colorer/common/Features.h>
#include <colorer/unicode/String.h>
#include <colorer/unicode/SString.h>
Expand All @@ -14,7 +16,36 @@ typedef unsigned char byte;
typedef std::unique_ptr<String> UString;
typedef std::unique_ptr<SString> USString;

#ifndef NOSPDLOG
extern std::shared_ptr<spdlog::logger> logger;
#else
class DummyLogger {
public:
void debug(const char* message) {}
void debug(const char* message, int value) {}
void debug(const char* message, size_t value) {}
void debug(const char* message, const char* value) {}
void debug(const char* message, const std::string& value) {}
void debug(const char* message, const char* value1, const char* value2) {}
void debug(const char* message, int value1, int value2, const char* value3) {}

void error(const char* message) {}
void error(const char* message, const char* value) {}
void error(const char* message, const char* value1, const char* value2) {}
void error(const char* message, const std::string& file, XMLFileLoc line, XMLFileLoc column,
const std::string& error_message) {}

void warn(const char* message) {}
void warn(const char* message, const char* value) {}
void warn(const char* message, const std::string& value1, const std::string& value2) {}
void warn(const char* message, const char* arg1, const char* arg2) {}
void warn(const char* message, const std::string& file, XMLFileLoc line, XMLFileLoc column,
const std::string& error_message) {}

void trace(const char* message, size_t value) {}
};
extern std::shared_ptr<DummyLogger> logger;
#endif

#endif

@@ -1,4 +1,5 @@
#include <colorer/parsers/KeywordList.h>
#include <stdlib.h>

KeywordList::KeywordList()
{
Expand Down
7 changes: 7 additions & 0 deletions colorer/src/pcolorer2/pcolorer.cpp
Expand Up @@ -8,10 +8,13 @@
#include"tools.h"
#include"FarEditorSet.h"
#include <utils.h>

#ifndef NOSPDLOG
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_sinks.h>

std::shared_ptr<spdlog::logger> logger;
#endif

XERCES_CPP_NAMESPACE_USE

Expand Down Expand Up @@ -68,7 +71,11 @@ SHAREDSYMBOL void PluginModuleOpen(const char *path)
int pos = module.lastIndexOf('/');
pos = module.lastIndexOf('/',pos);
PluginPath=new StringBuffer(SString(module, 0, pos));
#ifndef NOSPDLOG
logger = spdlog::stderr_logger_mt("far2l-colorer");
#else
DummyLogger logger;
#endif
}

StringBuffer *GetConfigPath(const SString &sub)
Expand Down

0 comments on commit d6821bf

Please sign in to comment.