Skip to content

Simplify Deprecated CMake Packages as Wrappers Around Current Packages #1384

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

Merged
merged 10 commits into from
Aug 18, 2023

Conversation

vector-of-bool
Copy link
Contributor

The old CMake config-file-packages were generated by mostly-identical scripts and processes, but are deprecated in favor of our newer config-file-packages. I think it is safe at this point to replace the content of the deprecated package scripts with scripts that import the new packages and expose them in a mostly-compatible* manner.

The legacy package generation significantly cluttered and complicated the CMakeLists for the respective projects, since a lot of work was done to populate variables that were inserted into the script templates, whereas now those usage requirements are propagated via targets alone.

The new deprecated scripts no longer define/use the INCLUDE_DIRS/DEFINES/etc variables, and only XYZ_LIBRARIES/XYZ_LIBRARY remain, which just contain the name of the equivalent imported target from the new CMake config-file-packages.

* "mostly compatible" because the primary case of linking to e.g. ${BSON_LIBRARIES} will "just work" with target_link_libraries, but users that depended on the specific find_library call and/or inspected other variables e.g. BSON_INCLUDE_DIRS will find that those are now not available. I think it is reasonable to assume that very few users, if any, were relying on this exact case.

(This PR contains commits that are already merged by #1382.)

- The computation of BUILD_VERSION is now lifted above project(), which allows
  us to use that value in the project() call itself, giving us correct
  PROJECT_VERSION values throughout.
- Define BUILD_VERSION using mongo_setting(), and use the
  calc_release_version.py to compute its default value.
- Remove a lot of variable capture that was relied upon when generating
- The _LIBRARY/_LIBRARIES variables in the legacy packages now point to
  the imported target of their respective packages, which will handle
  all other "magic variable" definitions.
Comment on lines -35 to -37
set (CPACK_PACKAGE_VERSION_MAJOR ${BSON_MAJOR_VERSION})
set (CPACK_PACKAGE_VERSION_MINOR ${BSON_MINOR_VERSION})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These values are inferred from project(), which now contains the correct version information.

(Not sure if we have many CPack users anyway, though)

Comment on lines -370 to -374
set_target_properties(${TARGETS_TO_INSTALL} PROPERTIES
pkg_config_NAME libbson
pkg_config_DESCRIPTION "The libbson BSON serialization library."
pkg_config_VERSION "${BSON_VERSION}"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inferred from project()

Comment on lines -393 to -408
set (LIBBSON_LIBRARIES "")
foreach (_lib ${BSON_LIBRARIES})
if (_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
set (LIBBSON_LIBRARIES "${LIBBSON_LIBRARIES} ${_lib}")
else ()
set (LIBBSON_LIBRARIES "${LIBBSON_LIBRARIES} -l${_lib}")
endif ()
endforeach ()
# System dependencies don't match the above regexs, but also don't want the -l
foreach (_lib ${BSON_SYSTEM_LIBRARIES})
set (LIBBSON_LIBRARIES "${LIBBSON_LIBRARIES} ${_lib}")
endforeach ()

include (CMakePackageConfigHelpers)
set (INCLUDE_INSTALL_DIRS "${BSON_HEADER_INSTALL_DIR}")
set (LIBRARY_INSTALL_DIRS ${CMAKE_INSTALL_LIBDIR})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only used by the old script generation during configure_file, so these aren't needed otherwise.

Copy link
Contributor

@rcsanchez97 rcsanchez97 left a comment

Choose a reason for hiding this comment

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

Nice! I'm all about simplifying and eliminating unnecessary code. Just a few typo fix recommendations, but aside from that LGTM.

Co-authored-by: Roberto C. Sánchez <[email protected]>
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

LGTM, the simplification is appreciated.

set (MONGOC_VERSION_FULL @libmongoc_VERSION_FULL@)

include(CMakeFindDependencyMacro)
find_dependency (mongoc-1.0 "@libmongoc_VERSION_MAJOR@.@libmongoc_VERSION_MINOR@")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is @libmongoc_VERSION_MAJOR@.@libmongoc_VERSION_MINOR@ needed? libbson-1.0-config.cmake.in does does not include the version in the call to find_dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Presumably, if this file is installed then the equivalent new package will be installed, so this version may be redundant.

@vector-of-bool vector-of-bool merged commit 3f9417f into master Aug 18, 2023
@kevinAlbs kevinAlbs deleted the simplify-legacy-pkgs branch April 16, 2025 12:01
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

Successfully merging this pull request may close these issues.

3 participants