Core/Common: Converted the common library to a shared library.

* There is still the possibility to static link against common.
This commit is contained in:
Aokromes
2016-08-10 08:19:25 +02:00
parent 0a40d49839
commit 384a5216fd
40 changed files with 123 additions and 101 deletions

View File

@@ -30,6 +30,8 @@ endif (USE_COREPCH)
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_definitions(-DTRINITY_API_EXPORT_COMMON)
add_library(common
${PRIVATE_PCH_SOURCE}
${PRIVATE_SOURCES}
@@ -78,6 +80,18 @@ set_target_properties(common
FOLDER
"server")
if( BUILD_SHARED_LIBS )
if( UNIX )
install(TARGETS common
LIBRARY
DESTINATION lib)
elseif( WIN32 )
install(TARGETS common
RUNTIME
DESTINATION "${CMAKE_INSTALL_PREFIX}")
endif()
endif()
# Generate precompiled header
if (USE_COREPCH)
add_cxx_pch(common ${PRIVATE_PCH_HEADER} ${PRIVATE_PCH_SOURCE})

View File

@@ -67,7 +67,7 @@ struct AABound
Copyright (c) 2003-2007 Christopher Kulla
*/
class BIH
class TC_COMMON_API BIH
{
private:
void init_empty()

View File

@@ -31,7 +31,7 @@ namespace G3D
class GameObjectModel;
struct DynTreeImpl;
class DynamicMapTree
class TC_COMMON_API DynamicMapTree
{
DynTreeImpl *impl;

View File

@@ -42,7 +42,7 @@ namespace VMAP
#define VMAP_INVALID_HEIGHT_VALUE -200000.0f // real assigned value in unknown height case
//===========================================================
class IVMapManager
class TC_COMMON_API IVMapManager
{
private:
bool iEnableLineOfSightCalc;

View File

@@ -38,7 +38,7 @@ namespace MMAP
// static class
// holds all mmap global data
// access point to MMapManager singleton
class MMapFactory
class TC_COMMON_API MMapFactory
{
public:
static MMapManager* createOrGetMMapManager();

View File

@@ -92,7 +92,7 @@ namespace MMAP
// singleton class
// holds all all access to mmap loading unloading and meshes
class MMapManager
class TC_COMMON_API MMapManager
{
public:
MMapManager() : loadedTiles(0), thread_safe_environment(true) {}

View File

@@ -29,7 +29,7 @@ namespace VMAP
{
//===========================================================
class VMapFactory
class TC_COMMON_API VMapFactory
{
public:
static IVMapManager* createOrGetVMapManager();

View File

@@ -51,7 +51,7 @@ namespace VMAP
class StaticMapTree;
class WorldModel;
class ManagedModel
class TC_COMMON_API ManagedModel
{
public:
ManagedModel() : iModel(nullptr), iRefCount(0) { }
@@ -75,7 +75,7 @@ namespace VMAP
VMAP_DISABLE_LIQUIDSTATUS = 0x8
};
class VMapManager2 : public IVMapManager
class TC_COMMON_API VMapManager2 : public IVMapManager
{
protected:
// Tree to check collision

View File

@@ -29,7 +29,7 @@ namespace VMAP
class GroupModel;
class VMapManager2;
struct LocationInfo
struct TC_COMMON_API LocationInfo
{
LocationInfo(): hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { }
const ModelInstance* hitInstance;
@@ -37,7 +37,7 @@ namespace VMAP
float ground_Z;
};
class StaticMapTree
class TC_COMMON_API StaticMapTree
{
typedef std::unordered_map<uint32, bool> loadedTileMap;
typedef std::unordered_map<uint32, uint32> loadedSpawnMap;
@@ -87,7 +87,7 @@ namespace VMAP
StaticMapTree& operator=(StaticMapTree const& right) = delete;
};
struct AreaInfo
struct TC_COMMON_API AreaInfo
{
AreaInfo(): result(false), ground_Z(-G3D::finf()), flags(0), adtId(0),
rootId(0), groupId(0) { }

View File

@@ -35,7 +35,7 @@ namespace VMAP
*/
//===============================================
class ModelPosition
class TC_COMMON_API ModelPosition
{
private:
G3D::Matrix3 iRotation;
@@ -55,7 +55,7 @@ namespace VMAP
typedef std::map<uint32, ModelSpawn> UniqueEntryMap;
typedef std::multimap<uint32, uint32> TileMap;
struct MapSpawns
struct TC_COMMON_API MapSpawns
{
UniqueEntryMap UniqueEntries;
TileMap TileEntries;
@@ -64,7 +64,7 @@ namespace VMAP
typedef std::map<uint32, MapSpawns*> MapData;
//===============================================
struct GroupModel_Raw
struct TC_COMMON_API GroupModel_Raw
{
uint32 mogpflags;
uint32 GroupWMOID;
@@ -82,7 +82,7 @@ namespace VMAP
bool Read(FILE* f);
};
struct WorldModel_Raw
struct TC_COMMON_API WorldModel_Raw
{
uint32 RootWMOID;
std::vector<GroupModel_Raw> groupsArray;
@@ -90,7 +90,7 @@ namespace VMAP
bool Read(const char * path);
};
class TileAssembler
class TC_COMMON_API TileAssembler
{
private:
std::string iDestDir;

View File

@@ -35,7 +35,7 @@ namespace VMAP
class GameObject;
struct GameObjectDisplayInfoEntry;
class GameObjectModelOwnerBase
class TC_COMMON_API GameObjectModelOwnerBase
{
public:
virtual bool IsSpawned() const { return false; }
@@ -47,7 +47,7 @@ public:
virtual void DebugVisualizeCorner(G3D::Vector3 const& /*corner*/) const { }
};
class GameObjectModel /*, public Intersectable*/
class TC_COMMON_API GameObjectModel /*, public Intersectable*/
{
GameObjectModel() : phasemask(0), iInvScale(0), iScale(0), iModel(NULL) { }
public:
@@ -84,6 +84,6 @@ private:
std::unique_ptr<GameObjectModelOwnerBase> owner;
};
void LoadGameObjectModelList(std::string const& dataPath);
TC_COMMON_API void LoadGameObjectModelList(std::string const& dataPath);
#endif // _GAMEOBJECT_MODEL_H

View File

@@ -39,7 +39,7 @@ namespace VMAP
MOD_HAS_BOUND = 1<<2
};
class ModelSpawn
class TC_COMMON_API ModelSpawn
{
public:
//mapID, tileX, tileY, Flags, ID, Pos, Rot, Scale, Bound_lo, Bound_hi, name
@@ -60,7 +60,7 @@ namespace VMAP
static bool writeToFile(FILE* rw, const ModelSpawn &spawn);
};
class ModelInstance: public ModelSpawn
class TC_COMMON_API ModelInstance: public ModelSpawn
{
public:
ModelInstance(): iInvScale(0.0f), iModel(nullptr) { }

View File

@@ -33,7 +33,7 @@ namespace VMAP
struct AreaInfo;
struct LocationInfo;
class MeshTriangle
class TC_COMMON_API MeshTriangle
{
public:
MeshTriangle() : idx0(0), idx1(0), idx2(0) { }
@@ -44,7 +44,7 @@ namespace VMAP
uint32 idx2;
};
class WmoLiquid
class TC_COMMON_API WmoLiquid
{
public:
WmoLiquid(uint32 width, uint32 height, const G3D::Vector3 &corner, uint32 type);
@@ -70,7 +70,7 @@ namespace VMAP
};
/*! holding additional info for WMO group files */
class GroupModel
class TC_COMMON_API GroupModel
{
public:
GroupModel() : iBound(), iMogpFlags(0), iGroupWMOID(0), iLiquid(NULL) { }
@@ -103,7 +103,7 @@ namespace VMAP
};
/*! Holds a model (converted M2 or WMO) in its original coordinate space */
class WorldModel
class TC_COMMON_API WorldModel
{
public:
WorldModel(): RootWMOID(0) { }

View File

@@ -20,7 +20,7 @@ class NodeCreatorFunc = NodeCreator<Node>,
/*class BoundsFunc = BoundsTrait<T>,*/
class PositionFunc = PositionTrait<T>
>
class RegularGrid2D
class TC_COMMON_API RegularGrid2D
{
public:

View File

@@ -136,9 +136,9 @@ const uint8 OLD_TOTAL_LOCALES = 9; /// @todo convert in simple system
#define MAX_LOCALES 10
#define MAX_ACCOUNT_TUTORIAL_VALUES 8
extern char const* localeNames[TOTAL_LOCALES];
TC_COMMON_API extern char const* localeNames[TOTAL_LOCALES];
LocaleConstant GetLocaleByName(const std::string& name);
TC_COMMON_API LocaleConstant GetLocaleByName(const std::string& name);
typedef std::vector<std::string> StringVector;

View File

@@ -19,6 +19,7 @@
#define BUILT_IN_CONFIG_H
#include <string>
#include "Define.h"
/// Provides helper functions to access built-in values
/// which can be overwritten in config
@@ -26,16 +27,16 @@ namespace BuiltInConfig
{
/// Returns the CMake command when any is specified in the config,
/// returns the built-in path otherwise
std::string GetCMakeCommand();
TC_COMMON_API std::string GetCMakeCommand();
/// Returns the build directory path when any is specified in the config,
/// returns the built-in one otherwise
std::string GetBuildDirectory();
TC_COMMON_API std::string GetBuildDirectory();
/// Returns the source directory path when any is specified in the config,
/// returns the built-in one otherwise
std::string GetSourceDirectory();
TC_COMMON_API std::string GetSourceDirectory();
/// Returns the path to the mysql executable (`mysql`) when any is specified
/// in the config, returns the built-in one otherwise
std::string GetMySQLExecutable();
TC_COMMON_API std::string GetMySQLExecutable();
} // namespace BuiltInConfig

View File

@@ -19,12 +19,14 @@
#ifndef CONFIG_H
#define CONFIG_H
include "Define.h"
#include <string>
#include <list>
#include <mutex>
#include <boost/property_tree/ptree.hpp>
class ConfigMgr
class TC_COMMON_API ConfigMgr
{
ConfigMgr() = default;
ConfigMgr(ConfigMgr const&) = delete;

View File

@@ -22,7 +22,7 @@
#include <openssl/evp.h>
#include "Define.h"
class ARC4
class TC_COMMON_API ARC4
{
public:
ARC4(uint32 len);

View File

@@ -22,7 +22,7 @@
class BigNumber;
class PacketCrypt
class TC_COMMON_API PacketCrypt
{
public:
PacketCrypt(uint32 rc4InitSize);

View File

@@ -25,7 +25,7 @@
struct bignum_st;
class BigNumber
class TC_COMMON_API BigNumber
{
public:
BigNumber();

View File

@@ -62,5 +62,5 @@ uint8* HmacHash<HashCreator, DigestLength>::ComputeHash(BigNumber* bn)
return _digest;
}
template class HmacHash<EVP_sha1, SHA_DIGEST_LENGTH>;
template class HmacHash<EVP_sha256, SHA256_DIGEST_LENGTH>;
template class TC_COMMON_API HmacHash<EVP_sha1, SHA_DIGEST_LENGTH>;
template class TC_COMMON_API HmacHash<EVP_sha256, SHA256_DIGEST_LENGTH>;

View File

@@ -31,7 +31,7 @@ class BigNumber;
typedef EVP_MD const* (*HashCreateFn)();
template<HashCreateFn HashCreator, uint32 DigestLength>
class HmacHash
class TC_COMMON_API HmacHash
{
public:
HmacHash(uint32 len, uint8 *seed);

View File

@@ -18,6 +18,8 @@
#ifndef OPENSSL_CRYPTO_H
#define OPENSSL_CRYPTO_H
#include "Define.h"
/**
* A group of functions which setup openssl crypto module to work properly in multithreaded enviroment
* If not setup properly - it will crash
@@ -25,9 +27,9 @@
namespace OpenSSLCrypto
{
/// Needs to be called before threads using openssl are spawned
void threadsSetup();
TC_COMMON_API void threadsSetup();
/// Needs to be called after threads using openssl are despawned
void threadsCleanup();
TC_COMMON_API void threadsCleanup();
}
#endif
#endif

View File

@@ -25,7 +25,7 @@
class BigNumber;
class SHA1Hash
class TC_COMMON_API SHA1Hash
{
public:
SHA1Hash();

View File

@@ -24,7 +24,7 @@
class BigNumber;
class SHA256Hash
class TC_COMMON_API SHA256Hash
{
public:
SHA256Hash();

View File

@@ -23,18 +23,18 @@
namespace Trinity
{
DECLSPEC_NORETURN void Assert(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
DECLSPEC_NORETURN void Assert(char const* file, int line, char const* function, char const* message, char const* format, ...) ATTR_NORETURN ATTR_PRINTF(5, 6);
DECLSPEC_NORETURN TC_COMMON_API void Assert(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
DECLSPEC_NORETURN TC_COMMON_API void Assert(char const* file, int line, char const* function, char const* message, char const* format, ...) ATTR_NORETURN ATTR_PRINTF(5, 6);
DECLSPEC_NORETURN void Fatal(char const* file, int line, char const* function, char const* message, ...) ATTR_NORETURN ATTR_PRINTF(4, 5);
DECLSPEC_NORETURN TC_COMMON_API void Fatal(char const* file, int line, char const* function, char const* message, ...) ATTR_NORETURN ATTR_PRINTF(4, 5);
DECLSPEC_NORETURN void Error(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
DECLSPEC_NORETURN TC_COMMON_API void Error(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
DECLSPEC_NORETURN void Abort(char const* file, int line, char const* function) ATTR_NORETURN;
DECLSPEC_NORETURN TC_COMMON_API void Abort(char const* file, int line, char const* function) ATTR_NORETURN;
void Warning(char const* file, int line, char const* function, char const* message);
TC_COMMON_API void Warning(char const* file, int line, char const* function, char const* message);
DECLSPEC_NORETURN void AbortHandler(int sigval) ATTR_NORETURN;
DECLSPEC_NORETURN TC_COMMON_API void AbortHandler(int sigval) ATTR_NORETURN;
} // namespace Trinity

View File

@@ -1,5 +1,4 @@
#include "GitRevision.h"
#include "CompilerDefs.h"
#include "revision_data.h"
char const* GitRevision::GetHash()

View File

@@ -19,22 +19,23 @@
#define __GITREVISION_H__
#include <string>
#include "Define.h"
namespace GitRevision
{
char const* GetHash();
char const* GetDate();
char const* GetBranch();
char const* GetCMakeCommand();
char const* GetBuildDirectory();
char const* GetSourceDirectory();
char const* GetMySQLExecutable();
char const* GetFullDatabase();
char const* GetFullVersion();
char const* GetCompanyNameStr();
char const* GetLegalCopyrightStr();
char const* GetFileVersionStr();
char const* GetProductVersionStr();
TC_COMMON_API char const* GetHash();
TC_COMMON_API char const* GetDate();
TC_COMMON_API char const* GetBranch();
TC_COMMON_API char const* GetCMakeCommand();
TC_COMMON_API char const* GetBuildDirectory();
TC_COMMON_API char const* GetSourceDirectory();
TC_COMMON_API char const* GetMySQLExecutable();
TC_COMMON_API char const* GetFullDatabase();
TC_COMMON_API char const* GetFullVersion();
TC_COMMON_API char const* GetCompanyNameStr();
TC_COMMON_API char const* GetLegalCopyrightStr();
TC_COMMON_API char const* GetFileVersionStr();
TC_COMMON_API char const* GetProductVersionStr();
}
#endif

View File

@@ -59,7 +59,7 @@ enum AppenderFlags
APPENDER_FLAGS_MAKE_FILE_BACKUP = 0x10 // only used by FileAppender
};
struct LogMessage
struct TC_COMMON_API LogMessage
{
LogMessage(LogLevel _level, std::string const& _type, std::string&& _text)
: level(_level), type(_type), text(std::forward<std::string>(_text)), mtime(time(NULL))
@@ -85,7 +85,7 @@ struct LogMessage
}
};
class Appender
class TC_COMMON_API Appender
{
public:
Appender(uint8 _id, std::string const& name, LogLevel level = LOG_LEVEL_DISABLED, AppenderFlags flags = APPENDER_FLAGS_NONE);
@@ -123,7 +123,7 @@ Appender* CreateAppender(uint8 id, std::string const& name, LogLevel level, Appe
return new AppenderImpl(id, name, level, flags, std::forward<ExtraAppenderArgs>(extraArgs));
}
class InvalidAppenderArgsException : public std::length_error
class TC_COMMON_API InvalidAppenderArgsException : public std::length_error
{
public:
explicit InvalidAppenderArgsException(std::string const& message) : std::length_error(message) { }

View File

@@ -42,7 +42,7 @@ enum ColorTypes
const uint8 MaxColors = uint8(WHITE) + 1;
class AppenderConsole : public Appender
class TC_COMMON_API AppenderConsole : public Appender
{
public:
typedef std::integral_constant<AppenderType, APPENDER_CONSOLE>::type TypeIndex;

View File

@@ -21,7 +21,7 @@
#include <atomic>
#include "Appender.h"
class AppenderFile : public Appender
class TC_COMMON_API AppenderFile : public Appender
{
public:
typedef std::integral_constant<AppenderType, APPENDER_FILE>::type TypeIndex;

View File

@@ -34,7 +34,7 @@
#define LOGGER_ROOT "root"
class Log
class TC_COMMON_API Log
{
typedef std::unordered_map<std::string, Logger> LoggerMap;

View File

@@ -23,7 +23,7 @@
class Logger;
struct LogMessage;
class LogOperation
class TC_COMMON_API LogOperation
{
public:
LogOperation(Logger const* _logger, std::unique_ptr<LogMessage>&& _msg)

View File

@@ -20,7 +20,7 @@
#include "Appender.h"
class Logger
class TC_COMMON_API Logger
{
public:
Logger();

View File

@@ -20,6 +20,7 @@
#include "Define.h"
#include "Random.h"
#include "Util.h"
#include <algorithm>
#include <functional>
#include <list>

View File

@@ -22,7 +22,7 @@
#include "Duration.h"
#include "Util.h"
class EventMap
class TC_COMMON_API EventMap
{
/**
* Internal storage type.

View File

@@ -25,7 +25,7 @@
// Note. All times are in milliseconds here.
class BasicEvent
class TC_COMMON_API BasicEvent
{
public:
BasicEvent()
@@ -55,7 +55,7 @@ class BasicEvent
typedef std::multimap<uint64, BasicEvent*> EventList;
class EventProcessor
class TC_COMMON_API EventProcessor
{
public:
EventProcessor();

View File

@@ -24,28 +24,28 @@
#include <random>
/* Return a random number in the range min..max. */
int32 irand(int32 min, int32 max);
TC_COMMON_API int32 irand(int32 min, int32 max);
/* Return a random number in the range min..max (inclusive). */
uint32 urand(uint32 min, uint32 max);
TC_COMMON_API uint32 urand(uint32 min, uint32 max);
/* Return a random millisecond value between min and max seconds. Functionally equivalent to urand(min*IN_MILLISECONDS, max*IN_MILLISECONDS). */
uint32 urandms(uint32 min, uint32 max);
TC_COMMON_API uint32 urandms(uint32 min, uint32 max);
/* Return a random number in the range 0 .. UINT32_MAX. */
uint32 rand32();
TC_COMMON_API uint32 rand32();
/* Return a random time in the range min..max (up to millisecond precision). Only works for values where millisecond difference is a valid uint32. */
Milliseconds randtime(Milliseconds const& min, Milliseconds const& max);
TC_COMMON_API Milliseconds randtime(Milliseconds const& min, Milliseconds const& max);
/* Return a random number in the range min..max */
float frand(float min, float max);
TC_COMMON_API float frand(float min, float max);
/* Return a random double from 0.0 to 1.0 (exclusive). */
double rand_norm();
TC_COMMON_API double rand_norm();
/* Return a random double from 0.0 to 100.0 (exclusive). */
double rand_chance();
TC_COMMON_API double rand_chance();
/* Return true if a random roll fits in the specified chance (range 0-100). */
inline bool roll_chance_f(float chance)
@@ -62,7 +62,7 @@ inline bool roll_chance_i(int chance)
/*
* SFMT wrapper satisfying UniformRandomNumberGenerator concept for use in <random> algorithms
*/
class SFMTEngine
class TC_COMMON_API SFMTEngine
{
public:
typedef uint32 result_type;

View File

@@ -46,7 +46,7 @@ class TaskContext;
/// with the same duration or a new one.
/// It also provides access to the repeat counter which is useful for task that repeat itself often
/// but behave different every time (spoken event dialogs for example).
class TaskScheduler
class TC_COMMON_API TaskScheduler
{
friend class TaskContext;
@@ -131,7 +131,7 @@ class TaskScheduler
};
};
class TaskQueue
class TC_COMMON_API TaskQueue
{
std::multiset<TaskContainer, Compare> container;
@@ -408,7 +408,7 @@ private:
void Dispatch(success_t const& callback);
};
class TaskContext
class TC_COMMON_API TaskContext
{
friend class TaskScheduler;

View File

@@ -40,7 +40,7 @@ template<typename T, class S> struct Finder
bool operator()(const std::pair<int, S> &obj) { return obj.second.*idMember_ == val_; }
};
class Tokenizer
class TC_COMMON_API Tokenizer
{
public:
typedef std::vector<char const*> StorageType;
@@ -68,15 +68,15 @@ private:
StorageType m_storage;
};
void stripLineInvisibleChars(std::string &src);
TC_COMMON_API void stripLineInvisibleChars(std::string &src);
int64 MoneyStringToMoney(const std::string& moneyString);
TC_COMMON_API int64 MoneyStringToMoney(const std::string& moneyString);
struct tm* localtime_r(const time_t* time, struct tm *result);
TC_COMMON_API struct tm* localtime_r(const time_t* time, struct tm *result);
std::string secsToTimeString(uint64 timeInSecs, bool shortText = false, bool hoursOnly = false);
uint32 TimeStringToSecs(const std::string& timestring);
std::string TimeToTimestampStr(time_t t);
TC_COMMON_API std::string secsToTimeString(uint64 timeInSecs, bool shortText = false, bool hoursOnly = false);
TC_COMMON_API uint32 TimeStringToSecs(const std::string& timestring);
TC_COMMON_API std::string TimeToTimestampStr(time_t t);
inline void ApplyPercentModFloatVar(float& var, float val, bool apply)
{
@@ -111,20 +111,22 @@ inline T RoundToInterval(T& num, T floor, T ceil)
}
// UTF8 handling
bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr);
TC_COMMON_API bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr);
// in wsize==max size of buffer, out wsize==real string size
bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize);
TC_COMMON_API bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize);
inline bool Utf8toWStr(const std::string& utf8str, wchar_t* wstr, size_t& wsize)
{
return Utf8toWStr(utf8str.c_str(), utf8str.size(), wstr, wsize);
}
bool WStrToUtf8(std::wstring const& wstr, std::string& utf8str);
TC_COMMON_API bool WStrToUtf8(std::wstring const& wstr, std::string& utf8str);
// size==real string size
bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str);
TC_COMMON_API bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str);
size_t utf8length(std::string& utf8str); // set string to "" if invalid utf8 sequence
void utf8truncate(std::string& utf8str, size_t len);
// set string to "" if invalid utf8 sequence
TC_COMMON_API size_t utf8length(std::string& utf8str);
TC_COMMON_API void utf8truncate(std::string& utf8str, size_t len);
inline bool isBasicLatinCharacter(wchar_t wchar)
{