Table of contents
Updated at 2020-03-20 16:00:22



Before reading this article, you must read basic concepts

There are two ways to manage C + + development services: makefile and cmake management

In tarscpp >= 2.1.0, cmake management is recommended as the main mode, and makefile mode is no longer supported by default

1. cmake spec

1.1. cmake use

For services implemented with tars, it is highly recommended to use the cmake specification.

The tars framework provides a basic tars-tools.cmake (/usr/local/tars/cpp/makefile/tars-tools.cmake), CMakelists.txt of business service can reference this file

The tars framework also provides scripts (/usr/local/tars/cpp/script/ can create empty bussiness server and CMakeLists.txt

CMakeLists.txt examples:

cmake_minimum_required(VERSION 2.8)


option(TARS_MYSQL "option for mysql" ON)
option(TARS_SSL "option for ssl" OFF)
option(TARS_HTTP2 "option for http2" OFF)

    include (c:\\tars\\cpp\\makefile\\tars-tools.cmake)
    include (/usr/local/tars/cpp/makefile/tars-tools.cmake)







server source code is in src directory,CMakeLists.txt as follow:

cmake_minimum_required(VERSION 2.8)


gen_server(Test HelloServer)


mkdir build
cd build 
cmake ..
make -j4

1.2. Manage multiple services

With cmake management service, you can manage multiple services in one directory, one directory for each service. In the root cmakelists.txt, call:


1.3. Include tars protocol

When you need to include the tars files of other services, you can reference the tars directory of the corresponding services in CMakelists.txt, for example:


1.4. Include library

When you need to reference the Lib library, such as MySQL:


If other services in the directory refer to different libraries, you can modify each service's own CMakeLists.txt

1.5. release tars protocol

In order to make it convenient for other services to use the tars file of the current service, you can execute the following command (note that it is executed in the build directory):

make HelloServer-release

1.5. Package and upload services

You can package and upload services with one click:

make HelloServer-tar
make HelloServer-upload

Upload service needs to set the web address correctly


And open the upload configuration of the web (usually done by the test environment), refer to basic concepts

2. Makefile specification

It is highly recommended to use the cmake specification when use service that realized with Tars.

But if you use makefile, you can use specification as follows.

The TARS framework provides a basic Makefile for makefile.tars. The service written in Tars contains the Makefile to help you maintain the Makefile.

The TARS framework also provides a script (installation directory /script/ to automatically generate an empty service framework and Makefile;

2.1. Makefile usage principle

In principle, a directory can only be a Server or a program, that is, a Makefile can only have one Target;

When you need to include other libraries, include them in the bottom of the Makefile according to the dependency order;


include /home/tarsproto/TestApp/HelloServer/
include /usr/local/tars/cpp/makefile/makefile.tars

Makefile.tars must be included.

2.2. Makefile template explanation

APP: the name space of the program (ie Application)

TARGET: Server name;

CONFIG: The name of the configuration file. When you make tar, the file is included in the tarball.

INCLUDE: Other paths that need to be included;

LIB: Required Library

The Makefile for Test.HelloServer is as follows:

#------------------------------------------------- ----------------------

APP            := TestApp
TARGET         := HelloServer
CONFIG         := HelloServer.conf

INCLUDE        +=
LIB            +=

#------------------------------------------------- ----------------------

Include /home/tarsproto/TestApp/HelloServer/
Include /usr/local/tars/cpp/makefile/makefile.tars

The key variables are usually not used, but the business can add its own values after these variables:

RELEASE_TARS: You need to publish the tars file in the /home/tarsproto/ directory. If you need to publish your own .h to /home/tarsproto, you can do the following:
CONFIG: The name of the configuration file. In fact, you can add the files you need later, so that the file will be included in the tarball when you call make tar.

For other variables, please read makefile.tars.

2.3. Makefile use

make help: You can see all the functions of the makefile.

make tar: generate a release file

make release: copy the tars file to the /home/tarsproto directory and automatically generate the relevant mk file

make clean: clear

make cleanall: clear all