Skip to content

Commit 7fe61ca

Browse files
tuduongquyetdeemar
authored andcommitted
Refactoring CMake, md files
1 parent 67063c7 commit 7fe61ca

10 files changed

Lines changed: 159 additions & 203 deletions

CMakeLists.txt

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
# create by lsm <lsm@skybility.com>
2-
# cmake
1+
# LICENSE: Apache License 2.0
2+
# Copyright (c) Hardy Simpson
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#/
316

417
cmake_minimum_required(VERSION 2.8.5)
518

@@ -9,20 +22,15 @@ message(STATUS "path : ${CMAKE_FIND_ROOT_PATH}")
922

1023
set(CMAKE_MODULE_PATH ${zlog_SOURCE_DIR}/cmake)
1124

12-
#=====================================
13-
# version of zlog
14-
#=====================================
1525
SET(CPACK_PACKAGE_VERSION_MAJOR "1")
1626
SET(CPACK_PACKAGE_VERSION_MINOR "2")
1727
SET(CPACK_PACKAGE_VERSION_PATCH "12")
18-
SET(CPACK_RPM_PACKAGE_RELEASE 1) #release version.
28+
SET(CPACK_RPM_PACKAGE_RELEASE 1) # release version.
1929
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
20-
SET(zlog_ver ${CPACK_PACKAGE_VERSION})
21-
SET(zlog_so_ver ${CPACK_PACKAGE_VERSION_MAJOR})
30+
SET(ZLOG_VERSION ${CPACK_PACKAGE_VERSION})
31+
SET(ZLOG_SO_VERSION ${CPACK_PACKAGE_VERSION_MAJOR})
2232

23-
#=======================================================
24-
25-
message(STATUS "plateform : ${CMAKE_SYSTEM}")
33+
message(STATUS "platform : ${CMAKE_SYSTEM}")
2634

2735
add_definitions("-g -Wall -Wstrict-prototypes")
2836
set(CMAKE_C_FLAGS "-std=c99 -pedantic -D_DEFAULT_SOURCE")
@@ -31,48 +39,28 @@ set(CMAKE_C_FLAGS_RELEASE "-O2")
3139

3240
if (WIN32)
3341
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 ")
34-
endif()
35-
36-
#=====================================================
37-
# include dir
38-
# include_directories(include)
39-
#=====================================================
42+
endif ()
4043

41-
#=====================================================
42-
# lib output path.
4344
cmake_policy(SET CMP0015 NEW)
4445
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${zlog_BINARY_DIR}/lib")
4546
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${zlog_BINARY_DIR}/lib")
46-
# bin output path.
47+
4748
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${zlog_BINARY_DIR}/bin")
48-
#=====================================================
4949

50-
#=====================================================
51-
# link path.
5250
link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
53-
#=====================================================
5451

55-
#=====================================================
56-
# library depend.
5752
set(Need_THREAD 1)
53+
5854
if (WIN32)
5955
set(Need_UNIXEM 1)
60-
endif()
56+
endif ()
6157

6258
include(cmake/LoadLibraries.cmake)
63-
#=====================================================
6459

65-
#========================================================
66-
# sub dir
6760
add_subdirectory(src)
6861
add_subdirectory(cpack)
69-
#========================================================
7062

71-
#========================================================
72-
# for unittest, call "cmake .. -DUNIT_TEST=on"
73-
if(UNIT_TEST)
63+
if (UNIT_TEST)
7464
enable_testing()
7565
add_subdirectory(test)
76-
endif()
77-
#========================================================
78-
66+
endif ()

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
zlog is a reliable, high-performance, thread safe, flexible, clear-model, pure C logging library.
44

5-
Actually, in the C world there was NO good logging library for applications like logback in java or log4cxx in c++. Using printf can work, but can not be redirected or reformatted easily. syslog is slow and is designed for system use.
5+
Actually, in the C world there was NO good logging library for applications like logback in java or log4cxx in c++.
6+
Using printf can work, but can not be redirected or reformatted easily. syslog is slow and is designed for system use.
67
So I wrote zlog.
78
It is faster, safer and more powerful than log4c. So it can be widely used.
89

@@ -24,25 +25,32 @@ make PREFIX=/usr/local/
2425
sudo make PREFIX=/usr/local/ install
2526
```
2627

27-
PREFIX indicates the installation destination for zlog. After installation, refresh your dynamic linker to make sure your program can find zlog library.
28+
PREFIX indicates the installation destination for zlog. After installation, refresh your dynamic linker to make sure
29+
your program can find zlog library.
2830

2931
```bash
3032
$ sudo vi /etc/ld.so.conf
3133
/usr/local/lib
3234
$ sudo ldconfig
3335
```
3436

35-
Before running a real program, make sure libzlog.so is in the directory where the system's dynamic lib loader can find it. The command metioned above are for linux. Other systems will need a similar set of actions.
37+
Before running a real program, make sure libzlog.so is in the directory where the system's dynamic lib loader can find
38+
it. The command metioned above are for linux. Other systems will need a similar set of actions.
3639

3740
## 2. Configuration file
3841

3942
There are 3 important concepts in zlog: categories, formats and rules.
4043

41-
Categories specify different kinds of log entries. In the zlog source code, category is a `zlog_cateogory_t *` variable. In your program, different categories for the log entries will distinguish them from each other.
44+
Categories specify different kinds of log entries. In the zlog source code, category is a `zlog_cateogory_t *` variable.
45+
In your program, different categories for the log entries will distinguish them from each other.
4246

4347
Formats describe log patterns, such as: with or without time stamp, source file, source line.
4448

45-
Rules consist of category, level, output file (or other channel) and format. In brief, if the category string in a rule in the configuration file equals the name of a category variable in the source, then they match. Still there is complex match range of category. Rule decouples variable conditions. For example, log4j must specify a level for each logger(or inherit from father logger). That's not convenient when each grade of logger has its own level for output(child logger output at the level of debug, when father logger output at the level of error)
49+
Rules consist of category, level, output file (or other channel) and format. In brief, if the category string in a rule
50+
in the configuration file equals the name of a category variable in the source, then they match. Still there is complex
51+
match range of category. Rule decouples variable conditions. For example, log4j must specify a level for each logger(or
52+
inherit from father logger). That's not convenient when each grade of logger has its own level for output(child logger
53+
output at the level of debug, when father logger output at the level of error)
4654

4755
Now create a configuration file. The function zlog_init takes the files path as its only argument.
4856

@@ -55,7 +63,9 @@ simple = "%m%n"
5563
my_cat.DEBUG >stdout; simple
5664
```
5765

58-
In the configuration file log messages in the category `my_cat` and a level of DEBUG or higher are output to standard output, with the format of simple `%m - usermessage %n - newline`. If you want to direct out to a file and limit the files maximum size, use this configuration
66+
In the configuration file log messages in the category `my_cat` and a level of DEBUG or higher are output to standard
67+
output, with the format of simple `%m - usermessage %n - newline`. If you want to direct out to a file and limit the
68+
files maximum size, use this configuration
5969

6070
```config
6171
my_cat.DEBUG "/var/log/aa.log", 1M; simple
@@ -111,7 +121,8 @@ hello, zlog
111121
112122
* syslog model, better than log4j model
113123
* log format customization
114-
* multiple output destinations including static file path, dynamic file path, stdout, stderr, syslog, user-defined output
124+
* multiple output destinations including static file path, dynamic file path, stdout, stderr, syslog, user-defined
125+
output
115126
* runtime manually or automatically refresh configure(safely)
116127
* high-performance, 250'000 logs/second on my laptop, about 1000 times faster than syslog(3) with rsyslogd
117128
* user-defined log level

cmake/FindUnixem.cmake

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@
44
if (NOT UNIXEM_FOUND)
55
if (NOT UNIXEM_INCLUDE_DIR)
66
find_path(UNIXEM_INCLUDE_DIR
7-
NAMES
7+
NAMES
88
unixem/unixem.h
9-
ONLY_CMAKE_FIND_ROOT_PATH
9+
ONLY_CMAKE_FIND_ROOT_PATH
1010
)
11-
endif()
12-
11+
endif ()
12+
1313
if (NOT UNIXEM_LIBRARY)
1414
find_library(UNIXEM_LIBRARY
15-
NAMES unixem
16-
ONLY_CMAKE_FIND_ROOT_PATH
15+
NAMES unixem
16+
ONLY_CMAKE_FIND_ROOT_PATH
1717
)
1818
endif (NOT UNIXEM_LIBRARY)
19-
19+
2020
message(STATUS " UNIXEM_INCLUDE_DIR = ${UNIXEM_INCLUDE_DIR}")
2121
message(STATUS " UNIXEM_LIBRARY = ${UNIXEM_LIBRARY}")
22-
22+
2323
if (UNIXEM_INCLUDE_DIR AND UNIXEM_LIBRARY)
2424
set(UNIXEM_FOUND TRUE)
2525
endif (UNIXEM_INCLUDE_DIR AND UNIXEM_LIBRARY)
26-
endif()
27-
26+
endif ()

cmake/LoadLibraries.cmake

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
#=======================================================
1+
# =======================================================
22
# 支持多线程
33
# 对于需要多线程的库,使用以下命令包含连接库:
44
# target_link_libraries(xxx ${CMAKE_THREAD_PREFER_PTHREAD})
5-
#=======================================================
6-
if(Need_THREAD)
5+
# =======================================================
6+
if (Need_THREAD)
77
find_package(Threads REQUIRED)
8-
if(NOT CMAKE_THREAD_PREFER_PTHREAD)
8+
9+
if (NOT CMAKE_THREAD_PREFER_PTHREAD)
910
set(CMAKE_THREAD_PREFER_PTHREAD ${CMAKE_THREAD_LIBS_INIT})
10-
endif()
11+
endif ()
12+
1113
message(STATUS "thread lib : ${CMAKE_THREAD_PREFER_PTHREAD}")
12-
endif(Need_THREAD)
14+
endif (Need_THREAD)
1315

14-
if(Need_UNIXEM)
16+
if (Need_UNIXEM)
1517
find_package(Unixem)
18+
1619
if (NOT UNIXEM_FOUND)
1720
message(FATAL_ERROR "unixem lib not found!")
18-
endif()
19-
endif()
21+
endif ()
22+
endif ()

cmake/toolchain-mingw64.cmake

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# this one is important
32
SET(CMAKE_SYSTEM_NAME Windows)
43

@@ -7,7 +6,7 @@ find_path(MINGW_BIN_PATH gcc.exe PATHS c:/mingw64 d:/mingw64 c:/mingw-build/ming
76

87
if (MINGW_PATH_NOTFOUND)
98
message(FATAL "mingw64 not found!")
10-
endif()
9+
endif ()
1110

1211
get_filename_component(MINGW_PATH ${MINGW_BIN_PATH} PATH)
1312

@@ -19,10 +18,10 @@ SET(CMAKE_CXX_COMPILER g++)
1918
SET(CMAKE_RC_COMPILER windres)
2019
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
2120

22-
#SET(_CMAKE_TOOLCHAIN_PREFIX x86_64-w64-mingw32-)
21+
# SET(_CMAKE_TOOLCHAIN_PREFIX x86_64-w64-mingw32-)
2322
SET(_CMAKE_TOOLCHAIN_LOCATION ${MINGW_BIN_PATH})
2423

25-
# where is the target environment
24+
# where is the target environment
2625
SET(CMAKE_FIND_ROOT_PATH ${MINGW_PATH} ${MINGW_PATH}/x86_64-w64-mingw32)
2726

2827
SET(CMAKE_SYSTEM_INCLUDE_PATH "${CMAKE_SYSTEM_INCLUDE_PATH} ${MINGW_PATH}/include ${MINGW_PATH}/x86_64-w64-mingw32/include")
@@ -34,7 +33,7 @@ add_definitions("-D_POSIX")
3433

3534
# search for programs in the build host directories
3635
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
36+
3737
# for libraries and headers in the target directories
3838
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
3939
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
40-

cpack/CMakeLists.txt

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,42 @@
11
# create by lsm <lsm@skybility.com>
22

3-
#======================================
4-
# vendor info
5-
#======================================
63
SET(CPACK_PACKAGE_VENDOR "zlog")
74
SET(CPACK_PACKAGE_CONTACT "HardySimpson1984@gmail.com")
85
SET(CPACK_RPM_PACKAGE_LICENSE "Apache License Version 2.0")
9-
10-
#======================================
11-
# default install prefix.
12-
#======================================
136
SET(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local")
147
SET(CPACK_RPM_PACKAGE_GROUP "System Environment/Base")
158

16-
#=================================
17-
# set platform.
18-
#=================================
199
message(STATUS "system process is ${CMAKE_HOST_SYSTEM_PROCESSOR}")
2010
message(STATUS "system process is ${CMAKE_SYSTEM_PROCESSOR}")
2111

2212
IF (NOT CMAKE_SYSTEM_PROCESSOR)
2313
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
24-
endif()
14+
endif ()
2515

26-
IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64|amd64")
16+
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64|amd64")
2717
set(CMAKE_SYSTEM_PROCESSOR x86_64)
2818
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64)
2919
SET(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64")
30-
ELSEIF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc64|ppc64")
20+
ELSEIF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc64|ppc64")
3121
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE powerpc64)
3222
SET(CPACK_RPM_PACKAGE_ARCHITECTURE "ppc64")
33-
ELSEIF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc|ppc")
23+
ELSEIF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc|ppc")
3424
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE powerpc)
3525
SET(CPACK_RPM_PACKAGE_ARCHITECTURE "ppc")
36-
ELSE()
26+
ELSE ()
3727
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
3828
SET(CPACK_RPM_PACKAGE_ARCHITECTURE i386)
39-
ENDIF()
40-
SET(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
29+
ENDIF ()
30+
31+
SET(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
4132
SET(CPACK_TOPLEVEL_TAG "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
4233

43-
#======================================
44-
# generator setting.
45-
#======================================
4634
SET(CPACK_CMAKE_GENERATOR "Unix Makefiles")
35+
4736
if (WIN32)
4837
SET(CPACK_GENERATOR "NSIS")
49-
else()
38+
else ()
5039
SET(CPACK_GENERATOR "RPM;DEB")
51-
endif()
40+
endif ()
5241

53-
#======================================
54-
# package.
55-
#======================================
5642
add_subdirectory(zlog)

0 commit comments

Comments
 (0)