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

AVRO-3088: [C++] Export CMake package config file #3299

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

wgtmac
Copy link
Member

@wgtmac wgtmac commented Jan 22, 2025

What is the purpose of the change

  • Apply modern CMake practice to use target-oriented functions.
  • Export and install CMake package configuration file.

Verifying this change

I have manually verified that the exported config file can be used by downstream projects like below:

find_package(Avro CONFIG REQUIRED)
target_link_libraries(xxx PRIVATE Avro::avrocpp_shared)
target_link_libraries(xxx PRIVATE Avro::avrocpp_static)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

@github-actions github-actions bot added the C++ Pull Requests for C++ binding label Jan 22, 2025
@wgtmac
Copy link
Member Author

wgtmac commented Jan 22, 2025

@mitjap @mkmkme @thiru-mg Could you help review this? Thanks!

Comment on lines +77 to +82
find_package (Boost 1.70 REQUIRED CONFIG COMPONENTS system)
if (TARGET Boost::system)
message("Found Boost version: ${Boost_VERSION}")
else ()
message(FATAL_ERROR "Boost::system not found")
endif ()
Copy link
Contributor

Choose a reason for hiding this comment

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

You mark this dependency as required. I think this check if target exists is not needed. CMake will fail if it does not find Boost and all requested components.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just want to make sure that the target with Boost:: namespace exists. Same for Snappy::snappy and ZLIB::ZLIB

Copy link
Contributor

Choose a reason for hiding this comment

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

Snappy and ZLIB are not marked as required.

Copy link
Member Author

Choose a reason for hiding this comment

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

Boost is not required. It is required only when AVRO_BUILD_TESTS or AVRO_USE_BOOST is enabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think what @mitjap was trying to say is that this if statement is superfluous as find_package is called with a REQUIRED keyword. It will fail by itself when Boost::system is not found, no need for doing it explicitly

Copy link
Member Author

Choose a reason for hiding this comment

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

This is slightly different. CMIW, sometimes Boost::system target is not available even if Boost_FOUND is true since older Boost distributions may not add Boost:: namespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say in that case maybe reflect this in an error message? At this point Boost::system is definitely available. But it would not be available as a target.

Not sure however what would be the best error message in that case.

lang/c++/CMakeLists.txt Outdated Show resolved Hide resolved
lang/c++/CMakeLists.txt Outdated Show resolved Hide resolved
wgtmac added a commit to wgtmac/iceberg-cpp that referenced this pull request Jan 23, 2025
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/AvroConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/AvroConfig.cmake"
INSTALL_DESTINATION lib/cmake/Avro
Copy link
Contributor

Choose a reason for hiding this comment

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

I see an inconsistency here. The headers are installed in include/avro while cmake files are in lib/cmake/Avro. Maybe it should be lib/cmake/avro instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a case-sensitive package name and it affects the behavior of calling find_package by downstream.

  • lib/cmake/avro -> find_package(avro)
  • lib/cmake/Avro -> find_package(Avro)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm actually not sure which one is more preferable here. I'll probably want to hear from the committers to this repo regarding the naming.

Copy link
Member

Choose a reason for hiding this comment

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

In my (poor) experience the convention is to use the one with the capital letter.

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

Successfully merging this pull request may close these issues.

4 participants