jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
4.91k stars 1.78k forks source link

Installation of yaml-cpp using Homebrew and CMake does not work. #1202

Closed vrtulka23 closed 11 months ago

vrtulka23 commented 11 months ago

Hi,

I was recently trying to install yaml-cpp on my M1 Macbook Pro using Homebrew compiling using CMake. The installation does not run properly. Maybe I miss something, but the variables in yaml-cpp-config.cmake seem to have empty values.

My CMakeList.txt tries to find and include YAML in a following way:

find_package(yaml-cpp REQUIRED)
include_directories(${YAML_CPP_INCLUDE_DIRS})
target_link_libraries(hydro1d ${YAML_CPP_LIBRARIES})

The installation of yaml-cpp using Homebrew creates directory: /opt/homebrew/Cellar/yaml-cpp/0.7.0/ CMake configuration files are generated here: /opt/homebrew/Cellar/yaml-cpp/0.7.0/share/cmake/yaml-cpp/yaml-cpp-....cmake

File yaml-cpp-config.cmake is defaultly set as:

# - Config file for the yaml-cpp package
# It defines the following variables
#  YAML_CPP_INCLUDE_DIR - include directory
#  YAML_CPP_LIBRARIES    - libraries to link against

# Compute paths
get_filename_component(YAML_CPP_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(YAML_CPP_INCLUDE_DIR "")

# Our library dependencies (contains definitions for IMPORTED targets)
include("${YAML_CPP_CMAKE_DIR}/yaml-cpp-targets.cmake")

# These are IMPORTED targets created by yaml-cpp-targets.cmake
set(YAML_CPP_LIBRARIES "")

This obviously does not work, but it can be FIXED manually. One has to set the proper YAML_CPP_INCLUDE_DIR and YAML_CPP_LIBRARIES variables as follow:

set(YAML_CPP_INCLUDE_DIR "/opt/homebrew/Cellar/yaml-cpp/0.7.0/include")
set(YAML_CPP_LIBRARIES "yaml-cpp")

I don't know why this happens, but those settings are simply missing in a standard Homebrew installation and library cannot be linked properly by CMake.

The above fix resolves the problem. Please repare it in the source code or explain me what is going on wrong.

Thanks!

jbeder commented 11 months ago

It sounds like this issue should be filed on the Homebrew project? Or do you have a suggestion for changing yaml-cpp's CMake file?

vrtulka23 commented 11 months ago

Well, as I said.

The issue resolves if one sets:

set(YAML_CPP_INCLUDE_DIR "/opt/homebrew/Cellar/yaml-cpp/0.7.0/include")
set(YAML_CPP_LIBRARIES "yaml-cpp")

in the yaml-cpp-config.cmake file.

How and where to do it during the Homebrew installation process is up to project developers. Where is the project located?

jbeder commented 11 months ago

I have no idea. I think Homebrew is a GitHub project. Have you looked it up?

vrtulka23 commented 11 months ago

Ok, I posted it to the Homebrew issues: https://github.com/Homebrew/homebrew-core/issues/136584

vrtulka23 commented 11 months ago

Hi, the Homebrew guy said, that it is an issue of yaml-cpp and not Homebrew: https://github.com/Homebrew/homebrew-core/issues/136584

jbeder commented 11 months ago

I don't really know anything about Homebrew, but I was going based on your suggestion to set some variable to use a Homebrew path. That's not going in yaml-cpp, obviously.

If yaml-cpp is doing something wrong and you want to fix it, please let me know and I'm happy to accept a PR. But a vague "yaml-cpp doesn't work with Homebrew" isn't a good issue here. Maybe ask on Stack Overflow to try to clarify the issue and then figure out if it's a bug with one of these systems?

carlocab commented 11 months ago

Hi there, Homebrew guy here. Based on the discussion at Homebrew/homebrew-core#136584, this issue can be reproduced without using Homebrew at all, so it doesn't seem like this is a Homebrew issue.

One can do this by following your installation instructions from the yaml-cpp-0.7.0 tag. This appears to be fixed on master, though, so it may suffice to cut a new release tag?

gromgit commented 11 months ago

The underlying issue is that Homebrew builds only from official releases. The latest yaml-cpp release is 0.7.0, over two years old now, and therefore didn't capture https://github.com/jbeder/yaml-cpp/pull/1077.

vrtulka23 commented 11 months ago

So please update the release number and problem solved!

jbeder commented 11 months ago

Ah, makes sense, will do!