CMAKE_MINIMUM_REQUIRED(VERSION 2.8.4)

SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Cmake)
SET(CMAKE_USE_RELATIVE_PATHS ON)
IF(NOT CMAKE_BUILD_TYPE)
	SET(CMAKE_BUILD_TYPE "Debug")
ENDIF()

PROJECT(Cpp)

OPTION(TESTS "Decide if the test suite shall be built or not" ON)
OPTION(PROFILE "Use Google Perftool Profile" OFF)
OPTION(TCMALLOC "Use Google Perftool Tcmalloc" OFF)

IF(TESTS)
	ENABLE_TESTING()
ENDIF()

# 设置头文件查找路径
INCLUDE_DIRECTORIES(Platform)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/Platform)
INCLUDE_DIRECTORIES(Game)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/Game)
INCLUDE_DIRECTORIES(ThirdParty)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/ThirdParty)

# 检查库
FIND_PACKAGE(Protobuf REQUIRED)
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIRS})

FIND_PACKAGE(MysqlConnector)
INCLUDE_DIRECTORIES(${MYSQL_CONNECTOR_INCLUDE_DIRS})

FIND_PACKAGE(Perftools REQUIRED)

FIND_PACKAGE(Mono)

SET(Boost_USE_STATIC_LIBS    ON)
SET(Boost_USE_MULTITHREADED  ON)
SET(Boost_USE_STATIC_RUNTIME ON)
FIND_PACKAGE(Boost REQUIRED thread system filesystem log)


# 设置第三方库
SET(ThirdPartyLibs
	gtest
	gmock
	${PROTOBUF_LIBRARIES}
	${Boost_LIBRARIES}
	${MYSQL_CONNECTOR_LIBRARIES}
)
IF(UNIX)
	SET(ThirdPartyLibs ${ThirdPartyLibs} pthread)
ENDIF()

IF(TCMALLOC)
	SET(ThirdPartyLibs ${ThirdPartyLibs} ${PERFTOOLS_DEBUG_LIBRARIES})
	INCLUDE_DIRECTORIES(${PERFTOOLS_INCLUDE_DIRS})
ENDIF()

IF(PROFILE)
	SET(ThirdPartyLibs ${ThirdPartyLibs} ${PERFTOOLS_PROFILE_LIBRARIES})
	INCLUDE_DIRECTORIES(${PERFTOOLS_INCLUDE_DIRS})
ENDIF()

# 设置编译选项
IF(WIN32)
	SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
	SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /WX /wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305 /wd4819")
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:libc.lib")
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:libcmt.lib")
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:msvcrt.lib")
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:libcd.lib")
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:msvcrtd.lib")
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:msvcprtd.lib")
	ADD_DEFINITIONS(-DBOOST_ALL_NO_LIB -D_WIN32_WINNT=0x0601)
	# gtest gmock 用到std::tuple超过了默认最大模板参数
	ADD_DEFINITIONS(-D_VARIADIC_MAX=10)
ELSEIF(UNIX)
	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
ENDIF()

# 子目录
ADD_SUBDIRECTORY(Platform)
ADD_SUBDIRECTORY(ThirdParty)