mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-17 06:37:43 -05:00
add yaml example
This commit is contained in:
25
examples/yaml/CMakeLists.txt
Normal file
25
examples/yaml/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
# ---- Dependencies ----
|
||||
|
||||
include(../../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME yaml-cpp
|
||||
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
|
||||
# 0.6.2 uses old CMake syntax
|
||||
VERSION 0.6.3
|
||||
# 0.6.3 not released yet
|
||||
GIT_TAG 012269756149ae99745b6dafefd415843d7420bb
|
||||
OPTIONS
|
||||
"YAML_CPP_BUILD_TESTS Off"
|
||||
"YAML_CPP_BUILD_CONTRIB On"
|
||||
"YAML_CPP_BUILD_TOOLS On"
|
||||
)
|
||||
|
||||
# ---- Executable ----
|
||||
|
||||
add_executable(CPMYamlExample "main.cpp")
|
||||
set_target_properties(CPMYamlExample PROPERTIES CXX_STANDARD 17)
|
||||
target_link_libraries(CPMYamlExample yaml-cpp)
|
||||
|
||||
14
examples/yaml/main.cpp
Normal file
14
examples/yaml/main.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char ** argv){
|
||||
if (argc != 2) {
|
||||
std::cout << "usage: " << argv[0] << " <path to yaml file>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
YAML::Node config = YAML::LoadFile(argv[1]);
|
||||
std::cout << "Parsed YAML:\n" << config << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
21
examples/yaml/monsters.yaml
Normal file
21
examples/yaml/monsters.yaml
Normal file
@@ -0,0 +1,21 @@
|
||||
- name: Ogre
|
||||
position: [0, 5, 0]
|
||||
powers:
|
||||
- name: Club
|
||||
damage: 10
|
||||
- name: Fist
|
||||
damage: 8
|
||||
- name: Dragon
|
||||
position: [1, 0, 10]
|
||||
powers:
|
||||
- name: Fire Breath
|
||||
damage: 25
|
||||
- name: Claws
|
||||
damage: 15
|
||||
- name: Wizard
|
||||
position: [5, -3, 0]
|
||||
powers:
|
||||
- name: Acid Rain
|
||||
damage: 50
|
||||
- name: Staff
|
||||
damage: 3
|
||||
Reference in New Issue
Block a user