math(EXPR BITS "8*${CMAKE_SIZEOF_VOID_P}")
message("find target bits: ${BITS}Bits")
message("cmake source dir is ${CMAKE_SOURCE_DIR}")
add_definitions(-DUNICODE -D_UNICODE -D_FILE_OFFSET_BITS=64 -D_USE_AES_MBEDTLS_)
IF(NOT MSVC)
    add_definitions(-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE)
ENDIF()
set(CMAKE_C_STANDARD 11)

# WIN32�ȹرս�������Ϊ����Ŀ��� /WX 
#cmake_policy(SET CMP0077 NEW)
IF(MSVC)
    set(CMAKE_C_FLAGS "/wd4819 /wd6011 /wd6387 /Zi /GS /W3 /Zc:wchar_t /EHsc /Zc:inline /fp:precise /Zc:forScope /GR- /Gd /FC")
    add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
ELSE()
    set(CMAKE_C_FLAGS "-g -Wall -Wno-comment -Wno-unused-function -Wno-unused-variable -fstrict-aliasing -fno-strict-aliasing")
ENDIF()

IF(CMAKE_BUILD_TYPE STREQUAL "")
    message("CMAKE_BUILD_TYPE not input, default DEBUG")
    set(CMAKE_BUILD_TYPE "Debug")
ENDIF()

IF(NOT TARGET_NAME)
	set(TARGET_NAME ${CMAKE_SYSTEM_NAME})
ENDIF()

IF(EMBEDDED_UBUNTU_12)
	add_definitions(-DEMBEDDED_UBUNTU_12)
ENDIF()

message("set target name to ${TARGET_NAME}")

IF (WIN32)
    
ELSEIF (APPLE)
    add_definitions(-D__MAC__ -D__MACOSX__)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-local-typedef -Wno-unused-private-field -Wno-format")
ELSEIF (ANDROID)
    add_definitions(-DANDROID -DBFX_OS_ANDROID)
ELSEIF (UNIX)
    add_definitions(-D__LINUX__ -D__linux__)
ENDIF ()

message("c complier is ${CMAKE_C_COMPILER_ID}")

IF(MSVC)
    set(CMAKE_C_FLAGS_DEBUG "/FR /Od /RTC1 /MDd")
    set(CMAKE_C_FLAGS_RELEASE "/O2 /Oi /MT /Gy /GL")
ELSE()
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -O0")
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wno-unused-variable -O3")
    IF(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
		message("not Clang")
	    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wno-unused-but-set-variable")
	ELSE()
		message("Clang")
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-incompatible-pointer-types-discards-qualifiers -Wno-missing-braces")
    ENDIF()
ENDIF()

set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
IF(NOT MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder")
ENDIF()

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")

#add_definitions(-DNDEBUG -DBLOG_DISABLE)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_definitions(-DDEBUG -D_DEBUG -DTSLOG -DXPF_LOG)
ELSE()
    add_definitions(-DNDEBUG -DBLOG_DISABLE)
ENDIF()

if (CMAKE_SYSTEM_NAME STREQUAL "Android")
	link_libraries(dl log)
else ()
	# link_libraries(rt pthread)
endif ()

#IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
#	IF(TARGET_NAME STREQUAL "Windows")
#		LINK_DIRECTORIES(3rd/openssl_1_1_1-stable/win/x64d/lib)
#	ELSEIF(TARGET_NAME STREQUAL "hiwifigx")
#		LINK_DIRECTORIES(3rd/openssl_1_1_1-stable/gx/debug/lib)
#	ENDIF()
#ELSE()
#	IF(TARGET_NAME STREQUAL "Windows")
#		LINK_DIRECTORIES(3rd/openssl_1_1_1-stable/win/x64r/lib)
#	ELSEIF(TARGET_NAME STREQUAL "hiwifigx")
#		LINK_DIRECTORIES(3rd/openssl_1_1_1-stable/gx/release/lib ${LIBRARY_OUTPUT_PATH})
#	ENDIF()
#ENDIF()

