Skip to content

Commit 7883e7f

Browse files
committed
Adding pkg-config generation to CMakeLists
Adding the necessary magic to the CMakeLists.txt, including a new version.cmake file that generates the pkg-config .pc file. This file makes it much easier when building other applications/libraries dependent on the installed package. As an example, the short go version has also been updated to demonstrate how compilers understanding pkg-config would make use of this file. Additionally, added information on building and running the Go example to go/README.md
1 parent 0fb896c commit 7883e7f

File tree

6 files changed

+67
-15
lines changed

6 files changed

+67
-15
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ cmake_install.cmake
1818
GraphQLParser.py
1919
install_manifest.txt
2020
build/
21+
libgraphqlparser.pc

CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
22
PROJECT(libgraphqlparser C CXX)
33

4+
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")
5+
6+
INCLUDE(version)
7+
48
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
59

610
FIND_PACKAGE(PythonInterp 2 REQUIRED)
@@ -97,6 +101,17 @@ INSTALL(FILES
97101
INSTALL(TARGETS graphqlparser
98102
LIBRARY DESTINATION lib)
99103

104+
if (UNIX)
105+
# generate pkgconfig file
106+
include(FindPkgConfig QUIET)
107+
if(PKG_CONFIG_FOUND)
108+
# generate .pc and install
109+
configure_file("libgraphqlparser.pc.in" "libgraphqlparser.pc" @ONLY)
110+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libgraphqlparser.pc"
111+
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
112+
endif()
113+
endif()
114+
100115
IF (test)
101116
ADD_SUBDIRECTORY(test)
102117

cmake/version.cmake

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
find_package(Git QUIET)
2+
3+
# default version string
4+
set(LIBGRAPHQLPARSER_VERSION "0.0-dev")
5+
6+
if(GIT_EXECUTABLE AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
7+
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags
8+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
9+
OUTPUT_VARIABLE LIBGRAPHQLPARSER_VERSION
10+
ERROR_QUIET
11+
OUTPUT_STRIP_TRAILING_WHITESPACE
12+
)
13+
string(SUBSTRING ${LIBGRAPHQLPARSER_VERSION} 1 -1 LIBGRAPHQLPARSER_VERSION)
14+
endif()

go/README.md

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
This directory contains an example usage of the GraphQL parser and AST
2-
library from Go. See [cgo's
3-
documentation](https://github.com/golang/go/wiki/cgo), particularly
4-
the "Function pointer callbacks" section, for explanation of the
5-
mechanisms in use.
6-
7-
To build, first build the main GraphQLParser library in the parent
8-
directory, and then set this directory to be your `GOPATH` and run `go
9-
build`.
1+
# About
2+
This directory contains an example using the libgraphqlparser C library from [Go](https://golang.org/project/).
3+
4+
For an overview of binding to C libraries in Go, please see the [cgo documentation](https://github.com/golang/go/wiki/cgo).
5+
Specifically, please read the overview of [Function pointer callbacks](https://github.com/golang/go/wiki/cgo#function-pointer-callbacks) in Go and C.
6+
7+
## Building and Running
8+
9+
To build with Go, please ensure that you have `pkg-config` installed for your
10+
system.
11+
12+
Assuming pkg-config has been installed, it should be possible to then build
13+
using Go in the normal fashion:
14+
```sh
15+
$ cd libgraphqlparser/go
16+
$ go build
17+
$ ./go
18+
field : myfield
19+
Example error: 1.18-19: syntax error, unexpected on, expecting ( or @ or {
20+
```

go/gotest.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
package main
1010

1111
/*
12-
#cgo CFLAGS: -I ../c -I ..
13-
#cgo LDFLAGS: -L .. -lgraphqlparser
14-
#include "GraphQLAst.h"
15-
#include "GraphQLAstNode.h"
16-
#include "GraphQLAstVisitor.h"
17-
#include "GraphQLParser.h"
12+
#cgo pkg-config: libgraphqlparser
13+
14+
#include "c/GraphQLAst.h"
15+
#include "c/GraphQLAstNode.h"
16+
#include "c/GraphQLAstVisitor.h"
17+
#include "c/GraphQLParser.h"
1818
#include <stdlib.h>
1919
2020
int printField_cgo(struct GraphQLAstField *field, void *unused);

libgraphqlparser.pc.in

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@CMAKE_INSTALL_PREFIX@
2+
exec_prefix=${prefix}
3+
libdir=${exec_prefix}/lib
4+
includedir=${prefix}/include/graphqlparser
5+
6+
Name: @CMAKE_PROJECT_NAME@
7+
Description: facebook graphql parsing library
8+
Version: @LIBGRAPHQLPARSER_VERSION@
9+
Libs: -L${libdir} -lgraphqlparser
10+
Libs.private:
11+
Cflags: -I${includedir}

0 commit comments

Comments
 (0)