Skip to content

Commit 4ba1ba2

Browse files
Merge bitcoin-core#1647: cmake: Adjust diagnostic flags for clang-cl
4c50d73 ci: Add new "Windows (clang-cl)" job (Hennadii Stepanov) 84c0bd1 cmake: Adjust diagnostic flags for clang-cl (Hennadii Stepanov) Pull request description: When building with `clang-cl` on Windows, the output is cluttered with warning messages because compiler diagnostic flags are not applied correctly: ``` > cmake -B build -G Ninja -DCMAKE_C_COMPILER="C:\Users\hebasto\Downloads\clang+llvm-18.1.8-x86_64-pc-windows-msvc\bin\clang-cl.exe" > cmake --build build [1/16] Building C object src\CMakeFiles\bench.dir\bench.c.obj In file included from C:\Users\hebasto\secp256k1\src\bench.c:11: C:\Users\hebasto\secp256k1\src\util.h(34,13): warning: unused function 'print_buf_plain' [-Wunused-function] 34 | static void print_buf_plain(const unsigned char *buf, size_t len) { | ^~~~~~~~~~~~~~~ 1 warning generated. [2/16] Building C object src\CMakeFiles\secp256k1_precomputed.dir\precomputed_ecmult_gen.c.obj In file included from C:\Users\hebasto\secp256k1\src\precomputed_ecmult_gen.c:3: In file included from C:\Users\hebasto\secp256k1\src\group.h:10: In file included from C:\Users\hebasto\secp256k1\src\field.h:10: C:\Users\hebasto\secp256k1\src\util.h(34,13): warning: unused function 'print_buf_plain' [-Wunused-function] 34 | static void print_buf_plain(const unsigned char *buf, size_t len) { | ^~~~~~~~~~~~~~~ ``` This PR resolves this issue. --- **Additional note for reviewers:** The VS builtin clang can also be used assuming that the following VS components are installed: ![photo_2024-12-12_12-38-17](https://github.com/user-attachments/assets/c69bafcc-3aa2-4a72-a162-071c593d1c4a) The user can generate a build system on Windows as follows: - Using the default "Visual Studio" generator: ``` cmake -B build -T ClangCL ``` - Using the "Ninja" generator: ``` cmake -B build -G Ninja -DCMAKE_C_COMPILER=clang-cl ``` --- Required for downstream projects which aim to build with `clang-cl` (see bitcoin/bitcoin#31456). ACKs for top commit: real-or-random: utACK 4c50d73 Tree-SHA512: 439eb53afd7be65d538cd569f3d095f58325bd26ffc5014ca5f94320689a45b20c9a5a963170578214a20fd3233ec15ef6ab75ab96ce3a4314c282b1b6229ca1
2 parents abd2505 + 4c50d73 commit 4ba1ba2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ jobs:
746746
cpp_flags: '/DSECP256K1_MSVC_MULH_TEST_OVERRIDE'
747747
- job_name: 'x86 (MSVC): Windows (VS 2022)'
748748
cmake_options: '-A Win32'
749+
- job_name: 'x64 (MSVC): Windows (clang-cl)'
750+
cmake_options: '-T ClangCL'
749751

750752
steps:
751753
- name: Checkout

CMakeLists.txt

+8-4
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,21 @@ endif()
242242

243243
include(TryAppendCFlags)
244244
if(MSVC)
245-
# Keep the following commands ordered lexicographically.
245+
# For both cl and clang-cl compilers.
246246
try_append_c_flags(/W3) # Production quality warning level.
247+
# Eliminate deprecation warnings for the older, less secure functions.
248+
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
249+
else()
250+
try_append_c_flags(-Wall) # GCC >= 2.95 and probably many other compilers.
251+
endif()
252+
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
253+
# Keep the following commands ordered lexicographically.
247254
try_append_c_flags(/wd4146) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned".
248255
try_append_c_flags(/wd4244) # Disable warning C4244 "'conversion' conversion from 'type1' to 'type2', possible loss of data".
249256
try_append_c_flags(/wd4267) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data".
250-
# Eliminate deprecation warnings for the older, less secure functions.
251-
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
252257
else()
253258
# Keep the following commands ordered lexicographically.
254259
try_append_c_flags(-pedantic)
255-
try_append_c_flags(-Wall) # GCC >= 2.95 and probably many other compilers.
256260
try_append_c_flags(-Wcast-align) # GCC >= 2.95.
257261
try_append_c_flags(-Wcast-align=strict) # GCC >= 8.0.
258262
try_append_c_flags(-Wconditional-uninitialized) # Clang >= 3.0 only.

0 commit comments

Comments
 (0)