Merge commit '8e97373d883c06e1c73791849561d1311c880bc0' as 'libs/loguru'

This commit is contained in:
Henry Winkel
2022-09-15 09:52:21 +02:00
30 changed files with 5801 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
cmake_minimum_required(VERSION 2.8)
project(glog_example)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
add_compile_options(-std=c++11 -Werror -Wall -Wextra)
file(GLOB source
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
)
# ------------------------------------------------------
# GFLAGS
find_library(GFLAGS_LIB NAMES "gflags" PATHS
${GFLAGS_ROOT}/lib
${GFLAGS_ROOT}/Lib)
if (MSVC)
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h PATHS ${GFLAGS_ROOT}/Include)
set(GFLAGS_LIB_DIR ${GFLAGS_ROOT}/Lib)
else()
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h PATHS
${GFLAGS_ROOT}/include)
set(GFLAGS_LIB_DIR ${GFLAGS_ROOT}/lib)
endif()
mark_as_advanced(
GFLAGS_INCLUDE_DIR
GFLAGS_LIB
)
# ------------------------------------------------------
# GLOG
find_library(GLOG_LIB NAMES "glog" libglog PATHS
${GLOG_ROOT})
if (MSVC)
find_path(GLOG_INCLUDE_DIR glog/logging.h PATHS ${GLOG_ROOT})
set(GLOG_LIB_DIR ${GLOG_ROOT})
add_definitions(-DUSE_OWN_CHECK)
else()
find_path(GLOG_INCLUDE_DIR glog/logging.h PATHS
${GLOG_ROOT}/include)
set(GLOG_LIB_DIR ${GLOG_ROOT}/lib)
endif()
add_definitions(-DGLOG_NO_ABBREVIATED_SEVERITIES=1)
mark_as_advanced(
GLOG_INCLUDE_DIR
GLOG_LIB
)
# ------------------------------------------------------
add_executable(glog_example ${source})
include_directories(
${GFLAGS_INCLUDE_DIR}
${GLOG_INCLUDE_DIR}
)
target_link_libraries(glog_example
${GFLAGS_LIB}
${GLOG_LIB}
)

View File

@@ -0,0 +1,12 @@
#!/bin/bash
set -e # Fail on error
ROOT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
cd "$ROOT_DIR"
mkdir -p build
cd build
cmake ..
make
./glog_example $@

View File

@@ -0,0 +1,26 @@
#include <chrono>
#include <thread>
#include <glog/logging.h>
inline void sleep_ms(int ms)
{
VLOG(2) << "Sleeping for " << ms << " ms";
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
inline void complex_calculation()
{
LOG(INFO) << "complex_calculation started";
LOG(INFO) << "Starting time machine...";
sleep_ms(200);
LOG(WARNING) << "The flux capacitor is not getting enough power!";
sleep_ms(400);
LOG(INFO) << "Lighting strike!";
VLOG(1) << "Found 1.21 gigawatts...";
sleep_ms(400);
std::thread([](){
LOG(ERROR) << "We ended up in 1985!";
}).join();
LOG(INFO) << "complex_calculation stopped";
}

View File

@@ -0,0 +1,13 @@
#include <iostream>
#include "glog_example.hpp"
int main(int argc, char* argv[])
{
FLAGS_alsologtostderr = true;
FLAGS_colorlogtostderr = true;
google::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
LOG(INFO) << "Hello from main.cpp!";
complex_calculation();
LOG(INFO) << "main function about to end!";
}