0

I have a parent project and a subproject using meson. Quite sadly the subproject only builds in release mode. However, even if I set the parent project to debug using --reconfigure and check with configure that the build type is debug, it seems the NDEBUG macro is not defined for the subproject, which causes it to fail compilation.

Is there a way to enable debug builds for subprojects?

Parent snippet:

project(
    'SdfParametrization',
    'cpp',
    version: '0.0.1',
    license: 'GPL',
    default_options : [
        'cpp_std=c++20',
        'default_library=static',
        'optimization=3',
        'b_ndebug=true'])

add_global_arguments(
    '-DVULKAN_HPP_NO_EXCEPTIONS',
    '-DVULKAN_HPP_TYPESAFE_CONVERSION',
    '-DNDEBUG',
    '-Wno-unused-function',
    '-fdiagnostics-color=always',
    '--coverage',
    language : 'cpp')

add_global_link_arguments(
    '-lgcov',
    '-lubsan',
    '-ldl',
    '-lvulkan',
    language : 'cpp')

cpp = meson.get_compiler('cpp')

neverengine_proj = subproject('neverengine', default_options:['buildtype=debugoptimized'])
neverengine_dep = neverengine_proj.get_variable('core_never_engine_dep')

executable('sdf_parameterization', 'ray_tracing.cpp', dependencies:[neverengine_dep])

Child snippet:

project(
    'NeverEngine',
    'cpp',
    version: '0.0.1',
    license: 'GPL',
    default_options : [
        'cpp_std=c++20',
        'default_library=static',
        'optimization=3'])

if not meson.is_subproject()
    add_global_arguments(
        '-DVULKAN_HPP_NO_EXCEPTIONS',
        '-DVULKAN_HPP_TYPESAFE_CONVERSION',
        '-Wno-unused-function',
        '-fdiagnostics-color=always',
        '-fsanitize=undefined',
        '--coverage',
        language : 'cpp')

    add_global_link_arguments(
        '-lgcov',
        '-lubsan',
        language : 'cpp')
endif

cpp = meson.get_compiler('cpp')

external_include_dirs = [
    'libraries/Eigen/',
    'libraries/imgui/',
    'libraries/incbin/']

sources = files(
    'Src/Engine/Animation/Animation.cpp',
    'Src/Engine/Animation/AnimationMesh.cpp',
    'Src/Engine/Animation/GltfLib.cpp',
    'Src/Engine/Animation/GltfLoaders.cpp',
    'Src/Engine/Animation/Image/CpuImage.cpp',
    'Src/Engine/Animation/NumericIntegration.cpp',
    'Src/Engine/Animation/SpringMass.cpp',
    'Src/Engine/DataSanitation/AttributeInputSanitation.cpp',
    'Src/Engine/DynamicLoading/DynamicLoader.cpp',
    'Src/Engine/EmbeddedShaders/EmbeddedShaders.cpp',
    'Src/Engine/GUI/Guizmo3D.cpp',
    'Src/Engine/GUI/_imgui.cpp',
    'Src/Engine/GUI/imgui_bridge.cpp',
    'Src/Engine/Geometry/DualContouring.cpp',
    'Src/Engine/Geometry/GeometryUtils.cpp',
    'Src/Engine/Geometry/HMesh.cpp',
    'Src/Engine/Geometry/HeatGeodesics.cpp',
    'Src/Engine/Geometry/MatrixMesh.cpp',
    'Src/Engine/Geometry/MeshGradient.cpp',
    'Src/Engine/Geometry/MeshUtils.cpp',
    'Src/Engine/Geometry/Parametrics.cpp',
    'Src/Engine/Geometry/SdfFramework.cpp',
    'Src/Engine/Geometry/Subdivision.cpp',
    'Src/Engine/Helpers/EigenHelpers.cpp',
    'Src/Engine/Helpers/FlotingPointArithmetic.cpp',
    'Src/Engine/Helpers/MiscUtils.cpp',
    'Src/Engine/Helpers/NumberTheory.cpp',
    'Src/Engine/Helpers/VectorManipulation.cpp',
    'Src/Engine/Helpers/log.cpp',
    'Src/Engine/Noise/Noise.cpp',
    'Src/Engine/Renderer/Camera/Camera.cpp',
    'Src/Engine/Renderer/IO/GLFW_tools.cpp',
    'Src/Engine/Renderer/IO/InputHandler.cpp',
    'Src/Engine/Renderer/IO/Window.cpp',
    'Src/Engine/Renderer/Renderer.cpp',
    'Src/Engine/Renderer/Rendering/Effects.cpp',
    'Src/Engine/Renderer/Rendering/Gallery.cpp',
    'Src/Engine/Renderer/Rendering/RenderTargetStorage.cpp',
    'Src/Engine/Renderer/Rendering/RenderingTechniques.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/HardwareInterface.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/Image.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/Memory.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/RenderTarget.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/RenderingPipeline.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/ShaderProgram.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/Utils.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/VkExtensionsStubs.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/VulkanBuffer.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/VulkanDebugging.cpp',
    'Src/Engine/Renderer/Scribe/Scribe.cpp',
    'Src/Engine/Shared/Shared.cpp')

external_incs = include_directories(external_include_dirs, is_system : true)
internal_incs = include_directories(['Src/Engine/', 'build/'])

all_includes = []
all_includes += external_incs
all_includes += internal_incs

pkg = import('pkgconfig')

linked_dependencies = []

linked_dependencies += dependency('vulkan', include_type : 'system')
linked_dependencies += dependency('vulkan-memory-allocator', include_type : 'system')
linked_dependencies += dependency('glfw3', include_type : 'system')
linked_dependencies += dependency('threads', include_type : 'system')
linked_dependencies += dependency('zlib', include_type : 'system')
linked_dependencies += dependency('shaderc_static', include_type : 'system')
linked_dependencies += dependency('freetype2', include_type : 'system')
linked_dependencies += dependency('stb', include_type : 'system')
linked_dependencies += dependency('tinygltf', include_type : 'system')

pre_target = custom_target(
    'Preprocess',
    output : [
        'UniformObjects.cpp',
        'UniformObjects.hpp'],
        build_always_stale : true,
        command : ['python3', '../Scripts/preprocessing.py'])

sources += pre_target
core_lib = library('CoreNeverEngine',
    sources,
    include_directories : all_includes,
    dependencies : linked_dependencies,
    build_by_default : true)
pkg.generate(core_lib)

example_path_template = 'Src/examples/@0@/@1@.cpp'

examples = [
    'base_example',
    'disk_terrain',
    'example2',
    'gaussian_subdivision',
    'gltf_loading',
    'heat_geodesics',
    'implicit_functions',
    'mesh_matrices',
    'ray_tracing',
    'sponza_scene',
    'spring_mass',
    'terrain_generation']

foreach example : examples
    tokens = example.split('_')
    camel_case_name = ''
    foreach word : tokens
        lower_case = word[0]
        upper_case = lower_case.to_upper()
        camel_case_name += upper_case + word
        camel_case_name = camel_case_name.replace(upper_case + lower_case, upper_case)
    endforeach

    path = example_path_template.format(camel_case_name, example)
    target = executable(camel_case_name, [path],
        include_directories : all_includes,
        link_with : core_lib,
        dependencies : [linked_dependencies])

endforeach

linked_dependencies += dependency('gtest')

geometry_test_files = [
    'Src/Engine/Geometry/tests/GeometryTests.cpp',
    'Src/Engine/Geometry/tests/TestsGeometryUtils_hpp.cpp',

    'Src/Engine/Geometry/GeometryUtils.cpp',
    'Src/Engine/Helpers/log.cpp',
]
test = executable(
    'GeometryTests',
    geometry_test_files,
    include_directories : all_includes,
    dependencies : linked_dependencies,
    link_args : ['-fprofile-arcs', '-ftest-coverage'],
    cpp_args : ['-fprofile-arcs', '-ftest-coverage'])

test('GeometryTests', test)


vulkan_test_files = [
    'Src/Engine/Renderer/Rendering/VulkanLayer/tests/VulkanLayerTests.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/tests/TestsHardwareInterface_cpp.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/tests/TestsHardwareInterface_hpp.cpp',

    'Src/Engine/Renderer/Rendering/VulkanLayer/VulkanDebugging.cpp',
    'Src/Engine/Renderer/Rendering/VulkanLayer/VkExtensionsStubs.cpp',
    'Src/Engine/Helpers/log.cpp',
]
test = executable(
    'VulkanTests',
    vulkan_test_files,
    include_directories : all_includes,
    dependencies : linked_dependencies,
    link_args : ['-fprofile-arcs', '-ftest-coverage'],
    cpp_args : ['-fprofile-arcs', '-ftest-coverage'])

test('VulkanTests', test)
Makogan
  • 8,208
  • 7
  • 44
  • 112
  • can you explain a bit about the real goal, as `Is there a way to enable debug builds for subprojects?` it means you want sub project built in debug mode while your question asks as if `Quite sadly the subproject only builds in debug mode.` – Vipin Varghese Oct 05 '21 at 06:23
  • I made a typo, I meant to say the subproject always builds in release mode. – Makogan Oct 05 '21 at 22:53
  • ok, so what you want is sub project to be build in the same mode as main project. That is if the main project is `debug` mode the subproject is also `debug` – Vipin Varghese Oct 06 '21 at 03:49
  • correct, that is exactly what the goal is. – Makogan Oct 06 '21 at 18:41
  • @Makagon can you share the meson snippet of main project and subproject, as I am not able to reproduce the error mentioned. – Vipin Varghese Oct 07 '21 at 03:34
  • Edited the question with the 2 snippets – Makogan Oct 08 '21 at 05:49
  • Are you setting a buildtype on the command line, debug is the default type and unless you are I would expect it to build in debug mode. – dcbaker Oct 09 '21 at 22:11
  • I am explicitely setting the build type to debug in the command line as well. – Makogan Oct 10 '21 at 05:29
  • @Makogan thanks for the update, let me try with your sample meson.build too. By the way, Normally, there is one main project, Just wanted to confirm if the intention of creating a separate project? – Vipin Varghese Oct 11 '21 at 03:03
  • Right now the parent project must be closed source for legal reasons, but the child project must remain open source (also for legal reasons). In addition to that, it gives a great opportunity to test what it would be like for someone to use the child project as a dependency. – Makogan Oct 11 '21 at 04:25

1 Answers1

1

This is currently not supported, as you could see from the table of core options, only 3 options are settable per subproject as of now: werror and default_library (since 0.54.0) and warning_level (since 0.56.0). And below in Specifying options per subproject you can find more details e.g. about order of applying.

Also I found from discussion in issue Subproject default_options are ignored one of the main contributor says:

Right now only a couple of options are allowed on a per-project basis: default_library, werror (and one more I can't remember off the top of my head). We keep adding more over time, but other ones are ignored, yes.

pmod
  • 10,450
  • 1
  • 37
  • 50