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

Support for grouping targets #1026

Closed
SirLynix opened this issue Nov 10, 2020 · 19 comments
Closed

Support for grouping targets #1026

SirLynix opened this issue Nov 10, 2020 · 19 comments

Comments

@SirLynix
Copy link
Member

Is your feature request related to a problem? Please describe.

I'm working on Visual Studio 2019, until now I was using premake to generate my projects. I'm considering replacing it by xmake (because your tool is truly awesome, congrats!) and I'm trying to replicate one feature premake had, groups.

Grouping targets (or projects in premake terms) corresponds to folders in Visual Studio:

Describe the solution you'd like

Some API like target.set_group to specify a group.

Describe alternatives you've considered

Using a prefix in the target name.

Additional context

Screenshots:
With folders (using Premake):
image

Without folders (using xmake):
image

@waruqi
Copy link
Member

waruqi commented Nov 10, 2020

Are you using xmake project -k vs plugin or xmake project -k vsxmake plugin?

@SirLynix
Copy link
Member Author

Here I used the vsxmake plugin, I know vs is deprecated (although it would be nice to add folders to it too).

@waruqi
Copy link
Member

waruqi commented Nov 10, 2020

We can consider adding a new configuration in future versions: set_values("vsxmake.target.group", "xxx") to set the group name of each target.

target("xx")
    set_values("vsxmake.target.group", "xxx")

But for version 2.3.9, we will not support this feature. For version 2.3.9, we focus on improving package management.

@waruqi waruqi added this to the todo milestone Nov 10, 2020
@SirLynix
Copy link
Member Author

SirLynix commented Nov 10, 2020

No problem. Thank you.

Wouldn't it be better to support groups as as target parameter? Groups could be implemented in multiple projects, as far as I know Visual Studio and XCode both support them. But adding support to makefiles could be done as well.

For example if I have two projects in the same group (let's say "common"), makefiles could support make common

And of course, if a project doesn't support groups they can be safely ignored.

@waruqi
Copy link
Member

waruqi commented Nov 10, 2020

set_groups("xxx", "yyy")? xmake build xxx yyy?

It seems a good idea, I will consider it, but it may not be supported soon. This involves a lot of changes, you may need to wait some time.

@SirLynix
Copy link
Member Author

Why not target.set_group?

Sure, no problem. I'm already glad you like the idea. 😄

@waruqi
Copy link
Member

waruqi commented Nov 10, 2020

Why not target.set_group?

Sure, no problem. I'm already glad you like the idea. 😄

only for target.

target()
    set_group()

@SirLynix
Copy link
Member Author

Yes that's what I was suggesting. Seems great! 👍

@waruqi waruqi modified the milestones: todo, v2.5.1 Nov 12, 2020
@waruqi
Copy link
Member

waruqi commented Nov 12, 2020

After the current 2.3.9 version is released, I will support it in the next version 2.5.1 and there won't be 2.4.x

@AntoineJT
Copy link

AntoineJT commented Dec 26, 2020

Okay, I've opened a similar issue, so I bring my ideas here. (You can see the original text here: #1172)

I think the way Premake handles this is not the best way to do.
I think it can be better handled by doing as target does:

group("name")
    target("first_target")
        ...
    target("second_target")
        ...
group_end()

Alternatively, it may be handled like this:

target("first_target")
    ...
target("second_target")
    ...
target_end()

group("name", "first_target", "second_target")
#or
group("name", {"first_target", "second_target"})

or maybe it can be handled the same way as Premake does, but I think the better solution here for users would be the first I propose.

@waruqi
Copy link
Member

waruqi commented Dec 28, 2020

group("name")
target("first_target")
...
target("second_target")
...
group_end()

The grouping feature is currently only used in the project generator plugin, and the focus of xmake is on xmake build, so I don’t consider adding an additional group() scope api to implement it for now. I will use the set_group("yyy") interface to set group for specify target.

@SirLynix
Copy link
Member Author

Maybe groups could be more useful for xmake, like to build a set of targets. Maybe also set a after build file (like something to execute only after all targets in a group are built). Wouldn't that be interesting?

@waruqi
Copy link
Member

waruqi commented Dec 28, 2020

Maybe groups could be more useful for xmake, like to build a set of targets. Maybe also set a after build file (like something to execute only after all targets in a group are built). Wouldn't that be interesting?

This can be achieved using add_rules for the same purpose.

@AntoineJT
Copy link

AntoineJT commented Dec 28, 2020

At least, can we consider

create_group("name", "first_target", "second_target")

or

create_group("name", {"first_target", "second_target"})

to avoid duplication everywhere?
Maybe it can be added with target.set_group too, as an alternative way to group targets

@waruqi
Copy link
Member

waruqi commented Dec 28, 2020

I will consider to add target.set_group

@waruqi
Copy link
Member

waruqi commented Dec 28, 2020

I have supported for vs project on group branch, but I still don’t support vsxmake, you can try vs project first. #1174

add_rules("mode.debug", "mode.release")

target("test1")
    set_kind("binary")
    add_files("src/*.cpp")
    set_group("group1")

target("test2")
    set_kind("binary")
    add_files("src/*.cpp")
    set_group("group1")

target("test3")
    set_kind("binary")
    add_files("src/*.cpp")
    set_group("group1/group2")

target("test4")
    set_kind("binary")
    add_files("src/*.cpp")
    set_group("group3/group4")

target("test5")
    set_kind("binary")
    add_files("src/*.cpp")

target("test6")
    set_kind("binary")
    add_files("src/*.cpp")

Snip20201228_7

@AntoineJT
Copy link

Yeah, it works, that's great.

image
image

Don't worry about the missing SDL2.dll, that's normal I guess with the vs2019 solution. I just need to add it manually in the build folder.

I'm using vsxmake for my C++ learning project so I will comment out the set_group things until you add it to vsxmake too.

@waruqi
Copy link
Member

waruqi commented Dec 29, 2020

I have also supported it for vsxmake project and merged into dev branch.

@waruqi
Copy link
Member

waruqi commented Apr 19, 2022

I added source groups for vs/vsxmake generator #2282

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

No branches or pull requests

3 participants