Skip to content

Commit 300e21d

Browse files
committed
[vcpkg] Major tool CMakeLists.txt updates
- Add the "VCPKG_DEVELOPMENT_WARNINGS" flag - setting "WERROR" will also set this flag - This flag is set by default - on GCC/clang, this will pass '-Wall -Wextra -Wpedantic -Werror' - on GCC, this will additionally pass '-Wmissing-declarations' - on clang, this will additionally pass '-Wmissing-prototypes' - on MSVC, this will pass '-W4 -WX' - On Visual Studio 2017 and later, pass '-permissive-' - Change the source for fallout of these changes - add `format` subcommand - formats all C++ source and header files using clang-format - move `include/vcpkg-test/catch.h` to `include/catch2/catch.hpp` - pass CONFIGURE_DEPENDS to file(GLOB)
1 parent 5d1751d commit 300e21d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+635
-574
lines changed

scripts/bootstrap.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ buildDir="$vcpkgRootDir/toolsrc/build.rel"
249249
rm -rf "$buildDir"
250250
mkdir -p "$buildDir"
251251

252-
(cd "$buildDir" && CXX=$CXX "$cmakeExe" .. -DCMAKE_BUILD_TYPE=Release -G "Ninja" "-DCMAKE_MAKE_PROGRAM=$ninjaExe" "-DBUILD_TESTING=OFF" "-DDEFINE_DISABLE_METRICS=$vcpkgDisableMetrics" "-DVCPKG_ALLOW_APPLE_CLANG=$vcpkgAllowAppleClang") || exit 1
252+
(cd "$buildDir" && CXX=$CXX "$cmakeExe" .. -DCMAKE_BUILD_TYPE=Release -G "Ninja" "-DCMAKE_MAKE_PROGRAM=$ninjaExe" "-DBUILD_TESTING=OFF" "-DVCPKG_DEVELOPMENT_WARNINGS=Off" "-DDEFINE_DISABLE_METRICS=$vcpkgDisableMetrics" "-DVCPKG_ALLOW_APPLE_CLANG=$vcpkgAllowAppleClang") || exit 1
253253
(cd "$buildDir" && "$cmakeExe" --build .) || exit 1
254254

255255
rm -rf "$vcpkgRootDir/vcpkg"

toolsrc/CMakeLists.txt

+57-34
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ cmake_minimum_required(VERSION 3.14)
22

33
project(vcpkg C CXX)
44

5-
OPTION(BUILD_TESTING "Option for enabling testing" ON)
6-
OPTION(VCPKG_BUILD_BENCHMARKING "Option for enabling benchmarking" OFF)
75
OPTION(DEFINE_DISABLE_METRICS "Option for disabling metrics" OFF)
86
OPTION(VCPKG_ALLOW_APPLE_CLANG "Option for allowing apple clang" OFF)
7+
OPTION(VCPKG_DEVELOPMENT_WARNINGS "Option for turning on all warnings, and making them errors" ON)
8+
OPTION(BUILD_TESTING "Option for enabling testing" ON)
9+
OPTION(VCPKG_BUILD_BENCHMARKING "Option for enabling benchmarking" OFF)
10+
11+
# for backwards compatibility with existing code
12+
if (WERROR)
13+
set(VCPKG_DEVELOPMENT_WARNINGS On)
14+
endif()
15+
916

1017
if (DEFINE_DISABLE_METRICS)
1118
set(DISABLE_METRICS_VALUE "1")
@@ -27,41 +34,18 @@ If you would like to try anyway, pass --allowAppleClang to bootstrap.sh.")
2734
endif()
2835
elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang")
2936
set(CLANG 1)
30-
elseif(MSVC)
31-
add_compile_options(/FC)
32-
else()
37+
elseif(NOT MSVC)
3338
message(FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}")
3439
endif()
3540

36-
if(GCC OR (CLANG AND NOT MSVC))
37-
if(WERROR)
38-
add_compile_options(-Wall -Wno-unknown-pragmas -Werror)
39-
endif()
40-
endif()
41-
42-
if (DEFINE_DISABLE_METRICS)
43-
set(DISABLE_METRICS_VALUE "1")
44-
else()
45-
set(DISABLE_METRICS_VALUE "0")
46-
endif()
47-
48-
file(GLOB_RECURSE VCPKGLIB_SOURCES src/vcpkg/*.cpp)
49-
50-
add_library(vcpkglib OBJECT ${VCPKGLIB_SOURCES})
51-
add_executable(vcpkg src/vcpkg.cpp $<TARGET_OBJECTS:vcpkglib>)
52-
53-
target_compile_features(vcpkg PRIVATE cxx_std_17)
54-
target_compile_definitions(vcpkg PRIVATE -DDISABLE_METRICS=${DISABLE_METRICS_VALUE})
55-
target_include_directories(vcpkg PRIVATE include)
56-
5741
set(THREADS_PREFER_PTHREAD_FLAG ON)
5842
find_package(Threads REQUIRED)
5943

6044
add_definitions(-DDISABLE_METRICS=${DISABLE_METRICS_VALUE})
6145
include_directories(include)
6246
link_libraries(Threads::Threads)
6347

64-
if(CLANG)
48+
if(CLANG AND NOT MSVC)
6549
include(CheckCXXSourceCompiles)
6650
check_cxx_source_compiles("#include <iostream>
6751
int main() { return __GLIBCXX__; }" USES_LIBSTDCXX)
@@ -73,31 +57,70 @@ if(CLANG)
7357
endif()
7458

7559
if(GCC OR (CLANG AND USES_LIBSTDCXX))
76-
target_link_libraries(vcpkg PRIVATE stdc++fs)
60+
link_libraries(stdc++fs)
7761
elseif(CLANG AND NOT MSVC)
78-
target_link_libraries(vcpkg PRIVATE c++fs)
62+
link_libraries(c++fs)
7963
endif()
8064

81-
if(GCC OR CLANG)
65+
if(MSVC)
66+
# either MSVC, or clang-cl
67+
add_compile_options(-FC)
68+
69+
if (MSVC_VERSION GREATER 1900)
70+
# Visual Studio 2017 or later
71+
add_compile_options(-std:c++17 -permissive-)
72+
else()
73+
# Visual Studio 2015
74+
add_compile_options(-std:c++latest)
75+
endif()
76+
77+
if(VCPKG_DEVELOPMENT_WARNINGS)
78+
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
79+
add_compile_options(-W4 -WX)
80+
81+
if (CLANG)
82+
add_compile_options(-Wmissing-prototypes -Wno-missing-field-initializers)
83+
endif()
84+
endif()
85+
elseif(GCC OR CLANG)
8286
add_compile_options(-std=c++1z)
83-
if(WERROR)
84-
add_compile_options(-Wall -Wno-unknown-pragmas -Werror)
87+
88+
if(VCPKG_DEVELOPMENT_WARNINGS)
89+
add_compile_options(-Wall -Wextra -Wpedantic -Wno-unknown-pragmas -Wno-missing-field-initializers -Werror)
90+
91+
# GCC and clang have different names for the same warning
92+
if (GCC)
93+
add_compile_options(-Wmissing-declarations)
94+
elseif(CLANG)
95+
add_compile_options(-Wmissing-prototypes)
96+
endif()
8597
endif()
8698
endif()
8799

100+
file(GLOB_RECURSE VCPKGLIB_SOURCES CONFIGURE_DEPENDS src/vcpkg/*.cpp)
101+
102+
add_library(vcpkglib OBJECT ${VCPKGLIB_SOURCES})
103+
add_executable(vcpkg src/vcpkg.cpp $<TARGET_OBJECTS:vcpkglib>)
104+
88105
if (BUILD_TESTING)
89-
file(GLOB_RECURSE VCPKGTEST_SOURCES src/vcpkg-test/*.cpp)
106+
file(GLOB_RECURSE VCPKGTEST_SOURCES CONFIGURE_DEPENDS src/vcpkg-test/*.cpp)
90107

91108
enable_testing()
92109
add_executable(vcpkg-test
93110
${VCPKGTEST_SOURCES}
94111
$<TARGET_OBJECTS:vcpkglib>)
95112

96-
add_test(NAME default COMMAND vcpkg-test [${TEST_NAME}])
113+
add_test(NAME default COMMAND vcpkg-test)
97114

98115
if (VCPKG_BUILD_BENCHMARKING)
99116
target_compile_options(vcpkg-test PRIVATE -DCATCH_CONFIG_ENABLE_BENCHMARKING)
100117
endif()
118+
119+
find_program(CLANG_FORMAT clang-format)
120+
if (CLANG_FORMAT)
121+
file(GLOB_RECURSE VCPKG_FORMAT_SOURCES CONFIGURE_DEPENDS src/*.cpp include/pch.h include/vcpkg/*.h include/vcpkg-test/*.h)
122+
add_custom_target(format COMMAND ${CLANG_FORMAT} -i -verbose ${VCPKG_FORMAT_SOURCES})
123+
endif()
101124
endif()
102125

103126
if(MSVC)
File renamed without changes.

toolsrc/include/vcpkg-test/util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22
#include <vcpkg/pragmas.h>
33

44
#include <vcpkg/base/files.h>

toolsrc/include/vcpkg/base/chrono.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace vcpkg::Chrono
5656
static Optional<CTime> get_current_date_time();
5757
static Optional<CTime> parse(CStringView str);
5858

59-
constexpr CTime() noexcept : m_tm{0} {}
59+
constexpr CTime() noexcept : m_tm{} {}
6060
explicit constexpr CTime(tm t) noexcept : m_tm{t} {}
6161

6262
CTime add_hours(const int hours) const;

toolsrc/include/vcpkg/base/graphs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace vcpkg::Graphs
4646
if (!r) return;
4747
for (auto i = c.size(); i > 1; --i)
4848
{
49-
auto j = r->random(static_cast<int>(i));
49+
std::size_t j = r->random(static_cast<int>(i));
5050
if (j != i - 1)
5151
{
5252
std::swap(c[i - 1], c[j]);

toolsrc/include/vcpkg/base/util.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,8 @@ namespace vcpkg::Util
221221
}
222222
}
223223

224-
template<class T>
225-
void unused(T&& param)
224+
template<class... Ts>
225+
void unused(const Ts&...)
226226
{
227-
(void)param;
228227
}
229228
}

toolsrc/src/vcpkg-test/arguments.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22

33
#include <vcpkg/vcpkgcmdarguments.h>
44

toolsrc/src/vcpkg-test/catch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define CATCH_CONFIG_RUNNER
2-
#include <vcpkg-test/catch.h>
2+
#include <catch2/catch.hpp>
33

44
#include <vcpkg/base/system.debug.h>
55

toolsrc/src/vcpkg-test/chrono.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22

33
#include <vcpkg/base/chrono.h>
44

toolsrc/src/vcpkg-test/dependencies.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22

33
#include <vcpkg/sourceparagraph.h>
44

toolsrc/src/vcpkg-test/files.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22
#include <vcpkg-test/util.h>
33

44
#include <vcpkg/base/files.h>
@@ -107,7 +107,7 @@ namespace
107107
CHECK_EC_ON_FILE(base, ec);
108108
}
109109

110-
for (int i = 0; i < width; ++i)
110+
for (std::uint64_t i = 0; i < width; ++i)
111111
{
112112
create_directory_tree(urbg,
113113
fs,

toolsrc/src/vcpkg-test/paragraph.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22
#include <vcpkg-test/util.h>
33

44
#include <vcpkg/base/strings.h>

toolsrc/src/vcpkg-test/plan.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22
#include <vcpkg-test/util.h>
33

44
#include <vcpkg/dependencies.h>

toolsrc/src/vcpkg-test/specifier.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22

33
#include <vcpkg/base/util.h>
44
#include <vcpkg/packagespec.h>
@@ -131,4 +131,4 @@ TEST_CASE ("specifier parsing", "[specifier]")
131131
REQUIRE(str == L"abc -x86-windows");
132132
}
133133
#endif
134-
};
134+
}

toolsrc/src/vcpkg-test/statusparagraphs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22
#include <vcpkg-test/util.h>
33

44
#include <vcpkg/base/util.h>

toolsrc/src/vcpkg-test/strings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22

33
#include <vcpkg/base/strings.h>
44

toolsrc/src/vcpkg-test/supports.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22

33
#include <vcpkg/sourceparagraph.h>
44

toolsrc/src/vcpkg-test/update.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22
#include <vcpkg-test/util.h>
33

44
#include <vcpkg/base/sortedvector.h>

toolsrc/src/vcpkg-test/util.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#include <vcpkg-test/catch.h>
1+
#include <catch2/catch.hpp>
22
#include <vcpkg-test/util.h>
33

44
#include <vcpkg/base/checks.h>
55
#include <vcpkg/base/files.h>
6+
#include <vcpkg/base/util.h>
67
#include <vcpkg/statusparagraph.h>
78

89
// used to get the implementation specific compiler flags (i.e., __cpp_lib_filesystem)
@@ -153,7 +154,7 @@ namespace vcpkg::Test
153154
ec.assign(errno, std::system_category());
154155
}
155156
#else
156-
static_cast<void>(ec);
157+
Util::unused(target, file, ec);
157158
vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, no_filesystem_message);
158159
#endif
159160
}
@@ -175,7 +176,7 @@ namespace vcpkg::Test
175176
#elif FILESYSTEM_SYMLINK == FILESYSTEM_SYMLINK_UNIX
176177
::vcpkg::Test::create_symlink(target, file, ec);
177178
#else
178-
static_cast<void>(ec);
179+
Util::unused(target, file, ec);
179180
vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, no_filesystem_message);
180181
#endif
181182
}

toolsrc/src/vcpkg.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static constexpr int SURVEY_INTERVAL_IN_HOURS = 24 * 30 * 6;
5353
// Initial survey appears after 10 days. Therefore, subtract 24 hours/day * 10 days
5454
static constexpr int SURVEY_INITIAL_OFFSET_IN_HOURS = SURVEY_INTERVAL_IN_HOURS - 24 * 10;
5555

56-
void invalid_command(const std::string& cmd)
56+
static void invalid_command(const std::string& cmd)
5757
{
5858
System::print2(System::Color::error, "invalid command: ", cmd, '\n');
5959
Help::print_usage();
@@ -285,6 +285,8 @@ static std::string trim_path_from_command_line(const std::string& full_command_l
285285
#endif
286286

287287
#if defined(_WIN32)
288+
// note: this prevents a false positive for -Wmissing-prototypes on clang-cl
289+
int wmain(int, const wchar_t* const*);
288290
int wmain(const int argc, const wchar_t* const* const argv)
289291
#else
290292
int main(const int argc, const char* const* const argv)

toolsrc/src/vcpkg/base/hash.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "pch.h"
22

3+
#include <vcpkg/base/hash.h>
4+
35
#include <vcpkg/base/checks.h>
46
#include <vcpkg/base/strings.h>
57
#include <vcpkg/base/system.process.h>

toolsrc/src/vcpkg/base/system.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <vcpkg/base/system.debug.h>
66
#include <vcpkg/base/system.h>
77
#include <vcpkg/base/system.process.h>
8+
#include <vcpkg/base/util.h>
89

910
#include <ctime>
1011

@@ -381,6 +382,8 @@ namespace vcpkg
381382
"CreateProcessW() returned ", exit_code, " after ", static_cast<int>(timer.microseconds()), " us\n");
382383
return static_cast<int>(exit_code);
383384
#else
385+
// TODO: this should create a clean environment on Linux/macOS
386+
Util::unused(extra_env, prepend_to_path);
384387
Debug::print("system(", cmd_line, ")\n");
385388
fflush(nullptr);
386389
int rc = system(cmd_line.c_str());
@@ -549,10 +552,7 @@ namespace vcpkg
549552
return Strings::to_utf8(ret);
550553
}
551554
#else
552-
Optional<std::string> System::get_registry_string(void* base_hkey, StringView sub_key, StringView valuename)
553-
{
554-
return nullopt;
555-
}
555+
Optional<std::string> System::get_registry_string(void*, StringView, StringView) { return nullopt; }
556556
#endif
557557

558558
static const Optional<fs::path>& get_program_files()

toolsrc/src/vcpkg/base/system.print.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "pch.h"
22

33
#include <vcpkg/base/system.print.h>
4+
#include <vcpkg/base/util.h>
45

56
namespace vcpkg::System
67
{
@@ -21,6 +22,9 @@ namespace vcpkg::System
2122
System::print2(message);
2223
SetConsoleTextAttribute(console_handle, original_color);
2324
#else
25+
// TODO: add color handling code
26+
// it should probably use VT-220 codes
27+
Util::unused(c);
2428
System::print2(message);
2529
#endif
2630
}

0 commit comments

Comments
 (0)