# 默认配置选项
#####################################################################
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)

if (CMAKE_CONFIGURATION_TYPES)
	message(STATUS "Available Build Type: ${CMAKE_CONFIGURATION_TYPES}")
else()
	message(STATUS "Available Build Type: Unknown")
endif()

if(NOT CMAKE_BUILD_TYPE)
	#set(CMAKE_BUILD_TYPE "Debug")
	set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()

# 设置公共编译选项 
set(ALL_FLAGS_IN_ONE_COMMON "")
set(C_FLAGS_IN_ONE_COMMON "")
set(CXX_FLAGS_IN_ONE_COMMON "")

# 编译器选项 (仅做了GCC、VC和Clang兼容)
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
        add_definitions(-Wall -Werror)

        # 检测GCC版本大于等于4.8时，默认-Wno-unused-local-typedefs (普片用于type_traits，故而关闭该警告)
        if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.8.0" OR CMAKE_CXX_COMPILER_VERSION  VERSION_EQUAL "4.8.0" )
                add_definitions(-Wno-unused-local-typedefs)
                message(STATUS "GCC Version ${CMAKE_CXX_COMPILER_VERSION} Found, -Wno-unused-local-typedefs added.")
        endif()
        if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.7.0" OR CMAKE_CXX_COMPILER_VERSION  VERSION_EQUAL "4.7.0" )
                set(CXX_FLAGS_IN_ONE_COMMON "${C_FLAGS_IN_ONE_COMMON} -std=gnu++11")
                set(C_FLAGS_IN_ONE_COMMON "${C_FLAGS_IN_ONE_COMMON} -std=gnu11")
                message(STATUS "GCC Version ${CMAKE_CXX_COMPILER_VERSION} , using -std=gnu11/gnu++11.")
        elseif( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.4.0" OR CMAKE_CXX_COMPILER_VERSION  VERSION_EQUAL "4.4.0" )
                set(CXX_FLAGS_IN_ONE_COMMON "${C_FLAGS_IN_ONE_COMMON} -std=gnu++0x")
                message(STATUS "GCC Version ${CMAKE_CXX_COMPILER_VERSION} , using -std=gnu++0x.")
        endif()

elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
        add_definitions(-Wall -Werror)
        set(CXX_FLAGS_IN_ONE_COMMON "${C_FLAGS_IN_ONE_COMMON} -std=c++11")
        message(STATUS "CLang Version ${CMAKE_CXX_COMPILER_VERSION} , using -std=c++11.")
endif()

# 配置公共编译选项 
if ( NOT MSVC )
        set(ALL_FLAGS_IN_ONE_DEBUG "-ggdb -O0 ${ALL_FLAGS_IN_ONE_COMMON}")
        set(ALL_FLAGS_IN_ONE_RELEASE "${ALL_FLAGS_IN_ONE_COMMON}")
        set(ALL_FLAGS_IN_ONE_RELWITHDEBINFO "-ggdb ${ALL_FLAGS_IN_ONE_COMMON}")
        set(ALL_FLAGS_IN_ONE_MINSIZEREL "${ALL_FLAGS_IN_ONE_COMMON}")
else()
        set(ALL_FLAGS_IN_ONE_DEBUG "/Od /MDd ${ALL_FLAGS_IN_ONE_COMMON}")
        set(ALL_FLAGS_IN_ONE_RELEASE "/O2 /MD ${ALL_FLAGS_IN_ONE_COMMON} /D NDEBUG")
        set(ALL_FLAGS_IN_ONE_RELWITHDEBINFO "/O2 /MDd ${ALL_FLAGS_IN_ONE_COMMON}")
        set(ALL_FLAGS_IN_ONE_MINSIZEREL "/Ox /MD ${ALL_FLAGS_IN_ONE_COMMON} /D NDEBUG")
endif()

# 设置实际的编译选项 
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${ALL_FLAGS_IN_ONE_DEBUG} ${CXX_FLAGS_IN_ONE_COMMON}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${ALL_FLAGS_IN_ONE_RELEASE} ${CXX_FLAGS_IN_ONE_COMMON}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${ALL_FLAGS_IN_ONE_RELWITHDEBINFO} ${CXX_FLAGS_IN_ONE_COMMON}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${ALL_FLAGS_IN_ONE_MINSIZEREL} ${CXX_FLAGS_IN_ONE_COMMON}")

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${ALL_FLAGS_IN_ONE_DEBUG} ${C_FLAGS_IN_ONE_COMMON}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${ALL_FLAGS_IN_ONE_RELEASE} ${C_FLAGS_IN_ONE_COMMON}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${ALL_FLAGS_IN_ONE_RELWITHDEBINFO} ${C_FLAGS_IN_ONE_COMMON}")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${ALL_FLAGS_IN_ONE_MINSIZEREL} ${C_FLAGS_IN_ONE_COMMON}")

# 库文件的附加参数 -fPIC, 多线程附加参数 -pthread -D_POSIX_MT_
