Skip to content

Commit

Permalink
[vcpkg] Major tool CMakeLists.txt updates
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
strega-nil committed Aug 17, 2019
1 parent 5d1751d commit 300e21d
Show file tree
Hide file tree
Showing 41 changed files with 635 additions and 574 deletions.
2 changes: 1 addition & 1 deletion scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ buildDir="$vcpkgRootDir/toolsrc/build.rel"
rm -rf "$buildDir"
mkdir -p "$buildDir"

(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
(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
(cd "$buildDir" && "$cmakeExe" --build .) || exit 1

rm -rf "$vcpkgRootDir/vcpkg"
Expand Down
91 changes: 57 additions & 34 deletions toolsrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ cmake_minimum_required(VERSION 3.14)

project(vcpkg C CXX)

OPTION(BUILD_TESTING "Option for enabling testing" ON)
OPTION(VCPKG_BUILD_BENCHMARKING "Option for enabling benchmarking" OFF)
OPTION(DEFINE_DISABLE_METRICS "Option for disabling metrics" OFF)
OPTION(VCPKG_ALLOW_APPLE_CLANG "Option for allowing apple clang" OFF)
OPTION(VCPKG_DEVELOPMENT_WARNINGS "Option for turning on all warnings, and making them errors" ON)
OPTION(BUILD_TESTING "Option for enabling testing" ON)
OPTION(VCPKG_BUILD_BENCHMARKING "Option for enabling benchmarking" OFF)

# for backwards compatibility with existing code
if (WERROR)
set(VCPKG_DEVELOPMENT_WARNINGS On)
endif()


if (DEFINE_DISABLE_METRICS)
set(DISABLE_METRICS_VALUE "1")
Expand All @@ -27,41 +34,18 @@ If you would like to try anyway, pass --allowAppleClang to bootstrap.sh.")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang")
set(CLANG 1)
elseif(MSVC)
add_compile_options(/FC)
else()
elseif(NOT MSVC)
message(FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()

if(GCC OR (CLANG AND NOT MSVC))
if(WERROR)
add_compile_options(-Wall -Wno-unknown-pragmas -Werror)
endif()
endif()

if (DEFINE_DISABLE_METRICS)
set(DISABLE_METRICS_VALUE "1")
else()
set(DISABLE_METRICS_VALUE "0")
endif()

file(GLOB_RECURSE VCPKGLIB_SOURCES src/vcpkg/*.cpp)

add_library(vcpkglib OBJECT ${VCPKGLIB_SOURCES})
add_executable(vcpkg src/vcpkg.cpp $<TARGET_OBJECTS:vcpkglib>)

target_compile_features(vcpkg PRIVATE cxx_std_17)
target_compile_definitions(vcpkg PRIVATE -DDISABLE_METRICS=${DISABLE_METRICS_VALUE})
target_include_directories(vcpkg PRIVATE include)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

add_definitions(-DDISABLE_METRICS=${DISABLE_METRICS_VALUE})
include_directories(include)
link_libraries(Threads::Threads)

if(CLANG)
if(CLANG AND NOT MSVC)
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("#include <iostream>
int main() { return __GLIBCXX__; }" USES_LIBSTDCXX)
Expand All @@ -73,31 +57,70 @@ if(CLANG)
endif()

if(GCC OR (CLANG AND USES_LIBSTDCXX))
target_link_libraries(vcpkg PRIVATE stdc++fs)
link_libraries(stdc++fs)
elseif(CLANG AND NOT MSVC)
target_link_libraries(vcpkg PRIVATE c++fs)
link_libraries(c++fs)
endif()

if(GCC OR CLANG)
if(MSVC)
# either MSVC, or clang-cl
add_compile_options(-FC)

if (MSVC_VERSION GREATER 1900)
# Visual Studio 2017 or later
add_compile_options(-std:c++17 -permissive-)
else()
# Visual Studio 2015
add_compile_options(-std:c++latest)
endif()

if(VCPKG_DEVELOPMENT_WARNINGS)
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
add_compile_options(-W4 -WX)

if (CLANG)
add_compile_options(-Wmissing-prototypes -Wno-missing-field-initializers)
endif()
endif()
elseif(GCC OR CLANG)
add_compile_options(-std=c++1z)
if(WERROR)
add_compile_options(-Wall -Wno-unknown-pragmas -Werror)

if(VCPKG_DEVELOPMENT_WARNINGS)
add_compile_options(-Wall -Wextra -Wpedantic -Wno-unknown-pragmas -Wno-missing-field-initializers -Werror)

# GCC and clang have different names for the same warning
if (GCC)
add_compile_options(-Wmissing-declarations)
elseif(CLANG)
add_compile_options(-Wmissing-prototypes)
endif()
endif()
endif()

file(GLOB_RECURSE VCPKGLIB_SOURCES CONFIGURE_DEPENDS src/vcpkg/*.cpp)

add_library(vcpkglib OBJECT ${VCPKGLIB_SOURCES})
add_executable(vcpkg src/vcpkg.cpp $<TARGET_OBJECTS:vcpkglib>)

if (BUILD_TESTING)
file(GLOB_RECURSE VCPKGTEST_SOURCES src/vcpkg-test/*.cpp)
file(GLOB_RECURSE VCPKGTEST_SOURCES CONFIGURE_DEPENDS src/vcpkg-test/*.cpp)

enable_testing()
add_executable(vcpkg-test
${VCPKGTEST_SOURCES}
$<TARGET_OBJECTS:vcpkglib>)

add_test(NAME default COMMAND vcpkg-test [${TEST_NAME}])
add_test(NAME default COMMAND vcpkg-test)

if (VCPKG_BUILD_BENCHMARKING)
target_compile_options(vcpkg-test PRIVATE -DCATCH_CONFIG_ENABLE_BENCHMARKING)
endif()

find_program(CLANG_FORMAT clang-format)
if (CLANG_FORMAT)
file(GLOB_RECURSE VCPKG_FORMAT_SOURCES CONFIGURE_DEPENDS src/*.cpp include/pch.h include/vcpkg/*.h include/vcpkg-test/*.h)
add_custom_target(format COMMAND ${CLANG_FORMAT} -i -verbose ${VCPKG_FORMAT_SOURCES})
endif()
endif()

if(MSVC)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion toolsrc/include/vcpkg-test/util.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>
#include <vcpkg/pragmas.h>

#include <vcpkg/base/files.h>
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/include/vcpkg/base/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace vcpkg::Chrono
static Optional<CTime> get_current_date_time();
static Optional<CTime> parse(CStringView str);

constexpr CTime() noexcept : m_tm{0} {}
constexpr CTime() noexcept : m_tm{} {}
explicit constexpr CTime(tm t) noexcept : m_tm{t} {}

CTime add_hours(const int hours) const;
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/include/vcpkg/base/graphs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace vcpkg::Graphs
if (!r) return;
for (auto i = c.size(); i > 1; --i)
{
auto j = r->random(static_cast<int>(i));
std::size_t j = r->random(static_cast<int>(i));
if (j != i - 1)
{
std::swap(c[i - 1], c[j]);
Expand Down
5 changes: 2 additions & 3 deletions toolsrc/include/vcpkg/base/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@ namespace vcpkg::Util
}
}

template<class T>
void unused(T&& param)
template<class... Ts>
void unused(const Ts&...)
{
(void)param;
}
}
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg-test/arguments.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>

#include <vcpkg/vcpkgcmdarguments.h>

Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg-test/catch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define CATCH_CONFIG_RUNNER
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>

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

Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg-test/chrono.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>

#include <vcpkg/base/chrono.h>

Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg-test/dependencies.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>

#include <vcpkg/sourceparagraph.h>

Expand Down
4 changes: 2 additions & 2 deletions toolsrc/src/vcpkg-test/files.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>
#include <vcpkg-test/util.h>

#include <vcpkg/base/files.h>
Expand Down Expand Up @@ -107,7 +107,7 @@ namespace
CHECK_EC_ON_FILE(base, ec);
}

for (int i = 0; i < width; ++i)
for (std::uint64_t i = 0; i < width; ++i)
{
create_directory_tree(urbg,
fs,
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg-test/paragraph.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>
#include <vcpkg-test/util.h>

#include <vcpkg/base/strings.h>
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg-test/plan.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>
#include <vcpkg-test/util.h>

#include <vcpkg/dependencies.h>
Expand Down
4 changes: 2 additions & 2 deletions toolsrc/src/vcpkg-test/specifier.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>

#include <vcpkg/base/util.h>
#include <vcpkg/packagespec.h>
Expand Down Expand Up @@ -131,4 +131,4 @@ TEST_CASE ("specifier parsing", "[specifier]")
REQUIRE(str == L"abc -x86-windows");
}
#endif
};
}
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg-test/statusparagraphs.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>
#include <vcpkg-test/util.h>

#include <vcpkg/base/util.h>
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg-test/strings.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>

#include <vcpkg/base/strings.h>

Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg-test/supports.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>

#include <vcpkg/sourceparagraph.h>

Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg-test/update.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>
#include <vcpkg-test/util.h>

#include <vcpkg/base/sortedvector.h>
Expand Down
7 changes: 4 additions & 3 deletions toolsrc/src/vcpkg-test/util.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <vcpkg-test/catch.h>
#include <catch2/catch.hpp>
#include <vcpkg-test/util.h>

#include <vcpkg/base/checks.h>
#include <vcpkg/base/files.h>
#include <vcpkg/base/util.h>
#include <vcpkg/statusparagraph.h>

// used to get the implementation specific compiler flags (i.e., __cpp_lib_filesystem)
Expand Down Expand Up @@ -153,7 +154,7 @@ namespace vcpkg::Test
ec.assign(errno, std::system_category());
}
#else
static_cast<void>(ec);
Util::unused(target, file, ec);
vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, no_filesystem_message);
#endif
}
Expand All @@ -175,7 +176,7 @@ namespace vcpkg::Test
#elif FILESYSTEM_SYMLINK == FILESYSTEM_SYMLINK_UNIX
::vcpkg::Test::create_symlink(target, file, ec);
#else
static_cast<void>(ec);
Util::unused(target, file, ec);
vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, no_filesystem_message);
#endif
}
Expand Down
4 changes: 3 additions & 1 deletion toolsrc/src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static constexpr int SURVEY_INTERVAL_IN_HOURS = 24 * 30 * 6;
// Initial survey appears after 10 days. Therefore, subtract 24 hours/day * 10 days
static constexpr int SURVEY_INITIAL_OFFSET_IN_HOURS = SURVEY_INTERVAL_IN_HOURS - 24 * 10;

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

#if defined(_WIN32)
// note: this prevents a false positive for -Wmissing-prototypes on clang-cl
int wmain(int, const wchar_t* const*);
int wmain(const int argc, const wchar_t* const* const argv)
#else
int main(const int argc, const char* const* const argv)
Expand Down
2 changes: 2 additions & 0 deletions toolsrc/src/vcpkg/base/hash.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "pch.h"

#include <vcpkg/base/hash.h>

#include <vcpkg/base/checks.h>
#include <vcpkg/base/strings.h>
#include <vcpkg/base/system.process.h>
Expand Down
8 changes: 4 additions & 4 deletions toolsrc/src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vcpkg/base/system.debug.h>
#include <vcpkg/base/system.h>
#include <vcpkg/base/system.process.h>
#include <vcpkg/base/util.h>

#include <ctime>

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

static const Optional<fs::path>& get_program_files()
Expand Down
4 changes: 4 additions & 0 deletions toolsrc/src/vcpkg/base/system.print.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pch.h"

#include <vcpkg/base/system.print.h>
#include <vcpkg/base/util.h>

namespace vcpkg::System
{
Expand All @@ -21,6 +22,9 @@ namespace vcpkg::System
System::print2(message);
SetConsoleTextAttribute(console_handle, original_color);
#else
// TODO: add color handling code
// it should probably use VT-220 codes
Util::unused(c);
System::print2(message);
#endif
}
Expand Down
Loading

0 comments on commit 300e21d

Please sign in to comment.