diff options
Diffstat (limited to 'dep')
25 files changed, 944 insertions, 464 deletions
diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt index 7f4f1cd884c..aeffd5b8469 100644 --- a/dep/CMakeLists.txt +++ b/dep/CMakeLists.txt @@ -14,31 +14,29 @@ else() add_definitions(-w) endif() -if(CMAKE_SYSTEM_NAME MATCHES "Linux") - if(SERVERS AND NOT NOJEM) - add_subdirectory(jemalloc) - endif() -endif() - -if(CMAKE_SYSTEM_NAME MATCHES "Windows") - if(TOOLS) - add_subdirectory(bzip2) - endif() - if(SERVERS OR TOOLS) - add_subdirectory(zlib) - endif() -endif() +add_subdirectory(threads) if(SERVERS OR TOOLS) + add_subdirectory(boost) + add_subdirectory(zlib) add_subdirectory(g3dlite) add_subdirectory(recastnavigation) add_subdirectory(cppformat) + add_subdirectory(SFMT) + add_subdirectory(utf8cpp) + add_subdirectory(valgrind) + add_subdirectory(openssl) + add_subdirectory(jemalloc) endif() if(SERVERS) + add_subdirectory(mysql) + add_subdirectory(readline) add_subdirectory(gsoap) + add_subdirectory(process) endif() if(TOOLS) + add_subdirectory(bzip2) add_subdirectory(libmpq) endif() diff --git a/dep/PackageList.txt b/dep/PackageList.txt index e84fef8d3b2..f855e8d493d 100644 --- a/dep/PackageList.txt +++ b/dep/PackageList.txt @@ -1,6 +1,6 @@ TrinityCore uses (parts of or in whole) the following opensource software : -Boost +Boost (external) http://www.boost.org Version: 1.55 @@ -14,7 +14,7 @@ bzip2 (a freely available, patent free, high-quality data compressor) cppformat (type safe format library) https://github.com/cppformat/cppformat - Version: 5c76d107cbaf5e851bd66b6c563e4fc7c90be7ad + Version: 5174b8ca281426af604b85fdf53be8a748b33f56 G3D (a commercial-grade C++ 3D engine available as Open Source (BSD License) http://g3d.sourceforge.net/ @@ -23,11 +23,19 @@ G3D (a commercial-grade C++ 3D engine available as Open Source (BSD License) jemalloc (a general-purpose scalable concurrent malloc-implementation) http://www.canonware.com/jemalloc/ Version: 3.6.0 - + libMPQ (a library for reading MPQ files) https://github.com/mbroemme/libmpq/ Version: d59b4cf1d107b5f6a0f67d6bc545c6c6ebef3d74 +libreadline (command line editing library) + https://cnswww.cns.cwru.edu/php/chet/readline/rltop.html + Version: external + +OpenSSL (general-purpose cryptography library) + https://www.openssl.org/ + Version: external + SFMT (SIMD-oriented Fast Mersenne Twister) Based on http://agner.org/random/ Version: 2010-Aug-03 diff --git a/dep/SFMT/CMakeLists.txt b/dep/SFMT/CMakeLists.txt new file mode 100644 index 00000000000..5cf1b9bf972 --- /dev/null +++ b/dep/SFMT/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +add_library(sfmt INTERFACE) + +target_include_directories(sfmt + INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/dep/boost/CMakeLists.txt b/dep/boost/CMakeLists.txt new file mode 100644 index 00000000000..118635c85bd --- /dev/null +++ b/dep/boost/CMakeLists.txt @@ -0,0 +1,67 @@ +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +if(WIN32) + set(BOOST_DEBUG ON) + if(DEFINED ENV{BOOST_ROOT}) + set(BOOST_ROOT $ENV{BOOST_ROOT}) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0) + set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib${PLATFORM}-msvc-12.0) + else() + set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib${PLATFORM}-msvc-14.0) + endif() + else() + message(FATAL_ERROR "No BOOST_ROOT environment variable could be found! Please make sure it is set and the points to your Boost installation.") + endif() + + set(Boost_USE_STATIC_LIBS ON) + set(Boost_USE_MULTITHREADED ON) + set(Boost_USE_STATIC_RUNTIME OFF) +endif() + +find_package(Boost 1.51 REQUIRED system filesystem thread program_options iostreams regex) + +# Find if Boost was compiled in C++03 mode because it requires -DBOOST_NO_CXX11_SCOPED_ENUMS + +include (CheckCXXSourceCompiles) + +set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR}) +set(CMAKE_REQUIRED_LIBRARIES ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_IOSTREAMS_LIBRARY}) +set(CMAKE_REQUIRED_FLAGS "-std=c++11") +unset(boost_filesystem_copy_links_without_NO_SCOPED_ENUM CACHE) +check_cxx_source_compiles(" + #include <boost/filesystem/path.hpp> + #include <boost/filesystem/operations.hpp> + int main() { boost::filesystem::copy_file(boost::filesystem::path(), boost::filesystem::path()); }" +boost_filesystem_copy_links_without_NO_SCOPED_ENUM) +unset(CMAKE_REQUIRED_INCLUDES CACHE) +unset(CMAKE_REQUIRED_LIBRARIES CACHE) +unset(CMAKE_REQUIRED_FLAGS CACHE) + +if (NOT boost_filesystem_copy_links_without_NO_SCOPED_ENUM) + set(OPTIONAL_BOOST_NO_SCOPED_ENUMS -DBOOST_NO_CXX11_SCOPED_ENUMS) +endif() + +add_library(boost INTERFACE) + +target_link_libraries(boost + INTERFACE + ${Boost_LIBRARIES}) + +target_include_directories(boost + INTERFACE + ${Boost_INCLUDE_DIRS}) + +target_compile_definitions(boost + INTERFACE + -DBOOST_DATE_TIME_NO_LIB + -DBOOST_REGEX_NO_LIB + -DBOOST_CHRONO_NO_LIB + ${OPTIONAL_BOOST_NO_SCOPED_ENUMS}) diff --git a/dep/bzip2/CMakeLists.txt b/dep/bzip2/CMakeLists.txt index d3aadbe002e..d5a7414f383 100644 --- a/dep/bzip2/CMakeLists.txt +++ b/dep/bzip2/CMakeLists.txt @@ -8,15 +8,30 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -file(GLOB sources *.c) +if(UNIX) + # Look for an installed bzip2 on unix + find_package(BZip2 REQUIRED) -set(bzip2_STAT_SRCS - ${sources} -) + add_library(bzip2 SHARED IMPORTED GLOBAL) -include_directories( - ${CMAKE_SOURCE_DIR}/dep/zlib - ${CMAKE_CURRENT_SOURCE_DIR} -) + set_target_properties(bzip2 + PROPERTIES + IMPORTED_LOCATION + "${BZIP2_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES + "${BZIP2_INCLUDE_DIRS}") +else() + # Use the bundled source on windows + file(GLOB sources *.c) + add_library(bzip2 STATIC + ${sources}) -add_library(bzip2 STATIC ${bzip2_STAT_SRCS}) + target_include_directories(bzip2 + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}) + + set_target_properties(bzip2 + PROPERTIES + FOLDER + "dep") +endif() diff --git a/dep/cppformat/CMakeLists.txt b/dep/cppformat/CMakeLists.txt index 3be3e5f6dbb..1cbff49b871 100644 --- a/dep/cppformat/CMakeLists.txt +++ b/dep/cppformat/CMakeLists.txt @@ -1,31 +1,37 @@ -include(CheckCXXCompilerFlag) -include(CheckSymbolExists) - -set(FMT_SOURCES format.cc format.h) - -# Use variadic templates -add_definitions(-DFMT_VARIADIC_TEMPLATES=1) - -# Use deleted functions -add_definitions(-DFMT_USE_DELETED_FUNCTIONS=1) - -# Use static assert -add_definitions(-DFMT_USE_STATIC_ASSERT=1) +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +include(CheckSymbolExists) if (WIN32) check_symbol_exists(open io.h HAVE_OPEN) else () check_symbol_exists(open fcntl.h HAVE_OPEN) endif () +set(FMT_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/cppformat/format.h + ${CMAKE_CURRENT_SOURCE_DIR}/cppformat/format.cc) + if (HAVE_OPEN) - add_definitions(-DFMT_USE_FILE_DESCRIPTORS=1) - set(FMT_SOURCES ${FMT_SOURCES} posix.cc posix.h) -endif () + set(FMT_SOURCES ${FMT_SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/cppformat/posix.h + ${CMAKE_CURRENT_SOURCE_DIR}/cppformat/posix.cc) +endif() -add_library(format STATIC ${FMT_SOURCES}) +add_library(cppformat STATIC ${FMT_SOURCES}) -if (CMAKE_COMPILER_IS_GNUCXX) - set_target_properties(format PROPERTIES COMPILE_FLAGS - "-Wall -Wextra -Wshadow -pedantic") -endif () +target_include_directories(cppformat + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}) + +set_target_properties(cppformat + PROPERTIES + FOLDER + "dep") diff --git a/dep/cppformat/README.rst b/dep/cppformat/README.rst index fb4399f0af4..e859f909466 100644 --- a/dep/cppformat/README.rst +++ b/dep/cppformat/README.rst @@ -28,9 +28,9 @@ Features * Format API with `format string syntax <http://cppformat.github.io/latest/syntax.html>`_ similar to the one used by `str.format - <http://docs.python.org/2/library/stdtypes.html#str.format>`_ in Python. + <https://docs.python.org/2/library/stdtypes.html#str.format>`_ in Python. * Safe `printf implementation - <http://cppformat.github.io/latest/reference.html#printf-formatting-functions>`_ + <http://cppformat.github.io/latest/api.html#printf-formatting-functions>`_ including the POSIX extension for positional arguments. * Support for user-defined types. * High speed: performance of the format API is close to that of @@ -103,10 +103,10 @@ An object of any user-defined type for which there is an overloaded // s == "The date is 2012-12-9" You can use the `FMT_VARIADIC -<http://cppformat.github.io/latest/reference.html#utilities>`_ +<http://cppformat.github.io/latest/api.html#utilities>`_ macro to create your own functions similar to `format -<http://cppformat.github.io/latest/reference.html#format>`_ and -`print <http://cppformat.github.io/latest/reference.html#print>`_ +<http://cppformat.github.io/latest/api.html#format>`_ and +`print <http://cppformat.github.io/latest/api.html#print>`_ which take arbitrary arguments: .. code:: c++ @@ -132,13 +132,17 @@ Projects using this library * `AMPL/MP <https://github.com/ampl/mp>`_: An open-source library for mathematical programming -* `HarpyWar/pvpgn <https://github.com/HarpyWar/pvpgn>`_: +* `HarpyWar/pvpgn <https://github.com/pvpgn/pvpgn-server>`_: Player vs Player Gaming Network with tweaks -* `KBEngine <http://www.kbengine.org/>`_: An open-source MMOG server engine +* `KBEngine <http://kbengine.org/>`_: An open-source MMOG server engine + +* `Keypirinha <http://keypirinha.com/>`_: A semantic launcher for Windows * `Lifeline <https://github.com/peter-clark/lifeline>`_: A 2D game +* `MongoDB Smasher <https://github.com/duckie/mongo_smasher>`_: A small tool to generate randomized datasets + * `PenUltima Online (POL) <http://www.polserver.com/>`_: An MMO server, compatible with most Ultima Online clients @@ -148,7 +152,7 @@ Projects using this library * `redis-cerberus <https://github.com/HunanTV/redis-cerberus>`_: A Redis cluster proxy -* `Saddy <https://code.google.com/p/saddy/>`_: +* `Saddy <https://github.com/mamontov-cpp/saddy-graphics-engine-2d>`_: Small crossplatform 2D graphic engine * `Salesforce Analytics Cloud <http://www.salesforce.com/analytics-cloud/overview/>`_: @@ -188,7 +192,7 @@ doesn't support user-defined types. Printf also has safety issues although they are mostly solved with `__attribute__ ((format (printf, ...)) <http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html>`_ in GCC. There is a POSIX extension that adds positional arguments required for -`i18n <http://en.wikipedia.org/wiki/Internationalization_and_localization>`_ +`i18n <https://en.wikipedia.org/wiki/Internationalization_and_localization>`_ to printf but it is not a part of C99 and may not be available on some platforms. @@ -376,18 +380,13 @@ C++ Format is distributed under the BSD `license The `Format String Syntax <http://cppformat.github.io/latest/syntax.html>`_ section in the documentation is based on the one from Python `string module -documentation <http://docs.python.org/3/library/string.html#module-string>`_ +documentation <https://docs.python.org/3/library/string.html#module-string>`_ adapted for the current library. For this reason the documentation is distributed under the Python Software Foundation license available in `doc/python-license.txt <https://raw.github.com/cppformat/cppformat/master/doc/python-license.txt>`_. It only applies if you distribute the documentation of C++ Format. -Links ------ - -`API changes/compatibility report <http://upstream-tracker.org/versions/cppformat.html>`_ - Acknowledgments --------------- diff --git a/dep/cppformat/format.cc b/dep/cppformat/cppformat/format.cc index 1970d53c500..daccd68f1da 100644 --- a/dep/cppformat/format.cc +++ b/dep/cppformat/cppformat/format.cc @@ -207,10 +207,15 @@ void format_error_code(fmt::Writer &out, int error_code, out.clear(); static const char SEP[] = ": "; static const char ERROR_STR[] = "error "; - fmt::internal::IntTraits<int>::MainType ec_value = error_code; // Subtract 2 to account for terminating null characters in SEP and ERROR_STR. std::size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2; - error_code_size += fmt::internal::count_digits(ec_value); + typedef fmt::internal::IntTraits<int>::MainType MainType; + MainType abs_value = static_cast<MainType>(error_code); + if (internal::is_negative(error_code)) { + abs_value = 0 - abs_value; + ++error_code_size; + } + error_code_size += fmt::internal::count_digits(abs_value); if (message.size() <= fmt::internal::INLINE_BUFFER_SIZE - error_code_size) out << message << SEP; out << ERROR_STR << error_code; @@ -252,7 +257,7 @@ class WidthHandler : public fmt::internal::ArgVisitor<WidthHandler, unsigned> { template <typename T> unsigned visit_any_int(T value) { typedef typename fmt::internal::IntTraits<T>::MainType UnsignedType; - UnsignedType width = value; + UnsignedType width = static_cast<UnsignedType>(value); if (fmt::internal::is_negative(value)) { spec_.align_ = fmt::ALIGN_LEFT; width = 0 - width; @@ -278,8 +283,21 @@ class PrecisionHandler : } }; -// Converts an integer argument to an integral type T for printf. +template <typename T, typename U> +struct is_same { + enum { value = 0 }; +}; + template <typename T> +struct is_same<T, T> { + enum { value = 1 }; +}; + +// An argument visitor that converts an integer argument to T for printf, +// if T is an integral type. If T is void, the argument is converted to +// corresponding signed or unsigned type depending on the type specifier: +// 'd' and 'i' - signed, other - unsigned) +template <typename T = void> class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> { private: fmt::internal::Arg &arg_; @@ -300,21 +318,25 @@ class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> { void visit_any_int(U value) { bool is_signed = type_ == 'd' || type_ == 'i'; using fmt::internal::Arg; - if (sizeof(T) <= sizeof(int)) { + typedef typename fmt::internal::Conditional< + is_same<T, void>::value, U, T>::type TargetType; + if (sizeof(TargetType) <= sizeof(int)) { // Extra casts are used to silence warnings. if (is_signed) { arg_.type = Arg::INT; - arg_.int_value = static_cast<int>(static_cast<T>(value)); + arg_.int_value = static_cast<int>(static_cast<TargetType>(value)); } else { arg_.type = Arg::UINT; - arg_.uint_value = static_cast<unsigned>( - static_cast<typename fmt::internal::MakeUnsigned<T>::Type>(value)); + typedef typename fmt::internal::MakeUnsigned<TargetType>::Type Unsigned; + arg_.uint_value = static_cast<unsigned>(static_cast<Unsigned>(value)); } } else { if (is_signed) { arg_.type = Arg::LONG_LONG; - arg_.long_long_value = - static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value); + // glibc's printf doesn't sign extend arguments of smaller types: + // std::printf("%lld", -42); // prints "4294967254" + // but we don't have to do the same because it's a UB. + arg_.long_long_value = static_cast<fmt::LongLong>(value); } else { arg_.type = Arg::ULONG_LONG; arg_.ulong_long_value = @@ -340,6 +362,21 @@ class CharConverter : public fmt::internal::ArgVisitor<CharConverter, void> { arg_.int_value = static_cast<char>(value); } }; + +// Write the content of w to os. +void write(std::ostream &os, fmt::Writer &w) { + const char *data = w.data(); + typedef internal::MakeUnsigned<std::streamsize>::Type UnsignedStreamSize; + UnsignedStreamSize size = w.size(); + UnsignedStreamSize max_size = + internal::to_unsigned((std::numeric_limits<std::streamsize>::max)()); + do { + UnsignedStreamSize n = size <= max_size ? size : max_size; + os.write(data, static_cast<std::streamsize>(n)); + data += n; + size -= n; + } while (size != 0); +} } // namespace namespace internal { @@ -551,27 +588,25 @@ FMT_FUNC void fmt::WindowsError::init( FMT_FUNC void fmt::internal::format_windows_error( fmt::Writer &out, int error_code, fmt::StringRef message) FMT_NOEXCEPT { - class String { - private: - LPWSTR str_; - - public: - String() : str_() {} - ~String() { LocalFree(str_); } - LPWSTR *ptr() { return &str_; } - LPCWSTR c_str() const { return str_; } - }; FMT_TRY { - String system_message; - if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, - error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - reinterpret_cast<LPWSTR>(system_message.ptr()), 0, 0)) { - UTF16ToUTF8 utf8_message; - if (utf8_message.convert(system_message.c_str()) == ERROR_SUCCESS) { - out << message << ": " << utf8_message; - return; + MemoryBuffer<wchar_t, INLINE_BUFFER_SIZE> buffer; + buffer.resize(INLINE_BUFFER_SIZE); + for (;;) { + wchar_t *system_message = &buffer[0]; + int result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + 0, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + system_message, static_cast<uint32_t>(buffer.size()), 0); + if (result != 0) { + UTF16ToUTF8 utf8_message; + if (utf8_message.convert(system_message) == ERROR_SUCCESS) { + out << message << ": " << utf8_message; + return; + } + break; } + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) + break; // Can't get error message, report error code instead. + buffer.resize(buffer.size() * 2); } } FMT_CATCH(...) {} fmt::format_error_code(out, error_code, message); // 'fmt::' is for bcc32. @@ -616,7 +651,7 @@ void fmt::internal::ArgMap<Char>::init(const ArgList &args) { return; case internal::Arg::NAMED_ARG: named_arg = static_cast<const NamedArg*>(args.values_[i].pointer); - map_.insert(Pair(named_arg->name, *named_arg)); + map_.push_back(Pair(named_arg->name, *named_arg)); break; default: /*nothing*/; @@ -628,7 +663,7 @@ void fmt::internal::ArgMap<Char>::init(const ArgList &args) { internal::Arg::Type arg_type = args.type(i); if (arg_type == internal::Arg::NAMED_ARG) { named_arg = static_cast<const NamedArg*>(args.args_[i].pointer); - map_.insert(Pair(named_arg->name, *named_arg)); + map_.push_back(Pair(named_arg->name, *named_arg)); } } for (unsigned i = ArgList::MAX_PACKED_ARGS;/*nothing*/; ++i) { @@ -637,7 +672,7 @@ void fmt::internal::ArgMap<Char>::init(const ArgList &args) { return; case internal::Arg::NAMED_ARG: named_arg = static_cast<const NamedArg*>(args.args_[i].pointer); - map_.insert(Pair(named_arg->name, *named_arg)); + map_.push_back(Pair(named_arg->name, *named_arg)); break; default: /*nothing*/; @@ -659,6 +694,7 @@ FMT_FUNC Arg fmt::internal::FormatterBase::do_get_arg( break; case Arg::NAMED_ARG: arg = *static_cast<const internal::Arg*>(arg.pointer); + break; default: /*nothing*/; } @@ -763,7 +799,7 @@ void fmt::internal::PrintfFormatter<Char>::format( if (*s == '.') { ++s; if ('0' <= *s && *s <= '9') { - spec.precision_ = parse_nonnegative_int(s); + spec.precision_ = static_cast<int>(parse_nonnegative_int(s)); } else if (*s == '*') { ++s; spec.precision_ = PrecisionHandler().visit(get_arg(s)); @@ -772,7 +808,7 @@ void fmt::internal::PrintfFormatter<Char>::format( Arg arg = get_arg(s, arg_index); if (spec.flag(HASH_FLAG) && IsZeroInt().visit(arg)) - spec.flags_ &= ~HASH_FLAG; + spec.flags_ &= ~to_unsigned<int>(HASH_FLAG); if (spec.fill_ == '0') { if (arg.type <= Arg::LAST_NUMERIC_TYPE) spec.align_ = ALIGN_NUMERIC; @@ -809,7 +845,7 @@ void fmt::internal::PrintfFormatter<Char>::format( break; default: --s; - ArgConverter<int>(arg, *s).visit(arg); + ArgConverter<void>(arg, *s).visit(arg); } // Parse type. @@ -861,10 +897,11 @@ FMT_FUNC void fmt::print(CStringRef format_str, ArgList args) { print(stdout, format_str, args); } -FMT_FUNC void fmt::print(std::ostream &os, CStringRef format_str, ArgList args) { +FMT_FUNC void fmt::print(std::ostream &os, CStringRef format_str, + ArgList args) { MemoryWriter w; w.write(format_str, args); - os.write(w.data(), w.size()); + write(os, w); } FMT_FUNC void fmt::print_colored(Color c, CStringRef format, ArgList args) { @@ -882,6 +919,13 @@ FMT_FUNC int fmt::fprintf(std::FILE *f, CStringRef format, ArgList args) { return std::fwrite(w.data(), 1, size, f) < size ? -1 : static_cast<int>(size); } +FMT_FUNC int fmt::fprintf(std::ostream &os, CStringRef format, ArgList args) { + MemoryWriter w; + printf(w, format, args); + write(os, w); + return static_cast<int>(w.size()); +} + #ifndef FMT_HEADER_ONLY template struct fmt::internal::BasicData<void>; diff --git a/dep/cppformat/format.h b/dep/cppformat/cppformat/format.h index a98a166091b..08bb9b5d9e8 100644 --- a/dep/cppformat/format.h +++ b/dep/cppformat/cppformat/format.h @@ -28,14 +28,6 @@ #ifndef FMT_FORMAT_H_ #define FMT_FORMAT_H_ -#if defined _MSC_VER && _MSC_VER <= 1500 -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; -typedef long long intmax_t; -#else -#include <stdint.h> -#endif - #include <cassert> #include <cmath> #include <cstdio> @@ -44,7 +36,8 @@ typedef long long intmax_t; #include <memory> #include <stdexcept> #include <string> -#include <map> +#include <vector> +#include <utility> #ifndef FMT_USE_IOSTREAMS # define FMT_USE_IOSTREAMS 1 @@ -64,40 +57,23 @@ typedef long long intmax_t; # include <iterator> #endif -#ifdef _MSC_VER -# include <intrin.h> // _BitScanReverse, _BitScanReverse64 - -namespace fmt { -namespace internal { -# pragma intrinsic(_BitScanReverse) -inline uint32_t clz(uint32_t x) { - unsigned long r = 0; - _BitScanReverse(&r, x); - return 31 - r; -} -# define FMT_BUILTIN_CLZ(n) fmt::internal::clz(n) - -# ifdef _WIN64 -# pragma intrinsic(_BitScanReverse64) -# endif - -inline uint32_t clzll(uint64_t x) { - unsigned long r = 0; -# ifdef _WIN64 - _BitScanReverse64(&r, x); -# else - // Scan the high 32 bits. - if (_BitScanReverse(&r, static_cast<uint32_t>(x >> 32))) - return 63 - (r + 32); +#if defined(_MSC_VER) && _MSC_VER <= 1500 +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +typedef __int64 intmax_t; +#else +#include <stdint.h> +#endif - // Scan the low 32 bits. - _BitScanReverse(&r, static_cast<uint32_t>(x)); +#if !defined(FMT_HEADER_ONLY) && defined(_WIN32) +# ifdef FMT_EXPORT +# define FMT_API __declspec(dllexport) +# elif defined(FMT_SHARED) +# define FMT_API __declspec(dllimport) # endif - return 63 - r; -} -# define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n) -} -} +#endif +#ifndef FMT_API +# define FMT_API #endif #ifdef __GNUC__ @@ -174,21 +150,6 @@ inline uint32_t clzll(uint64_t x) { # include <utility> // for std::move #endif -// Define FMT_USE_NOEXCEPT to make C++ Format use noexcept (C++11 feature). -#ifndef FMT_USE_NOEXCEPT -# define FMT_USE_NOEXCEPT 0 -#endif - -#ifndef FMT_NOEXCEPT -# if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ - (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \ - _MSC_VER >= 1900 -# define FMT_NOEXCEPT noexcept -# else -# define FMT_NOEXCEPT throw() -# endif -#endif - // Check if exceptions are disabled. #if defined(__GNUC__) && !defined(__EXCEPTIONS) # define FMT_EXCEPTIONS 0 @@ -208,6 +169,25 @@ inline uint32_t clzll(uint64_t x) { # endif #endif +// Define FMT_USE_NOEXCEPT to make C++ Format use noexcept (C++11 feature). +#ifndef FMT_USE_NOEXCEPT +# define FMT_USE_NOEXCEPT 0 +#endif + +#ifndef FMT_NOEXCEPT +# if FMT_EXCEPTIONS +# if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ + (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \ + _MSC_VER >= 1900 +# define FMT_NOEXCEPT noexcept +# else +# define FMT_NOEXCEPT throw() +# endif +# else +# define FMT_NOEXCEPT +# endif +#endif + // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class #ifndef FMT_USE_DELETED_FUNCTIONS @@ -241,6 +221,67 @@ inline uint32_t clzll(uint64_t x) { # define FMT_ASSERT(condition, message) assert((condition) && message) #endif + +#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz) +# define FMT_BUILTIN_CLZ(n) __builtin_clz(n) +#endif + +#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll) +# define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n) +#endif + +// Some compilers masquerade as both MSVC and GCC-likes or +// otherwise support __builtin_clz and __builtin_clzll, so +// only define FMT_BUILTIN_CLZ using the MSVC intrinsics +// if the clz and clzll builtins are not available. +#if defined(_MSC_VER) && !defined(FMT_BUILTIN_CLZLL) +# include <intrin.h> // _BitScanReverse, _BitScanReverse64 + +namespace fmt { +namespace internal { +# pragma intrinsic(_BitScanReverse) +inline uint32_t clz(uint32_t x) { + unsigned long r = 0; + _BitScanReverse(&r, x); + + assert(x != 0); + // Static analysis complains about using uninitialized data + // "r", but the only way that can happen is if "x" is 0, + // which the callers guarantee to not happen. +# pragma warning(suppress: 6102) + return 31 - r; +} +# define FMT_BUILTIN_CLZ(n) fmt::internal::clz(n) + +# ifdef _WIN64 +# pragma intrinsic(_BitScanReverse64) +# endif + +inline uint32_t clzll(uint64_t x) { + unsigned long r = 0; +# ifdef _WIN64 + _BitScanReverse64(&r, x); +# else + // Scan the high 32 bits. + if (_BitScanReverse(&r, static_cast<uint32_t>(x >> 32))) + return 63 - (r + 32); + + // Scan the low 32 bits. + _BitScanReverse(&r, static_cast<uint32_t>(x)); +# endif + + assert(x != 0); + // Static analysis complains about using uninitialized data + // "r", but the only way that can happen is if "x" is 0, + // which the callers guarantee to not happen. +# pragma warning(suppress: 6102) + return 63 - r; +} +# define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n) +} +} +#endif + namespace fmt { namespace internal { struct DummyInt { @@ -396,7 +437,7 @@ class BasicStringRef { return std::basic_string<Char>(data_, size_); } - /** Returns the pointer to a C string. */ + /** Returns a pointer to the string data. */ const Char *data() const { return data_; } /** Returns the string size. */ @@ -492,6 +533,29 @@ class FormatError : public std::runtime_error { }; namespace internal { + +// MakeUnsigned<T>::Type gives an unsigned type corresponding to integer type T. +template <typename T> +struct MakeUnsigned { typedef T Type; }; + +#define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \ + template <> \ + struct MakeUnsigned<T> { typedef U Type; } + +FMT_SPECIALIZE_MAKE_UNSIGNED(char, unsigned char); +FMT_SPECIALIZE_MAKE_UNSIGNED(signed char, unsigned char); +FMT_SPECIALIZE_MAKE_UNSIGNED(short, unsigned short); +FMT_SPECIALIZE_MAKE_UNSIGNED(int, unsigned); +FMT_SPECIALIZE_MAKE_UNSIGNED(long, unsigned long); +FMT_SPECIALIZE_MAKE_UNSIGNED(LongLong, ULongLong); + +// Casts nonnegative integer to unsigned. +template <typename Int> +inline typename MakeUnsigned<Int>::Type to_unsigned(Int value) { + FMT_ASSERT(value >= 0, "negative value"); + return static_cast<typename MakeUnsigned<Int>::Type>(value); +} + // The number of characters to store in the MemoryBuffer object itself // to avoid dynamic memory allocation. enum { INLINE_BUFFER_SIZE = 500 }; @@ -581,8 +645,7 @@ class Buffer { template <typename T> template <typename U> void Buffer<T>::append(const U *begin, const U *end) { - assert(begin <= end); - std::size_t new_size = size_ + (end - begin); + std::size_t new_size = size_ + internal::to_unsigned(end - begin); if (new_size > capacity_) grow(new_size); std::uninitialized_copy(begin, end, @@ -592,8 +655,8 @@ void Buffer<T>::append(const U *begin, const U *end) { namespace internal { -// A memory buffer for POD types with the first SIZE elements stored in -// the object itself. +// A memory buffer for trivially copyable/constructible types with the first SIZE +// elements stored in the object itself. template <typename T, std::size_t SIZE, typename Allocator = std::allocator<T> > class MemoryBuffer : private Allocator, public Buffer<T> { private: @@ -676,7 +739,7 @@ class FixedBuffer : public fmt::Buffer<Char> { FixedBuffer(Char *array, std::size_t size) : fmt::Buffer<Char>(array, size) {} protected: - void grow(std::size_t size); + FMT_API void grow(std::size_t size); }; template <typename Char> @@ -704,7 +767,7 @@ class CharTraits<char> : public BasicCharTraits<char> { // Formats a floating-point number. template <typename T> - static int format_float(char *buffer, std::size_t size, + FMT_API static int format_float(char *buffer, std::size_t size, const char *format, unsigned width, int precision, T value); }; @@ -715,7 +778,7 @@ class CharTraits<wchar_t> : public BasicCharTraits<wchar_t> { static wchar_t convert(wchar_t value) { return value; } template <typename T> - static int format_float(wchar_t *buffer, std::size_t size, + FMT_API static int format_float(wchar_t *buffer, std::size_t size, const wchar_t *format, unsigned width, int precision, T value); }; @@ -754,27 +817,12 @@ struct IntTraits { TypeSelector<std::numeric_limits<T>::digits <= 32>::Type MainType; }; -// MakeUnsigned<T>::Type gives an unsigned type corresponding to integer type T. -template <typename T> -struct MakeUnsigned { typedef T Type; }; - -#define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \ - template <> \ - struct MakeUnsigned<T> { typedef U Type; } - -FMT_SPECIALIZE_MAKE_UNSIGNED(char, unsigned char); -FMT_SPECIALIZE_MAKE_UNSIGNED(signed char, unsigned char); -FMT_SPECIALIZE_MAKE_UNSIGNED(short, unsigned short); -FMT_SPECIALIZE_MAKE_UNSIGNED(int, unsigned); -FMT_SPECIALIZE_MAKE_UNSIGNED(long, unsigned long); -FMT_SPECIALIZE_MAKE_UNSIGNED(LongLong, ULongLong); - -void report_unknown_type(char code, const char *type); +FMT_API void report_unknown_type(char code, const char *type); // Static data is placed in this class template to allow header-only // configuration. template <typename T = void> -struct BasicData { +struct FMT_API BasicData { static const uint32_t POWERS_OF_10_32[]; static const uint64_t POWERS_OF_10_64[]; static const char DIGITS[]; @@ -782,22 +830,14 @@ struct BasicData { typedef BasicData<> Data; -#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz) -# define FMT_BUILTIN_CLZ(n) __builtin_clz(n) -#endif - -#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll) -# define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n) -#endif - #ifdef FMT_BUILTIN_CLZLL // Returns the number of decimal digits in n. Leading zeros are not counted // except for n == 0 in which case count_digits returns 1. inline unsigned count_digits(uint64_t n) { // Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10 // and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits. - unsigned t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12; - return t - (n < Data::POWERS_OF_10_64[t]) + 1; + int t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12; + return to_unsigned(t) - (n < Data::POWERS_OF_10_64[t]) + 1; } #else // Fallback version of count_digits used when __builtin_clz is not available. @@ -820,8 +860,8 @@ inline unsigned count_digits(uint64_t n) { #ifdef FMT_BUILTIN_CLZ // Optional version of count_digits for better performance on 32-bit platforms. inline unsigned count_digits(uint32_t n) { - uint32_t t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12; - return t - (n < Data::POWERS_OF_10_32[t]) + 1; + int t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12; + return to_unsigned(t) - (n < Data::POWERS_OF_10_32[t]) + 1; } #endif @@ -863,7 +903,7 @@ class UTF8ToUTF16 { MemoryBuffer<wchar_t, INLINE_BUFFER_SIZE> buffer_; public: - explicit UTF8ToUTF16(StringRef s); + FMT_API explicit UTF8ToUTF16(StringRef s); operator WStringRef() const { return WStringRef(&buffer_[0], size()); } size_t size() const { return buffer_.size() - 1; } const wchar_t *c_str() const { return &buffer_[0]; } @@ -878,7 +918,7 @@ class UTF16ToUTF8 { public: UTF16ToUTF8() {} - explicit UTF16ToUTF8(WStringRef s); + FMT_API explicit UTF16ToUTF8(WStringRef s); operator StringRef() const { return StringRef(&buffer_[0], size()); } size_t size() const { return buffer_.size() - 1; } const char *c_str() const { return &buffer_[0]; } @@ -887,15 +927,15 @@ class UTF16ToUTF8 { // Performs conversion returning a system error code instead of // throwing exception on conversion error. This method may still throw // in case of memory allocation error. - int convert(WStringRef s); + FMT_API int convert(WStringRef s); }; -void format_windows_error(fmt::Writer &out, int error_code, - fmt::StringRef message) FMT_NOEXCEPT; +FMT_API void format_windows_error(fmt::Writer &out, int error_code, + fmt::StringRef message) FMT_NOEXCEPT; #endif -void format_system_error(fmt::Writer &out, int error_code, - fmt::StringRef message) FMT_NOEXCEPT; +FMT_API void format_system_error(fmt::Writer &out, int error_code, + fmt::StringRef message) FMT_NOEXCEPT; // A formatting argument value. struct Value { @@ -938,8 +978,8 @@ struct Value { }; }; -// A formatting argument. It is a POD type to allow storage in -// internal::MemoryBuffer. +// A formatting argument. It is a trivially copyable/constructible type to +// allow storage in internal::MemoryBuffer. struct Arg : Value { Type type; }; @@ -976,6 +1016,7 @@ template <typename T> T &get(); struct DummyStream : std::ostream { + DummyStream(); // Suppress a bogus warning in MSVC. // Hide all operator<< overloads from std::ostream. void operator<<(Null<>); }; @@ -1199,17 +1240,27 @@ class MakeValue : public Arg { static uint64_t type(const NamedArg<Char_> &) { return Arg::NAMED_ARG; } }; +template <typename Formatter> +class MakeArg : public Arg { +public: + MakeArg() { + type = Arg::NONE; + } + + template <typename T> + MakeArg(const T &value) + : Arg(MakeValue<Formatter>(value)) { + type = static_cast<Arg::Type>(MakeValue<Formatter>::type(value)); + } +}; + template <typename Char> struct NamedArg : Arg { BasicStringRef<Char> name; - typedef internal::MakeValue< BasicFormatter<Char> > MakeValue; - template <typename T> NamedArg(BasicStringRef<Char> argname, const T &value) - : Arg(MakeValue(value)), name(argname) { - type = static_cast<Arg::Type>(MakeValue::type(value)); - } + : Arg(MakeArg< BasicFormatter<Char> >(value)), name(argname) {} }; #define FMT_DISPATCH(call) static_cast<Impl*>(this)->call @@ -1631,17 +1682,22 @@ namespace internal { template <typename Char> class ArgMap { private: - typedef std::map<fmt::BasicStringRef<Char>, internal::Arg> MapType; + typedef std::vector<std::pair<fmt::BasicStringRef<Char>, internal::Arg> > MapType; typedef typename MapType::value_type Pair; MapType map_; public: - void init(const ArgList &args); + FMT_API void init(const ArgList &args); const internal::Arg* find(const fmt::BasicStringRef<Char> &name) const { - typename MapType::const_iterator it = map_.find(name); - return it != map_.end() ? &it->second : 0; + // The list is unsorted, so just return the first matching name. + for (typename MapType::const_iterator it = map_.begin(), end = map_.end(); + it != end; ++it) { + if (it->first == name) + return &it->second; + } + return 0; } }; @@ -1767,7 +1823,7 @@ class FormatterBase { int next_arg_index_; // Returns the argument with specified index. - Arg do_get_arg(unsigned arg_index, const char *&error); + FMT_API Arg do_get_arg(unsigned arg_index, const char *&error); protected: const ArgList &args() const { return args_; } @@ -1780,7 +1836,7 @@ class FormatterBase { // Returns the next argument. Arg next_arg(const char *&error) { if (next_arg_index_ >= 0) - return do_get_arg(next_arg_index_++, error); + return do_get_arg(internal::to_unsigned(next_arg_index_++), error); error = "cannot switch from manual to automatic argument indexing"; return Arg(); } @@ -1803,7 +1859,7 @@ class FormatterBase { template <typename Char> void write(BasicWriter<Char> &w, const Char *start, const Char *end) { if (start != end) - w << BasicStringRef<Char>(start, end - start); + w << BasicStringRef<Char>(start, internal::to_unsigned(end - start)); } }; @@ -1823,14 +1879,16 @@ class PrintfFormatter : private FormatterBase { public: explicit PrintfFormatter(const ArgList &args) : FormatterBase(args) {} - void format(BasicWriter<Char> &writer, BasicCStringRef<Char> format_str); + FMT_API void format(BasicWriter<Char> &writer, + BasicCStringRef<Char> format_str); }; } // namespace internal -// A formatter. +/** This template formats data and writes the output to a writer. */ template <typename CharType> class BasicFormatter : private internal::FormatterBase { public: + /** The character type for the output. */ typedef CharType Char; private: @@ -1852,13 +1910,23 @@ class BasicFormatter : private internal::FormatterBase { internal::Arg parse_arg_name(const Char *&s); public: + /** + \rst + Constructs a ``BasicFormatter`` object. References to the arguments and + the writer are stored in the formatter object so make sure they have + appropriate lifetimes. + \endrst + */ BasicFormatter(const ArgList &args, BasicWriter<Char> &w) : internal::FormatterBase(args), writer_(w) {} + /** Returns a reference to the writer associated with this formatter. */ BasicWriter<Char> &writer() { return writer_; } + /** Formats stored arguments and writes the output to the writer. */ void format(BasicCStringRef<Char> format_str); + // Formats a single argument and advances format_str, a format string pointer. const Char *format(const Char *&format_str, const internal::Arg &arg); }; @@ -1889,16 +1957,29 @@ inline uint64_t make_type(const T &arg) { return MakeValue< BasicFormatter<char> >::type(arg); } +template <unsigned N, bool/*IsPacked*/= (N < ArgList::MAX_PACKED_ARGS)> +struct ArgArray; + +template <unsigned N> +struct ArgArray<N, true/*IsPacked*/> { + typedef Value Type[N > 0 ? N : 1]; + + template <typename Formatter, typename T> + static Value make(const T &value) { + Value result = MakeValue<Formatter>(value); + // Workaround a bug in Apple LLVM version 4.2 (clang-425.0.28) of clang: + // https://github.com/cppformat/cppformat/issues/276 + (void)result.custom.format; + return result; + } +}; + template <unsigned N> -struct ArgArray { - // Computes the argument array size by adding 1 to N, which is the number of - // arguments, if N is zero, because array of zero size is invalid, or if N - // is greater than ArgList::MAX_PACKED_ARGS to accommodate for an extra - // argument that marks the end of the list. - enum { SIZE = N + (N == 0 || N >= ArgList::MAX_PACKED_ARGS ? 1 : 0) }; - - typedef typename Conditional< - (N < ArgList::MAX_PACKED_ARGS), Value, Arg>::type Type[SIZE]; +struct ArgArray<N, false/*IsPacked*/> { + typedef Arg Type[N + 1]; // +1 for the list end Arg::NONE + + template <typename Formatter, typename T> + static Arg make(const T &value) { return MakeArg<Formatter>(value); } }; #if FMT_USE_VARIADIC_TEMPLATES @@ -1907,47 +1988,6 @@ inline uint64_t make_type(const Arg &first, const Args & ... tail) { return make_type(first) | (make_type(tail...) << 4); } -inline void do_set_types(Arg *) {} - -template <typename T, typename... Args> -inline void do_set_types(Arg *args, const T &arg, const Args & ... tail) { - args->type = static_cast<Arg::Type>( - MakeValue< BasicFormatter<char> >::type(arg)); - do_set_types(args + 1, tail...); -} - -template <typename... Args> -inline void set_types(Arg *array, const Args & ... args) { - if (check(sizeof...(Args) > ArgList::MAX_PACKED_ARGS)) - do_set_types(array, args...); - array[sizeof...(Args)].type = Arg::NONE; -} - -template <typename... Args> -inline void set_types(Value *, const Args & ...) { - // Do nothing as types are passed separately from values. -} - -template <typename Formatter, typename Value> -inline void store_args(Value *) {} - -template <typename Formatter, typename Arg, typename T, typename... Args> -inline void store_args(Arg *args, const T &arg, const Args & ... tail) { - // Assign only the Value subobject of Arg and don't overwrite type (if any) - // that is assigned by set_types. - Value &value = *args; - value = MakeValue<Formatter>(arg); - store_args<Formatter>(args + 1, tail...); -} - -template <typename Formatter, typename... Args> -ArgList make_arg_list(typename ArgArray<sizeof...(Args)>::Type array, - const Args & ... args) { - if (check(sizeof...(Args) >= ArgList::MAX_PACKED_ARGS)) - set_types(array, args...); - store_args<Formatter>(array, args...); - return ArgList(make_type(args...), array); -} #else struct ArgType { @@ -1985,7 +2025,7 @@ class FormatBuf : public std::basic_streambuf<Char> { int_type overflow(int_type ch = traits_type::eof()) { if (!traits_type::eq_int_type(ch, traits_type::eof())) { - size_t size = this->pptr() - start_; + size_t size = this->size(); buffer_.resize(size); buffer_.reserve(size * 2); @@ -1997,7 +2037,7 @@ class FormatBuf : public std::basic_streambuf<Char> { } size_t size() const { - return this->pptr() - start_; + return to_unsigned(this->pptr() - start_); } }; } // namespace internal @@ -2015,18 +2055,20 @@ class FormatBuf : public std::basic_streambuf<Char> { # define FMT_VARIADIC_VOID(func, arg_type) \ template <typename... Args> \ void func(arg_type arg0, const Args & ... args) { \ - typename fmt::internal::ArgArray<sizeof...(Args)>::Type array; \ - func(arg0, fmt::internal::make_arg_list< \ - fmt::BasicFormatter<Char> >(array, args...)); \ + typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \ + typename ArgArray::Type array{ \ + ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \ + func(arg0, fmt::ArgList(fmt::internal::make_type(args...), array)); \ } // Defines a variadic constructor. # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \ template <typename... Args> \ ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \ - typename fmt::internal::ArgArray<sizeof...(Args)>::Type array; \ - func(arg0, arg1, fmt::internal::make_arg_list< \ - fmt::BasicFormatter<Char> >(array, args...)); \ + typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \ + typename ArgArray::Type array{ \ + ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \ + func(arg0, arg1, fmt::ArgList(fmt::internal::make_type(args...), array)); \ } #else @@ -2207,7 +2249,8 @@ class BasicWriter { // Writes a decimal integer. template <typename Int> void write_decimal(Int value) { - typename internal::IntTraits<Int>::MainType abs_value = value; + typedef typename internal::IntTraits<Int>::MainType MainType; + MainType abs_value = static_cast<MainType>(value); if (internal::is_negative(value)) { abs_value = 0 - abs_value; *write_unsigned_decimal(abs_value, 1) = '-'; @@ -2474,9 +2517,9 @@ void BasicWriter<Char>::write_str( return; } } - std::size_t precision = spec.precision_; + std::size_t precision = static_cast<std::size_t>(spec.precision_); if (spec.precision_ >= 0 && precision < str_size) - str_size = spec.precision_; + str_size = precision; write_str(str_value, str_size, spec); } @@ -2510,7 +2553,8 @@ typename BasicWriter<Char>::CharPtr // is specified. if (prefix_size > 0 && prefix[prefix_size - 1] == '0') --prefix_size; - unsigned number_size = prefix_size + spec.precision(); + unsigned number_size = + prefix_size + internal::to_unsigned(spec.precision()); AlignSpec subspec(number_size, '0', ALIGN_NUMERIC); if (number_size >= width) return prepare_int_buffer(num_digits, subspec, prefix, prefix_size); @@ -2564,7 +2608,7 @@ template <typename T, typename Spec> void BasicWriter<Char>::write_int(T value, Spec spec) { unsigned prefix_size = 0; typedef typename internal::IntTraits<T>::MainType UnsignedType; - UnsignedType abs_value = value; + UnsignedType abs_value = static_cast<UnsignedType>(value); char prefix[4] = ""; if (internal::is_negative(value)) { prefix[0] = '-'; @@ -2643,8 +2687,7 @@ void BasicWriter<Char>::write_int(T value, Spec spec) { template <typename Char> template <typename T> -void BasicWriter<Char>::write_double( - T value, const FormatSpec &spec) { +void BasicWriter<Char>::write_double(T value, const FormatSpec &spec) { // Check type. char type = spec.type(); bool upper = false; @@ -2744,6 +2787,8 @@ void BasicWriter<Char>::write_double( // Format using snprintf. Char fill = internal::CharTraits<Char>::cast(spec.fill()); + unsigned n = 0; + Char *start = 0; for (;;) { std::size_t buffer_size = buffer_.capacity() - offset; #ifdef _MSC_VER @@ -2755,41 +2800,44 @@ void BasicWriter<Char>::write_double( buffer_size = buffer_.capacity() - offset; } #endif - Char *start = &buffer_[offset]; - int n = internal::CharTraits<Char>::format_float( + start = &buffer_[offset]; + int result = internal::CharTraits<Char>::format_float( start, buffer_size, format, width_for_sprintf, spec.precision(), value); - if (n >= 0 && offset + n < buffer_.capacity()) { - if (sign) { - if ((spec.align() != ALIGN_RIGHT && spec.align() != ALIGN_DEFAULT) || - *start != ' ') { - *(start - 1) = sign; - sign = 0; - } else { - *(start - 1) = fill; - } - ++n; - } - if (spec.align() == ALIGN_CENTER && - spec.width() > static_cast<unsigned>(n)) { - width = spec.width(); - CharPtr p = grow_buffer(width); - std::memmove(get(p) + (width - n) / 2, get(p), n * sizeof(Char)); - fill_padding(p, spec.width(), n, fill); - return; - } - if (spec.fill() != ' ' || sign) { - while (*start == ' ') - *start++ = fill; - if (sign) - *(start - 1) = sign; - } - grow_buffer(n); - return; + if (result >= 0) { + n = internal::to_unsigned(result); + if (offset + n < buffer_.capacity()) + break; // The buffer is large enough - continue with formatting. + buffer_.reserve(offset + n + 1); + } else { + // If result is negative we ask to increase the capacity by at least 1, + // but as std::vector, the buffer grows exponentially. + buffer_.reserve(buffer_.capacity() + 1); } - // If n is negative we ask to increase the capacity by at least 1, - // but as std::vector, the buffer grows exponentially. - buffer_.reserve(n >= 0 ? offset + n + 1 : buffer_.capacity() + 1); } + if (sign) { + if ((spec.align() != ALIGN_RIGHT && spec.align() != ALIGN_DEFAULT) || + *start != ' ') { + *(start - 1) = sign; + sign = 0; + } else { + *(start - 1) = fill; + } + ++n; + } + if (spec.align() == ALIGN_CENTER && spec.width() > n) { + width = spec.width(); + CharPtr p = grow_buffer(width); + std::memmove(get(p) + (width - n) / 2, get(p), n * sizeof(Char)); + fill_padding(p, spec.width(), n, fill); + return; + } + if (spec.fill() != ' ' || sign) { + while (*start == ' ') + *start++ = fill; + if (sign) + *(start - 1) = sign; + } + grow_buffer(n); } /** @@ -2920,22 +2968,21 @@ void format(BasicFormatter<Char> &f, const Char *&format_str, const T &value) { output << value; BasicStringRef<Char> str(&buffer[0], format_buf.size()); - typedef internal::MakeValue< BasicFormatter<Char> > MakeValue; - internal::Arg arg = MakeValue(str); - arg.type = static_cast<internal::Arg::Type>(MakeValue::type(str)); - format_str = f.format(format_str, arg); + typedef internal::MakeArg< BasicFormatter<Char> > MakeArg; + format_str = f.format(format_str, MakeArg(str)); } // Reports a system error without throwing an exception. // Can be used to report errors from destructors. -void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT; +FMT_API void report_system_error(int error_code, + StringRef message) FMT_NOEXCEPT; #if FMT_USE_WINDOWS_H /** A Windows error. */ class WindowsError : public SystemError { private: - void init(int error_code, CStringRef format_str, ArgList args); + FMT_API void init(int error_code, CStringRef format_str, ArgList args); public: /** @@ -2974,7 +3021,8 @@ class WindowsError : public SystemError { // Reports a Windows error without throwing an exception. // Can be used to report errors from destructors. -void report_windows_error(int error_code, StringRef message) FMT_NOEXCEPT; +FMT_API void report_windows_error(int error_code, + StringRef message) FMT_NOEXCEPT; #endif @@ -2986,7 +3034,7 @@ enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }; Example: print_colored(fmt::RED, "Elapsed time: {0:.2f} seconds", 1.23); */ -void print_colored(Color c, CStringRef format, ArgList args); +FMT_API void print_colored(Color c, CStringRef format, ArgList args); /** \rst @@ -3018,7 +3066,7 @@ inline std::wstring format(WCStringRef format_str, ArgList args) { print(stderr, "Don't {}!", "panic"); \endrst */ -void print(std::FILE *f, CStringRef format_str, ArgList args); +FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args); /** \rst @@ -3029,7 +3077,7 @@ void print(std::FILE *f, CStringRef format_str, ArgList args); print("Elapsed time: {0:.2f} seconds", 1.23); \endrst */ -void print(CStringRef format_str, ArgList args); +FMT_API void print(CStringRef format_str, ArgList args); template <typename Char> void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args) { @@ -3066,7 +3114,7 @@ inline std::wstring sprintf(WCStringRef format, ArgList args) { fmt::fprintf(stderr, "Don't %s!", "panic"); \endrst */ -int fprintf(std::FILE *f, CStringRef format, ArgList args); +FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args); /** \rst @@ -3132,10 +3180,10 @@ class FormatInt { explicit FormatInt(unsigned long value) : str_(format_decimal(value)) {} explicit FormatInt(ULongLong value) : str_(format_decimal(value)) {} - /** - Returns the number of characters written to the output buffer. - */ - std::size_t size() const { return buffer_ - str_ + BUFFER_SIZE - 1; } + /** Returns the number of characters written to the output buffer. */ + std::size_t size() const { + return internal::to_unsigned(buffer_ - str_ + BUFFER_SIZE - 1); + } /** Returns a pointer to the output buffer content. No terminating null @@ -3165,7 +3213,8 @@ class FormatInt { // write a terminating null character. template <typename T> inline void format_decimal(char *&buffer, T value) { - typename internal::IntTraits<T>::MainType abs_value = value; + typedef typename internal::IntTraits<T>::MainType MainType; + MainType abs_value = static_cast<MainType>(value); if (internal::is_negative(value)) { *buffer++ = '-'; abs_value = 0 - abs_value; @@ -3245,10 +3294,11 @@ void arg(WStringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED; template <typename... Args> \ ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \ const Args & ... args) { \ - typename fmt::internal::ArgArray<sizeof...(Args)>::Type array; \ + typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \ + typename ArgArray::Type array{ \ + ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \ call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \ - fmt::internal::make_arg_list< \ - fmt::BasicFormatter<Char> >(array, args...)); \ + fmt::ArgList(fmt::internal::make_type(args...), array)); \ } #else // Defines a wrapper for a function taking __VA_ARGS__ arguments @@ -3361,8 +3411,20 @@ FMT_VARIADIC(int, fprintf, std::FILE *, CStringRef) print(cerr, "Don't {}!", "panic"); \endrst */ -void print(std::ostream &os, CStringRef format_str, ArgList args); +FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args); FMT_VARIADIC(void, print, std::ostream &, CStringRef) + +/** + \rst + Prints formatted data to the stream *os*. + + **Example**:: + + fprintf(cerr, "Don't %s!", "panic"); + \endrst + */ +FMT_API int fprintf(std::ostream &os, CStringRef format_str, ArgList args); +FMT_VARIADIC(int, fprintf, std::ostream &, CStringRef) #endif namespace internal { @@ -3374,7 +3436,7 @@ inline bool is_name_start(Char c) { // Parses an unsigned integer advancing s to the end of the parsed input. // This function assumes that the first character of s is a digit. template <typename Char> -int parse_nonnegative_int(const Char *&s) { +unsigned parse_nonnegative_int(const Char *&s) { assert('0' <= *s && *s <= '9'); unsigned value = 0; do { @@ -3453,7 +3515,6 @@ inline internal::Arg BasicFormatter<Char>::parse_arg_name(const Char *&s) { return arg; } -// Should be after FormatSpec template <typename Char> const Char *BasicFormatter<Char>::format( const Char *&format_str, const internal::Arg &arg) { diff --git a/dep/cppformat/posix.cc b/dep/cppformat/cppformat/posix.cc index 756281a0ebd..c6c2ae2c413 100644 --- a/dep/cppformat/posix.cc +++ b/dep/cppformat/cppformat/posix.cc @@ -173,7 +173,7 @@ std::size_t fmt::File::read(void *buffer, std::size_t count) { FMT_RETRY(result, FMT_POSIX_CALL(read(fd_, buffer, convert_rwcount(count)))); if (result < 0) throw SystemError(errno, "cannot read from file"); - return result; + return internal::to_unsigned(result); } std::size_t fmt::File::write(const void *buffer, std::size_t count) { @@ -181,7 +181,7 @@ std::size_t fmt::File::write(const void *buffer, std::size_t count) { FMT_RETRY(result, FMT_POSIX_CALL(write(fd_, buffer, convert_rwcount(count)))); if (result < 0) throw SystemError(errno, "cannot write to file"); - return result; + return internal::to_unsigned(result); } fmt::File fmt::File::dup(int fd) { diff --git a/dep/cppformat/posix.h b/dep/cppformat/cppformat/posix.h index 88bcb4f557b..bfbd3851838 100644 --- a/dep/cppformat/posix.h +++ b/dep/cppformat/cppformat/posix.h @@ -34,11 +34,17 @@ #endif #include <errno.h> -#include <fcntl.h> // for O_RDONLY +#include <fcntl.h> // for O_RDONLY +#include <locale.h> // for locale_t #include <stdio.h> +#include <stdlib.h> // for strtod_l #include <cstddef> +#ifdef __APPLE__ +# include <xlocale.h> // for LC_NUMERIC_MASK on OS X +#endif + #include "format.h" #ifndef FMT_POSIX @@ -299,7 +305,8 @@ class File { // Closes the file. void close(); - // Returns the file size. + // Returns the file size. The size has signed type for consistency with + // stat::st_size. LongLong size() const; // Attempts to read count bytes from the file into the specified buffer. @@ -331,6 +338,58 @@ class File { // Returns the memory page size. long getpagesize(); + +#if defined(LC_NUMERIC_MASK) || defined(_MSC_VER) +# define FMT_LOCALE +#endif + +#ifdef FMT_LOCALE +// A "C" numeric locale. +class Locale { + private: +# ifdef _MSC_VER + typedef _locale_t locale_t; + + enum { LC_NUMERIC_MASK = LC_NUMERIC }; + + static locale_t newlocale(int category_mask, const char *locale, locale_t) { + return _create_locale(category_mask, locale); + } + + static void freelocale(locale_t locale) { + _free_locale(locale); + } + + static double strtod_l(const char *nptr, char **endptr, _locale_t locale) { + return _strtod_l(nptr, endptr, locale); + } +# endif + + locale_t locale_; + + FMT_DISALLOW_COPY_AND_ASSIGN(Locale); + + public: + typedef locale_t Type; + + Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", NULL)) { + if (!locale_) + throw fmt::SystemError(errno, "cannot create locale"); + } + ~Locale() { freelocale(locale_); } + + Type get() const { return locale_; } + + // Converts string to floating-point number and advances str past the end + // of the parsed input. + double strtod(const char *&str) const { + char *end = 0; + double result = strtod_l(str, &end, locale_); + str = end; + return result; + } +}; +#endif // FMT_LOCALE } // namespace fmt #if !FMT_USE_RVALUE_REFERENCES diff --git a/dep/g3dlite/CMakeLists.txt b/dep/g3dlite/CMakeLists.txt index f1166c72e6d..4e579951d63 100644 --- a/dep/g3dlite/CMakeLists.txt +++ b/dep/g3dlite/CMakeLists.txt @@ -8,7 +8,6 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - set(g3dlib_STAT_SRCS source/AABox.cpp source/Any.cpp @@ -55,20 +54,18 @@ set(g3dlib_STAT_SRCS source/Vector4.cpp ) -if(WIN32) - include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_SOURCE_DIR}/dep/zlib - ) -else() - include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/include - ) -endif() - add_library(g3dlib STATIC ${g3dlib_STAT_SRCS}) +target_include_directories(g3dlib + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include) + target_link_libraries(g3dlib - ${ZLIB_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} -) + PUBLIC + zlib + threads) + +set_target_properties(g3dlib + PROPERTIES + FOLDER + "dep") diff --git a/dep/gsoap/CMakeLists.txt b/dep/gsoap/CMakeLists.txt index b5fed7809af..bdcadf6e4dc 100644 --- a/dep/gsoap/CMakeLists.txt +++ b/dep/gsoap/CMakeLists.txt @@ -10,17 +10,22 @@ file(GLOB sources *.cpp *.h) -set(gsoap_STAT_SRCS - ${sources} -) +add_library(gsoap STATIC ${sources}) -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} -) +set_target_properties(gsoap PROPERTIES LINKER_LANGUAGE CXX) -# Little fix for MSVC / Windows platforms -add_definitions(-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=0) +target_include_directories(gsoap + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}) -add_library(gsoap STATIC ${gsoap_STAT_SRCS}) +set_target_properties(gsoap + PROPERTIES + FOLDER + "dep") -set_target_properties(gsoap PROPERTIES LINKER_LANGUAGE CXX) +if (MSVC) + # Little fix for MSVC / Windows platforms + target_compile_definitions(gsoap + PRIVATE + -D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=0) +endif() diff --git a/dep/jemalloc/CMakeLists.txt b/dep/jemalloc/CMakeLists.txt index cf0ac435f0a..6774e5a75d2 100644 --- a/dep/jemalloc/CMakeLists.txt +++ b/dep/jemalloc/CMakeLists.txt @@ -8,54 +8,79 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# We need to generate the jemalloc_def.h header based on platform-specific settings -if (PLATFORM EQUAL 32) - set(JEM_SIZEDEF 2) - set(JEM_TLSMODEL) +if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT NOJEM) + # We need to generate the jemalloc_def.h header based on platform-specific settings + if (PLATFORM EQUAL 32) + set(JEM_SIZEDEF 2) + set(JEM_TLSMODEL) + else() + set(JEM_SIZEDEF 3) + set(JEM_TLSMODEL "__attribute__\(\(tls_model\(\"initial-exec\"\)\)\)") + endif() + + # Create the header, so we can use it + configure_file( + "${CMAKE_SOURCE_DIR}/dep/jemalloc/jemalloc_defs.h.in.cmake" + "${BUILDDIR}/jemalloc_defs.h" + @ONLY + ) + + # Done, let's continue + set(jemalloc_STAT_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/src/arena.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/atomic.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/base.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/bitmap.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/chunk.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/chunk_dss.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/chunk_mmap.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/ckh.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/ctl.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/extent.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/hash.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/huge.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/jemalloc.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/mb.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/mutex.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/prof.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/quarantine.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/rtree.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/stats.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/tcache.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/tsd.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/util.c + ) + + add_library(jemalloc STATIC ${jemalloc_STAT_SRC}) + + target_include_directories(jemalloc + PRIVATE + ${BUILDDIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include) + + target_compile_definitions(jemalloc + PUBLIC + -DNO_BUFFERPOOL + PRIVATE + -D_GNU_SOURCE + -D_REENTRAN) + + target_link_libraries(jemalloc + PUBLIC + threads + valgrind) + + set_target_properties(jemalloc + PROPERTIES + FOLDER + "dep") + else() - set(JEM_SIZEDEF 3) - set(JEM_TLSMODEL "__attribute__\(\(tls_model\(\"initial-exec\"\)\)\)") -endif() + # Provide a dummy target for jemalloc which is used when jemalloc + # is disabled or not supported. + add_library(jemalloc INTERFACE) + target_link_libraries(jemalloc + INTERFACE + valgrind) -# Create the header, so we can use it -configure_file( - "${CMAKE_SOURCE_DIR}/dep/jemalloc/jemalloc_defs.h.in.cmake" - "${BUILDDIR}/jemalloc_defs.h" - @ONLY -) - -# Done, let's continue -set(jemalloc_STAT_SRC - ${CMAKE_CURRENT_SOURCE_DIR}/src/arena.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/atomic.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/base.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/bitmap.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/chunk.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/chunk_dss.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/chunk_mmap.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/ckh.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/ctl.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/extent.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/hash.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/huge.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/jemalloc.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/mb.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/mutex.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/prof.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/quarantine.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/rtree.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/stats.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/tcache.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/tsd.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/util.c -) - -include_directories( - ${BUILDDIR}/ - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${VALGRIND_INCLUDE_DIR} -) - -add_definitions(-D_GNU_SOURCE -D_REENTRANT) - -add_library(jemalloc STATIC ${jemalloc_STAT_SRC}) +endif() diff --git a/dep/libmpq/CMakeLists.txt b/dep/libmpq/CMakeLists.txt index 1213e6b11b7..e8b420fca53 100644 --- a/dep/libmpq/CMakeLists.txt +++ b/dep/libmpq/CMakeLists.txt @@ -8,27 +8,29 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -file(GLOB sources_mpq libmpq/*.c libmpq/*.h) +file(GLOB sources libmpq/*.c libmpq/*.h) -set(mpq_STAT_SRCS - ${sources_mpq} -) +add_library(mpq STATIC ${sources}) -if( UNIX ) - include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/dep/zlib - ${CMAKE_SOURCE_DIR}/dep/bzip2 - ) -elseif( WIN32 ) - include_directories( +set_target_properties(mpq PROPERTIES LINKER_LANGUAGE CXX) + +if(WIN32) + set(WIN_EXTRA_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/win) +endif() + +target_include_directories(mpq + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/win + ${WIN_EXTRA_INCLUDE} ${CMAKE_SOURCE_DIR}/dep/zlib - ${CMAKE_SOURCE_DIR}/dep/bzip2 - ) -endif() + ${CMAKE_SOURCE_DIR}/dep/bzip2) -add_library(mpq STATIC ${mpq_STAT_SRCS}) +target_link_libraries(mpq + PUBLIC + zlib + bzip2) -set_target_properties(mpq PROPERTIES LINKER_LANGUAGE CXX) +set_target_properties(mpq + PROPERTIES + FOLDER + "dep") diff --git a/dep/mysql/CMakeLists.txt b/dep/mysql/CMakeLists.txt new file mode 100644 index 00000000000..472535b0356 --- /dev/null +++ b/dep/mysql/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +if (NOT MYSQL_FOUND) + message(FATAL_ERROR "MySQL wasn't found on your system but it's required to build the servers!") +endif() + +add_library(mysql STATIC IMPORTED GLOBAL) + +set_target_properties(mysql + PROPERTIES + IMPORTED_LOCATION + "${MYSQL_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES + "${MYSQL_INCLUDE_DIR}") diff --git a/dep/openssl/CMakeLists.txt b/dep/openssl/CMakeLists.txt new file mode 100644 index 00000000000..98561b2a0ed --- /dev/null +++ b/dep/openssl/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + +# basic packagesearching and setup +# (further support will be needed, this is a preliminary release!) +set(OPENSSL_EXPECTED_VERSION 1.0.0) + +find_package(OpenSSL REQUIRED) + +add_library(openssl INTERFACE) + +target_link_libraries(openssl + INTERFACE + ${OPENSSL_LIBRARIES}) + +target_include_directories(openssl + INTERFACE + ${OPENSSL_INCLUDE_DIR}) diff --git a/dep/process/CMakeLists.txt b/dep/process/CMakeLists.txt new file mode 100644 index 00000000000..5a51917a00c --- /dev/null +++ b/dep/process/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +add_library(process INTERFACE) + +target_include_directories(process + INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}) + +target_link_libraries(process + INTERFACE + boost) diff --git a/dep/readline/CMakeLists.txt b/dep/readline/CMakeLists.txt new file mode 100644 index 00000000000..0e8679ba718 --- /dev/null +++ b/dep/readline/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +if( UNIX ) + # find Readline (terminal input library) includes and library + # + # READLINE_INCLUDE_DIR - where the directory containing the READLINE headers can be found + # READLINE_LIBRARY - full path to the READLINE library + find_path(READLINE_INCLUDE_DIR readline/readline.h) + find_library(READLINE_LIBRARY NAMES readline) + + message(STATUS "Found Readline library: ${READLINE_LIBRARY}") + message(STATUS "Include dir is: ${READLINE_INCLUDE_DIR}") + + if (NOT READLINE_INCLUDE_DIR OR NOT READLINE_LIBRARY) + message(FATAL_ERROR "** Readline library not found!\n** Your distro may provide a binary for Readline e.g. for ubuntu try apt-get install libreadline5-dev") + endif () + + add_library(readline SHARED IMPORTED GLOBAL) + + set_target_properties(readline + PROPERTIES + IMPORTED_LOCATION + "${READLINE_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES + "${READLINE_INCLUDE_DIR}") + +else() + # Provide a dummy target + add_library(readline INTERFACE) +endif() diff --git a/dep/recastnavigation/Detour/CMakeLists.txt b/dep/recastnavigation/Detour/CMakeLists.txt index b21e4ca6273..12be71d32b4 100644 --- a/dep/recastnavigation/Detour/CMakeLists.txt +++ b/dep/recastnavigation/Detour/CMakeLists.txt @@ -16,14 +16,18 @@ set(Detour_STAT_SRCS Source/DetourNavMeshQuery.cpp Source/DetourNode.cpp ) -include_directories(Include) - -if(WIN32) - include_directories( - ${CMAKE_SOURCE_DIR}/dep/zlib - ) -endif() add_library(Detour STATIC ${Detour_STAT_SRCS}) -target_link_libraries(Detour ${ZLIB_LIBRARIES}) +target_include_directories(Detour + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/Include) + +target_link_libraries(Detour + PUBLIC + zlib) + +set_target_properties(Detour + PROPERTIES + FOLDER + "dep") diff --git a/dep/recastnavigation/Recast/CMakeLists.txt b/dep/recastnavigation/Recast/CMakeLists.txt index 738c010eb05..1eac4e75399 100644 --- a/dep/recastnavigation/Recast/CMakeLists.txt +++ b/dep/recastnavigation/Recast/CMakeLists.txt @@ -14,21 +14,24 @@ set(Recast_STAT_SRCS Source/RecastArea.cpp Source/RecastContour.cpp Source/RecastFilter.cpp - Source/RecastLayers.cpp + Source/RecastLayers.cpp Source/RecastMesh.cpp Source/RecastMeshDetail.cpp Source/RecastRasterization.cpp Source/RecastRegion.cpp ) -include_directories(Include) +add_library(Recast STATIC ${Recast_STAT_SRCS}) -if(WIN32) - include_directories( - ${CMAKE_SOURCE_DIR}/dep/zlib - ) -endif() +target_include_directories(Recast + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/Include) -add_library(Recast STATIC ${Recast_STAT_SRCS}) +target_link_libraries(Recast + PUBLIC + zlib) -target_link_libraries(Recast ${ZLIB_LIBRARIES})
\ No newline at end of file +set_target_properties(Recast + PROPERTIES + FOLDER + "dep") diff --git a/dep/threads/CMakeLists.txt b/dep/threads/CMakeLists.txt new file mode 100644 index 00000000000..48e5eb00723 --- /dev/null +++ b/dep/threads/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +find_package(Threads REQUIRED) + +add_library(threads INTERFACE) +target_link_libraries(threads + INTERFACE + ${CMAKE_THREAD_LIBS_INIT}) diff --git a/dep/utf8cpp/CMakeLists.txt b/dep/utf8cpp/CMakeLists.txt new file mode 100644 index 00000000000..edf8604d44c --- /dev/null +++ b/dep/utf8cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +add_library(utf8cpp INTERFACE) + +target_include_directories(utf8cpp + INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/dep/valgrind/CMakeLists.txt b/dep/valgrind/CMakeLists.txt new file mode 100644 index 00000000000..d67cd33b426 --- /dev/null +++ b/dep/valgrind/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +add_library(valgrind INTERFACE) + +target_include_directories(valgrind + INTERFACE + "${VALGRIND_INCLUDE_DIR}") diff --git a/dep/zlib/CMakeLists.txt b/dep/zlib/CMakeLists.txt index 7feb134bcd5..b3e3d58fe55 100644 --- a/dep/zlib/CMakeLists.txt +++ b/dep/zlib/CMakeLists.txt @@ -8,22 +8,43 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -SET(zlib_STAT_SRCS - adler32.c - compress.c - crc32.c - deflate.c - infback.c - inffast.c - inflate.c - inftrees.c - trees.c - uncompr.c - zutil.c -) +if(UNIX) + # Look for an installed zlib on unix + find_package(ZLIB REQUIRED) -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} -) + add_library(zlib SHARED IMPORTED GLOBAL) -add_library(zlib STATIC ${zlib_STAT_SRCS}) + set_target_properties(zlib + PROPERTIES + IMPORTED_LOCATION + "${ZLIB_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES + "${ZLIB_INCLUDE_DIRS}") +else() + # Use the bundled source on windows + SET(zlib_STAT_SRCS + adler32.c + compress.c + crc32.c + deflate.c + infback.c + inffast.c + inflate.c + inftrees.c + trees.c + uncompr.c + zutil.c + ) + + add_library(zlib STATIC + ${zlib_STAT_SRCS}) + + target_include_directories(zlib + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}) + + set_target_properties(zlib + PROPERTIES + FOLDER + "dep") +endif() |
