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

Show a quickPick of all the CMakeLists.txt inside the project (if not in the root) #533

Closed
Zingam opened this issue Sep 6, 2018 · 17 comments · Fixed by #1803
Closed

Show a quickPick of all the CMakeLists.txt inside the project (if not in the root) #533

Zingam opened this issue Sep 6, 2018 · 17 comments · Fixed by #1803
Assignees
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: configure fixed (release pending) fixed in pre-release and is pending official release
Projects
Milestone

Comments

@Zingam
Copy link
Contributor

Zingam commented Sep 6, 2018

Brief Issue Summary

CMake Tools doesn't detect CMakeLists.txt automatically if it is not in the root directory on Linux (I haven't tried other OSs). The CMakeLists.txt is in a subdirectory of the root directory and cmake.sourceDirectory is set to point to that subdirectory.
If I execute the command to configure the project manually it runs as expected.

Expected:

The same behavior as if CMakeLists.txt is in the root directory: when the project is opened CMake Tools should ask me if I want to configure the project.

@Zingam Zingam changed the title CMake Tools doesn't detect CMakeLists.txt if it is not in the root directory CMake Tools doesn't detect CMakeLists.txt automatically if it is not in the root directory Sep 6, 2018
@nyanpasu64
Copy link

nyanpasu64 commented Sep 13, 2018

Building a CMakeLists.txt in a subdirectory (Windows) is a pain.

First I have to go to VS Code settings, change the workspace cmake.sourceDirectoryto the subfolder.

Then I get exception "[rollbar] Unhandled exception: Unhandled Promise rejection: configure [cmake-server] Failed to activate protocol version: "CMAKE_HOME_DIRECTORY" is set but incompatible with configured source directory value. {}".

To fix this, I have to remove the build directory and run "Clean reconfigure" (#508 (comment) )

@vector-of-bool
Copy link
Contributor

VSCode extensions have something called "activation events," which they register in their package.json. Most activation events are when one of the command palette commands is invoked. When an activation event is triggered, only then will VSCode load the extension and it can register itself. CMake Tools has an activation event if it detects a CMakeLists.txt in the root directory of the workspace, but any subdirectories do not work. It is during extension activation that it generates this prompt.

There is a special * activation event that will immediately and always load the extension in VSCode. Its usage is dis-recommended, however. I would need to be careful about using it, but it may be an option.

@vector-of-bool vector-of-bool added the enhancement an enhancement to the product that is either not present or an improvement to an existing feature label Sep 17, 2018
@vector-of-bool vector-of-bool added this to the Backlog milestone Sep 17, 2018
@mwheeler
Copy link

Doesn't this just require "workspaceContains:**/CMakeLists.txt" ? (though cmake.sourceDirectory is still needed to decide 'which' CMakeLists.txt to use if there are multiple)

@Zingam
Copy link
Contributor Author

Zingam commented Feb 16, 2019

cmake.sourceDirectory

Doesn't seem to work now:

[cmake] CMake version: 3.10.2
[cmake] The C compiler identification is unknown
[cmake] The C compiler identification is unknown
[cmake] CMake Error: Could not find cmake module file: ./CMakeFiles/3.10.2/CMakeCCompiler.cmake
[cmake] CMake Error: Could not find cmake module file: ./CMakeFiles/3.10.2/CMakeCCompiler.cmake
[cmake] The CXX compiler identification is unknown
[cmake] The CXX compiler identification is unknown
[cmake] CMake Error: Could not find cmake module file: ./CMakeFiles/3.10.2/CMakeCXXCompiler.cmake
[cmake] CMake Error: Could not find cmake module file: ./CMakeFiles/3.10.2/CMakeCXXCompiler.cmake
[cmake] Check for working C compiler: /usr/bin/gcc-7
[cmake] Check for working C compiler: /usr/bin/gcc-7
[cmake] CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:37 (try_compile):
[cmake]   Unknown extension ".c" for file
[cmake] 
[cmake]     ./CMakeFiles/CMakeTmp/testCCompiler.c
[cmake] 
[cmake]   try_compile() works only for enabled languages.  Currently these are:
[cmake] 
[cmake]     C CXX
[cmake] 
[cmake]   See project() command to enable other languages.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:7 (project)
[cmake] 
[cmake] 
[cmake] CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:37 (try_compile):
[cmake]   Unknown extension ".c" for file
[cmake] 
[cmake]     ./CMakeFiles/CMakeTmp/testCCompiler.c
[cmake] 
[cmake]   try_compile() works only for enabled languages.  Currently these are:
[cmake] 
[cmake]     C CXX
[cmake] 
[cmake]   See project() command to enable other languages.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:7 (project)
[cmake] 
[cmake] 
[cmake] Check for working C compiler: /usr/bin/gcc-7 -- broken
[cmake] Check for working C compiler: /usr/bin/gcc-7 -- broken
[cmake] CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
[cmake]   The C compiler
[cmake] 
[cmake]     "/usr/bin/gcc-7"
[cmake] 
[cmake]   is not able to compile a simple test program.
[cmake] 
[cmake]   It fails with the following output:
[cmake] 
[cmake]     
[cmake] 
[cmake]   
[cmake] 
[cmake]   CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:7 (project)
[cmake] 
[cmake] 
[cmake] CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
[cmake]   The C compiler
[cmake] 
[cmake]     "/usr/bin/gcc-7"
[cmake] 
[cmake]   is not able to compile a simple test program.
[cmake] 
[cmake]   It fails with the following output:
[cmake] 
[cmake]     
[cmake] 
[cmake]   
[cmake] 
[cmake]   CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:7 (project)
[cmake] 
[cmake] 
[cmake] Configuring incomplete, errors occurred!
[cmake] Configuring incomplete, errors occurred!
[cmake] CMake version: 3.10.2
[cmake] CMake version: 3.10.2
[cms-driver] Error during CMake configure: [cmake-server] Configuration failed.
[cmake] The C compiler identification is unknown
[cmake] CMake Error: Could not find cmake module file: ./CMakeFiles/3.10.2/CMakeCCompiler.cmake
[cmake] The CXX compiler identification is unknown
[cmake] CMake Error: Could not find cmake module file: ./CMakeFiles/3.10.2/CMakeCXXCompiler.cmake
[cmake] Check for working C compiler: /usr/bin/gcc-7
[cmake] CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:37 (try_compile):
[cmake]   Unknown extension ".c" for file
[cmake] 
[cmake]     ./CMakeFiles/CMakeTmp/testCCompiler.c
[cmake] 
[cmake]   try_compile() works only for enabled languages.  Currently these are:
[cmake] 
[cmake]     C CXX
[cmake] 
[cmake]   See project() command to enable other languages.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:7 (project)
[cmake] 
[cmake] 
[cmake] Check for working C compiler: /usr/bin/gcc-7 -- broken
[cmake] CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
[cmake]   The C compiler
[cmake] 
[cmake]     "/usr/bin/gcc-7"
[cmake] 
[cmake]   is not able to compile a simple test program.
[cmake] 
[cmake]   It fails with the following output:
[cmake] 
[cmake]     
[cmake] 
[cmake]   
[cmake] 
[cmake]   CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:7 (project)
[cmake] 
[cmake] 
[cmake] Configuring incomplete, errors occurred!
[cms-driver] Error during CMake configure: [cmake-server] Configuration failed.

@akanakia
Copy link

Would love to have the ability to use CMake tools in vscode from a sub-directory of current working dir. It is particularly painful when using something like pybind with cmake where it is necessary to put the CMakeLists.txt in a sub-folder instead of the root to keep the project structure sensible (see below).

/root
|
|- /cpp
|- /cpp/src
|- /cpp/include
|- /cpp/CMakeLists.txt
|- /python
|- /python/python-setup-stuff...

with the above project structure, the extension cannot find /root/cpp/CMakeLists.txt and so we have to do all the building manually.

@HunterZ
Copy link

HunterZ commented May 14, 2019

CMake's Eclipse generator requires that CMakeLists.txt live in a sibling of the build directory, so I've got an existing project with myProject/src/CMakeLists.txt and a myProject/debug build directory. This all works, but I can't seem to get vscode + CMake Tools working with it.

I tried opening the folder configuration and putting this in settings.json:

{
    "cmake.buildDirectory": "${workspaceRoot}/debug",
    "cmake.sourceDirectory": "${workspaceRoot}/src"
}

But I get [rollbar] Unhandled exception: Unhandled Promise rejection: clean [cmake-server] Failed to activate protocol version: "sourceDirectory" is not a directory. {}

Edit: Well, cleaning out myProject/debug seems to have helped.

@bobbrow
Copy link
Member

bobbrow commented Jul 22, 2019

I submitted a PR for this. It should be included in the 1.2.0 release.

@bobbrow bobbrow modified the milestones: Backlog, 1.2.0 Jul 22, 2019
@Zingam
Copy link
Contributor Author

Zingam commented Jul 23, 2019

@bobbrow I just found out that: "Maintainer Changes (7/12/19)
vector-of-bool has moved on to other things and Microsoft is now maintaining this extension. Thank you vector-of-bool for all of your hard work getting this extension to where it is today!"
And this is awesome news! I don't know if my nagging on the VS blog helped but thank you very much!
Please consider next adding support for CMakeSettings.json, etc. to equalize the CMake features/workflow between VS2019 and VSCode.

@bobbrow
Copy link
Member

bobbrow commented Jul 24, 2019

@Zingam, we are tracking your issue #529 and do plan to do it but we haven't cooked up the timeline for that yet. When we know with more certainty, we will assign it to a milestone.

@bobbrow bobbrow added the fixed (release pending) fixed in pre-release and is pending official release label Sep 23, 2019
@bobbrow
Copy link
Member

bobbrow commented Nov 5, 2019

This issue has been addressed in CMake Tools 1.2.0 which is available in the VS Code Marketplace or on the Releases Page

Because the publisher id has changed, VS Code does not automatically upgrade you yet. The Marketplace team will enable this in the next few days. If you want to install 1.2.0 now, please make sure you uninstall any earlier versions of CMake Tools manually to avoid any conflicts.

@bobbrow bobbrow closed this as completed Nov 5, 2019
@Zingam
Copy link
Contributor Author

Zingam commented Nov 7, 2019

Can this be made to support more than two levels of subfolders?
Folder3/Folder2/Folder1/CMakeLists.txt

If I select Folder3 get:
[cms-client] Configuring using the "Ninja" CMake generator with plattform "undefined" and toolset {}
[cms-client] Configuring using the "Ninja" CMake generator with plattform "undefined" and toolset {}

The reason why I want to do this is that I have:
Readme.MD and .gitgnore files inside of Folder2 and I want the build and any other VSCode generated stuff to go into Folder3 so that my sources remain clean of third party generated files for easy maintenance.

Concepts3.zip

@bobbrow
Copy link
Member

bobbrow commented Nov 7, 2019

The change simply activates the extension if a CMakeLists.txt is found in the workspace. If your CMakeLists.txt is not directly in the ${workspaceFolder}, you still need to set the "cmake.sourceDirectory" setting to "${workspaceFolder}/Folder2/Folder1" (where Folder3 == ${workspaceFolder}).

Are you asking for a feature to automatically detect the root CMakeLists.txt?

@jaudiger
Copy link

jaudiger commented Nov 8, 2019

I was facing the same issue this morning. I tried to set "cmake.sourceDirectory" and it worked, thanks.

I think the message displayed is not relevant when the CMakeLists.txt is not found. For a first approach, it could be updated to point to this setting.

But the best approach in my case, would be to automatically detect the CMakeLists.txt in the workspace folder and prompts which one to use in case more than one have been found.

@Zingam
Copy link
Contributor Author

Zingam commented Nov 8, 2019

@bobbrow Yes, I also would like to have CMakeTools to dectect automatically the first root CMakeLists.txt
jaudiger's suggestion is also plausible.

@bobbrow bobbrow modified the milestones: 1.2.0, 1.3.0 Nov 13, 2019
@bobbrow bobbrow removed the fixed (release pending) fixed in pre-release and is pending official release label Nov 13, 2019
@andreeis andreeis modified the milestones: 1.3.0, 1.4.0 Jan 27, 2020
@andreeis andreeis modified the milestones: 1.4.0, 1.5.0 Apr 1, 2020
@SchweizS SchweizS mentioned this issue Apr 18, 2020
@mcandre
Copy link

mcandre commented Nov 19, 2020

Hilariously enough, the plugin prompts the user to "Don't ask again"... and then proceeds asks again, for every project.

@bobbrow
Copy link
Member

bobbrow commented Nov 19, 2020

Yeah, the "Don't Show Again" button was intended to inherit the context of the question: "CMakeLists.txt was not found in the root of the folder <foo>. How would you like to proceed?" It was only meaning "Don't show again for this folder", but I can see how that can be confusing.

@elahehrashedi elahehrashedi added this to to do in 1.6.0 Dec 14, 2020
@elahehrashedi elahehrashedi removed this from To Do in 1.6.0 Feb 11, 2021
@elahehrashedi elahehrashedi added this to ToDo in 1.7.0 Feb 11, 2021
@bobbrow bobbrow modified the milestones: 1.6.0, 1.7.0 Feb 16, 2021
@andreeis andreeis changed the title CMake Tools doesn't detect CMakeLists.txt automatically if it is not in the root directory Show a quickPick of all the CMakeLists.txt inside the project (if not in the root) Mar 2, 2021
@andreeis andreeis removed this from ToDo in 1.7.0 Mar 2, 2021
@andreeis andreeis modified the milestones: 1.7.0, 1.8.0 Mar 2, 2021
@andreeis andreeis added this to Triage in 1.8.0 Mar 29, 2021
@bobbrow bobbrow moved this from Triage to To do in 1.8.0 Mar 29, 2021
@bobbrow
Copy link
Member

bobbrow commented Apr 16, 2021

Starting work on this feature for 1.8

  • In place of the "open file" dialog when the user chooses to "Locate" the CMakeLists.txt, we will present a "quick pick" drop down that contains the paths to all the CMakeLists.txt we found in the workspace.
  • An additional option in the list would allow you to "browse" for a CMakeLists.txt which might be outside of the workspace.

@bobbrow bobbrow moved this from To do to In progress in 1.8.0 Apr 23, 2021
@elahehrashedi elahehrashedi added the fixed (release pending) fixed in pre-release and is pending official release label Jun 25, 2021
@bobbrow bobbrow moved this from In progress to Done in 1.8.0 Jun 28, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: configure fixed (release pending) fixed in pre-release and is pending official release
Projects
No open projects
1.8.0
Done
Development

Successfully merging a pull request may close this issue.