Skip to content

Conversation

JKot-Coder
Copy link
Contributor

Summary

When building with clang-cl (Clang frontend for MSVC):

  • Previously, both Clang-specific and MSVC-specific compiler flags were
    applied, producing duplicate warnings and huge warning output.
  • Compilation could slow down by orders of magnitude due to -Wall/-Wextra.

Changes

  • Clang-cl now only uses MSVC-specific compile options.
  • Pure Clang builds continue using Clang-specific warnings and suppressions.
  • Redundant -Wall/-Wextra removed for clang-cl.

Benefits

  • Builds with clang-cl are significantly faster.
  • Warning output is reasonable and manageable.
  • Maintains correct compile flags for each compiler.

Previously, clang-cl inherited both Clang-specific and MSVC-specific
flags in `target_compile_options`, leading to duplicate flags and
excessive warnings.

After this change:
- Clang-cl builds now only apply MSVC compile options (/W4, etc.).
- Native Clang builds retain only Clang-specific flags.
- -Wall/-Wextra for clang are avoided in clang-cl, preventing
  gigabytes of warnings and drastically improving build times.
@TheMostDiligent
Copy link
Contributor

There are a few other places where clang-specific compiler options are set e.g.
Should they also be disabled for clang-cl?

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(Diligent-ShaderTools PRIVATE -fms-extensions)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_link_libraries(Diligent-ShaderTools PRIVATE dl)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# WARNING: set_source_files_properties() does not append
# properties, but overwrites them!
# Disable warnings like this one:
# comparison of function 'glPolygonMode' not equal to a null pointer is always true [-Wtautological-pointer-compare]
set_property(SOURCE
src/RenderDeviceGLImpl.cpp
src/GLContextState.cpp
src/DeviceContextGLImpl.cpp
APPEND_STRING PROPERTY
COMPILE_FLAGS " -Wno-tautological-pointer-compare"
)
if (PLATFORM_IOS)
# Disable warnings like this one:
# unused variable 'BottomLeftY' [-Wunused-variable]
set_property(SOURCE
src/DeviceContextGLImpl.cpp
src/GLContextState.cpp
src/RenderDeviceGLImpl.cpp
src/Texture1D_GL.cpp
APPEND_STRING PROPERTY
COMPILE_FLAGS " -Wno-unused-variable"
)
endif()
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Disable the following warning:
# explicitly moving variable of type '(anonymous namespace)::SmartPtr' (aka 'RefCntAutoPtr<(anonymous namespace)::Object>') to itself [-Wself-move]
set_source_files_properties(src/Common/RefCntAutoPtrTest.cpp
PROPERTIES
COMPILE_FLAGS "-Wno-self-move -Wno-self-assign"
)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Disable the following warning:
# comparison of function 'glPolygonMode' not equal to a null pointer is always true [-Wtautological-pointer-compare]
set_property(SOURCE
src/GL/TestingEnvironmentGL.cpp
APPEND_STRING PROPERTY
COMPILE_FLAGS -Wno-tautological-pointer-compare
)
if (PLATFORM_WEB)
set_property(SOURCE
src/GPUTestingEnvironment.cpp
APPEND_STRING PROPERTY
COMPILE_FLAGS "-Wno-unused-variable"
)
endif()
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Disable warnings like this one:
# comparison of function 'glPolygonMode' not equal to a null pointer is always true [-Wtautological-pointer-compare]
set_source_files_properties(
src/GL/DrawCommandReferenceGL.cpp
src/GL/GeometryShaderReferenceGL.cpp
src/GL/TessellationReferenceGL.cpp
PROPERTIES
COMPILE_FLAGS -Wno-tautological-pointer-compare
)
if (PLATFORM_WEB)
set_property(SOURCE ${C_INTERFACE_SOURCE} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-unknown-warning-option -Wno-unused-but-set-variable")
endif()
endif()

@JKot-Coder
Copy link
Contributor Author

I'm 99% sure they all should be fixed same way. But I didn't checked any of this.
I'm just started use Diligent and faced with issued that clang++ fails to link at windows.
clang-cl - fails to compile 😄 So I'm just fixed most critical one issues for me. I'm use complied only core and dx12 for now.

@TheMostDiligent
Copy link
Contributor

Did you figure out how to make the build faster?
Last time I tried clang-cl, it took almost 1.5 hours to build everything.

@TheMostDiligent
Copy link
Contributor

This change does not seem to be correct.
If clang-cl only takes MSVC-like command line arguments, the entire branch should be disabled:

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT MSVC)

This reduces the number of warnings, but build time is still ridiculous. It takes more than 5 minutes to build only Diligent-GraphicsEngineD3D11-static

@JKot-Coder
Copy link
Contributor Author

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT MSVC)
Yes, that makes sense.

With all errors ignored using -w, the build completed in less than a minute. Warnings significantly affect build performance.

@TheMostDiligent
Copy link
Contributor

For me, it feels like linking takes most of the time.
Which generator do you use? VS or Ninja?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants