Squashed 'libs/loguru/' content from commit 644f60d
git-subtree-dir: libs/loguru git-subtree-split: 644f60dca77de3b0f718a03d370c8ebdf5f97968
This commit is contained in:
71
glog_example/CMakeLists.txt
Normal file
71
glog_example/CMakeLists.txt
Normal 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}
|
||||
)
|
||||
12
glog_example/build_and_run.sh
Executable file
12
glog_example/build_and_run.sh
Executable 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 $@
|
||||
26
glog_example/glog_example.hpp
Normal file
26
glog_example/glog_example.hpp
Normal 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";
|
||||
}
|
||||
13
glog_example/main.cpp
Normal file
13
glog_example/main.cpp
Normal 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!";
|
||||
}
|
||||
Reference in New Issue
Block a user