From f9c92910a7d0ee328aaeead71c8a5c59a1189a97 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Wed, 14 Aug 2019 23:06:00 +0200 Subject: [PATCH] Change CMakeLists.txt in toolsrc to allow compiling with llvm toolset (#4572) * llvm warning pessimistic move * warning missing override * warning invalid noreturn. ::TerminateProcess ist not marked as noreturn! * use more modern cmake features instead of adding c++ standard by hand. * Normalize line endings * Fix add_executable() * Fix target commands * Clean up CMakeLists.txt --- toolsrc/CMakeLists.txt | 36 ++++++++++++++++++++++--------- toolsrc/src/vcpkg/base/checks.cpp | 3 +-- toolsrc/src/vcpkg/install.cpp | 2 +- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/toolsrc/CMakeLists.txt b/toolsrc/CMakeLists.txt index 7a41874a68..7245179f20 100644 --- a/toolsrc/CMakeLists.txt +++ b/toolsrc/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.14) project(vcpkg C CXX) @@ -28,11 +28,32 @@ If you would like to try anyway, pass --allowAppleClang to bootstrap.sh.") elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang") set(CLANG 1) elseif(MSVC) - add_compile_options(/std:c++17 /FC) + add_compile_options(/FC) else() 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_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) @@ -52,9 +73,9 @@ if(CLANG) endif() if(GCC OR (CLANG AND USES_LIBSTDCXX)) - link_libraries(stdc++fs) -elseif(CLANG) - link_libraries(c++fs) + target_link_libraries(vcpkg PRIVATE stdc++fs) +elseif(CLANG AND NOT MSVC) + target_link_libraries(vcpkg PRIVATE c++fs) endif() if(GCC OR CLANG) @@ -64,11 +85,6 @@ if(GCC OR CLANG) endif() endif() -file(GLOB_RECURSE VCPKGLIB_SOURCES src/vcpkg/*.cpp) - -add_library(vcpkglib OBJECT ${VCPKGLIB_SOURCES}) -add_executable(vcpkg src/vcpkg.cpp $) - if (BUILD_TESTING) file(GLOB_RECURSE VCPKGTEST_SOURCES src/vcpkg-test/*.cpp) diff --git a/toolsrc/src/vcpkg/base/checks.cpp b/toolsrc/src/vcpkg/base/checks.cpp index 0266ad683c..c7584258a8 100644 --- a/toolsrc/src/vcpkg/base/checks.cpp +++ b/toolsrc/src/vcpkg/base/checks.cpp @@ -27,9 +27,8 @@ namespace vcpkg #if defined(_WIN32) ::TerminateProcess(::GetCurrentProcess(), exit_code); -#else - std::exit(exit_code); #endif + std::exit(exit_code); } void Checks::unreachable(const LineInfo& line_info) diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index 974e5f798a..f6330e4089 100644 --- a/toolsrc/src/vcpkg/install.cpp +++ b/toolsrc/src/vcpkg/install.cpp @@ -174,7 +174,7 @@ namespace vcpkg::Install const std::vector package_file_paths = fs.get_files_recursive(package_dir); const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash auto package_files = Util::fmap(package_file_paths, [package_remove_char_count](const fs::path& path) { - return std::move(std::string(path.generic_string(), package_remove_char_count)); + return std::move(std::string(path.generic_string(), package_remove_char_count)); }); return SortedVector(std::move(package_files));