I want to build my project with clang, but only to setup omni completion (intellisense) in my editor (gVim). Doing this because at this time nothing else supports semantic completion with C++ modules.
Even if I fix my project to compile with this new compiler, linking still gives errors, and linking is not needed for my purpose.
Is it possible to tell CMake to skip the link step and only compile the source files ? Is it possible to some how set the link program to /bin/true, or a similiar option ?
There’s a plan for a similar feature in the works. Not sure of an exact deadline yet.
Well…at least the shared infrastructure. What, exactly, do you need done for this use case?
- scanning (discovering dependencies/module usages)
- module file generation (just compilation)
All I need is to build my project without linking. Something like a ‘compile’ target for make / ninja would help. If possible I would try the -fsyntax-only option for clang as well.
Scanning for modules should happen as usual for the project.
Once I know the compilation is successfull, I want to manually copy the resulting build commands into a compile_commands.json file. This file is used by clangd plugin in my text editor (YCM plugin for gVim) for semantic completion, and error hints during code editing.
CMake already has an option to generate the compilation database for clangd, but it only works for trivial cases. If I have a module file, like std.ixx, outside the project directory (from Visual Studio install directory, used as instructed by Microsoft), for which I create and interface library or an object library, the file and the build command will not show up in the compilation database.
There are plans in the work for modules support; I don’t think
compile_commands.json will be sufficient anyways.
Note that some linking may occur anyways in order to satisfy other CMake model requirements, but executables almost certainly won’t be linked at least. I’ll keep a
compile target in mind when the related feature gets implemented, though I think your use case better fits under the “tooling support for C++ modules” umbrella (your
compile target just being a mechanism to hack a solution up).
I already have some “good enough” semantic completion for my small project (about 10 source files), with a
.json file that I fixed by hand. So I still think the semantic engine or language server (clangd) can do the job, with a nice
compile_commands.json file. Also I noticed clangd needs to access my intermediate directory for the pre-compiled modules. But even without the
.json file, the YCM plugin can use an alternative python script, that essentially provides the build flags on request when clangd needs them.
I guess my real issue is: when I switched my project to use clang (instead of msvc) I started getting some build errors, including link errors. But the link errors I do not want to fix, because my project builds fine with msvc, and I only need clang for intellisense. So I started looking for a way to skip the link step.
Could you fake the linking by setting the CMAKE_C/CXX_LINK_EXECUTABLE variables to something that doesn’t actually link, but just “touches” the resulting file, or something like this ?
I assume cmake needs to identify the linker version, and makes a try-compile to probe the linker is in working order … it could maybe even try to run the test executable (like I think autoconf does…).
So it’s not clear how good the fake needs to be, if it works, might be non-trivial still … and how much argument parsing and what arguments I need to support.
It would be nice if cmake could identify /bin/true as a valid linker type … and assume I do not want to link. But not sure if that is even possible in case the linker is invoked by the compiler …
Any use of binaries in the graph will want a real linker (e.g., a codegen tool). Ithink just giving a handle into what is needed and letting the graph dictate what is needed from there is the most robust and general solution.