microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.44k stars 432 forks source link

Cmake cache variables getting deleted #1373

Open rijobro opened 4 years ago

rijobro commented 4 years ago

Brief Issue Summary

I run cmake externally and successfully set all variables, configure and build the project. I then open VSCode, and cached variables get reset, causing the cmake to fail. I then open the CMake project externally, and the cached variables has been deleted there, too.

It seems that VSCode isn't properly parsing the CMakeCache.txt. Since I've correctly configured the build repository prior to running VSCode, it should just need to run the CMake, and shouldn't need to modify any variables.

Expected:

  1. Create CMake binary folder outside of VSCode
  2. Set any required variables and successfully run make install
  3. Open VSCode and CMake configure successfully completes

Apparent Behavior:

  1. Create CMake binary folder outside of VSCode
  2. Set any required variables and successfully run make install
  3. Open VSCode and CMake configure fails because of missing variables
  4. Open external CMake for second time, and variables have also been deleted there.

CMake Tools Log

[proc] Executing command: /Applications/CMake.app/Contents/bin/cmake -H/Users/rich/Documents/Code/SIRF -B/Users/rich/Documents/Code/SIRF-SuperBuild/Build/builds/SIRF/build -G "Unix Makefiles"
[proc] Executing command: /Applications/CMake.app/Contents/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++ -H/Users/rich/Documents/Code/SIRF -B/Users/rich/Documents/Code/SIRF-SuperBuild/Build/builds/SIRF/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Python libraries found
[cmake] -- SIRF Python modules will be installed in /Users/rich/Documents/Code/SIRF-SuperBuild/Install/python
[cmake] -- Attempting to find MATLAB Mex extension (This might launch MATLAB so might take a while)
[cmake] -- Matlab libraries found
[cmake] -- SIRF Matlab libraries will be installed in /Users/rich/Documents/Code/SIRF-SuperBuild/Install/matlab
[cmake] CMake Warning (dev) at /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:460 (message):
[cmake]   Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
[cmake]   flag.  Run "cmake --help-policy CMP0086" for policy details.  Use the
[cmake]   cmake_policy command to set the policy and suppress this warning.
[cmake] 
[cmake] Call Stack (most recent call first):
[cmake]   /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:702 (SWIG_ADD_SOURCE_TO_MODULE)
[cmake]   src/iUtilities/CMakeLists.txt:50 (SWIG_ADD_LIBRARY)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] -- HDF5: Using hdf5 compiler wrapper to determine C configuration
[cmake] -- HDF5_DIR: HDF5_DIR-NOTFOUND
[cmake] -- HDF5_DEFINITIONS: 
[cmake] -- HDF5_INCLUDE_DIRS: /usr/local/Cellar/hdf5/1.12.0_1/include;/usr/local/opt/szip/include
[cmake] -- HDF5_LIBRARIES: /usr/local/Cellar/hdf5/1.12.0_1/lib/libhdf5.dylib;/usr/local/opt/szip/lib/libsz.dylib;/Users/rich/Documents/Code/SIRF-SuperBuild/Install/lib/libz.a;/usr/lib/libdl.dylib;/usr/lib/libm.dylib
[cmake] -- HDF5_HL_LIBRARIES: 
[cmake] -- HDF5_C_DEFINITIONS: 
[cmake] -- HDF5_C_INCLUDE_DIR: 
[cmake] -- HDF5_C_INCLUDE_DIRS: /usr/local/Cellar/hdf5/1.12.0_1/include;/usr/local/opt/szip/include
[cmake] -- HDF5_C_LIBRARY: 
[cmake] -- HDF5_C_LIBRARIES: /usr/local/Cellar/hdf5/1.12.0_1/lib/libhdf5.dylib;/usr/local/opt/szip/lib/libsz.dylib;/Users/rich/Documents/Code/SIRF-SuperBuild/Install/lib/libz.a;/usr/lib/libdl.dylib;/usr/lib/libm.dylib
[cmake] -- HDF5_C_HL_LIBRARY: 
[cmake] -- HDF5_C_HL_LIBRARIES: 
[cmake] -- FFTW3 UNIX libraries: /usr/local/lib/libfftw3f.dylib
[cmake] CMake Warning (dev) at /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:460 (message):
[cmake]   Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
[cmake]   flag.  Run "cmake --help-policy CMP0086" for policy details.  Use the
[cmake]   cmake_policy command to set the policy and suppress this warning.
[cmake] 
[cmake] Call Stack (most recent call first):
[cmake]   /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:702 (SWIG_ADD_SOURCE_TO_MODULE)
[cmake]   src/xGadgetron/pGadgetron/CMakeLists.txt:38 (SWIG_ADD_LIBRARY)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] -- SPM found
[cmake] -- VTK found: 1
[cmake] CMake Warning (dev) at /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:460 (message):
[cmake]   Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
[cmake]   flag.  Run "cmake --help-policy CMP0086" for policy details.  Use the
[cmake]   cmake_policy command to set the policy and suppress this warning.
[cmake] 
[cmake] Call Stack (most recent call first):
[cmake]   /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:702 (SWIG_ADD_SOURCE_TO_MODULE)
[cmake]   src/Registration/pReg/CMakeLists.txt:40 (SWIG_ADD_LIBRARY)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] -- ITK support in STIR enabled.
[cmake] -- STIR not built with NiftyPET.
[cmake] CMake Warning (dev) at /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:460 (message):
[cmake]   Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
[cmake]   flag.  Run "cmake --help-policy CMP0086" for policy details.  Use the
[cmake]   cmake_policy command to set the policy and suppress this warning.
[cmake] 
[cmake] Call Stack (most recent call first):
[cmake]   /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:702 (SWIG_ADD_SOURCE_TO_MODULE)
[cmake]   src/xSTIR/pSTIR/CMakeLists.txt:39 (SWIG_ADD_LIBRARY)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] -- Registration, ISMRMRD and STIR (with ITK) have been built. Building synergistic code.
[cmake] -- Downloading (if not already done)...
[cmake]         Path:     /Users/rich/Documents/Code/SIRF/data/examples/MR/zenodo/SIRF_recon.h5
[cmake]         URL:      https://zenodo.org/record/3571228/files/SIRF_recon.h5?download=1
[cmake]         MD5:      0d69892502d3a5cd220716a717cc2c26
[cmake] -- Downloading (if not already done)...
[cmake]         Path:     /Users/rich/Documents/Code/SIRF/data/examples/MR/zenodo/dicom_as_nifti.nii
[cmake]         URL:      https://zenodo.org/record/3571228/files/dicom_as_nifti.nii?download=1
[cmake]         MD5:      c5f5b519e5c032560ead912713479b53
[cmake] -- Registration, ISMRMRD and STIR (with ITK) have been built.
[cmake] CMake Warning (dev) at /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:460 (message):
[cmake]   Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
[cmake]   flag.  Run "cmake --help-policy CMP0086" for policy details.  Use the
[cmake]   cmake_policy command to set the policy and suppress this warning.
[cmake] 
[cmake] Call Stack (most recent call first):
[cmake]   /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:702 (SWIG_ADD_SOURCE_TO_MODULE)
[cmake]   src/common/CMakeLists.txt:59 (SWIG_ADD_LIBRARY)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] -- python alias:pGadgetron<-sirf.Gadgetron
[cmake] -- python alias:pSTIR<-sirf.STIR
[cmake] -- python alias:pUtilities<-sirf.Utilities
[cmake] -- python alias:pygadgetron<-sirf.pygadgetron
[cmake] -- python alias:pystir<-sirf.pystir
[cmake] -- python alias:pyiutilities<-sirf.pyiutilities
[cmake] -- python alias:pReg<-sirf.Reg
[cmake] -- python alias:pyreg<-sirf.pyreg
[cmake] -- setup.py:/Users/rich/Documents/Code/SIRF-SuperBuild/Install/python/setup.py
[cmake] -- Configuring done
[cmake] You have changed variables that require your cache to be deleted.
[cmake] Configure will be re-run and you may have to reset some variables.
[cmake] The following variables have changed:
[cmake] CMAKE_C_COMPILER= /usr/bin/clang
[cmake] CMAKE_CXX_COMPILER= /usr/bin/clang++
[cmake] 
[cmake] -- The C compiler identification is AppleClang 11.0.3.11030032
[cmake] -- The CXX compiler identification is AppleClang 11.0.3.11030032
[cmake] -- Check for working C compiler: /usr/bin/clang
[cmake] -- Check for working C compiler: /usr/bin/clang - works
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Check for working CXX compiler: /usr/bin/clang++
[cmake] -- Check for working CXX compiler: /usr/bin/clang++ - works
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Found Boost: /usr/local/lib/cmake/Boost-1.72.0/BoostConfig.cmake (found suitable version "1.72.0", minimum required is "1.36.0") found components: system filesystem thread date_time chrono 
[cmake] -- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.16") 
[cmake] -- Python libraries found
[cmake] -- SIRF Python modules will be installed in /usr/local/python
[cmake] -- Attempting to find MATLAB Mex extension (This might launch MATLAB so might take a while)
[cmake] -- Matlab libraries found
[cmake] -- SIRF Matlab libraries will be installed in /usr/local/matlab
[cmake] -- Found SWIG: /usr/local/bin/swig (found version "4.0.2") 
[cmake] CMake Warning (dev) at /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:460 (message):
[cmake]   Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
[cmake]   flag.  Run "cmake --help-policy CMP0086" for policy details.  Use the
[cmake]   cmake_policy command to set the policy and suppress this warning.
[cmake] 
[cmake] Call Stack (most recent call first):
[cmake]   /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:702 (SWIG_ADD_SOURCE_TO_MODULE)
[cmake]   src/iUtilities/CMakeLists.txt:50 (SWIG_ADD_LIBRARY)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] -- HDF5: Using hdf5 compiler wrapper to determine C configuration
[cmake] -- Found HDF5: /usr/local/Cellar/hdf5/1.12.0_1/lib/libhdf5.dylib;/usr/local/opt/szip/lib/libsz.dylib;/usr/lib/libz.dylib;/usr/lib/libdl.dylib;/usr/lib/libm.dylib (found version "1.12.0") found components: C 
[cmake] -- FFTW3 UNIX libraries: /usr/local/lib/libfftw3f.dylib
[cmake] -- Found FFTW3: /usr/local/lib/libfftw3f.dylib  
[cmake] CMake Warning (dev) at /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:460 (message):
[cmake]   Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
[cmake]   flag.  Run "cmake --help-policy CMP0086" for policy details.  Use the
[cmake]   cmake_policy command to set the policy and suppress this warning.
[cmake] 
[cmake] Call Stack (most recent call first):
[cmake]   /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:702 (SWIG_ADD_SOURCE_TO_MODULE)
[cmake]   src/xGadgetron/pGadgetron/CMakeLists.txt:38 (SWIG_ADD_LIBRARY)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] -- SPM not found
[cmake] -- VTK found: 1
[cmake] CMake Warning (dev) at /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:460 (message):
[cmake]   Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
[cmake]   flag.  Run "cmake --help-policy CMP0086" for policy details.  Use the
[cmake]   cmake_policy command to set the policy and suppress this warning.
[cmake] 
[cmake] Call Stack (most recent call first):
[cmake]   /Applications/CMake.app/Contents/share/cmake-3.17/Modules/UseSWIG.cmake:702 (SWIG_ADD_SOURCE_TO_MODULE)
[cmake]   src/Registration/pReg/CMakeLists.txt:40 (SWIG_ADD_LIBRARY)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] CMake Error at src/CMakeLists.txt:84 (find_package):
[cmake]   By not providing "FindSTIR.cmake" in CMAKE_MODULE_PATH this project has
[cmake]   asked CMake to find a package configuration file provided by "STIR", but
[cmake]   CMake did not find one.
[cmake] 
[cmake]   Could not find a package configuration file provided by "STIR" with any of
[cmake]   the following names:
[cmake] 
[cmake]     STIRConfig.cmake
[cmake]     stir-config.cmake
[cmake] 
[cmake]   Add the installation prefix of "STIR" to CMAKE_PREFIX_PATH or set
[cmake]   "STIR_DIR" to a directory containing one of the above files.  If "STIR"
[cmake]   provides a separate development package or SDK, be sure it has been
[cmake]   installed.
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "/Users/rich/Documents/Code/SIRF-SuperBuild/Build/builds/SIRF/build/CMakeFiles/CMakeOutput.log".

Developer Tools Log

<!-- Paste the log contents HERE -->

Platform and Versions

Screenshots

Project configured externally. STIR_DIR correctly set

image

Open VSCode, STIR_DIR not found

image

Re-open CMake externally, STIR_DIR has been reset

image

cjdb commented 3 years ago

Likely related: #1370.

jpfeuffer commented 3 years ago

We are experiencing similar (or equivalent issues). Our use case is to prebuild our repository outside of VSCode for cloud-based codespaces. However, as soon as VSCode with our settings is opened it seems to clear the build folder or at least some cache variables since a complete reconfigure is triggered and targets are invalidated in the sense that when you try to build them, everything needs to be built again. I lost track of which combinations of the following variables we tried, together with the choice of "Unspecified" Kit or a pre-defined Kit (of course matching the compilers used for the prebuild):

    "cmake.clearOutputBeforeBuild": false,
    "cmake.ignoreKitEnv": true,
    "cmake.configureOnOpen": false,
    "cmake.skipConfigureIfCachePresent": true,
andreeis commented 3 years ago

There is one more possible cause for the unwanted configure. Similar to configureOnOpen, there is also configureOnEdit which has effect when editing the CMakeLists.txt or changing cmake.sourceDirectory setting. Do you happen to do any of this?

Increase the logging verbosity with "cmake.loggingLevel": "Debug" in your .vscode/settings.json, reload the project (and do any operations that usually trigger this to happen) and share with us the content of the "CMake/Build" output channel.

pbertoni89 commented 3 years ago

I also suffer for the same problem. My CMake includes another (header-only) CMake project with

add_subdirectory ("path/to/subproject")
pbertoni89 commented 3 years ago

I also suffer for the same problem. My CMake includes another (header-only) CMake project with

add_subdirectory ("path/to/subproject")

Mine was in facts related with #997. I had to leave the toolkit unspecified, because my own CMakeLists was forcing a particular version of GCC. Anyway that was bringing me here to the same error.

rijobro commented 2 years ago

Hi, any update on this?

GreyHak commented 1 year ago

I ran into this same issue, only I was using g++. I saw the problem when both the first and second cmakes occurred in vscode. Since I knew things worked outside vscode, I tried running vscode’s cmake command instead of my cmake command, and I got the same error. So this issue can be reproduced with cmake directly, without vscode. I’ve found that this is a known cmake issue, but vscode pushes the user down that path. The cmake issue is that it forgets command line defines when it’s doing its reset. The critical difference between the command I use for cmake directly and the command vscode generates is vscode specifies CMAKE_C_COMPILER and CMAKE_CXX_COMPILER. When I don’t specify the compiler, cmake uses the ones in /usr/bin/. vscode is using the ones in /bin/. The path shouldn’t matter since the binaries are the same, but the difference makes cmake unhappy. I can’t see how to get vscode to exclude these arguments or give different paths. The core problem started when I created the project. vscode asked if I wanted GCC using the compiles in /bin/, and I said yes. The ones in /usr/bin/ weren’t an option. I needed to answer Unspecified so that cmake figures it out on its own. This solved my problem. I just wish I knew how to undo that compiler selection without deleting all my vscode settings.