一个小项目的构建系统 glog CMake, Bazel 和 configure Makefile
一,CMake
1.1下载源代码
最新的源代码主页为,构建系统已经改为 Bazel和CMake,可从如下代码学习:
github主页:https://github.com/google/glog
下载最新代码:
git clone https://github.com/google/glog.git
1.2 CMake构建:
cmake -S . -B build -G "Unix Makefiles"
cmake --build build
cmake --build build --target test
cmake --build build --target install
1.3 如何在自己的使用CMake构建的项目中使用glog
cmake_minimum_required (VERSION 3.16)
project (myproj VERSION 1.0)
find_package (glog 0.6.0 REQUIRED)
add_executable (myapp main.cpp)
target_link_libraries (myapp glog::glog)
二,configure 生成 Makefile
2.1 下载源代码
旧代码中configure如何生成Makefile的,只能移步至旧项目网页:
https://code.google.com/archive/p/google-glog/
从Download处下载源码包:
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/google-glog/glog-0.3.3.tar.gz
解压:
tar zxvf glog-0.3.3.tar.gz
2.2 构建:
./configure
make -j
make install
三,示例:
#include <glog/logging.h>
int main(int argc, char* argv[]) {
// Initialize Google’s logging library.
google::InitGoogleLogging(argv[0]);
// ...
LOG(INFO) << "Found " << num_cookies << " cookies";
}