jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
5.18k stars 1.87k forks source link

Question about Integrate it within your project using CMake #1320

Closed copilot0058 closed 1 month ago

copilot0058 commented 1 month ago

https://github.com/jbeder/yaml-cpp?tab=readme-ov-file#how-to-integrate-it-within-your-project-using-cmake

Q1. YAML_CPP_INCLUDE_DIR and YAML_CPP_LIBRARIES are ""?

Q2. Why is it unnecessary to use target_include_directories(test ${YAML_CPP_INCLUDE_DIR})? only use target_link_libraries

Q3. I write a library with opencv and yaml-cpp and set this

# lib cmake
target_link_libraries(YOUR_LIBRARY PRIVATE ${OpenCV_LIBS} yaml-cpp::yaml-cpp)

Now I want to use another program to call YOUR_LIBRARY

# new project cmake
target_link_libraries(test PRIVATE YOUR_LIBRARY::YOUR_LIBRARY)

It show the

# on new project error
'yaml-cpp/yaml.h': No such file or directory

Until I only change yaml-cpp::yaml-cpp from PRIVATE to PUBLIC, it build successly.

# lib cmake
target_link_libraries(YOUR_LIBRARY PRIVATE ${OpenCV_LIBS} 
PUBLIC yaml-cpp::yaml-cpp)

Why does it must be PUBLIC for yaml? But the opencv can PRIVATE.

jbeder commented 1 month ago

I have no idea. I'd ask on Stack Overflow.