conan icon indicating copy to clipboard operation
conan copied to clipboard

[feature] `CMakeFlagsInitBlock` only works for multi-config generators

Open friendlyanon opened this issue 1 year ago • 2 comments

What is your suggestion?

See the comment at https://github.com/conan-io/conan/pull/15736#issuecomment-1959323582

This class iterates CMAKE_CONFIGURATION_TYPES even if the generator in use is not multi-config and doesn't do the same for CMAKE_BUILD_TYPE in case of a single-config generator. I think this should be fixed, or at least explained.

@memsharded added this in 7d93ccc5c77b9c5829162c11b52bdbaaf3e9bcb6 a week ago.

Have you read the CONTRIBUTING guide?

  • [X] I've read the CONTRIBUTING guide

friendlyanon avatar Feb 22 '24 15:02 friendlyanon

Hi @friendlyanon - please refer to the original reported issue: https://github.com/conan-io/conan/issues/13920.

Is there a bug that we can reproduce where it does not work as expected? The CMakeFlagsInitBlock has always worked correctly for single configuration CMake generators. Only recently does has the behaviour been improved to account for projects that use multi-config CMake generators, and need to propagate different flags per configuration.

For single-configuration CMake generators, cmake_toolchain.cmake will operate on the CMAKE_CXX_FLAGS_INIT variables, and it is expected to generate the toolchain each time for each different configuration ahead of configuring the cmake project, so the variables passed to cmake and eventually the compiler will be correct.

jcar87 avatar Feb 22 '24 16:02 jcar87

For single-configuration CMake generators, cmake_toolchain.cmake will operate on the CMAKE_CXX_FLAGS_INIT variables, and it is expected to generate the toolchain each time for each different configuration ahead of configuring the cmake project, so the variables passed to cmake and eventually the compiler will be correct.

Ah, that clarifies things. Even still, the loop should be protected with a multi config generator check, since it will still pick up the variable for singe-config generators if the user's command line sets CMAKE_CONFIGURATION_TYPES.

friendlyanon avatar Feb 22 '24 16:02 friendlyanon

Ah, that clarifies things. Even still, the loop should be protected with a multi config generator check, since it will still pick up the variable for singe-config generators if the user's command line sets CMAKE_CONFIGURATION_TYPES.

But even if it picks the variables, the variables are CONAN_xxx defined ones, that are already protected by a multi-configuration check, so it shouldn't be an issue. Are you seeing some problems with this?

memsharded avatar Feb 26 '24 08:02 memsharded

But even if it picks the variables, the variables are CONAN_xxx defined ones, that are already protected by a multi-configuration check, so it shouldn't be an issue.

Sounds good to me. I think with that explanation this issue can be closed then.

friendlyanon avatar Feb 27 '24 16:02 friendlyanon