Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: handle backward compatibility #1285

Open
aberaud opened this issue Jun 6, 2024 · 3 comments
Open

CMake: handle backward compatibility #1285

aberaud opened this issue Jun 6, 2024 · 3 comments

Comments

@aberaud
Copy link

aberaud commented Jun 6, 2024

Some versions of yaml-cpp require to link cmake targets with yaml-cpp,
while more recent version require to link them with yaml-cpp::yaml-cpp.

Is there a way to handle backward compatibility in CMake so it would work in both cases ? Many Linux distros still ship with versions that require yaml-cpp.

Many thanks

@sei-mwd
Copy link

sei-mwd commented Jun 6, 2024

Well, I haven't tried it with yaml-cpp, but I have had to deal with this problem before. Here's a snippet from that:

  find_package(date CONFIG NAMES date howardhinnant-date REQUIRED)
  message(STATUS "Found and using libdate.")
  if(TARGET howardhinnant-date::howardhinnant-date-tz)
    add_library(date::date-tz ALIAS howardhinnant-date::howardhinnant-date-tz)
  endif()

I imagine you can use something similar.

@aberaud
Copy link
Author

aberaud commented Jun 7, 2024

Thanks :)

We ended up using a similar approach:

    if (TARGET yaml-cpp)
        target_link_libraries(${PROJECT_NAME} PRIVATE yaml-cpp)
    else()
        target_link_libraries(${PROJECT_NAME} PRIVATE yaml-cpp::yaml-cpp)
    endif()

This should probably documented somewhere.

@md5i
Copy link
Contributor

md5i commented Jun 7, 2024

The advantage of creating the ALIAS library is if you ever need to use it more than one place in your build system, you only have to have the conditional in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants