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

Explicit and smart CMake target #2935

Merged
merged 2 commits into from
Oct 31, 2023
Merged

Conversation

AntoinePrv
Copy link
Member

No description provided.

Copy link
Member

@JohanMabille JohanMabille left a comment

Choose a reason for hiding this comment

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

I like the namespacing of the targets, but I am a bit skeptical about the target alias (see my comment below).

@Klaim @jjerphan @Hind-M @jonashaag any comment about this?

if(BUILD_SHARED_LIBS AND TARGET mamba::libmamba-dyn)
add_library(mamba::libmamba ALIAS mamba::libmamba-dyn)
else()
add_library(mamba::libmamba ALIAS mamba::libmamba-static)
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit skeptical about this alias, I find it confusing to have a target that can be either the dynamic or the static library depending on what has been built and/or installed. The pattern "libname" / "libname-static" for the target names is quite widespread and more explicit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Very often though libname would also be either static or dynamic depending on the options, so I thought let's make one target that is always dynlib, and keep the dispatch.

I'm also not such a fan, but it is convenient for inside our own CMake, otherwise we keep repeating if/else in tests/libmambapy/mamba-package...

Copy link
Member

@jjerphan jjerphan Oct 30, 2023

Choose a reason for hiding this comment

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

It seems possible to build both the shared and static libraries (options seem not exclusive). This might cause a problem if this is actually the case.

As a developer using libmamba, I think I would find it normal to have mamba::libmamba alias mamba::libmamba-dyn, but I am not sure about having it alias mamba::libmamba-static conditionally.

Note: I am just getting started on contributing to mamba.

Copy link
Member

@Klaim Klaim Oct 30, 2023

Choose a reason for hiding this comment

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

Naive question: it seems possible to build both the shared and static libraries (options seem not exclusive). This might cause a problem if this is actually the case.

Outside Conda it's quite classic to provide both this way, so that the end-user decides what to use easilly.

Note that in this project, we use the static version to build the stand-alone micromamba. I'm ignoring the conda packaging mess in this comment, obviously. :)

Copy link
Member

@JohanMabille JohanMabille Oct 30, 2023

Choose a reason for hiding this comment

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

Very often though libname would also be either static or dynamic depending on the options, so I thought let's make one target that is always dynlib, and keep the dispatch.

I agree, and I think it's a bad practice that we should fix (at least in conda where we can).

I'm also not such a fan, but it is convenient for inside our own CMake, otherwise we keep repeating if/else in tests/libmambapy/mamba-package...

Then let's use an alias internally, but I realy think we should not expose it.

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 think the use case for pubic mamba::libmamba is in a VCPKG (or source) like workflow, you configure static/dynamic externally, so then it is not the responsibility of the user CMake script to choose the target.
In fact, that is the bahaviour for CMake add_library: it dispatches between dynamic and static.

But really, that works for me too, I don't really care.

Copy link
Member

@Klaim Klaim left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

Looks good to the neophyte that I am modulo a comment.

Comment on lines +622 to +632
if(BUILD_SHARED_LIBS AND BUILD_SHARED)
add_library(mamba::libmamba ALIAS libmamba-dyn)
elseif(BUILD_STATIC)
add_library(mamba::libmamba ALIAS libmamba-static)
elseif(BUILD_SHARED)
add_library(mamba::libmamba ALIAS libmamba-dyn)
else()
Copy link
Member

Choose a reason for hiding this comment

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

Continuing the discussion from https://github.com/mamba-org/mamba/pull/2935/files#r1375979846: what if BUILD_SHARED_LIBS AND BUILD_SHARED AND BUILD_STATIC?

Also, could it be simplified to:

Suggested change
if(BUILD_SHARED_LIBS AND BUILD_SHARED)
add_library(mamba::libmamba ALIAS libmamba-dyn)
elseif(BUILD_STATIC)
add_library(mamba::libmamba ALIAS libmamba-static)
elseif(BUILD_SHARED)
add_library(mamba::libmamba ALIAS libmamba-dyn)
else()
if(BUILD_SHARED_LIBS OR BUILD_SHARED)
add_library(mamba::libmamba ALIAS libmamba-dyn)
elseif(BUILD_STATIC)
add_library(mamba::libmamba ALIAS libmamba-static)
else()

Copy link
Member Author

Choose a reason for hiding this comment

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

if BUILD_SHARED_LIBS is set but not BUILD_SHARED (which IMHO we should really scope with MAMBA_BUILD_SHARED), then the libmamba-dyn target will not exists. The Point of the mamba::libmamba alias is more "whaterver, as long as it works".

@AntoinePrv
Copy link
Member Author

Remaining tests are not impacted by CMake.

@AntoinePrv AntoinePrv merged commit 80e3475 into mamba-org:main Oct 31, 2023
18 checks passed
@AntoinePrv AntoinePrv deleted the libmambapy branch October 31, 2023 11:07
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