Skip to content

Commit 261bed3

Browse files
feat: 1. Windows Desktop Backend firstly setup ; 2. Refactorize the CMake Scripts, to avoid multi instance of logger
fix: 1. multi instance of logger due to static link 2. quit stuck of CFDesktop due to deconstruction of static instance 3. Windows Compile Issue, LLVM Compile Issue of Queue test, caused by big objects directly placed in stack.
2 parents 61830d7 + 4928551 commit 261bed3

72 files changed

Lines changed: 3354 additions & 86 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

desktop/CMakeLists.txt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ log_info("Desktop" "Creating unified CFDesktop shared library")
1616
add_library(CFDesktop_shared SHARED)
1717

1818
# Export symbols for Windows DLL
19+
# CFLOG_STATIC_BUILD: cflogger symbols resolve as regular refs within the DLL
20+
# CFDESKTOP_STATIC_BUILD: NOT set here — desktop_run_session.cpp needs
21+
# CF_DESKTOP_EXPORT = dllexport (CFDESKTOP_EXPORTS is defined on this target)
1922
if(WIN32)
20-
target_compile_definitions(CFDesktop_shared PRIVATE CFDESKTOP_EXPORTS)
23+
target_compile_definitions(CFDesktop_shared PRIVATE
24+
CFDESKTOP_EXPORTS
25+
CFLOG_STATIC_BUILD
26+
)
2127
endif()
2228

2329
# Set symbol visibility to hidden on Unix/Linux
@@ -42,6 +48,12 @@ set(CFDESKTOP_STATIC_LIBS
4248
cfasciiart
4349
CFDesktopMain
4450
CFDesktopUi
51+
cf_desktop_render
52+
)
53+
54+
# Sources compiled directly into the DLL (with CFDESKTOP_EXPORTS defined)
55+
target_sources(CFDesktop_shared PRIVATE
56+
${CMAKE_CURRENT_SOURCE_DIR}/desktop_run_session.cpp
4557
)
4658

4759
# Link all static libraries using --whole-archive
@@ -86,14 +98,14 @@ endif()
8698
# Add alias for consistent naming
8799
add_library(CFDesktop::lib ALIAS CFDesktop_shared)
88100
# ============================================================
89-
# Main executable (links against the shared library)
101+
# Main executable — thin shell that calls into the DLL
90102
# ============================================================
91-
add_executable(CFDesktop main.cpp desktop_entry.cpp)
103+
add_executable(CFDesktop main.cpp)
92104

93-
# Link against the unified CFDesktop shared library
94-
# Also link CFDesktopEarlySession directly for symbols not exported from DLL
105+
# The EXE only links the DLL import library.
106+
# All code (CFDesktopMain, desktop_entry, init stages, etc.) lives in the DLL.
95107
target_link_libraries(CFDesktop PRIVATE
96-
CFDesktop_shared CFDesktopMain cflogger cfbase
108+
CFDesktop_shared
97109
)
98110

99111
log_info("Desktop Buildings" "Configuring Desktop Buildings Done")

desktop/base/logger/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,23 @@ target_link_libraries(cflogger PUBLIC
2929

3030
# Alias for consistent naming
3131
add_library(CFDesktop::logger ALIAS cflogger)
32+
33+
# =============================================================================
34+
# cflogger_headers — Header-only INTERFACE library
35+
# =============================================================================
36+
# DLL-internal modules that only call the public API (cflog.h free functions)
37+
# should link this instead of the static lib, to avoid duplicating compiled
38+
# symbols. Only CFDesktop_shared (via --whole-archive) and CFDesktopMain
39+
# (PRIVATE, for internal classes like FileSink/ConsoleSink) link the real lib.
40+
add_library(cflogger_headers INTERFACE)
41+
target_include_directories(cflogger_headers INTERFACE
42+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
43+
$<INSTALL_INTERFACE:include>
44+
)
45+
target_link_libraries(cflogger_headers INTERFACE CFDesktop::base)
46+
add_library(CFDesktop::logger_headers ALIAS cflogger_headers)
47+
48+
# cflogger itself: mark symbols for DLL export when building on Windows
49+
if(WIN32)
50+
target_compile_definitions(cflogger PRIVATE CFLOG_BUILDING)
51+
endif()

desktop/base/logger/include/cflog.h

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@
66
#pragma once
77

88
#include "cflog/cflog.hpp"
9+
#include "cflog/cflog_export.h"
910
#include <format>
1011
#include <source_location>
1112
#include <string_view>
1213

1314
namespace cf::log {
1415

15-
void trace(std::string_view msg, std::string_view tag = "CFLog",
16-
std::source_location loc = std::source_location::current());
16+
CFLOG_API void trace(std::string_view msg, std::string_view tag = "CFLog",
17+
std::source_location loc = std::source_location::current());
1718

18-
void debug(std::string_view msg, std::string_view tag = "CFLog",
19-
std::source_location loc = std::source_location::current());
19+
CFLOG_API void debug(std::string_view msg, std::string_view tag = "CFLog",
20+
std::source_location loc = std::source_location::current());
2021

21-
void info(std::string_view msg, std::string_view tag = "CFLog",
22-
std::source_location loc = std::source_location::current());
22+
CFLOG_API void info(std::string_view msg, std::string_view tag = "CFLog",
23+
std::source_location loc = std::source_location::current());
2324

24-
void warning(std::string_view msg, std::string_view tag = "CFLog",
25-
std::source_location loc = std::source_location::current());
25+
CFLOG_API void warning(std::string_view msg, std::string_view tag = "CFLog",
26+
std::source_location loc = std::source_location::current());
2627

27-
void error(std::string_view msg, std::string_view tag = "CFLog",
28-
std::source_location loc = std::source_location::current());
28+
CFLOG_API void error(std::string_view msg, std::string_view tag = "CFLog",
29+
std::source_location loc = std::source_location::current());
2930

3031
// ============================================================================
3132
// Formatted logging functions (std::format style)
@@ -203,8 +204,8 @@ template <typename... Args> struct traceftag {
203204
detail::log_helper<level::TRACE, Args...>{tag, fmt, std::forward<Args>(args)..., loc};
204205
}
205206
};
206-
template <typename... Args>
207-
traceftag(std::string_view, std::format_string<Args...>, Args&&...) -> traceftag<Args...>;
207+
template <typename... Args> traceftag(std::string_view, std::format_string<Args...>, Args&&...)
208+
-> traceftag<Args...>;
208209

209210
/**
210211
* @brief Temporary object for debug-level formatted logging with custom tag.
@@ -229,8 +230,8 @@ template <typename... Args> struct debugftag {
229230
detail::log_helper<level::DEBUG, Args...>{tag, fmt, std::forward<Args>(args)..., loc};
230231
}
231232
};
232-
template <typename... Args>
233-
debugftag(std::string_view, std::format_string<Args...>, Args&&...) -> debugftag<Args...>;
233+
template <typename... Args> debugftag(std::string_view, std::format_string<Args...>, Args&&...)
234+
-> debugftag<Args...>;
234235

235236
/**
236237
* @brief Temporary object for info-level formatted logging with custom tag.
@@ -255,8 +256,8 @@ template <typename... Args> struct infoftag {
255256
detail::log_helper<level::INFO, Args...>{tag, fmt, std::forward<Args>(args)..., loc};
256257
}
257258
};
258-
template <typename... Args>
259-
infoftag(std::string_view, std::format_string<Args...>, Args&&...) -> infoftag<Args...>;
259+
template <typename... Args> infoftag(std::string_view, std::format_string<Args...>, Args&&...)
260+
-> infoftag<Args...>;
260261

261262
/**
262263
* @brief Temporary object for warning-level formatted logging with custom tag.
@@ -281,8 +282,8 @@ template <typename... Args> struct warningftag {
281282
detail::log_helper<level::WARNING, Args...>{tag, fmt, std::forward<Args>(args)..., loc};
282283
}
283284
};
284-
template <typename... Args>
285-
warningftag(std::string_view, std::format_string<Args...>, Args&&...) -> warningftag<Args...>;
285+
template <typename... Args> warningftag(std::string_view, std::format_string<Args...>, Args&&...)
286+
-> warningftag<Args...>;
286287

287288
/**
288289
* @brief Temporary object for error-level formatted logging with custom tag.
@@ -307,34 +308,36 @@ template <typename... Args> struct errorftag {
307308
detail::log_helper<level::ERROR, Args...>{tag, fmt, std::forward<Args>(args)..., loc};
308309
}
309310
};
310-
template <typename... Args>
311-
errorftag(std::string_view, std::format_string<Args...>, Args&&...) -> errorftag<Args...>;
311+
template <typename... Args> errorftag(std::string_view, std::format_string<Args...>, Args&&...)
312+
-> errorftag<Args...>;
312313

313314
/**
314315
* @brief Sets the minimum log level.
315316
*
316317
* Only messages at or above this level are processed.
317318
*
318319
* @param[in] lvl Minimum log level to set.
320+
* @return None
319321
* @throws None
320322
* @note None
321323
* @warning None
322324
* @since N/A
323325
* @ingroup cflog
324326
*/
325-
void set_level(level lvl);
327+
CFLOG_API void set_level(level lvl);
326328

327329
/**
328330
* @brief Flushes all pending log messages.
329331
*
330332
* Blocks until all queued messages are written to sinks.
331333
*
334+
* @return None
332335
* @throws None
333336
* @note This operation may block if the queue is full.
334337
* @warning None
335338
* @since N/A
336339
* @ingroup cflog
337340
*/
338-
void flush();
341+
CFLOG_API void flush();
339342

340343
} // namespace cf::log

desktop/base/logger/include/cflog/cflog.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#pragma once
1515

1616
#include "base/singleton/simple_singleton.hpp"
17+
#include "cflog_export.h"
1718
#include "cflog_level.hpp"
1819
#include <atomic>
1920
#include <memory>
@@ -40,7 +41,7 @@ class ISink;
4041
* logger.log(level::INFO, "Hello, world!", "MyApp", std::source_location::current());
4142
* @endcode
4243
*/
43-
class Logger : public SimpleSingleton<Logger> {
44+
class CFLOG_API Logger {
4445
public:
4546
/**
4647
* @brief Constructor.
@@ -62,7 +63,16 @@ class Logger : public SimpleSingleton<Logger> {
6263
*/
6364
~Logger();
6465

65-
/* Native Interface */
66+
/**
67+
* @brief Intentionally leaks to avoid deadlock on Ctrl+C
68+
* that occurs with Meyer Singletons.
69+
*
70+
* @return Logger&
71+
*/
72+
static Logger& instance() {
73+
static Logger* inst = new Logger();
74+
return *inst;
75+
}
6676

6777
/**
6878
* @brief Logs a message with the specified level and metadata.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @file cflog_export.h
3+
* @brief Export/import macros for CFLog library symbols.
4+
*
5+
* When building cflogger (static lib merged into CFDesktop_shared DLL),
6+
* CFLOG_BUILDING is defined so symbols are marked dllexport.
7+
* When consuming from the EXE or other targets, symbols are marked dllimport.
8+
*/
9+
#pragma once
10+
11+
#if defined(_WIN32) || defined(_MSC_VER)
12+
# ifdef CFLOG_STATIC_BUILD
13+
# define CFLOG_API
14+
# elif defined(CFLOG_BUILDING)
15+
# define CFLOG_API __declspec(dllexport)
16+
# else
17+
# define CFLOG_API __declspec(dllimport)
18+
# endif
19+
#else
20+
# define CFLOG_API __attribute__((visibility("default")))
21+
#endif

desktop/base/logger/include/cflog/cflog_level.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ enum class level {
3434
};
3535

3636
static constexpr const level kDEFAULT_LEVEL =
37-
#ifdef CFDESKTOP_DEBUG_BUILD
37+
#if defined(CFDESKTOP_DEBUG_BUILD) || defined(CFDESKTOP_DEVELOP_BUILD)
3838
level::TRACE;
39-
#elif defined(CFDESKTOP_DEVELOP_BUILD)
40-
level::INFO;
4139
#else
42-
level::DEBUG;
40+
level::INFO;
4341
#endif
4442

4543
/**

desktop/base/logger/include/cflog/formatter/console_formatter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
#pragma once
1515

16+
#include "cflog/cflog_export.h"
1617
#include "cflog/cflog_format.h"
1718
#include "cflog/cflog_format_config.h"
1819
#include <memory>
@@ -34,7 +35,7 @@ enum class level : int;
3435
*
3536
* @note Thread-safe for format operations.
3637
*/
37-
class AsciiColorFormatter : public IFormatter {
38+
class CFLOG_API AsciiColorFormatter : public IFormatter {
3839
public:
3940
/**
4041
* @brief Constructs a new AsciiColorFormatter.

desktop/base/logger/include/cflog/formatter/file_formatter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
#pragma once
1515

16+
#include "cflog/cflog_export.h"
1617
#include "cflog/cflog_format.h"
1718
#include "cflog/cflog_format_config.h"
1819
#include <memory>
@@ -37,7 +38,7 @@ enum class level : int;
3738
* @note COLOR flag is always ignored since ANSI escape codes
3839
* should not appear in log files.
3940
*/
40-
class FileFormatter : public IFormatter {
41+
class CFLOG_API FileFormatter : public IFormatter {
4142
public:
4243
/**
4344
* @brief Constructs a new FileFormatter.

desktop/base/logger/include/cflog/sinks/console_sink.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
#pragma once
1515

16+
#include "cflog/cflog_export.h"
1617
#include "cflog/cflog_sink.h"
1718

1819
namespace cf::log {
@@ -33,7 +34,7 @@ namespace cf::log {
3334
* sink.flush();
3435
* @endcode
3536
*/
36-
class ConsoleSink : public ISink {
37+
class CFLOG_API ConsoleSink : public ISink {
3738
public:
3839
/**
3940
* @brief Writes a log record to the console.

desktop/base/logger/include/cflog/sinks/file_sink.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
#pragma once
1414

15+
#include "cflog/cflog_export.h"
1516
#include "cflog/cflog_sink.h"
1617
#include <fstream>
1718
#include <string>
@@ -45,7 +46,7 @@ enum class OpenMode {
4546
* sink.flush();
4647
* @endcode
4748
*/
48-
class FileSink : public ISink {
49+
class CFLOG_API FileSink : public ISink {
4950
public:
5051
/**
5152
* @brief Constructs a new FileSink.

0 commit comments

Comments
 (0)