mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-08 12:21:17 +00:00
CMake: Fixes for generated config (#1212)
* CMake: Add option to set the package install dir. * CMake: Fix generated config. - `YAML_CPP_SHARED_LIBS_BUILT` should not be set with a `PATH_VAR` as it would always evaluate to true. - `YAML_CPP_LIBRARIES` should used the exported target name including the namespace, but `check_required_components` shouldn't. - Use `CMAKE_CURRENT_LIST_DIR` to find the target file, instead of a `PATH_VAR`. Package managers such as vcpkg move CMake configs after installing. * CI: Test the generated CMake package. * CMake: Create add a deprecated yaml-cpp target. This target is meant to provide compatibility with versions prior to 0.8.0. * CMake: mark the yaml-cpp target as IMPORTED. --------- Co-authored-by: Jesse Beder <jbeder+github@gmail.com>
This commit is contained in:
19
test/cmake/CMakeLists.txt
Normal file
19
test/cmake/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(yaml-cpp-consumer LANGUAGES CXX)
|
||||
|
||||
find_package(yaml-cpp CONFIG REQUIRED)
|
||||
get_target_property(LIBRARY_TYPE yaml-cpp::yaml-cpp TYPE)
|
||||
|
||||
if(LIBRARY_TYPE STREQUAL "SHARED_LIBRARY")
|
||||
if(NOT YAML_CPP_SHARED_LIBS_BUILT)
|
||||
message(FATAL_ERROR "Library type (${LIBRARY_TYPE}) contradicts config: ${YAML_CPP_SHARED_LIBS_BUILT}")
|
||||
endif()
|
||||
else()
|
||||
if(YAML_CPP_SHARED_LIBS_BUILT)
|
||||
message(FATAL_ERROR "Library type (${LIBRARY_TYPE}) contradicts config: ${YAML_CPP_SHARED_LIBS_BUILT}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_executable(main main.cpp)
|
||||
set_target_properties(main PROPERTIES CXX_STANDARD 11)
|
||||
target_link_libraries(main PRIVATE ${YAML_CPP_LIBRARIES})
|
3
test/cmake/main.cpp
Normal file
3
test/cmake/main.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "yaml-cpp/yaml.h"
|
||||
|
||||
int main(int, char**) { YAML::Parser foo{}; }
|
Reference in New Issue
Block a user