The real CMake support

This patch provides a CMakeLists.txt file to build JSON-C library without relying on auto-tools support. This makes the build a bit more portable and cleaner.

It can detect headers and symbols and generate config.h header file based on those detections. It cannot yet handle ctest(1) as the testing itself depends on comparing the output against files. Testing would need some creative abuse of CMake :) This will be provided a few patches later and may possibly involve refactoring test cases.

The patch has been tested on GCC 4.8.5 (Linux), GCC 7.2.0 (MinGW) and Microsoft Visual C++ 16.0 (2010?) locally. Also, compiles correctly on Travis CI and AppVeyor without errors.
This commit is contained in:
Unmanned Player
2018-07-24 08:06:13 +10:00
parent 2327b23d8e
commit f2e991a341
6 changed files with 487 additions and 155 deletions

View File

@@ -5,8 +5,9 @@
2. [Building on Unix](#buildunix)
3. [Install Prerequisites](#installprereq)
4. [Building with partial threading support](#buildthreaded)
5. [Linking to libjson-c](#linking)
6. [Using json-c](#using)
5. [Building with CMake](#CMake)
6. [Linking to libjson-c](#linking)
7. [Using json-c](#using)
JSON-C - A JSON implementation in C <a name="overview"></a>
-----------------------------------
@@ -15,8 +16,8 @@ Build Status
* [AppVeyor Build](https://ci.appveyor.com/project/hawicz/json-c) ![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/json-c/json-c?branch=master&svg=true)
* [Travis Build](https://travis-ci.org/json-c/json-c) ![Travis Build Status](https://travis-ci.org/json-c/json-c.svg?branch=master)
JSON-C implements a reference counting object model that allows you to easily
construct JSON objects in C, output them as JSON formatted strings and parse
JSON-C implements a reference counting object model that allows you to easily
construct JSON objects in C, output them as JSON formatted strings and parse
JSON formatted strings back into the C representation of JSON objects.
It aims to conform to [RFC 7159](https://tools.ietf.org/html/rfc7159).
@@ -72,7 +73,7 @@ Install prerequisites <a name="installprereq"></a>
-----------------------
If you are on a relatively modern system, you'll likely be able to install
the prerequisites using your OS's packaging system.
the prerequisites using your OS's packaging system.
### Install using apt (e.g. Ubuntu 16.04.2 LTS)
```sh
@@ -134,6 +135,31 @@ lh_char_hash, uses a compare-and-swap operation to ensure the randomly
seed is only generated once. Because this is a one-time operation, it
is always compiled in when the compare-and-swap operation is available.
Building with CMake <a name="CMake"></a>
--------------------
To use [CMake](https://cmake.org/cmake-tutorial/), build it like:
```sh
mkdir build
cd build
cmake ../
make
```
CMake can take a few options.
Variable | Type | Description
------------------|------|--------------
BUILD_SHARED_LIBS | Bool | The default build generates static library. Enable this to generate shared (dll/so) library.
ENABLE_RDRAND | Bool | Enable RDRAND Hardware RNG Hash Seed
ENABLE_THREADING | Bool | Enable partial threading support
Pass these options as `-D` on CMake's command-line.
```sh
cmake -DBUILD_SHARED_LIBS=On ...
```
Linking to `libjson-c` <a name="linking">
----------------------