-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Implicit include directories are incomplete, resulting in compile errors (CMake + Clang-Tidy) #23444
Comments
Can you give an example of how you are using clang-tidy / cppcheck such that it fails? Since you are referring to cmake I imagine they must be getting their information from some kind of cmake metatdata file? Could show the exact command that fail? |
Ah, I see the problem. In Also, I do have a fix in flight but I'm trying to figure out how that |
Hello, thank you for taking a look at it. Most projects have this in their CMake file: # Generate compile_commands.json to make it easier to work with clang based tools
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Include implicit directories in the compile commands file
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) This doesn't yet work for Emscripten. One workaround would be to do:
But this would mean to adjust many project files. |
So this is needed to make thing like clang-tidy work? Seems like a big of hack, but if that is what folks do we can certainly make sure we are compatible with that. |
When you say it "doesn't yet work" for emscripten what exactly do you mean? We do set CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES, right? Are you jut saying that that this list is incomplete are is somehow missing for you? |
Since clang-tidy (and other tools which use
"yet" means - if could be fixed ;)
Yes. Because the list is incomplete, even Emscripten itself cannot compile a simple program anymore (see the code example above). I think the include problem comes from the fact, that instead this include order is used:
This one is used:
|
This fixes CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES for the case when we don't use compiler-auto-detection. i.e. `-DEMSCRIPTEN_FORCE_COMPILERS=OFF` which happens to be the default today. As a followup we should consider completely removing `EMSCRIPTEN_FORCE_COMPILERS`. Fixes: emscripten-core#23444
This fixes CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES for the case when we don't use compiler-auto-detection. i.e. `-DEMSCRIPTEN_FORCE_COMPILERS=OFF` which happens to be the default today. As a followup we should consider completely removing `EMSCRIPTEN_FORCE_COMPILERS`. Fixes: emscripten-core#23444
Ok great. I have an initial fix in #23535. As a followup I hope to completely remove |
This fixes CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES for the case when we don't use compiler-auto-detection. i.e. `-DEMSCRIPTEN_FORCE_COMPILERS=OFF` which happens to be the default today. As a followup we should consider completely removing `EMSCRIPTEN_FORCE_COMPILERS`. Fixes: emscripten-core#23444
This fixes CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES for the case when we don't use compiler-auto-detection. i.e. `-DEMSCRIPTEN_FORCE_COMPILERS=OFF` which happens to be the default today. As a followup we should consider completely removing `EMSCRIPTEN_FORCE_COMPILERS`. Fixes: emscripten-core#23444
This fixes CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES for the case when we don't use compiler-auto-detection. i.e. `-DEMSCRIPTEN_FORCE_COMPILERS=OFF` which happens to be the default today. As a followup we should consider completely removing `EMSCRIPTEN_FORCE_COMPILERS`. Fixes: emscripten-core#23444
This fixes CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES for the case when we don't use compiler-auto-detection. i.e. `-DEMSCRIPTEN_FORCE_COMPILERS=OFF` which happens to be the default today. As a followup we should consider completely removing `EMSCRIPTEN_FORCE_COMPILERS`. Fixes: emscripten-core#23444
This change disables `EMSCRIPTEN_FORCE_COMPILERS` by default which means cmake will run all the normal compiler detection phases. This has the advantage that things get setup correctly without taking any shortcuts. See emscripten-core#23444. The downside is the that cmake phase itself is now slower since its needs to compiler, link and run a bunch of test binaries. On my machine running all the cmake tests went from 27 to 36 seconds. Running a single empty cmake project when from 1s to 4.5s. Since running cmake is normally rare compared to building the project itself I think this slowdown is worth it, but I've left the `EMSCRIPTEN_FORCE_COMPILERS` setting in place for now that folks that want fast cmake. Also, remember that cmake itself caches all this stuff so its only the first run that get slowed down.
This change disables `EMSCRIPTEN_FORCE_COMPILERS` by default which means cmake will run all the normal compiler detection phases. This has the advantage that things get setup correctly without taking any shortcuts. See emscripten-core#23444. The downside is the that cmake phase itself is now slower since its needs to compiler, link and run a bunch of test binaries. On my machine running all the cmake tests went from 27 to 36 seconds. Running a single empty cmake project when from 1s to 4.5s. Since running cmake is normally rare compared to building the project itself I think this slowdown is worth it, but I've left the `EMSCRIPTEN_FORCE_COMPILERS` setting in place for now that folks that want fast cmake. Also, remember that cmake itself caches all this stuff so its only the first run that get slowed down.
This change disables `EMSCRIPTEN_FORCE_COMPILERS` by default which means cmake will run all the normal compiler detection phases. This has the advantage that things get setup correctly without taking any shortcuts. See #23444. The downside is the that cmake phase itself is now slower since its needs to compiler, link and run a bunch of test binaries. On my machine running all the cmake tests went from 27 to 36 seconds. Running a single empty cmake project when from 1s to 4.5s. Since running cmake is normally rare compared to building the project itself I think this slowdown is worth it, but I've left the `EMSCRIPTEN_FORCE_COMPILERS` setting in place for now that folks that want fast cmake. Also, remember that cmake itself caches all this stuff so its only the first run that get slowed down.
In order to make clang-tidy (and cppcheck and other static analyzer happy) they need all includes of an compiler.
But here:
emscripten/cmake/Modules/Platform/Emscripten.cmake
Lines 371 to 376 in bb16735
Only
include/
is set. But there are more includes if you run:echo | em++ -xc++ -E -v -
Maybe
cmake_parse_implicit_include_info
from CMakeParseImplicitIncludeInfo should be used (it works).Without the complete list, a simple program is not compileable.
Version of emscripten/emsdk:
3.1.74/4.0.0
Failing command line in full:
.em++ -std=c++20 -isystem $EMSCRIPTEN/cache/sysroot/include/ test.cpp
./em++ -std=c++20 -isystem /home/neubertt/projects/emsdk/upstream/emscripten/cache/sysroot/include/ test.cpp
The text was updated successfully, but these errors were encountered: