Heka CMake compilation configuration analysis

Source: Internet
Author: User

CMake is a cross-platform automated construction system that uses a file named CMakeLists.txt to describe the building process and generate standard building files.

 

The syntax of CMakeLists.txt is simple and consists of commands, comments, and spaces. Commands are case-insensitive and the content after the symbol "#" is considered as comments. The command consists of the command name, parentheses, and parameters. The parameters are separated by spaces.

 

Common commands are as follows:

SET command

Used to explicitly define variables

Syntax: SET (VAR [VALUE] [cache type docstring [FORCE])

 

Find_package command

The find_package can be used to automatically find the library required to configure the build project in the system.

 

Option command

Set compilation options


MESSAGE command

ParametersContentOutput to terminal

 

Include command

To load the cmakelists.txt file. It is also used to load the pre-defined cmake module.
INCLUDE (file1 [OPTIONAL])
INCLUDE (module [OPTIONAL])

The OPTIONAL parameter does not exist in the file and does not produce errors.
You can specify to load a file. If a module is defined, it will be searched in CMAKE_MODULE_PATH.
Load this module.

 

Install Command

Equivalent to the copy command,

INSTALL (files copyright readme destination share/doc/cmake_demo)

INSTALL (PROGRAMS run. sh DESTINATION bin)

INSTALL (PROGRAMS bin/hello DESTINATION bin)

INSTALL (DIRECTORY doc/DESTINATION share/doc/cmake_demo)

These commands indicate that when the make install command is executed, the installer will copy the corresponding files, directories, or programs to the directories starting with the specified prefix.

 

Find_program command

Find executable programs


ADD_CUSTOM_COMMAND command

ADD_CUSTOM_COMMAND (
TARGET name
PRE_BUILD | PRE_LINK | POST_BUILD
COMMAND cmd1 [COMMAND cmd2…] ):
Add one or more new custom compilation rules cmd1 and cmd2 to the target project name. You can select pre-compilation, pre-connection, or post-compilation as the execution time. It serves as the "M Build Step" attribute of the Visual Studio project.

 

 

Add_custom_target command

Add_custom_target (Name [ALL] [command1 [args1...]
[COMMAND command2 [args2....]
[DEPENDS depend...]
[WORKING_DIRECTORY dir]
[COMMENT comment] [VERBATIM]
[SOURCES src1 [src2...])
Add a compilation target named name and specify one or more custom commands, such as cmd1 and cmd2. Note the difference between ADD_CUSTOM_COMMAND and this command: the former sets custom compilation rules for an existing sub-project, and the latter sets up a new custom target project, for example, an INSTALL project dedicated to copying generated files to the specified folder, and an UNINSTALL project that works in the opposite way.

If the ALL option is specified, it indicates that the target will be added to the default build target, so that it will be run every time. (The name of this command cannot be named ALL.) the command and parameters are optional. If not specified, an empty target will be created.

If WORKING_DIRECTORY is set, this command runs in the specified directory. If it is a relative path, it will be resolved to the build directory corresponding to the current source directory.

If COMMENT is set, the value is displayed as information before the command is executed.

The DEPENDS parameter can be output of a file and other customized commands in the same directory.

If VERBATIM is specified, all parameters passed to the command will be properly converted. We recommend that you use this option.

The SOURCES option specifies an additional source file that contains the customized target. Even if these source files do not have build rules, they are added to the IDE project files for ease of editing.

 

We can see the following command in the CMakeLists.txt file of Heka.

Add_custom_target (sbmgr ALL
$ {GO_EXECUTABLE} install $ {LDFLAGS} github.com/?illa-services/heka/#/?a-sbmgr
DEPENDS dead AD)

The corresponding go compilation Command is:

Go install command.

Compared with the build command, the install command installs executable files or library files to the agreed directory after compiling the source code.

  • The executable file compiled by go install is named by its directory name (DIR).
  • Go install installs executable files in the bin directory of the same level as src. The bin directory is automatically created by go install.
  • Go install compiles various packages on which executable files depend and stores them in the pkg directory at the same level as src.
Reference: http://www.cnblogs.com/ghj1976/archive/2013/04/23/3038347.html

Since Cmake has already set the environment variable env. bat file:

Set BUILD_DIR = % CD % \ build
Set NEWGOPATH = % BUILD_DIR % \ heka
If NOT "% GOBIN %" = "" (set p =! PATH: % GOBIN %; = !) Else (set p =! PATH !)
Endlocal & set GOPATH = % NEWGOPATH % & set GOBIN = % NEWGOPATH % \ bin & set PATH = % p %; % NEWGOPATH % \ bin;

 

References:

Getting started with CMake
Http://hahack.com/codes/cmake/

CMake usage & CMakeList.txt
Http://blog.csdn.net/u012150179/article/details/17852273

Chapter 1 of OSG you do not know: CMake preliminary (2)
Http://bbs.osgchina.org/forum.php? Mod = viewthread & tid = 1229 & fromuid = 3434

Use CMake in linux to build applications
Http://www.ibm.com/developerworks/cn/linux/l-cn-cmake/

Heka CMake compilation configuration analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.