Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why CMAKE_BUILD_TYPE is always Debug? #3821

Closed
zchrissirhcz opened this issue Jun 9, 2024 · 19 comments · Fixed by #3879
Closed

Why CMAKE_BUILD_TYPE is always Debug? #3821

zchrissirhcz opened this issue Jun 9, 2024 · 19 comments · Fixed by #3879
Assignees
Labels
bug a bug in the product Feature: configure
Milestone

Comments

@zchrissirhcz
Copy link

zchrissirhcz commented Jun 9, 2024

Brief Issue Summary

CMake: Configure always uses -DCMAKE_BUILD_TYPE:STRING=Debug even if I delete CMAKE_BUILD_TYPE or set CMAKE_BUILD_TYPE=Release in setting of CMake Tools extension, and I've already set environment variable: export CMAKE_BUILD_TYPE=Release

CMake Tools Diagnostics

{
  "os": "darwin",
  "vscodeVersion": "1.90.0",
  "cmtVersion": "1.18.41",
  "configurations": [
    {
      "folder": "/Users/zz/work/cppsober/kcv",
      "cmakeVersion": "3.29.5",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "/Library/Developer/CommandLineTools/usr/bin/cc",
        "CXX": "/Library/Developer/CommandLineTools/usr/bin/c++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 7,
    "executablesCount": 1,
    "librariesCount": 3,
    "targets": [
      {
        "name": "birch-autotimer-update",
        "type": "UTILITY"
      },
      {
        "name": "imgui",
        "type": "STATIC_LIBRARY"
      },
      {
        "name": "konacv",
        "type": "STATIC_LIBRARY"
      },
      {
        "name": "test",
        "type": "EXECUTABLE"
      },
      {
        "name": "glfw",
        "type": "STATIC_LIBRARY"
      },
      {
        "name": "update_mappings",
        "type": "UTILITY"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "never",
      "configureOnOpen": false
    }
  ]
}

Debug Log

No response

Additional Information

No response

@github-actions github-actions bot added the triage label Jun 9, 2024
@Luvideria
Copy link

I would like to add that I can't find the correct way to simply add more build types. The CMakeFiles I use have for instance ServRel or ToolRel as build types, which I can't access at all.

@Evelyn-001 Evelyn-001 added more info needed More info is needed from the community for us to properly triage and investigate. and removed triage labels Jun 13, 2024
@Evelyn-001
Copy link
Collaborator

Evelyn-001 commented Jun 13, 2024

Thanks for reporting this issue. Today we try to repro using a simple CMake Project, but we didn't repro it. We find that if we set the "CMAKE_BUILD_TYPE": "Release" in related configuration, and the -DCMAKE_BUILD_TYPE=Release displays on CMake output when configure the project. For further investigation, could you please share us a demo project with clear repro steps? We are looking forward to hearing from you. Thanks.

ENV:
VS code version: 1.90.0
CMake Extension version: 1.18.42

Please see the verified results as below.
0613VScode

@zchrissirhcz
Copy link
Author

zchrissirhcz commented Jun 13, 2024

@Evelyn-001 Hi, thanks for the reply. This gif looks okay, and maybe I need a little time to learn to use CMakePresets.json. Actually I begin to use CMake since about CMake 3.12 or before that.

My previous trial was on a Apple M1 machine, which is not available now.
I'm currently using a Windows 11, x86-64 machine, and I can reproduce it.

I guess Ninja as generator is the key to reproduce.

Here is the detail:

  • C/C++ compiler: Visual Studio 2022 (17.10.1)
  • CMake: 3.29.5 (manually installed, instead of the VS2022 installed one)
  • Build Tool: Ninja 1.12.1 (manually installed, instead of the VS2022 installed one)

VSCode: Version: 1.90.0
VSCode CMake Tools plugin version: v1.18.42
VSCode User setting.json

{
    "cmake.generator": "Ninja",
    "cmake.pinnedCommands": [
        "workbench.action.tasks.configureTaskRunner",
        "workbench.action.tasks.runTask"
    ],
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.29)
project(x)
message(STATUS "[x] CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
add_executable(x x.c)

x.c:

int main() {}

CMake Configure output by CMake: Configure in VSCode command palette:
image

Do I set CMAKE_BUILD_TYPE environment variable? No
image

image

@zchrissirhcz
Copy link
Author

zchrissirhcz commented Jun 13, 2024

@Evelyn-001 Using the aforementioned CMakeLists.txt and x.c files, I can reproduce the bug on my Apple-M1 machine, where I does not specify Ninja as generator:

  • VSCode version: 1.90.0
  • CMake version: 3.29.5
  • VSCode CMake Tools extension version: v1.18.42
  • VSCode User settings.json keep minimal as:
{
    "cmake.pinnedCommands": [
        "workbench.action.tasks.configureTaskRunner",
        "workbench.action.tasks.runTask"
    ]
}
  • Environment variable CMAKE_BUILD_TYPE is not defined
  • All VSCode instances closed and restarted
截屏2024-06-13 20 04 06

I suggest removing the use of CMakePresets.json for a clean reproduce.

@Evelyn-001
Copy link
Collaborator

Thanks for your reply. According to your comment, we try to repro it using above demo files, please see the verified results as below. Is it your issue? Thanks.
ENV:
VS code version: 1.90.0
CMake Extension version: 1.18.42
061404

@zchrissirhcz
Copy link
Author

Thanks for your reply. According to your comment, we try to repro it using above demo files, please see the verified results as below. Is it your issue? Thanks. ENV: VS code version: 1.90.0 CMake Extension version: 1.18.42 061404 061404

Thanks for the reply. The verified result you provided in the gif is nearly what I thing the issue is. And to be precise, I think there are two sub-issues:

  1. When the C/C++ compiler is cl.exe, if specified Ninja as generator in settings.json, the bug appears
  2. When the C/C++ compiler is Clang, including Clang.exe from Visual Studio (for Windows), and AppleClang (for macOS), the bug appears

@Evelyn-001
Copy link
Collaborator

This issue reproduces with below Conditions:

  1. When the C/C++ compiler is cl.exe, if specified Ninja as generator in settings.json, the bug appears
  2. When the C/C++ compiler is Clang, the bug appears

ENV
VSCode version: 1.90.1
CMake version: 3.28.3-msvc11
Ninja version: 1.11.0
VSCode CMake Tools extension version: v1.18.42

image
339677189-1b80d526-7837-4b98-ab9b-391739f02862

@Evelyn-001
Copy link
Collaborator

@gcampbell-msft, if user do not explicitly specify a value for CMAKE_BUILD_TYPE when executing CMake, or do not explicitly set it before building, will CMake choose a default CMAKE_BUILD_TYPE of Debug? Coud you please help look at this issue? Thanks in advance.

@gcampbell-msft
Copy link
Collaborator

@Evelyn-001 Yes, if there is no CMAKE_BUILD_TYPE specified, then the default is Debug.

@zchrissirhcz
Copy link
Author

@Evelyn-001 Yes, if there is no CMAKE_BUILD_TYPE specified, then the default is Debug.

😂😂 Could you please drop this default "Debug"? I think this "Debug" may sometimes become a "Bug" in my C/C++ projects

@gcampbell-msft
Copy link
Collaborator

@zchrissirhcz @Evelyn-001 Let me take some time to investigate, I actually believe I may have been wrong about our default, let me look more closely into it and get you the full understanding and context. Thanks!

@gcampbell-msft
Copy link
Collaborator

gcampbell-msft commented Jun 21, 2024

@zchrissirhcz Okay I've investigated closer and we do in fact default to "Debug". What are you expecting the default to be? I'm guessing simply an empty string?

@gcampbell-msft
Copy link
Collaborator

@zchrissirhcz Follow up to help us understand your scenario better, is there a reason that you don't want to explicitly set the build type?

@zchrissirhcz
Copy link
Author

I think CMAKE_BUILD_TYPE should be set by user, and a default value provided by "VSCode CMake Tools" is not required. Consider this case: a cross-platform C/C++ project, in its CMakeLists.txt, automatically detect and set value for CMAKE_BUILD_TYPE:

cmake_minimum_required(VERSION 3.5)
projet(x)
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
message(STATUS "[x] CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

When invoked in command like:

cmake -S . -B build

it will print [x] CMAKE_BUILD_TYPE: Release

But when invoked in VSCode CMake Tools' "cmake configure", it prints [x] CMAKE_BUILD_TYPE: Debug.

I see this usage in:

@gcampbell-msft @Evelyn-001

@zchrissirhcz
Copy link
Author

zchrissirhcz commented Jun 24, 2024

@zchrissirhcz Okay I've investigated closer and we do in fact default to "Debug". What are you expecting the default to be? I'm guessing simply an empty string?

@gcampbell-msft
To be precise, I expect CMake Tools extension not passing -DCMAKE_BUILD_TYPE=Debug, and also don't passing -DCMAKE_BUILD_TYPE="".

An empty string (-DCMAKE_BUILD_TYPE="") will also make existing project's CMakeLists.txt not working as expected. Just don't passing this variable by default.

If user do specify CMAKE_BUILD_TYPE in settings by UI/json file, passing that value. And this value can be one of : Debug, Release, MinSizeRel, RelWithDebInfo. And meanwhile, user can also specify other values, such as ToolRel in @Luvideria 's case.

@gcampbell-msft
Copy link
Collaborator

@zchrissirhcz Thanks for all of this information, we will definitely assess this on the backlog and investigate. Again, thanks!

@gcampbell-msft gcampbell-msft added bug a bug in the product Feature: configure and removed more info needed More info is needed from the community for us to properly triage and investigate. labels Jun 24, 2024
@gcampbell-msft gcampbell-msft added this to the 1.19 milestone Jun 24, 2024
@snehara99 snehara99 assigned snehara99 and unassigned moyo1997 Jun 26, 2024
@Evelyn-001
Copy link
Collaborator

Verify this issue has been fixed. Thanks.
ENV:
VS code: 1.91.1
CMake Tools Extension: v1.19.19 (pre-release)
071201

@smp73
Copy link

smp73 commented Jul 12, 2024

Brief Issue Summary

CMake: Configure always uses -DCMAKE_BUILD_TYPE:STRING=Debug even if I delete CMAKE_BUILD_TYPE or set CMAKE_BUILD_TYPE=Release in setting of CMake Tools extension, and I've already set environment variable: export CMAKE_BUILD_TYPE=Release

CMake Tools Diagnostics

{
  "os": "darwin",
  "vscodeVersion": "1.90.0",
  "cmtVersion": "1.18.41",
  "configurations": [
    {
      "folder": "/Users/zz/work/cppsober/kcv",
      "cmakeVersion": "3.29.5",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "/Library/Developer/CommandLineTools/usr/bin/cc",
        "CXX": "/Library/Developer/CommandLineTools/usr/bin/c++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 7,
    "executablesCount": 1,
    "librariesCount": 3,
    "targets": [
      {
        "name": "birch-autotimer-update",
        "type": "UTILITY"
      },
      {
        "name": "imgui",
        "type": "STATIC_LIBRARY"
      },
      {
        "name": "konacv",
        "type": "STATIC_LIBRARY"
      },
      {
        "name": "test",
        "type": "EXECUTABLE"
      },
      {
        "name": "glfw",
        "type": "STATIC_LIBRARY"
      },
      {
        "name": "update_mappings",
        "type": "UTILITY"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "never",
      "configureOnOpen": false
    }
  ]
}

Debug Log

No response

Additional Information

No response

12bc6cdb375f9688ba2eff535c36b26dbbaff710

@Evelyn-001
Copy link
Collaborator

@smp73, thanks for your reply. Do you want to use -DCMAKE_BUILD_TYPE:STRING=Release ? you need to add Adding "configuration": "release" in CMakePresets.json file. Please refer to this comment in that issue. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in the product Feature: configure
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

7 participants