mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.65k stars 1.64k forks source link

Build script output from cmake module is missing include directories #10911

Open LAK132 opened 2 years ago

LAK132 commented 2 years ago

Describe the bug

The meson.build produced from the cmake module is missing a number of the include directories specified in the original cmake build scripts. They (subprojects/SPIRV-Headers/include in this case) appear in both the trace output:

{"args":["SPIRV-Tools-static","PUBLIC","$<BUILD_INTERFACE:D:/Repos/Renderer/subprojects/SPIRV-Tools/include>","$<INSTALL_INTERFACE:include>","PRIVATE","D:/Repos/Renderer/Output/subprojects/SPIRV-Tools/__CMake_build","PRIVATE","D:/Repos/Renderer/subprojects/SPIRV-Headers/include"],"cmd":"target_include_directories","file":"D:/Repos/Renderer/subprojects/SPIRV-Tools/source/CMakeLists.txt","frame":2,"line":363,"time":1665479263.5249653}

and json output:

            "includes" : 
            [
                {
                    "backtrace" : 10,
                    "path" : "D:/Repos/Renderer/subprojects/SPIRV-Tools"
                },
                {
                    "backtrace" : 11,
                    "path" : "D:/Repos/Renderer/subprojects/SPIRV-Tools/include"
                },
                {
                    "backtrace" : 11,
                    "path" : "D:/Repos/Renderer/Output/subprojects/SPIRV-Tools/__CMake_build"
                },
                {
                    "backtrace" : 11,
                    "path" : "D:/Repos/Renderer/subprojects/SPIRV-Headers/include"
                }
            ],

but are missing from the final meson.build:

SPIRV_Tools_static_dir = include_directories('.', 'include', '__CMake_build')

this is resulting in build failures as it can't find all the headers needed to build the given targets.

To Reproduce

cmake = import('cmake')

spirv_headers_opts = cmake.subproject_options()
spirv_headers_opts.add_cmake_defines({
})
spirv_headers_subprj = cmake.subproject('SPIRV-Headers', options: spirv_headers_opts)
spirv_headers_dep = spirv_headers_subprj.dependency('SPIRV-Headers')

spirv_tools_opts = cmake.subproject_options()
spirv_tools_opts.add_cmake_defines({
  'SPIRV-Headers_SOURCE_DIR': meson.source_root()/'subprojects/SPIRV-Headers',
})
spirv_tools_subprj = cmake.subproject('SPIRV-Tools', options: spirv_tools_opts)
spirv_tools_dep = spirv_tools_subprj.dependency('SPIRV-Tools-static')

system parameters

LAK132 commented 2 years ago

it appears this is being caused by the

WARNING: CMake: path <path> is inside the root project but not inside the subproject.
WARNING:  --> Ignoring. This can lead to build errors.

handling code

LAK132 commented 2 years ago

looks like I can use

spirv_tools_opts.append_compile_args(
  'cpp',
  '-I'+(meson.source_root()/'subprojects/SPIRV-Headers/include'),
)

as a workaround

LAK132 commented 2 years ago

I understand that setting up dependencies between subprojects behind meson's back is a recipe for disaster, perhaps this could instead be fixed with something like

cmake.subproject('SPIRV-Tools', options: spirv_tools_opts, dependencies: [spirv_headers_dep])