google / fruit

Fruit, a dependency injection framework for C++

Home Page:https://github.com/google/fruit/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VS2022 Just My Code for Fruit Library fails using CMAKE

IrisPeter opened this issue · comments

Previously I have been using vcpkg to consume the fruit library, and when I step into the debugger and get to getComponent in one of the examples the debugger skips over this because I have put
<File Name="*\vcpkg\buildtrees\*" /> into my default.natjmc file.

However when I add <File Name="*\fruit-3.6.0\*" /> to the .natjmc and use CMAKE to generate everything, it steps into injector.defn.h when it gets to the getComponent part of the exmaples. I tried adding set(CMAKE_VS_JUST_MY_CODE_DEBUGGING ON) to the CMakeLists.txt. However this makes no difference

commented

vcpkg is not maintained in this repository. I recommend moving it to https://github.com/microsoft/vcpkg.

@tt4g ,

Hi,

I think you've misunderstood my problem. With vcpkg its working fine, in contrast its building fruit with CMake where the "Just My Code" feature doesn't seem to work.

Whilst I don't think this is specific to the fruit library, was hoping some of the other users of fruit, had built it with CMake targeting a Visual Studio build. Or others who have had experience of CMake projects and VS, who might understand why the Just My Code feature it fails to work.

commented

As you pointed out I did not understand your problem exactly.

CMAKE_VS_JUST_MY_CODE_DEBUGGING must be defined before the CMake target is created, is it defined when fruit is built?
And since fruit is a library, you will need to debug build and generate .pdb file.

Thanks @tt4g

I edited the top level CMakeLists.txt as follows:

#cmake_minimum_required(VERSION 3.19)

# Visual Studio 2022
cmake_minimum_required(VERSION 3.21)

# Visual Studio 2019
#cmake_minimum_required(VERSION 3.20)

project(Fruit VERSION 3.6.0 LANGUAGES CXX)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_VS_JUST_MY_CODE_DEBUGGING ON)

I'm not sure what edits I need to make to ensure the .pdb file is built but just for CMake configurations with the text debug in their name

I see that the build did generate a fruit.pdb in the fruit-3.6.0\out\build\x64-Debug\src folder along with the fruit.dll

However in the fruit-3.6.0\out\install\x64-Debug\bin from which the debugger loads the fruit library, it has not come across

commented

fruit.pdb will be loaded if you move it to the same directory as fruit.dll.

See official document: https://docs.microsoft.com/en-us/visualstudio/debugger/specify-symbol-dot-pdb-and-source-files-in-the-visual-studio-debugger?view=vs-2022

NOTE that symbols that do not appear in the .pdb file cannot be debugged. If the function body is defined in the header file, the code may have been removed for optimization.