conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.22k stars 979 forks source link

NDEBUG not set in multi-target when build in conan cache #10680

Open michkrom opened 2 years ago

michkrom commented 2 years ago

I have a single-target conan project that is consuming a multi-target conan component. I observe that NDEBUG is not set for component when the component is build as part of conan install of the consumer. The same is observed with conan test-package (a simple consumer test). The build is a RELEASE build just that NDEBUG is not set. However, the NDEBUG is set correctly when the subcomponent is build locally via conan build or from VS IDE.

Looking for any pointers to investigate it further.

memsharded commented 2 years ago

Hi @michkrom

The adding of flags to build systems is done via different generators, there is no single logic that manage that. It is necessary to know which generators (MSBuildToolchain? MSBuildDeps? assuming your are using MSBuild directly, or are you using other build system?) are being involved. A minimal reproducible case would be very helpful.

michkrom commented 2 years ago

The conanfile.py of the component specifies generators = cmake, cmake_multi, 'visual studio' And indeed all are used during install. Conan version 1.44.1 cmake version 3.20.3

memsharded commented 2 years ago

Those are 3 different generators, only 1 is used when building. We have different tests that uses #ifdef NDEBUG and they are working as expected, so if something is failing on your side, you should provide a reproducible case. A good idea is to start with some of the conan new predefined code. Or to put something small in a git repo or in a zip, and specify the steps to reproduce the case.

Also a side (but relevant) note: those are considered legacy generators. They are not getting new features, unless they are very relevant bugs. New generators that are under active development now are in https://docs.conan.io/en/latest/reference/conanfile/tools.html, so I'd recommend checking them. A good start is trying conan new hello/0.1 --template=cmake_lib

michkrom commented 2 years ago

I think it's using just the text and cmake gens, according to output during in-cache build. However, the local build prints about text, cmake, cmake-multi and visual studio generators. Also in conan code it looks like the NDEBUG is set by this (?): https://github.com/conan-io/conan/blob/f230bf104842c160be6ea377497151fe1ea64c38/conans/client/build/visual_environment.py#L137

Unfortunately, this is a part of a rather big project - can't change to new and better quickly :-(.

memsharded commented 2 years ago

It is totally possible that if cmake_multi is being used, it will not set the NDEBUG. As it is a multi-config generator, it will not handle things regarding Debug/Release, as it will only set common things to both configurations.

As a general rule of thumb, for build systems that explicitly define the configuration Debug/Release, Conan will not be setting NDEBUG (or any other config related flag). This include both CMake and Visual Studio.