-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
CMake subprojects #4969
CMake subprojects #4969
Conversation
b1b5d22
to
ea227f1
Compare
58013fc
to
84d435c
Compare
I haven't looked too closely at the implementation, but as we discussed on IRC and from your proposal this seems like a fine approach, and probably very useful. The one thing I think I'd prefer is to have a module to handle this rather than being part of subproject. My reasoning is that a subproject generally has a in meson defined dependency: dep = declare_dependency(link_with : lib, include_directories : incs) CMake obviously doesn't have that in the form we would expect, Since we may not want to build all of the targets in the cmake build definition, a module would make it easier to take the AST, store it, and then pull out only the bits that we want so if we wanted two targets out of a CMake build (but at different times or under different condtions) we could do that. Ultimately this is a @jpakkane decision. P.S. This is really interesting to me, and if we land this I think I'll work on a version for make/automake that does something similar. |
I haven't looked at the patches themself, but my PR also allows building cmake subprojects: #4321 |
@xclaesse, I think this is a better approach, as the goal is to use cmake to configure the project, then use cmake's introspection API to create a meson representation and allow the subproject to be built as part of the main ninja call like a native meson subproject. If it can be made to work reliably of course :) |
2240f63
to
01c0d00
Compare
This PR now also works on Windows so it is no longer WIP. There are some weird issues with the msvc2015 CI that I can't resolve so I disabled the tests there. |
01c0d00
to
eb8e607
Compare
ping :) |
Flake8 detected 6 issues on 926269e posted by Sider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: Typo in the commit comment "available"
Just a question from a meson newbie: How do include dirs work with this patch? Other than that your code worked great for me - even cross-compiling with Windows worked. :-) (Excuse me if this comment derails the pull request. If you want me to post in a different - or not at all - please just tell me.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of changes due to trailing newline in this commit. Not sure what meson's policy is about unrelated cosmetic changes.
@FelixSchwarz for each CMake target, this PR generates a meson target with the same name and the variables Basically this CMake code: set(source_list "docopt.cpp")
include_directories(...)
add_executable(foo ${source_list}) is converted into this meson code: foo_inc = include_directories('__CMake_build', '.', ...)
foo_src = files('docopt.cpp')
foo = executable(
'foo',
foo_src,
link_args : [],
link_with : [],
include_directories : foo_inc,
install : false,
install_dir : '',
override_options : [],
objects : [],
cpp_args : []
)
foo_dep = declare_dependency(
link_args : [],
link_with : foo,
include_directories : foo_inc
) Then, something like executable('mainPro', main_src, dependencies: [subPro.get_variable('foo_dep')]) in your main project should work 99% of the time. You can also view the generated meson code for the subproject in Could you please provide an example repository, if this didn't answer your question? |
Fixed. Let's hope for the CI. |
Thanks! |
This PR adds support for using CMake projects as subprojects (without requiring a
meson.build
).Basic principle
Current limitations:
add_custom_command()
and/or other code generators won't workTested projects:
This PR was tested with the following projects:
cmake_options: ['-DVIDEO_WAYLAND=OFF']
(wayland uses a code generator).y
file meson doesn't recognizeIf someone has tested other projects with this PR, please let me know.