From 90350662c9e5493aa128bf1b1fe791b6b23f53d5 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Tue, 10 Sep 2019 10:50:10 -0400 Subject: [PATCH 1/6] Use VERSION on the CMake project (#733) This sets the other variables: https://cmake.org/cmake/help/latest/command/project.html --- CMakeLists.txt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb522f9..60bff7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,13 +9,7 @@ include(CheckCXXCompilerFlag) ### ### Project settings ### -project(YAML_CPP) - -set(YAML_CPP_VERSION_MAJOR "0") -set(YAML_CPP_VERSION_MINOR "6") -set(YAML_CPP_VERSION_PATCH "2") -set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML_CPP_VERSION_PATCH}") - +project(YAML_CPP VERSION 0.6.2) ### ### Project options From d638508d332958c618264c432e71138f44f81794 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Tue, 10 Sep 2019 10:51:13 -0400 Subject: [PATCH 2/6] Set C++ standard options in CMake per-target instead of globally (#735) Setting CMAKE_CXX_STANDARD and CMAKE_CXX_STANDARD_REQUIRED directly is problematic when including yaml-cpp as a subproject. The proper way is to set these per-target. --- CMakeLists.txt | 9 +++++---- test/CMakeLists.txt | 5 +++++ util/CMakeLists.txt | 12 ++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60bff7e..03848bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,10 +26,6 @@ option(YAML_CPP_INSTALL "Enable generation of install target" ON) # http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) -# Set minimum C++ to 2011 standards -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - # --> Apple option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF) @@ -261,6 +257,11 @@ if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) PRIVATE $) endif() +set_target_properties(yaml-cpp PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON +) + set_target_properties(yaml-cpp PROPERTIES COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags}" ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8bdf303..0a669d5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -51,6 +51,11 @@ add_executable(run-tests ${test_headers} ) +set_target_properties(run-tests PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON +) + add_dependencies(run-tests googletest_project) set_target_properties(run-tests PROPERTIES diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 8a803b0..09dafa2 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -2,13 +2,25 @@ cmake_minimum_required(VERSION 3.5) add_sources(parse.cpp) add_executable(parse parse.cpp) +set_target_properties(parse PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON +) target_link_libraries(parse yaml-cpp) add_sources(sandbox.cpp) add_executable(sandbox sandbox.cpp) +set_target_properties(sandbox PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON +) target_link_libraries(sandbox yaml-cpp) add_sources(read.cpp) add_executable(read read.cpp) +set_target_properties(read PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON +) target_link_libraries(read yaml-cpp) From 6cdf36362519b4b8c38d162533a87152533f4de7 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Tue, 10 Sep 2019 13:00:07 -0400 Subject: [PATCH 3/6] CMake: Prefix options with "YAML" and hide platform-specific options (#734) * CMake: Prefix options with "YAML" and hide platform-specific options When including yaml-cpp as a subproject, some option names can conflict with other projects. (1) Make sure the yaml-cpp options are prefixed with YAML (2) Hide platform-specific options when possible to avoid cluttering the cmake option list * Update docs for change from BUILD_SHARED_LIBS to YAML_BUILD_SHARED_LIBS --- CMakeLists.txt | 28 ++++++++++++++++------------ README.md | 4 ++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03848bb..cede142 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,16 +24,20 @@ option(YAML_CPP_INSTALL "Enable generation of install target" ON) # --> General # see http://www.cmake.org/cmake/help/cmake2.6docs.html#variable:BUILD_SHARED_LIBS # http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library -option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) +option(YAML_BUILD_SHARED_LIBS "Build Shared Libraries" OFF) # --> Apple -option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF) +if(APPLE) + option(YAML_APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF) +endif() # --> Microsoft Visual C++ # see http://msdn.microsoft.com/en-us/library/aa278396(v=VS.60).aspx # http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=VS.71).aspx -option(MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON) -option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF) +if(MSVC) + option(YAML_MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON) + option(YAML_MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF) +endif() ### ### Sources, headers, directories and libs @@ -106,14 +110,14 @@ endif() set(yaml_c_flags ${CMAKE_C_FLAGS}) set(yaml_cxx_flags ${CMAKE_CXX_FLAGS}) -if(BUILD_SHARED_LIBS) +if(YAML_BUILD_SHARED_LIBS) set(LABEL_SUFFIX "shared") else() set(LABEL_SUFFIX "static") endif() if(APPLE) - if(APPLE_UNIVERSAL_BIN) + if(YAML_APPLE_UNIVERSAL_BIN) set(CMAKE_OSX_ARCHITECTURES ppc;i386) endif() endif() @@ -124,7 +128,7 @@ if(IPHONE) endif() if(WIN32) - if(BUILD_SHARED_LIBS) + if(YAML_BUILD_SHARED_LIBS) add_definitions(-D${PROJECT_NAME}_DLL) # use or build Windows DLL endif() if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) @@ -151,7 +155,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR # set(GCC_EXTRA_OPTIONS "") # - if(BUILD_SHARED_LIBS) + if(YAML_BUILD_SHARED_LIBS) set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} -fPIC") endif() # @@ -186,8 +190,8 @@ if(MSVC) set(LIB_RT_SUFFIX "md") # CMake defaults to /MD for MSVC set(LIB_RT_OPTION "/MD") # - if(NOT MSVC_SHARED_RT) # User wants to have static runtime libraries (/MT, /ML) - if(MSVC_STHREADED_RT) # User wants to have old single-threaded static runtime libraries + if(NOT YAML_MSVC_SHARED_RT) # User wants to have static runtime libraries (/MT, /ML) + if(YAML_MSVC_STHREADED_RT) # User wants to have old single-threaded static runtime libraries set(LIB_RT_SUFFIX "ml") set(LIB_RT_OPTION "/ML") if(NOT ${MSVC_VERSION} LESS 1400) @@ -217,7 +221,7 @@ if(MSVC) set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # to distinguish static libraries from DLL import libs # c) Correct suffixes for static libraries - if(NOT BUILD_SHARED_LIBS) + if(NOT YAML_BUILD_SHARED_LIBS) ### General stuff set(LIB_TARGET_SUFFIX "${LIB_SUFFIX}${LIB_RT_SUFFIX}") endif() @@ -279,7 +283,7 @@ if(IPHONE) endif() if(MSVC) - if(NOT BUILD_SHARED_LIBS) + if(NOT YAML_BUILD_SHARED_LIBS) # correct library names set_target_properties(yaml-cpp PROPERTIES DEBUG_POSTFIX "${LIB_TARGET_SUFFIX}d" diff --git a/README.md b/README.md index f33d350..e793143 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ cd build 3. Run CMake. The basic syntax is: ``` -cmake [-G generator] [-DBUILD_SHARED_LIBS=ON|OFF] .. +cmake [-G generator] [-DYAML_BUILD_SHARED_LIBS=ON|OFF] .. ``` * The `generator` is whatever type of build system you'd like to use. To see a full list of generators on your platform, just run `cmake` (with no arguments). For example: @@ -34,7 +34,7 @@ cmake [-G generator] [-DBUILD_SHARED_LIBS=ON|OFF] .. * On OS X, you might use "Xcode" to generate an Xcode project * On a UNIX-y system, simply omit the option to generate a makefile - * yaml-cpp defaults to building a static library, but you may build a shared library by specifying `-DBUILD_SHARED_LIBS=ON`. + * yaml-cpp defaults to building a static library, but you may build a shared library by specifying `-DYAML_BUILD_SHARED_LIBS=ON`. * For more options on customizing the build, see the [CMakeLists.txt](https://github.com/jbeder/yaml-cpp/blob/master/CMakeLists.txt) file. From db0bda7087a6fac811e78957787fc5037465ac4e Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sat, 14 Sep 2019 20:23:22 -0400 Subject: [PATCH 4/6] Static analysis fix: replace 0 and NULL with nullptr (#738) --- include/yaml-cpp/binary.h | 2 +- include/yaml-cpp/exceptions.h | 4 ++-- include/yaml-cpp/node/detail/impl.h | 14 +++++++------- include/yaml-cpp/node/detail/node_iterator.h | 4 ++-- include/yaml-cpp/node/impl.h | 2 +- include/yaml-cpp/ostream_wrapper.h | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/yaml-cpp/binary.h b/include/yaml-cpp/binary.h index 0267a3a..1050dae 100644 --- a/include/yaml-cpp/binary.h +++ b/include/yaml-cpp/binary.h @@ -39,7 +39,7 @@ class YAML_CPP_API Binary { rhs.clear(); rhs.resize(m_unownedSize); std::copy(m_unownedData, m_unownedData + m_unownedSize, rhs.begin()); - m_unownedData = 0; + m_unownedData = nullptr; m_unownedSize = 0; } else { m_data.swap(rhs); diff --git a/include/yaml-cpp/exceptions.h b/include/yaml-cpp/exceptions.h index 25523c9..ecf870a 100644 --- a/include/yaml-cpp/exceptions.h +++ b/include/yaml-cpp/exceptions.h @@ -117,7 +117,7 @@ inline const std::string KEY_NOT_FOUND_WITH_KEY( template inline const std::string BAD_SUBSCRIPT_WITH_KEY( - const T&, typename disable_if>::type* = 0) { + const T&, typename disable_if>::type* = nullptr) { return BAD_SUBSCRIPT; } @@ -129,7 +129,7 @@ inline const std::string BAD_SUBSCRIPT_WITH_KEY(const std::string& key) { template inline const std::string BAD_SUBSCRIPT_WITH_KEY( - const T& key, typename enable_if>::type* = 0) { + const T& key, typename enable_if>::type* = nullptr) { std::stringstream stream; stream << BAD_SUBSCRIPT << " (key: \"" << key << "\")"; return stream.str(); diff --git a/include/yaml-cpp/node/detail/impl.h b/include/yaml-cpp/node/detail/impl.h index 46615a9..4123b85 100644 --- a/include/yaml-cpp/node/detail/impl.h +++ b/include/yaml-cpp/node/detail/impl.h @@ -17,7 +17,7 @@ template struct get_idx { static node* get(const std::vector& /* sequence */, const Key& /* key */, shared_memory_holder /* pMemory */) { - return 0; + return nullptr; } }; @@ -27,7 +27,7 @@ struct get_idx::value>::type> { static node* get(const std::vector& sequence, const Key& key, shared_memory_holder /* pMemory */) { - return key < sequence.size() ? sequence[key] : 0; + return key < sequence.size() ? sequence[key] : nullptr; } static node* get(std::vector& sequence, const Key& key, @@ -46,13 +46,13 @@ struct get_idx::value>::type> { shared_memory_holder pMemory) { return key >= 0 ? get_idx::get( sequence, static_cast(key), pMemory) - : 0; + : nullptr; } static node* get(std::vector& sequence, const Key& key, shared_memory_holder pMemory) { return key >= 0 ? get_idx::get( sequence, static_cast(key), pMemory) - : 0; + : nullptr; } }; @@ -109,11 +109,11 @@ inline node* node_data::get(const Key& key, break; case NodeType::Undefined: case NodeType::Null: - return NULL; + return nullptr; case NodeType::Sequence: if (node* pNode = get_idx::get(m_sequence, key, pMemory)) return pNode; - return NULL; + return nullptr; case NodeType::Scalar: throw BadSubscript(key); } @@ -124,7 +124,7 @@ inline node* node_data::get(const Key& key, } } - return NULL; + return nullptr; } template diff --git a/include/yaml-cpp/node/detail/node_iterator.h b/include/yaml-cpp/node/detail/node_iterator.h index 088090f..ab6916f 100644 --- a/include/yaml-cpp/node/detail/node_iterator.h +++ b/include/yaml-cpp/node/detail/node_iterator.h @@ -26,9 +26,9 @@ template struct node_iterator_value : public std::pair { typedef std::pair kv; - node_iterator_value() : kv(), pNode(0) {} + node_iterator_value() : kv(), pNode(nullptr) {} explicit node_iterator_value(V& rhs) : kv(), pNode(&rhs) {} - explicit node_iterator_value(V& key, V& value) : kv(&key, &value), pNode(0) {} + explicit node_iterator_value(V& key, V& value) : kv(&key, &value), pNode(nullptr) {} V& operator*() const { return *pNode; } V& operator->() const { return *pNode; } diff --git a/include/yaml-cpp/node/impl.h b/include/yaml-cpp/node/impl.h index 0b0e296..7a3deac 100644 --- a/include/yaml-cpp/node/impl.h +++ b/include/yaml-cpp/node/impl.h @@ -52,7 +52,7 @@ inline Node::Node(Zombie) : m_isValid(false), m_invalidKey{}, m_pMemory{}, m_pNode(nullptr) {} inline Node::Node(Zombie, const std::string& key) - : m_isValid(false), m_invalidKey(key), m_pMemory{}, m_pNode(NULL) {} + : m_isValid(false), m_invalidKey(key), m_pMemory{}, m_pNode(nullptr) {} inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory) : m_isValid(true), m_invalidKey{}, m_pMemory(pMemory), m_pNode(&node) {} diff --git a/include/yaml-cpp/ostream_wrapper.h b/include/yaml-cpp/ostream_wrapper.h index 259801b..cf89741 100644 --- a/include/yaml-cpp/ostream_wrapper.h +++ b/include/yaml-cpp/ostream_wrapper.h @@ -30,7 +30,7 @@ class YAML_CPP_API ostream_wrapper { const char* str() const { if (m_pStream) { - return 0; + return nullptr; } else { m_buffer[m_pos] = '\0'; return &m_buffer[0]; From b218787b984239c2311b91ac5386e642e94e9095 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sat, 14 Sep 2019 20:24:17 -0400 Subject: [PATCH 5/6] Remove extraneous conversion from string -> c_str -> string (#739) --- include/yaml-cpp/exceptions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/yaml-cpp/exceptions.h b/include/yaml-cpp/exceptions.h index ecf870a..eef2283 100644 --- a/include/yaml-cpp/exceptions.h +++ b/include/yaml-cpp/exceptions.h @@ -160,7 +160,7 @@ class YAML_CPP_API Exception : public std::runtime_error { static const std::string build_what(const Mark& mark, const std::string& msg) { if (mark.is_null()) { - return msg.c_str(); + return msg; } std::stringstream output; From 968e0c1f0281fdaf66d0983bd8bd694263400810 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sat, 14 Sep 2019 21:21:35 -0400 Subject: [PATCH 6/6] Fix shared lib build with new YAML_BUILD_SHARED_LIBS option (#737) --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cede142..f3380b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -252,7 +252,11 @@ set(_INSTALL_DESTINATIONS ### ### Library ### -add_library(yaml-cpp ${library_sources}) +if(YAML_BUILD_SHARED_LIBS) + add_library(yaml-cpp SHARED ${library_sources}) +else() + add_library(yaml-cpp STATIC ${library_sources}) +endif() if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) target_include_directories(yaml-cpp