Skip to content

Commit 1a00d05

Browse files
committed
Merge #44: cmake: Silent MSVC warnings
816fd3b fixup! cmake: Add platform-specific definitions and properties (Hennadii Stepanov) e26415b fixup! cmake: Build `secp256k1` static library (Hennadii Stepanov) 077a534 fixup! cmake: Build `minisketch` static library (Hennadii Stepanov) 2a17419 fixup! cmake: Build `leveldb` static library (Hennadii Stepanov) Pull request description: This PR follows the master branch approach and amends the previous commits. Subtrees are treated separately from our code. Also please refer to: - https://github.com/hebasto/bitcoin/blob/953d302a242381ae13112ea42f87d57e6e796147/build_msvc/libleveldb/libleveldb.vcxproj#L54 - https://github.com/hebasto/bitcoin/blob/953d302a242381ae13112ea42f87d57e6e796147/build_msvc/libminisketch/libminisketch.vcxproj#L31 - https://github.com/hebasto/bitcoin/blob/953d302a242381ae13112ea42f87d57e6e796147/build_msvc/libsecp256k1/libsecp256k1.vcxproj#L20 - https://github.com/hebasto/bitcoin/blob/953d302a242381ae13112ea42f87d57e6e796147/build_msvc/common.init.vcxproj.in#L91-L93 - and bitcoin#28798 All warning suppressions are documented, ACKs for top commit: TheCharlatan: lgtm ACK 816fd3b Tree-SHA512: bfb5f44629312f1aefe97ec1508dc56fe54efb7b35ecc865eb735f3569367d527589a25585b19f5a42b45c66cc46ed65c0b8f6ce6bcca9addd9321b6110fbfb6
2 parents d86340b + 816fd3b commit 1a00d05

File tree

4 files changed

+58
-34
lines changed

4 files changed

+58
-34
lines changed

CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ if(WIN32)
131131
# Improve parallelism in MSBuild.
132132
# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.
133133
list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true")
134+
135+
try_append_cxx_flags("/W3" TARGET core)
136+
try_append_cxx_flags("/wd4018" TARGET core)
137+
try_append_cxx_flags("/wd4244" TARGET core)
138+
try_append_cxx_flags("/wd4267" TARGET core)
139+
try_append_cxx_flags("/wd4715" TARGET core)
140+
try_append_cxx_flags("/wd4805" TARGET core)
141+
target_compile_definitions(core INTERFACE
142+
_CRT_SECURE_NO_WARNINGS
143+
_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
144+
)
134145
endif()
135146

136147
if(MINGW)

cmake/leveldb.cmake

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Copyright (c) 2023 The Bitcoin Core developers
1+
# Copyright (c) 2023-present The Bitcoin Core developers
22
# Distributed under the MIT software license, see the accompanying
3-
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
3+
# file COPYING or https://opensource.org/license/mit/.
44

55
# This file is part of the transition from Autotools to CMake. Once CMake
66
# support has been merged we should switch to using the upstream CMake
@@ -41,6 +41,8 @@ add_library(leveldb STATIC EXCLUDE_FROM_ALL
4141
${PROJECT_SOURCE_DIR}/src/leveldb/util/comparator.cc
4242
${PROJECT_SOURCE_DIR}/src/leveldb/util/crc32c.cc
4343
${PROJECT_SOURCE_DIR}/src/leveldb/util/env.cc
44+
$<$<NOT:$<BOOL:${WIN32}>>:${PROJECT_SOURCE_DIR}/src/leveldb/util/env_posix.cc>
45+
$<$<BOOL:${WIN32}>:${PROJECT_SOURCE_DIR}/src/leveldb/util/env_windows.cc>
4446
${PROJECT_SOURCE_DIR}/src/leveldb/util/filter_policy.cc
4547
${PROJECT_SOURCE_DIR}/src/leveldb/util/hash.cc
4648
${PROJECT_SOURCE_DIR}/src/leveldb/util/histogram.cc
@@ -49,14 +51,6 @@ add_library(leveldb STATIC EXCLUDE_FROM_ALL
4951
${PROJECT_SOURCE_DIR}/src/leveldb/util/status.cc
5052
${PROJECT_SOURCE_DIR}/src/leveldb/helpers/memenv/memenv.cc
5153
)
52-
if(WIN32)
53-
target_sources(leveldb PRIVATE ${PROJECT_SOURCE_DIR}/src/leveldb/util/env_windows.cc)
54-
set_property(SOURCE ${PROJECT_SOURCE_DIR}/src/leveldb/util/env_windows.cc
55-
APPEND PROPERTY COMPILE_OPTIONS $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/wd4722>
56-
)
57-
else()
58-
target_sources(leveldb PRIVATE ${PROJECT_SOURCE_DIR}/src/leveldb/util/env_posix.cc)
59-
endif()
6054

6155
target_compile_definitions(leveldb
6256
PRIVATE
@@ -67,27 +61,33 @@ target_compile_definitions(leveldb
6761
HAVE_O_CLOEXEC=$<BOOL:${HAVE_O_CLOEXEC}>
6862
FALLTHROUGH_INTENDED=[[fallthrough]]
6963
LEVELDB_IS_BIG_ENDIAN=${WORDS_BIGENDIAN}
64+
$<$<NOT:$<BOOL:${WIN32}>>:LEVELDB_PLATFORM_POSIX>
65+
$<$<BOOL:${WIN32}>:LEVELDB_PLATFORM_WINDOWS>
66+
$<$<BOOL:${WIN32}>:_UNICODE;UNICODE>
67+
$<$<BOOL:${MINGW}>:__USE_MINGW_ANSI_STDIO=1>
7068
)
7169

72-
if(WIN32)
73-
target_compile_definitions(leveldb
74-
PRIVATE
75-
LEVELDB_PLATFORM_WINDOWS
76-
_UNICODE
77-
UNICODE
78-
__USE_MINGW_ANSI_STDIO=1
79-
)
80-
else()
81-
target_compile_definitions(leveldb PRIVATE LEVELDB_PLATFORM_POSIX)
82-
endif()
83-
8470
target_include_directories(leveldb
8571
PRIVATE
8672
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/leveldb>
8773
PUBLIC
8874
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/leveldb/include>
8975
)
9076

77+
if(MSVC)
78+
target_compile_options(leveldb
79+
PRIVATE
80+
/wd4244
81+
/wd4267
82+
$<$<CONFIG:Release>:/wd4722>
83+
)
84+
target_compile_definitions(leveldb
85+
PRIVATE
86+
_CRT_NONSTDC_NO_DEPRECATE
87+
_CRT_SECURE_NO_WARNINGS
88+
)
89+
endif()
90+
9191
#TODO: figure out how to filter out:
9292
# -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override
9393

cmake/minisketch.cmake

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Copyright (c) 2023 The Bitcoin Core developers
1+
# Copyright (c) 2023-present The Bitcoin Core developers
22
# Distributed under the MIT software license, see the accompanying
3-
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
3+
# file COPYING or https://opensource.org/license/mit/.
44

55
# Check for clmul instructions support.
66
if(MSVC)
@@ -24,12 +24,21 @@ check_cxx_source_compiles_with_flags("${CLMUL_CXXFLAGS}" "
2424
" HAVE_CLMUL
2525
)
2626

27-
add_library(minisketch_defs INTERFACE)
28-
target_compile_definitions(minisketch_defs INTERFACE
27+
add_library(minisketch_common INTERFACE)
28+
target_compile_definitions(minisketch_common INTERFACE
2929
DISABLE_DEFAULT_FIELDS
3030
ENABLE_FIELD_32
3131
$<$<AND:$<BOOL:${HAVE_BUILTIN_CLZL}>,$<BOOL:${HAVE_BUILTIN_CLZLL}>>:HAVE_CLZ>
3232
)
33+
if(MSVC)
34+
target_compile_options(minisketch_common INTERFACE
35+
/wd4060
36+
/wd4065
37+
/wd4146
38+
/wd4244
39+
/wd4267
40+
)
41+
endif()
3342

3443
if(HAVE_CLMUL)
3544
add_library(minisketch_clmul OBJECT EXCLUDE_FROM_ALL
@@ -47,7 +56,7 @@ if(HAVE_CLMUL)
4756
target_link_libraries(minisketch_clmul
4857
PRIVATE
4958
core
50-
minisketch_defs
59+
minisketch_common
5160
)
5261
endif()
5362

@@ -71,6 +80,6 @@ target_include_directories(minisketch
7180
target_link_libraries(minisketch
7281
PRIVATE
7382
core
74-
minisketch_defs
83+
minisketch_common
7584
$<TARGET_NAME_IF_EXISTS:minisketch_clmul>
7685
)

cmake/secp256k1.cmake

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Copyright (c) 2023 The Bitcoin Core developers
1+
# Copyright (c) 2023-present The Bitcoin Core developers
22
# Distributed under the MIT software license, see the accompanying
3-
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
3+
# file COPYING or https://opensource.org/license/mit/.
44

55
# This file is part of the transition from Autotools to CMake. Once CMake
66
# support has been merged we should switch to using the upstream CMake
@@ -48,9 +48,13 @@ target_include_directories(secp256k1
4848
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/secp256k1/include>
4949
)
5050

51-
target_compile_options(secp256k1
52-
PRIVATE
53-
$<$<CXX_COMPILER_ID:MSVC>:/wd4146 /wd4334>
54-
)
51+
if(MSVC)
52+
target_compile_options(secp256k1
53+
PRIVATE
54+
/wd4146
55+
/wd4244
56+
/wd4267
57+
)
58+
endif()
5559

5660
target_link_libraries(secp256k1 PRIVATE core)

0 commit comments

Comments
 (0)