summaryrefslogtreecommitdiff
path: root/backport-Improve-CMake-build-system.patch
blob: b4ee5e843eeb10cb88396e12a6f611b516774c5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
From fe3d086fa75a289d6e4085df6f855f4c88c8d7c2 Mon Sep 17 00:00:00 2001
From: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
Date: Thu, 30 Nov 2017 08:14:27 -0500
Subject: [PATCH] Improve CMake build system

New build options
-----------------

* Add option BUILD_TESTING by default ON
See https://cmake.org/cmake/help/v2.8.12/cmake.html#module:CTest

* Simplify library type selection using standard option BUILD_SHARED_LIBS
See https://cmake.org/cmake/help/v3.0/variable/BUILD_SHARED_LIBS.html

yamlConfig.cmake
----------------

* Generate and install yamlConfig.cmake, yamlConfigVersion.cmake and yamlTargets.cmake

* Bump CMake version and explicitly associate include dirs with targets
See https://cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#include-directories-and-usage-requirements

* Ensure building against libyaml using "find_package(yaml)" uses expected compile options: Set HAVE_CONFIG_H
as private compile option, YAML_DECLARE_STATIC as public

Testing
-------

* Build all examples from "tests" directory

CMake Best practices
--------------------

* configure "config.h" based on version info found in CMakeLists.txt

* Ensure buildsystem re-generation listing sources (best-practice)

It is not recommended to use GLOB to collect a list of source files from
the source tree. If no CMakeLists.txt file changes when a source is added
or removed then the generated build system cannot know when to ask CMake
to regenerate.

See https://cmake.org/cmake/help/v3.8/command/file.html

Compilation warnings
--------------------

* Set _CRT_SECURE_NO_WARNINGS if building using VisualStudio

This will avoid warnings like this one:

```
C:\projects\libyaml\tests\run-emitter.c(268): warning C4996: 'fopen':
This function or variable may be unsafe. Consider using fopen_s instead.
To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for
details.
```

Continuous Integration
----------------------

* travis: Install CMake >= 3.x using scikit-ci-addons

* Add comments to appveyor.yml and run-tests.sh
---
 cmake/config.h.in    |   4 ++
 tests/CMakeLists.txt |  27 +++++++
 yamlConfig.cmake.in  |  16 +++++
 3 files changed, 47 insertions(+), 0 deletions(-)
 create mode 100644 cmake/config.h.in
 create mode 100644 tests/CMakeLists.txt
 create mode 100644 yamlConfig.cmake.in

diff --git a/cmake/config.h.in b/cmake/config.h.in
new file mode 100644
index 0000000..51e2e24
--- /dev/null
+++ b/cmake/config.h.in
@@ -0,0 +1,4 @@
+#define YAML_VERSION_MAJOR @YAML_VERSION_MAJOR@
+#define YAML_VERSION_MINOR @YAML_VERSION_MINOR@
+#define YAML_VERSION_PATCH @YAML_VERSION_PATCH@
+#define YAML_VERSION_STRING "@YAML_VERSION_STRING@"
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..d10b424
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,27 @@
+
+function(add_yaml_executable name)
+  add_executable(${name} ${name}.c)
+  target_link_libraries(${name} yaml)
+endfunction()
+
+foreach(name IN ITEMS
+  example-deconstructor
+  example-deconstructor-alt
+  example-reformatter
+  example-reformatter-alt
+  run-dumper
+  run-emitter
+  run-emitter-test-suite
+  run-loader
+  run-parser
+  run-parser-test-suite
+  run-scanner
+  test-reader
+  test-version
+  )
+  add_yaml_executable(${name})
+endforeach()
+
+add_test(NAME version COMMAND test-version)
+add_test(NAME reader COMMAND test-reader)
+
diff --git a/yamlConfig.cmake.in b/yamlConfig.cmake.in
new file mode 100644
index 0000000..dd3f8ee
--- /dev/null
+++ b/yamlConfig.cmake.in
@@ -0,0 +1,16 @@
+# Config file for the yaml library.
+#
+# It defines the following variables:
+#   yaml_LIBRARIES    - libraries to link against
+
+@PACKAGE_INIT@
+
+set_and_check(yaml_TARGETS "@PACKAGE_CONFIG_DIR_CONFIG@/yamlTargets.cmake")
+
+if(NOT yaml_TARGETS_IMPORTED)
+  set(yaml_TARGETS_IMPORTED 1)
+  include(${yaml_TARGETS})
+endif()
+
+set(yaml_LIBRARIES yaml)
+
-- 
2.27.0