Skip to content

Cleanup pkg-config #1326

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
Jun 30, 2023
Merged

Conversation

vector-of-bool
Copy link
Contributor

@vector-of-bool vector-of-bool commented Jun 28, 2023

On my yak-shaving journey to remove the source-dist, I ended up needing to rewrite the generation of pkg-config files (again) (long story). Fortunately, this is much cleaner and more robust than my prior silliness in #1301. The following now Just Works™:

  1. If you build with instrumentation (coverage, sanitizers), the installed pkg-config files will now include the necessary link flags as usage requirements. This came up while testing the link-with scripts, since my local system would enable sanitizers, but the generated example executable did not have the appropriate link flags when it consumed libmongoc/libbson via pkg-config. This will now work out-of-the-box.
  2. The prefix value in the installed .pc values is now bound at install-time, and not at configure-time. This allows using cmake --install --prefix=<some-dir> to do an install into an arbitrary <some-dir> which may not be the CMAKE_INSTALL_PREFIX. This is a somewhat-obscure feature, but I've found it useful and it was easy enough to make it work.
  3. Multi-config generation is now supported. Now you can cmake --install --config=<config> to install the named configuration, and the appropriate .pc file will be installed. (But multi-config .pc install requires each configuration to receive a different .pc filename, which is really weird for pkg-config and is not used here.)

@vector-of-bool vector-of-bool marked this pull request as ready for review June 28, 2023 19:07
@@ -1,6 +1,9 @@
include(CheckSymbolExists)
include(CMakePushCheckState)

# Required so that some libresolv symbols will be visible:
set(CMAKE_C_EXTENSIONS ON)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seemingly-unrelated change is due to changing cmake_minimum_required in libmongoc, which changed the way that the C_STANDARD property is propagated through try_compile

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be scoped or moved into a target property? I have reservations about enabling C extensions for potentially all targets that follow include(ResSearch). If this must be set unconditionally, suggest moving up into the root CMakeLists.txt file alongside other project-wide variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also did not like this change, and it isn't obvious from the documentation that this variable effects try_compile. I believe the reason we get away with it is that we enable bits and pieces by using platform-specific feature toggle macros. I will narrow it down and find what macros actually need to be defined to enable libresolv to compile properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks to actually be _BSD_SOURCE, which we already set, and I'm dropping it on the floor by using cmake_push_check_state(RESET). Oops.

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.

LGTM, modulo the one typo I found.


DESTINATION <dir>
- If provided, specify the *directory* (relative to the install-prefix)
in which the generated file will be installed. If unspecfied, the default
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
in which the generated file will be installed. If unspecfied, the default
in which the generated file will be installed. If unspecified, the default

@@ -1,6 +1,9 @@
include(CheckSymbolExists)
include(CMakePushCheckState)

# Required so that some libresolv symbols will be visible:
set(CMAKE_C_EXTENSIONS ON)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be scoped or moved into a target property? I have reservations about enabling C extensions for potentially all targets that follow include(ResSearch). If this must be set unconditionally, suggest moving up into the root CMakeLists.txt file alongside other project-wide variables.

@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.1)
cmake_minimum_required (VERSION 3.15)
Copy link
Contributor

@eramongodb eramongodb Jun 28, 2023

Choose a reason for hiding this comment

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

This is a significant change. I suggest at least creating a CXX C ticket to track/document this new requirement.

Side question: is there a compelling reason we should continue to support a per-library CMake Project configuration instead of using only the root CMake project for all targets defined in the CXX Driver C Driver? I don't think we intend to support add_subdirectory() of a CXX Driver C Driver library (i.e. bsoncxx libbson) without going through the root directory, do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're already requiring this at the top level, so this line could likely actually just be removed. It's actually probably bad that we had 3.1 there, since it would rewind a bunch of CMake policies and probably had some unintentional effects. (Such as the problem in ResSearch).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we intend to support add_subdirectory() of a CXX Driver library (i.e. bsoncxx) without going through the root directory, do we?

AFAIK there is no expectation to support add_subdirectory() without going through the root directory.

I expect C++ driver can be included with add_subdirectory of the root CMakeLists.txt, and CXX-2104 was filed to document.

This PR is for the C driver (not C++).

Copy link
Contributor

Choose a reason for hiding this comment

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

Had my repos mixed up. Sorry for the confusion.

All named parameters accept generator expressions.

]==]
function(mongo_generate_pkg_config target)
Copy link
Contributor

Choose a reason for hiding this comment

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

It baffles me that CMake doesn't provide any utilities to support smart target-based pkg-config file generation. 😞

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.

GeneratePkgConfig.cmake seems generally useful.

@@ -807,6 +807,7 @@ set_target_properties (mongoc_shared PROPERTIES
SOVERSION 0
pkg_config_REQUIRES "libbson-1.0"
)
mongo_generate_pkg_config(mongoc_shared INSTALL RENAME libmongoc-${MONGOC_API_VERSION}.pc)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using FILENAME for consistency with other mongo_generate_pkg_config calls.

Is there a use case for setting different values for RENAME and FILENAME? Consider removing RENAME.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RENAME comes from install(FILES ...). The split in this case helps with multi-config generators. We want to allow multi-conf generation to work in the build, but we only need to install one version at a time.

@vector-of-bool vector-of-bool merged commit 3c7951b into mongodb:master Jun 30, 2023
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.

4 participants