Skip to content

Commit 24878fb

Browse files
author
Eduardo Ramos Testillano (eramedu)
committed
Add JSON2XML_BuildExamples option to cmake
1 parent 0e620b3 commit 24878fb

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
cmake_minimum_required (VERSION 3.5.1)
55
project(ert_json2xml VERSION 1.0.0 LANGUAGES CXX)
66

7+
set(MAIN_PROJECT OFF)
8+
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
9+
set(MAIN_PROJECT ON)
10+
endif()
11+
712
###########
813
# Modules #
914
###########
1015
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/")
1116

12-
#################
13-
# Configuration #
14-
#################
17+
###########################
18+
# Options & Configuration #
19+
###########################
20+
option(JSON2XML_BuildExamples "Build the examples." ${MAIN_PROJECT})
1521
set(ERT_JSON2XML_TARGET_NAME ${PROJECT_NAME})
1622
set(ERT_JSON2XML_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
1723

@@ -75,5 +81,7 @@ target_include_directories(
7581
##################
7682
# Subdirectories #
7783
##################
78-
add_subdirectory( examples )
84+
if (JSON2XML_BuildExamples)
85+
add_subdirectory( examples )
86+
endif()
7987

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,61 @@
1+
[TOC]
2+
13
# C++ json2xml converter
24

35
C++ header-only converter from Json to XML.
46
Include [json2xml.hpp](include/ert/json2xml.hpp) into your project.
7+
See more at Integration.
58

69
CICD tested with [Codefresh](https://codefresh.io/).
710

11+
## Integration
12+
13+
[`json2xml.hpp`](https://github.com/testillano/json2xml/blob/master/include/ert/json2xml.hpp) is the single required file in `include/ert` or [released here](https://github.com/testillano/json2xml/releases). You need to add
14+
15+
```cpp
16+
#include <ert/json2xml.hpp>
17+
```
18+
19+
### CMake
20+
21+
#### Embedded
22+
23+
To embed the library directly into an existing CMake project, place the entire source tree in a subdirectory and call `add_subdirectory()` in your `CMakeLists.txt` file:
24+
25+
```cmake
26+
# Typically you don't care so much for a third party library's examples to be
27+
# run from your own project's code.
28+
set(JSON2XML_BuildExamples OFF CACHE INTERNAL "")
29+
30+
add_subdirectory(ert_json2xml)
31+
...
32+
add_library(foo ...)
33+
...
34+
target_link_libraries(foo PRIVATE ert_json2xml::ert_json2xml)
35+
```
36+
37+
##### Embedded (FetchContent)
38+
39+
Since CMake v3.11,
40+
[FetchContent](https://cmake.org/cmake/help/v3.11/module/FetchContent.html) can be used to automatically download the repository as a dependency at configure type.
41+
42+
Example:
43+
```cmake
44+
include(FetchContent)
45+
46+
FetchContent_Declare(ert_json2xml
47+
GIT_REPOSITORY https://github.com/testillano/json2xml.git
48+
GIT_TAG v1.0.1)
49+
50+
FetchContent_GetProperties(ert_json2xml)
51+
if(NOT ert_json_POPULATED)
52+
FetchContent_Populate(ert_json2xml)
53+
add_subdirectory(${ert_json2xml_SOURCE_DIR} ${ert_json2xml_BINARY_DIR} EXCLUDE_FROM_ALL)
54+
endif()
55+
56+
target_link_libraries(foo PRIVATE ert_json2xml::ert_json2xml)
57+
```
58+
859
## Build example and test natively
960

1061
### Build

0 commit comments

Comments
 (0)