Improve clangd support #8867

Open
Tmpod wants to merge 1 commit from Tmpod/task/improve-clangd-support into master
3 changed files with 9 additions and 0 deletions

4
.clangd Normal file
View file

@ -0,0 +1,4 @@
CompileFlags:
Remove:
# clang has an issue with this flag, while gcc does not
- "-mno-direct-extern-access"
biodranik commented 2024-08-06 20:50:51 +00:00 (Migrated from github.com)
Review

It would be great to know where does this flag come from :) Is it your system-specific issue?

It would be great to know where does this flag come from :) Is it your system-specific issue?
Tmpod commented 2024-08-06 21:21:58 +00:00 (Migrated from github.com)
Review

This flag appears in the CMake-generated build.ninja files. Can you confirm if it appears in yours?
Indeed, I'm not sure where it comes from...

This flag appears in the CMake-generated `build.ninja` files. Can you confirm if it appears in yours? Indeed, I'm not sure where it comes from...
biodranik commented 2024-08-06 21:28:12 +00:00 (Migrated from github.com)
Review

It looks like some dependency sets it. Can you try to trace cmake with debug/verbose/trace mode?

It looks like some dependency sets it. Can you try to trace cmake with debug/verbose/trace mode?
Tmpod commented 2024-08-06 21:39:46 +00:00 (Migrated from github.com)
Review

According to gcc's man page:

-mdirect-extern-access
-mno-direct-extern-access
    Do  not  use  or  use  GOT  to  access external symbols.  The default is -mno-direct-extern-access: GOT is used for external symbols with default visibility, but not used for other
    external symbols.

    With -mdirect-extern-access, GOT is not used and all external symbols are PC-relatively addressed.  It is only suitable for environments where no dynamic link  is  performed,  like
    firmwares, OS kernels, executables linked with -static or -static-pie.  -mdirect-extern-access is not compatible with -fPIC or -fpic.

It's rather weird because I'm clearly using GCC to compile OM, yet CMake adds that flag, which is already the default.

Seems like the issue stems from clang having a different name for this: -fdirect-access-external-data.

According to gcc's man page: ``` -mdirect-extern-access -mno-direct-extern-access Do not use or use GOT to access external symbols. The default is -mno-direct-extern-access: GOT is used for external symbols with default visibility, but not used for other external symbols. With -mdirect-extern-access, GOT is not used and all external symbols are PC-relatively addressed. It is only suitable for environments where no dynamic link is performed, like firmwares, OS kernels, executables linked with -static or -static-pie. -mdirect-extern-access is not compatible with -fPIC or -fpic. ``` It's rather weird because I'm clearly using GCC to compile OM, yet CMake adds that flag, which is already the default. Seems like the issue stems from clang having a different name for this: [`-fdirect-access-external-data`](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fdirect-access-external-data).
Tmpod commented 2024-08-06 22:33:31 +00:00 (Migrated from github.com)
Review

It looks like some dependency sets it. Can you try to trace cmake with debug/verbose/trace mode?

Looks like it's a Qt6 thing:

   Called from: [3]     /usr/lib/cmake/Qt6/Qt6Targets.cmake
                [2]     /usr/lib/cmake/Qt6/Qt6Config.cmake
                [1]     /home/tmpod/Programming/GSoC/2024/organicmaps/CMakeLists.txt
/usr/lib/cmake/Qt6/Qt6Targets.cmake(70):  set_target_properties(Qt6::Platform PROPERTIES INTERFACE_COMPILE_FEATURES cxx_std_17 INTERFACE_COMPILE_OPTIONS \$<\$<CXX_COMPILER_ID:GNU>:-mno-direct-extern-access>;\$<\$<CXX_COMPILER_ID:Clang>:-fno-direct-access-external-data> INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/lib/qt6/mkspecs/linux-g++;${_IMPORT_PREFIX}/include/qt6 INTERFACE_LINK_LIBRARIES Threads::Threads _qt_package_version 6.7.2 )
> It looks like some dependency sets it. Can you try to trace cmake with debug/verbose/trace mode? Looks like it's a Qt6 thing: ``` Called from: [3] /usr/lib/cmake/Qt6/Qt6Targets.cmake [2] /usr/lib/cmake/Qt6/Qt6Config.cmake [1] /home/tmpod/Programming/GSoC/2024/organicmaps/CMakeLists.txt /usr/lib/cmake/Qt6/Qt6Targets.cmake(70): set_target_properties(Qt6::Platform PROPERTIES INTERFACE_COMPILE_FEATURES cxx_std_17 INTERFACE_COMPILE_OPTIONS \$<\$<CXX_COMPILER_ID:GNU>:-mno-direct-extern-access>;\$<\$<CXX_COMPILER_ID:Clang>:-fno-direct-access-external-data> INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/lib/qt6/mkspecs/linux-g++;${_IMPORT_PREFIX}/include/qt6 INTERFACE_LINK_LIBRARIES Threads::Threads _qt_package_version 6.7.2 ) ```
Tmpod commented 2024-08-13 10:53:38 +00:00 (Migrated from github.com)
Review

@biodranik What is your Qt6 version?

@biodranik What is your Qt6 version?
biodranik commented 2024-08-13 14:05:24 +00:00 (Migrated from github.com)
Review

6.6 on Mac

6.6 on Mac

3
.gitignore vendored
View file

@ -188,3 +188,6 @@ screenshots/
android/src/google/play/listings/
keywords/
iphone/metadata/**/keywords.txt
# clangd cache
.cache/clangd/

View file

@ -11,6 +11,8 @@ set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Fixes warning ld: warning: ignoring duplicate libraries on Mac and Windows.
if (POLICY CMP0156)
cmake_policy(SET CMP0156 NEW)