cpp-best-practices / gui_starter_template

A template CMake project to get you started with C++ and tooling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build type other than RelWithDebInfo fails build on visual studio (multi config build)

LtdSauce opened this issue · comments

While playing around with the multi configuration generator for VisualStudio, i noticed that i cannot set the BUILD_TYPE to anything else than RelWithDebInfo. Because VisualStudios Generator sets the CMAKE_CONFIGURATION_TYPES to Debug;Release;MinSizeRel;RelWithDebInfo as it could handle multi-configurations.
When conan is invoked the Cmake module iterates over CMAKE_CONFIGURATION_TYPES and installs the dependencies for them and puts the build-files and Find.cmake modules in the build directory. Because RelWithDebInfo is the last in the list, my build is only able to find the libraries for RelWithDebInfo...
Trying to invoke the Debug configuration with cmake --build build --config Debug leads to errors like the following:

docopt.lib(docopt.obj) : error LNK2038: Konflikt ermittelt für "_ITERATOR_DEBUG_LEVEL": Der Wert "0" stimmt nicht mit dem Wert "2" in main.obj überein. [C:\Users\ldetj\develop\EnCoDaTr\build-2\src
\encodatr.vcxproj]

Which looks like my Debug-Build is linked to the Libs from the RelWithDebInfo configuration. Is this a bug in the conan module from this project or have i misconfigured something? (I did a fresh configure on the project and build it with the command above)

Could you or someone else try this aswell? (Do you need more information to reproduce?)

I reproduced this with a github action by setting the BUILD_TYPE to Debug --> https://github.com/LtdSauce/cpp_starter_project/runs/4967074084?check_suite_focus=true.

Initial Issue Description. This was just a symptom of the above issue and a deprecated CMake-Cache Hi,

i'm not shure if i got an issue here or if it is just me beeing stupid.

It seems that the default build type is not correctly set. When i configure a project created from the cpp-starter-project template and just configure it, i do not get the message "Setting build type to 'RelWithDebInfo' as none was specified." from StandardProjectSettings.cmake:3.

I injected a message to check if those variables are already set to something:

message(STATUS "Got CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}' or CMAKE_CONFIGURATION_TYPES: '${CMAKE_CONFIGURATION_TYPES}'")

This got me the following message:

[cmake] -- Got CMAKE_BUILD_TYPE: '' or CMAKE_CONFIGURATION_TYPE: 'Debug;Release;MinSizeRel;RelWithDebInfo'

Because CMAKE_CONFIGURATION_TYPES is not empty the if evaluates to false and does not set a default for CMAKE_BUILD_TYPE. This later leads to the following error with conan:

[cmake] -- Conan: Adding bincrafters remote repository (https://bincrafters.jfrog.io/artifactory/api/conan/public-conan) verify ssl (True)
[cmake] -- Multi-configuration build: 'Debug;Release;MinSizeRel;RelWithDebInfo'!
[cmake] -- Running Conan for build type 'Debug'
[cmake] CMake Error at build/conan.cmake:71 (message):
[cmake]   Please specify in command line CMAKE_BUILD_TYPE
[cmake]   (-DCMAKE_BUILD_TYPE=Release)
[cmake] Call Stack (most recent call first):
[cmake]   build/conan.cmake:430 (_conan_detect_build_type)
[cmake]   build/_deps/_project_options-src/src/Conan.cmake:39 (conan_cmake_autodetect)
[cmake]   build/_deps/_project_options-src/src/Index.cmake:174 (run_conan)
[cmake]   CMakeLists.txt:22 (project_options)

By explicitly setting CMAKE_BUILD_TYPE the conan error is "fixed".

EDIT: After doing a clean configure the conan error vanished. And i cannot reproduce it.
The issue was due to the explanation from The second comment to this issue

I'm on Windows 10 using the Visual Studio 2019 BuildTools with the MSVC Version 19.29.30037.0.

Solution

The error was caused by the generators in the conanfile.txt. cmake_find_package_multi was missing and the other generators just kept overwriting the find_packages of the previous BUILD_TYPE for the libs fetched from conan. By adding that generator and removing all the others the problem is fixed.

@aminya not sure if i found another issue while testing my changes for PR aminya/project_options#41...

Comment became issue description while playing around with the multi configuration generator for VisualStudio i noticed, that i cannot set the BUILD_TYPE to anything else than `RelWithDebInfo`. Because VisualStudios Generator sets the `CMAKE_CONFIGURATION_TYPES` to `Debug;Release;MinSizeRel;RelWithDebInfo` as it could handle multi-configurations. When conan is invoked the Cmake module iterates over `CMAKE_CONFIGURATION_TYPES` and installs the dependencies for them and puts the build-files and Find.cmake modules in the build directory. Because `RelWithDebInfo` is the last in the list, my build is only able to find the libraries for `RelWithDebInfo`... Trying to invoke the Debug configuration with `cmake --build build --config Debug` leads to errors like the following: ``` docopt.lib(docopt.obj) : error LNK2038: Konflikt ermittelt für "_ITERATOR_DEBUG_LEVEL": Der Wert "0" stimmt nicht mit dem Wert "2" in main.obj überein. [C:\Users\ldetj\develop\EnCoDaTr\build-2\src \encodatr.vcxproj] ``` Which looks like my Debug-Build is linked to the Libs from the `RelWithDebInfo` configuration. Is this a bug in the conan module from this project or have i misconfigured something? (I did a fresh configure on the project and build it with the command above)

Could you or someone else try this aswell? (Do you need more information to reproduce?)

I reproduced this with a github action by setting the BUILD_TYPE to Debug --> https://github.com/LtdSauce/cpp_starter_project/runs/4967074084?check_suite_focus=true.

It looks like my previous conan error could be related to conan-io/cmake-conan#336.
Maybe the current issue is also related to that? The approach in Conan.cmake looks exactly like it is described in their docs. 🤷‍♂️

Ah! Got it. It is actually an issue with the conanfile.txt from the cpp_starter_project. There is the generator cmake_multi missing in order to be able to realy use multi configuration builds. Additionally cmake_find_package_multi seems to be needed aswell... I'm investigating if the non-multi and multi can coexistence in a project: they cannot it seems.
Checking now if the multi versions work with non-multi generators like ninja or make: looks good.
I'm going to open a PR in the cpp_starter_project to use the multi generators.

Edit: after a little exploration it seems only the cmake_find_package_multi is realy needed and no other.

But as mentioned in conan-io/conan#9108 that generator is likely to be deprecated in Conan2.0.

huh... the changes in #181 to the conanfile.txt are exactly what i'm currently making ready for a PR.

@lefticus would it be possible to put that change on a fastlane? Had some headache why my builds on Windows would only accept RelWithDebInfo BUILD_TYPE...

I made the changes before finding your PR, would have saved me some headache finding that earlier...

Additionally to your changes i added CI-Builds for Debug to check if everything is working: LtdSauce@df347b5

I'm thinking of closing this issue and reopening one in the cpp_starter_project.
My real issue and what i thought to be my issue have diverged a little to far i guess.

I can transfer it for you! 🙂

Oh yes! My changes fix MANY issues with visual studio right now. I do need to get that merged. I assumed no one else was hitting them

I can work around it and only use RelWithDebInfo... As that is the only BUILD_TYPE working when building with VS Code (even the changes proposed have no effect... So i'll just keep on compiling directly in Powershell)

But maybe there are other people soon experiencing the same 😅

Oh yes! My changes fix MANY issues with visual studio right now. I do need to get that merged. I assumed no one else was hitting them

Does it make sens building Debug and RelWithDebInfo on All three OS in CI like i did? I could open a PR with that change if it is reasonable.

The project is very fast to compile, and I agree we should check as many things as we can. I know @aminya has another PR open that adds a whole lot more to the build matrix.

One thing that's in my PR is fixing WARNINGS_AS_ERRORS which was broken on all 3 platforms, but I don't really know how to test that.

I think I'm almost ready to say the PR is ready

We're continuing to enhance and double check the build matrix in #181

I'm going to mark this one as closed. The dashboard shows all kinds of multi-config and single config builds working now. Please advise if you see any further issues @LtdSauce