Symbolizer support for mingw and cygwin (#208)
[platform/upstream/glog.git] / cmake / INSTALL.md
1 # Glog - CMake Support
2
3 Glog comes with a CMake build script ([CMakeLists.txt](../CMakeLists.txt)) that can be used on a wide range of platforms.  
4 If you don't have CMake installed already, you can download it for free from <http://www.cmake.org/>.
5
6 CMake works by generating native makefiles or build projects that can be used in the compiler environment of your choice.  
7 You can either build Glog with CMake as a standalone project or it can be incorporated into an existing CMake build for another project.
8
9 ## Table of Contents
10
11 - [Building Glog with CMake](#building-glog-with-cmake)
12 - [Consuming Glog in a CMake Project](#consuming-glog-in-a-cmake-project)
13 - [Incorporating Glog into a CMake Project](#incorporating-glog-into-a-cmake-project)
14
15 ## Building Glog with CMake
16
17 When building Glog as a standalone project, on Unix-like systems with GNU Make as build tool, the typical workflow is:  
18
19 1. Get the source code and change to it.
20 e.g. cloning with git:
21 ```bash
22 git clone git@github.com:google/glog.git
23 cd glog
24 ```
25
26 2. Run CMake to configure the build tree.
27 ```bash
28 cmake -H. -Bbuild -G "Unix Makefiles"
29 ```
30 note: To get the list of available generators (e.g. Visual Studio), use `-G ""`
31
32 3. Afterwards, generated files can be used to compile the project.
33 ```bash
34 cmake --build build
35 ```
36
37 4. Test the build software (optional).
38 ```bash
39 cmake --build build --target test
40 ```
41
42 5. Install the built files (optional).
43 ```bash
44 cmake --build build --target install
45 ```
46
47 ## Consuming Glog in a CMake Project
48
49 If you have Glog installed in your system, you can use the CMake command
50 `find_package()` to include it in your CMake Project.
51
52 ```cmake
53 cmake_minimum_required(VERSION 3.0.2)
54 project(myproj VERSION 1.0)
55
56 find_package(glog 0.3.5 REQUIRED)
57
58 add_executable(myapp main.cpp)
59 target_link_libraries(myapp glog::glog)
60 ```
61
62 Compile definitions and options will be added automatically to your target as
63 needed.
64
65 ## Incorporating Glog into a CMake Project
66
67 You can also use the CMake command `add_subdirectory()` to include Glog directly from a subdirectory of your project.  
68 The **glog::glog** target is in this case an ALIAS library target for the **glog** library target. 
69
70 ```cmake
71 cmake_minimum_required(VERSION 3.0.2)
72 project(myproj VERSION 1.0)
73
74 add_subdirectory(glog)
75
76 add_executable(myapp main.cpp)
77 target_link_libraries(myapp glog::glog)
78 ```
79
80 Again, compile definitions and options will be added automatically to your target as
81 needed.