mesonbuild / meson

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

[Bug] CMake: Subdirectories may introduce file conflicts #13521

Open LDAP opened 1 month ago

LDAP commented 1 month ago

Describe the bug CMake projects that output files with the same name to ${CMAKE_CURRENT_BINARY_DIR} do not work because in Meson this seems to point to the same directory.

To Reproduce Try to include shaderc as submodule:

  1. Clone shaderc@v2024.1 into subprojects
  2. Run ./utils/git-sync-deps
  3. Try to include it in Meson
shaderc_options = cmake.subproject_options()
shaderc_options.add_cmake_defines({'SHADERC_SKIP_TESTS': true})
shaderc_options.add_cmake_defines({'SHADERC_SKIP_EXAMPLES': true})
shaderc_options.add_cmake_defines({'SHADERC_ENABLE_SHARED_CRT': true})
shaderc_subp = cmake.subproject('shaderc', options: shaderc_options)
# ideally we would use shaderc_subp.dependency('shaderc_combined') but that does not work
# therefore we combine all dependencies into one.
shaderc = declare_dependency(
    dependencies: [
        shaderc_subp.dependency('shaderc'),
        shaderc_subp.dependency('glslang'),
        shaderc_subp.dependency('MachineIndependent'),
        shaderc_subp.dependency('GenericCodeGen'),
        shaderc_subp.dependency('shaderc_util'),
        shaderc_subp.dependency('SPIRV'),
        shaderc_subp.dependency('SPIRV-Tools-static'),
        shaderc_subp.dependency('SPIRV-Tools-opt'),
    ],
)

# use shaderc dependency...

It failes with the following error message because the spirv-tools project with is built by shaderc also generates build-version.inc and overwrites the file from shaderc:

FAILED: subprojects/shaderc/glslc_exe.p/glslc_src_main.cc.o
c++ -Isubprojects/shaderc/glslc_exe.p -Isubprojects/shaderc -I../subprojects/shaderc -Isubprojects/shaderc/__CMake_build -I../subprojects/shaderc/__CMake_build -I../subprojects/shaderc/third_party/spirv-tools/include -I../subprojects/shaderc/third_party/glslang -I../subprojects/shaderc/libshaderc_util/include -I../subprojects/shaderc/libshaderc/include -fdiagnostics-color=always -D_GLIBCXX_ASSERTIONS=1 -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -std=gnu++17 -O2 -g -fPIE -Wimplicit-fallthrough -O2 -g -DNDEBUG -Wextra-semi -fvisibility=hidden -MD -MQ subprojects/shaderc/glslc_exe.p/glslc_src_main.cc.o -MF subprojects/shaderc/glslc_exe.p/glslc_src_main.cc.o.d -o subprojects/shaderc/glslc_exe.p/glslc_src_main.cc.o -c ../subprojects/shaderc/glslc/src/main.cc
In file included from ../subprojects/shaderc/glslc/src/main.cc:208:
subprojects/shaderc/build-version.inc:1:12: error: expected unqualified-id before string constant
    1 | "v2024.2", "SPIRV-Tools v2024.2 v2024.2-0-gdd4b663e"

Expected behavior Subdirectories in cmake also get subdirectories in meson. Files do not overwrite each other. Building the project with CMake works fine.

Maybe related: https://github.com/mesonbuild/meson/issues/12655

system parameters

LDAP commented 1 month ago

I would be happy to provide a PR if anyone can point me into the right direction