2019-08-15 05:06:00 +08:00
|
|
|
cmake_minimum_required(VERSION 3.14)
|
2019-04-11 15:32:03 +08:00
|
|
|
|
2018-03-13 20:21:17 +08:00
|
|
|
project(vcpkg C CXX)
|
2017-11-26 07:53:32 +08:00
|
|
|
|
2018-06-12 08:01:13 +08:00
|
|
|
OPTION(DEFINE_DISABLE_METRICS "Option for disabling metrics" OFF)
|
2019-04-11 15:32:03 +08:00
|
|
|
OPTION(VCPKG_ALLOW_APPLE_CLANG "Option for allowing apple clang" OFF)
|
2019-08-10 02:16:35 +08:00
|
|
|
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()
|
|
|
|
|
2018-06-09 09:01:35 +08:00
|
|
|
|
2019-08-03 00:52:39 +08:00
|
|
|
if (DEFINE_DISABLE_METRICS)
|
|
|
|
set(DISABLE_METRICS_VALUE "1")
|
|
|
|
else()
|
|
|
|
set(DISABLE_METRICS_VALUE "0")
|
|
|
|
endif()
|
|
|
|
|
2017-12-15 06:31:16 +08:00
|
|
|
if(CMAKE_COMPILER_IS_GNUXX OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
2017-11-29 05:06:56 +08:00
|
|
|
set(GCC 1)
|
2018-03-30 06:29:16 +08:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
|
2018-03-31 05:46:22 +08:00
|
|
|
if(NOT VCPKG_ALLOW_APPLE_CLANG)
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"Building the vcpkg tool requires support for the C++ Filesystem TS.
|
2019-05-13 19:11:35 +08:00
|
|
|
Apple clang versions 10.01 and below do not have support for it.
|
2018-03-31 05:46:22 +08:00
|
|
|
Please install gcc6 or newer from homebrew (brew install gcc6).
|
2019-04-11 15:32:03 +08:00
|
|
|
If you would like to try anyway, pass --allowAppleClang to bootstrap.sh.")
|
2018-03-30 06:29:16 +08:00
|
|
|
else()
|
|
|
|
set(CLANG 1)
|
|
|
|
endif()
|
2017-11-29 05:06:56 +08:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang")
|
|
|
|
set(CLANG 1)
|
2019-08-10 02:16:35 +08:00
|
|
|
elseif(NOT MSVC)
|
2017-12-15 06:31:16 +08:00
|
|
|
message(FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}")
|
2017-11-29 05:06:56 +08:00
|
|
|
endif()
|
|
|
|
|
2019-07-25 04:50:45 +08:00
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
2019-07-19 10:07:00 +08:00
|
|
|
|
2019-08-03 00:52:39 +08:00
|
|
|
add_definitions(-DDISABLE_METRICS=${DISABLE_METRICS_VALUE})
|
|
|
|
include_directories(include)
|
|
|
|
link_libraries(Threads::Threads)
|
2019-07-19 10:07:00 +08:00
|
|
|
|
2019-08-10 02:16:35 +08:00
|
|
|
if(CLANG AND NOT MSVC)
|
2019-03-06 06:52:26 +08:00
|
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
check_cxx_source_compiles("#include <iostream>
|
|
|
|
int main() { return __GLIBCXX__; }" USES_LIBSTDCXX)
|
|
|
|
check_cxx_source_compiles("#include <iostream>
|
|
|
|
int main() { return _LIBCPP_VERSION; }" USES_LIBCXX)
|
|
|
|
if ( NOT USES_LIBSTDCXX AND NOT USES_LIBCXX )
|
|
|
|
message(FATAL_ERROR "Can't find which C++ runtime is in use")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(GCC OR (CLANG AND USES_LIBSTDCXX))
|
2019-08-10 02:16:35 +08:00
|
|
|
link_libraries(stdc++fs)
|
2019-08-15 05:06:00 +08:00
|
|
|
elseif(CLANG AND NOT MSVC)
|
2019-08-10 02:16:35 +08:00
|
|
|
link_libraries(c++fs)
|
2019-08-03 00:52:39 +08:00
|
|
|
endif()
|
|
|
|
|
2019-08-10 02:16:35 +08:00
|
|
|
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)
|
2019-08-03 00:52:39 +08:00
|
|
|
add_compile_options(-std=c++1z)
|
2019-08-10 02:16:35 +08:00
|
|
|
|
|
|
|
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()
|
2019-08-03 00:52:39 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-08-10 02:16:35 +08:00
|
|
|
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>)
|
|
|
|
|
2019-08-03 00:52:39 +08:00
|
|
|
if (BUILD_TESTING)
|
2019-08-10 02:16:35 +08:00
|
|
|
file(GLOB_RECURSE VCPKGTEST_SOURCES CONFIGURE_DEPENDS src/vcpkg-test/*.cpp)
|
2019-08-03 00:52:39 +08:00
|
|
|
|
|
|
|
enable_testing()
|
|
|
|
add_executable(vcpkg-test
|
|
|
|
${VCPKGTEST_SOURCES}
|
|
|
|
$<TARGET_OBJECTS:vcpkglib>)
|
|
|
|
|
2019-08-10 02:16:35 +08:00
|
|
|
add_test(NAME default COMMAND vcpkg-test)
|
[vcpkg] Make Filesystem::remove_all faster #7570
I added benchmarks to measure how fast the parallel remove_all code was
-- it turns out, about 3x slower than stdfs::remove_all. Since this was
the case, I removed all of the parallelism and rewrote it serially, and
ended up about 30% faster than stdfs::remove_all (in addition to
supporting symlinks).
In addition, I did the following three orthogonal changes:
- simplified the work queue, basing it on Billy O'Neal's idea
- Fix warnings on older versions of compilers in tests, by splitting
the pragmas out of pch.h.
- Ran clang-format on some files
In fixing up remove_all, the following changes were made:
- On Windows, regular symlinks and directory symlinks are distinct;
as an example, to remove directory symlinks (and junctions, for that
matter), one must use RemoveDirectory. Only on Windows, I added new
`file_type` and `file_status` types, with `file_type` including a new
`directory_symlink` enumerator, and `file_status` being exactly the
same as the old one except using the new `file_type`. On Unix, I
didn't make that change since they don't make a distinction.
- I added new `symlink_status` and `status` functions which use the
new `file_status` on Windows.
- I made `Filesystem::exists` call `fs::exists(status(p))`, as opposed
to the old version which called `stdfs::exists` directly.
- Added benchmarks to `vcpkg-test/files.cpp`. They test the
performance of `remove_all` on small directories (~20 files), with
symlinks and without, and on large directories (~2000 files), with
symlinks and without.
2019-08-03 07:49:45 +08:00
|
|
|
|
|
|
|
if (VCPKG_BUILD_BENCHMARKING)
|
|
|
|
target_compile_options(vcpkg-test PRIVATE -DCATCH_CONFIG_ENABLE_BENCHMARKING)
|
|
|
|
endif()
|
2019-08-10 02:16:35 +08:00
|
|
|
|
|
|
|
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()
|
2017-11-29 02:50:33 +08:00
|
|
|
endif()
|
2018-03-13 20:21:17 +08:00
|
|
|
|
2019-04-09 14:26:18 +08:00
|
|
|
if(MSVC)
|
|
|
|
get_target_property(_srcs vcpkg SOURCES)
|
|
|
|
|
|
|
|
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio .*")
|
|
|
|
set_property(SOURCE src/pch.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR}/pch.pch")
|
|
|
|
set_property(SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pch.pch")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set_source_files_properties(src/pch.cpp PROPERTIES COMPILE_FLAGS "/Ycpch.h")
|
|
|
|
target_sources(vcpkg PRIVATE src/pch.cpp)
|
|
|
|
target_compile_options(vcpkg PRIVATE /Yupch.h /FIpch.h /Zm200)
|
2018-06-27 02:40:44 +08:00
|
|
|
endif()
|