Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Не включать эти папки в GitHub source archive (tar.gz/zip)
vcpkg-overlay/ export-ignore
.github/ export-ignore
98 changes: 98 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
std: [11, 17]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- run: git submodule update --init --recursive
- name: Configure
run: cmake -S . -B build -DLOG_IT_CPP_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=${{ matrix.std }}
- name: Build
run: cmake --build build
- name: Install
run: cmake --install build --prefix install
- name: Test
run: ctest --test-dir build
- name: Configure consumer project
run: cmake -S tests/install_consumer -B build-consumer -DCMAKE_PREFIX_PATH=${{ github.workspace }}/install -DCMAKE_CXX_STANDARD=${{ matrix.std }}
- name: Build consumer project
run: cmake --build build-consumer

windows:
runs-on: windows-latest
strategy:
matrix:
std: [11, 17]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- run: git submodule update --init --recursive
- name: Configure
run: cmake -S . -B build -DLOG_IT_CPP_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=${{ matrix.std }}
- name: Build
run: cmake --build build --config Release
- name: Install
run: cmake --install build --prefix install --config Release
- name: Test
run: ctest --test-dir build -C Release
- name: Configure consumer project
run: cmake -S tests/install_consumer -B build-consumer -DCMAKE_PREFIX_PATH="${{ github.workspace }}/install" -DCMAKE_CXX_STANDARD=${{ matrix.std }}
- name: Build consumer project
run: cmake --build build-consumer --config Release

macos:
runs-on: macos-latest
strategy:
matrix:
std: [11, 17]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- run: git submodule update --init --recursive
- name: Configure
run: cmake -S . -B build -DLOG_IT_CPP_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=${{ matrix.std }}
- name: Build
run: cmake --build build
- name: Install
run: cmake --install build --prefix install
- name: Test
run: ctest --test-dir build
- name: Configure consumer project
run: cmake -S tests/install_consumer -B build-consumer -DCMAKE_PREFIX_PATH=${{ github.workspace }}/install -DCMAKE_CXX_STANDARD=${{ matrix.std }}
- name: Build consumer project
run: cmake --build build-consumer

vcpkg-install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- run: git submodule update --init --recursive
- name: Install vcpkg
run: |
git clone https://github.com/microsoft/vcpkg.git
./vcpkg/bootstrap-vcpkg.sh -disableMetrics
- name: Validate port
run: |
./vcpkg/vcpkg install log-it-cpp \
--overlay-ports=vcpkg-overlay/ports \
--overlay-ports=libs/time-shield-cpp/vcpkg-overlay/ports
- name: Configure consumer project
run: cmake -B build -S tests/install_consumer -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake
- name: Build consumer project
run: cmake --build build
105 changes: 52 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,71 +1,70 @@
# When generating a Code::Blocks project with MinGW, you can use:
# cmake -G "CodeBlocks - MinGW Makefiles" -S . -B build-cb
cmake_minimum_required(VERSION 3.18)
project(time_shield LANGUAGES CXX)
project(log-it-cpp VERSION 1.0.0 LANGUAGES CXX)

if(MINGW OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(COMMON_WARN_FLAGS -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wshadow)
endif()

if(MSVC)
set(COMMON_WARN_FLAGS /W4 /wd4996)
endif()
option(LOG_IT_CPP_BUILD_TESTS "Build log-it-cpp tests" ${PROJECT_IS_TOP_LEVEL})
option(LOG_IT_CPP_BUILD_EXAMPLES "Build log-it-cpp examples" OFF)

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Absolute path to the project root (where CMakeLists.txt resides)
get_filename_component(PROJECT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
# Dependency: TimeShield
find_package(TimeShield 1.0.3 QUIET CONFIG)
if(NOT TimeShield_FOUND)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libs/time-shield-cpp/CMakeLists.txt")
add_subdirectory(libs/time-shield-cpp)
else()
message(FATAL_ERROR "TimeShield not found. Please install it or add as submodule.")
endif()
endif()

# Define the LOGIT_BASE_PATH macro
add_compile_definitions(LOGIT_BASE_PATH="${PROJECT_ROOT}")
add_library(log-it-cpp INTERFACE)

# Include and library paths
set(PROJECT_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/include/logit_cpp
${CMAKE_CURRENT_SOURCE_DIR}/libs/fmt/include
${CMAKE_CURRENT_SOURCE_DIR}/libs/time-shield-cpp/include/time_shield_cpp
)
add_compile_definitions(LOGIT_BASE_PATH="$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")

# Header files from include/
file(GLOB_RECURSE PROJECT_HEADERS
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
include/*.hpp
target_include_directories(log-it-cpp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/logit_cpp>
$<INSTALL_INTERFACE:include/logit_cpp>
)

# Create a virtual target for headers so IDEs show them
add_custom_target(project_headers SOURCES ${PROJECT_HEADERS})
target_link_libraries(log-it-cpp INTERFACE time_shield::time_shield)

# Locate all .cpp files in examples/
file(GLOB EXAMPLES_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} examples/*.cpp)
if(LOG_IT_CPP_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

# Create a separate target for each example
foreach(example_src ${EXAMPLES_SOURCES})
get_filename_component(example_name ${example_src} NAME_WE)
if(LOG_IT_CPP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

add_executable(${example_name} ${example_src})
include(CMakePackageConfigHelpers)

target_include_directories(${example_name} PRIVATE ${PROJECT_INCLUDE_DIRS})

if(COMMON_WARN_FLAGS)
target_compile_options(${example_name} PRIVATE ${COMMON_WARN_FLAGS})
endif()
install(DIRECTORY include/ DESTINATION include)

target_link_directories(${example_name} PRIVATE ${PROJECT_LIBRARY_DIRS})
target_compile_definitions(${example_name} PRIVATE ${PROJECT_DEFINES})
target_link_libraries(${example_name} PRIVATE ${PROJECT_LIBS})

# Add headers as SOURCES so IDEs display them
set_source_files_properties(${PROJECT_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)
target_sources(${example_name} PRIVATE ${PROJECT_HEADERS})

foreach(dll ${DLL_FILES})
add_custom_command(TARGET ${example_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${dll}"
"$<TARGET_FILE_DIR:${example_name}>"
)
endforeach()
endforeach()
install(TARGETS log-it-cpp EXPORT log-it-cppTargets)

install(EXPORT log-it-cppTargets
FILE log-it-cppTargets.cmake
NAMESPACE log-it-cpp::
DESTINATION lib/cmake/log-it-cpp
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/log-it-cppConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

configure_package_config_file(
cmake/log-it-cppConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/log-it-cppConfig.cmake"
INSTALL_DESTINATION lib/cmake/log-it-cpp
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/log-it-cppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/log-it-cppConfigVersion.cmake"
DESTINATION lib/cmake/log-it-cpp
)
6 changes: 6 additions & 0 deletions cmake/log-it-cppConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(TimeShield)

include("${CMAKE_CURRENT_LIST_DIR}/log-it-cppTargets.cmake")
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
file(GLOB EXAMPLES_SOURCES *.cpp)
foreach(example_src ${EXAMPLES_SOURCES})
get_filename_component(example_name ${example_src} NAME_WE)
add_executable(${example_name} ${example_src})
target_link_libraries(${example_name} PRIVATE log-it-cpp)
endforeach()
29 changes: 28 additions & 1 deletion include/logit_cpp/logit/utils/path_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@
#include <windows.h>
#include <locale>
#include <codecvt>
#elif defined(__APPLE__)
// For macOS systems
#include <mach-o/dyld.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>
#else
// For POSIX systems
// For other POSIX systems
#include <unistd.h>
#include <limits.h>
#include <dirent.h>
Expand Down Expand Up @@ -95,6 +104,24 @@ namespace logit {
// Convert from std::wstring (UTF-16) to std::string (UTF-8)
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
return converter.to_bytes(exe_path);
# elif defined(__APPLE__)
uint32_t size = 0;
_NSGetExecutablePath(nullptr, &size);
std::vector<char> path(size);
if (_NSGetExecutablePath(path.data(), &size) != 0) {
throw std::runtime_error("Failed to get executable path.");
}
std::string exe_path(path.data());
char resolved[PATH_MAX];
if (realpath(exe_path.c_str(), resolved) == nullptr) {
throw std::runtime_error("Failed to resolve executable path.");
}
exe_path = resolved;
size_t pos = exe_path.find_last_of("\\/");
if (pos != std::string::npos) {
exe_path = exe_path.substr(0, pos);
}
return exe_path;
# else
char result[PATH_MAX];
ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
Expand Down
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
file(GLOB TEST_SOURCES *.cpp)
foreach(test_src ${TEST_SOURCES})
get_filename_component(test_name ${test_src} NAME_WE)
add_executable(${test_name} ${test_src})
target_link_libraries(${test_name} PRIVATE log-it-cpp)
add_test(NAME ${test_name} COMMAND ${test_name})
endforeach()
16 changes: 16 additions & 0 deletions tests/file_logger_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#define LOGIT_FILE_LOGGER_PATH "."
#include <LogIt.hpp>
#include <fstream>
#include <string>

int main() {
LOGIT_ADD_FILE_LOGGER_DEFAULT();
const std::string message = "test log message";
LOGIT_INFO(message);
LOGIT_WAIT();
const std::string log_path = LOGIT_GET_LAST_FILE_PATH(0);
std::ifstream in(log_path);
std::string line;
std::getline(in, line);
return line.find(message) != std::string::npos ? 0 : 1;
}
7 changes: 7 additions & 0 deletions tests/install_consumer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.18)
project(install_consumer LANGUAGES CXX)

find_package(log-it-cpp CONFIG REQUIRED)

add_executable(install_consumer main.cpp)
target_link_libraries(install_consumer PRIVATE log-it-cpp::log-it-cpp)
9 changes: 9 additions & 0 deletions tests/install_consumer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#define LOGIT_SHORT_NAME
#include <LogIt.hpp>

int main() {
LOGIT_ADD_CONSOLE_DEFAULT();
LOG_INFO("consumer works");
LOGIT_WAIT();
return 0;
}
24 changes: 24 additions & 0 deletions vcpkg-overlay/ports/log-it-cpp/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO NewYaroslav/log-it-cpp
REF a5ef55f060f720063bbbb5c9dfdb57086d618e96
SHA512 1a5a418fcae653ab9731068a21c17a56577f98162d2c292418f60d2722ef3075c83f065c4b6115979dd1f38dd54d50f2ecb635ac0049cafd3cfc2a33aa708fff
HEAD_REF main
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS -DLOG_IT_CPP_BUILD_TESTS=OFF
)

vcpkg_cmake_install()

vcpkg_cmake_config_fixup(PACKAGE_NAME log-it-cpp CONFIG_PATH lib/cmake/log-it-cpp)

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/debug/lib"
"${CURRENT_PACKAGES_DIR}/debug/share/${PORT}"
)
11 changes: 11 additions & 0 deletions vcpkg-overlay/ports/log-it-cpp/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "log-it-cpp",
"version-string": "1.0.0",
"description": "LogIt++ logging library",
"homepage": "https://github.com/NewYaroslav/log-it-cpp",
"dependencies": [
"vcpkg-cmake",
"vcpkg-cmake-config",
"time-shield-cpp"
]
}
Loading