Qt创建生成pkg-config工程库的方法

1、文件:qmake-example.pro

## We get the PREFIX, QMAKE_EXAMPLE_MAJOR_VERSION, QMAKE_EXAMPLE_SOVERSION,
## QMAKE_EXAMPLE_MINOR_VERSION, QMAKE_EXAMPLE_PATCH_VERSION,
## QMAKE_EXAMPLE_CURRENT_VERSION, QMAKE_EXAMPLE_REVISION_VERSION,
## QMAKE_EXAMPLE_VERSION and QMAKE_EXAMPLE_AGE_VERSION from this project-wide
## qmake-example.pri include file.

include(../../../qmake-example.pri)

## In qmake we have to remove qt explicitly if we don't want to link against it

CONFIG -= qt

## We will use the standard lib template of qmake

TEMPLATE = lib

# In qmake you need to use this VERSION variable for libtool's -version-info

VERSION = $${QMAKE_EXAMPLE_VERSION}

## We will therefor also make ourselves a semver-version, to be put in
## the config.h as a VERSION #define.

SEMVER_VERSION = $${QMAKE_EXAMPLE_MAJOR_VERSION}"."$${QMAKE_EXAMPLE_MINOR_VERSION}"."$${QMAKE_EXAMPLE_PATCH_VERSION}

## According to https://autotools.io/libtool/version.html, section 4.3
## Multiple libraries versions, we should have as target-name the API
## version in the library's name. The so called APIVERSION variable is
## a perfect candidate to use for this purpose.
##
## Noting that for example a project like GLib keeps the API version
## number on 2.0, while they change the minor. They say that GLib 2.4
## has a GLib 2.0 API, I guess (up to you when maintaining a library)

TARGET = qmake-example-$${QMAKE_EXAMPLE_APIVERSION}

## We will write a define in config.h for access to the semantic version
## as a double quoted string

QMAKE_SUBSTITUTES += config.h.in

## We will be using libtool style libraries

CONFIG += compile_libtool create_libtool

## These will create a pkg-config .pc file for us

CONFIG += create_pc create_prl no_install_prl

## Project sources

SOURCES = \
	qmake-example.cpp

## Project's private and public headers

HEADERS = \
	qmake-example.h

## We will install the headers in a API specific include path

headers.path = $${PREFIX}/include/qmake-example-$${QMAKE_EXAMPLE_APIVERSION}

## Here we put only the publicly installed headers

headers.files = $${HEADERS}

## Here we will install the library to. If somebody has a better or
## more standardized way, let me know (I don't like this very much)

target.path = $${PREFIX}/lib

## This is the configuration for generating the pkg-config file

# This makes sure that the pkg-config file is qmake-example-4.3.pc
QMAKE_PKGCONFIG_FILE = $${TARGET}

# This fills in the Name property
QMAKE_PKGCONFIG_NAME = $${TARGET}

# This fills in the Description property
QMAKE_PKGCONFIG_DESCRIPTION = An example on how to do it right with qmake

# This is our libdir
QMAKE_PKGCONFIG_LIBDIR = $$target.path

# This is where our API specific headers are
QMAKE_PKGCONFIG_INCDIR = $$headers.path
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
QMAKE_PKGCONFIG_PREFIX = $${PREFIX}

# Usually people take the semver version here
QMAKE_PKGCONFIG_VERSION = $${SEMVER_VERSION}

## Installation targets (the pkg-config seems to install automatically)

INSTALLS += headers target

2、文件:config.h.in

#ifndef CONFIG_H
#define CONFIG_H

#define VERSION '"$$SEMVER_VERSION"'

#endif

3、文件:qmake-example.h

#ifndef QMAKE_EXAMPLE
#define QMAKE_EXAMPLE

class QMakeExample {
public:
	explicit QMakeExample() { }
	void hello();
};


#endif

4、文件:qmake-example.cpp

#include "config.h"

#include "qmake-example.h"

void QMakeExample::hello()
{
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值