Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ find_program(YAML_CPP_CLANG_FORMAT_EXE NAMES clang-format)
option(YAML_CPP_BUILD_CONTRIB "Enable yaml-cpp contrib in library" ON)
option(YAML_CPP_BUILD_TOOLS "Enable parse tools" ON)
option(YAML_BUILD_SHARED_LIBS "Build yaml-cpp shared library" ${BUILD_SHARED_LIBS})
option(YAML_CPP_INSTALL "Enable generation of yaml-cpp install targets" ON)
Copy link

@madebr madebr Jul 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always install yaml-cpp, even when included as a subproject, which is often undesired.
I would change the default to only install when yaml-cpp is the main project.

So something as follows:

Add this to the top of the cmake script:

set(YAML_CPP_MAIN_PROJECT ON)
if(DEFINED PROJECT_SOURCE_DIR
    set(YAML_CPP_MAIN_PROJECT OFF)
endif()

# 3.5 is actually available almost everywhere, but this a good minimum
cmake_minimum_required(VERSION 3.4)
project(YAML_CPP VERSION 0.6.3 LANGUAGES CXX)

And then change this line to:

Suggested change
option(YAML_CPP_INSTALL "Enable generation of yaml-cpp install targets" ON)
option(YAML_CPP_INSTALL "Enable generation of yaml-cpp install targets" ${YAML_CPP_MAIN_PROJECT})

This combines the best of both worlds:

  • yaml-cpp is not installed (by default) when included as a subproject
  • if it is really wanted, yaml-cpp can be installed by enabling the YAML_CPP_INSTALL cache definition.


cmake_dependent_option(YAML_CPP_BUILD_TESTS
"Enable yaml-cpp tests" ON
"BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
cmake_dependent_option(YAML_CPP_INSTALL
"Enable generation of yaml-cpp install targets" ON
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
cmake_dependent_option(YAML_MSVC_SHARED_RT
"MSVC: Build yaml-cpp with shared runtime libs (/MD)" ON
"MSVC" OFF)
Expand Down