diff options
Diffstat (limited to 'docs/markdown/snippets')
-rw-r--r-- | docs/markdown/snippets/cmake_subprojects.md | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/docs/markdown/snippets/cmake_subprojects.md b/docs/markdown/snippets/cmake_subprojects.md index 94f68a1..07ff868 100644 --- a/docs/markdown/snippets/cmake_subprojects.md +++ b/docs/markdown/snippets/cmake_subprojects.md @@ -1,33 +1,29 @@ ## CMake subprojects -Meson can now directly consume CMake based subprojects. Using CMake -subprojects is almost identical to using the "normal" meson subprojects: +Meson can now directly consume CMake based subprojects with the +CMake module. -```meson -sub_proj = subproject('libsimple_cmake', method : 'cmake') -``` - -The `method` key is optional if the subproject only has a `CMakeList.txt`. -Without specifying a method meson will always first try to find and use a -`meson.build` in the subproject. - -Project specific CMake options can be added with the new `cmake_options` key. - -The returned `sub_proj` supports the same options as a "normal" subproject. -Meson automatically detects build targets, which can be retrieved with -`get_variable`. Meson also generates a dependency object for each target. +Using CMake subprojects is similar to using the "normal" meson +subprojects. They also have to be located in the `subprojects` +directory. -These variable names are generated based on the CMake target name. +Example: ```cmake -add_library(cm_exe SHARED ${SOURCES}) +add_library(cm_lib SHARED ${SOURCES}) ``` -For `cm_exe`, meson will then define the following variables: +```meson +cmake = import('cmake') + +# Configure the CMake project +sub_proj = cmake.subproject('libsimple_cmake') -- `cm_exe` The raw library target (similar to `cm_exe = library('cm_exe', ...)` in meson) -- `cm_exe_dep` The dependency object for the target (similar to `declare_dependency()` in meson) -- `cm_exe_inc` A meson include directory object, containing all include irectories of the target. +# Fetch the dependency object +cm_lib = sub_proj.dependency('cm_lib') + +executable(exe1, ['sources'], dependencies: [cm_lib]) +``` It should be noted that not all projects are guaranteed to work. The safest approach would still be to create a `meson.build` for the |