Hayden Raymond Ramm
Hayden Raymond Ramm

Reputation: 1

Using CMake Tools in VS to Update Include Path

I'm trying to build a project using GEANT4 in Visual Studio. I have CMake Tools installed, and here is what my CMakeLists.txt file looks like:

#-------------------------------------------------
#Set up the project
cmake_minimum_required(VERSION 3.31)
project(B1_Clone)

#-------------------------------------------------
#Find the GEANT4 package
find_package(Geant4 REQUIRED)

#-------------------------------------------------
#Include headers
include(${Geant4_USE_FILE})
include_directories(${PROJECT_SOURCE_DIR}/include) #Points to include subdir

The structure of my project is:

/B1_Clone
|---CMakeLists.txt
|---exampleB1.cc
|---/include
    |---header1.hh
    |---header2.hh
   

The problem is that when I open by exampleB1.cc source file, my IntelliSense isn't finding the header files that I specified in my CMakeLists.txt file (i.e. include(${Geant4_USE_FILE}) and include_directories(${PROJECT_SOURCE_DIR}/include)) so when I use #include "header1.hh" etc., I get build errors because my IntelliSense isn't actually being updated. My .json file doesn't change to include the new paths to my /include subdirectory, or any of the GEANT4 /include folders.

Here is the .json:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX14.5.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm64"
        }
    ],
    "version": 4
}

As you can see, the "includePath" isn't updating, so my VS isn't recognising any of the #include commands I pass.

In reality, this is more of a development issue. When I compile everything into an executable, it won't make a difference because the compiler will just go and find the relevant headers, but it's properly annoying when I'm trying to debug everything. Using >CMake Configure on the command palette isn't doing anything either. :(

Upvotes: 0

Views: 16

Answers (0)

Related Questions