<commit_before>cmake_minimum_required(VERSION 2.8.8)
project(libchewing)

set(LIBCHEWING_VERSION 0.3.4)

string(COMPARE NOTEQUAL ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} OUT_OF_SOURCE)

option(ENABLE_DEBUG "Debug support" false)
if(ENABLE_DEBUG)
	add_definitions(-DENABLE_DEBUG=1)
endif()

if(UNIX)
	set(CMAKE_C_FLAGS "-g -O2 -Wall -fPIC ${CMAKE_C_FLAGS}")
	add_definitions(-DUNDER_POSIX -DPIC)
endif()

if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
	set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
	add_definitions(-D_GNU_SOURCE)
	option(ENABLE_GCOV "Coverage support" false)
	if(ENABLE_GCOV)
		set(CMAKE_C_FLAGS "-coverage ${CMAKE_C_FLAGS}")
	endif()
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
	add_definitions(-D_GNU_SOURCE)
	option(ENABLE_GCOV "Coverage support" false)
	if(ENABLE_GCOV)
		set(CMAKE_C_FLAGS "-coverage ${CMAKE_C_FLAGS}")
	endif()
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
	# /wd4819
	# Without BOM, Visual Studio does not treat source file as UTF-8
	# encoding, thus it will complain about invalid character. Use
	# /wd4819 can suppress this warning.
	set(CMAKE_C_FLAGS "/wd4819 ${CMAKE_C_FLAGS}")
	add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE)
	add_definitions(/Dsnprintf=_snprintf /D__func__=__FUNCTION__)
endif()

include(CheckCCompilerFlag)
check_c_compiler_flag(-fvisibility=hidden FVISIBILITY_HIDDEN)
if(${FVISIBILITY_HIDDEN})
	set(CMAKE_C_FLAGS "-fvisibility=hidden ${CMAKE_C_FLAGS}")
endif()

# automake compatibility
add_definitions(-DHAVE_CONFIG_H=1)

# binary data representation
option(USE_BINARY_DATA "Use binary representation for internal data manipulation" true)
if (USE_BINARY_DATA)
	add_definitions(-DUSE_BINARY_DATA=1)
endif()

# Feature probe
include(CheckTypeSize)
check_type_size(uint16_t UINT16_T)
<commit_msg>Fix Visual Studio build in cmake<commit_after>cmake_minimum_required(VERSION 2.8.8)
project(libchewing)

set(LIBCHEWING_VERSION 0.3.4)

string(COMPARE NOTEQUAL ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} OUT_OF_SOURCE)

option(ENABLE_DEBUG "Debug support" false)
if(ENABLE_DEBUG)
	add_definitions(-DENABLE_DEBUG=1)
endif()

if(UNIX)
	set(CMAKE_C_FLAGS "-g -O2 -Wall -fPIC ${CMAKE_C_FLAGS}")
	add_definitions(-DUNDER_POSIX -DPIC)
endif()

if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
	set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
	add_definitions(-D_GNU_SOURCE)
	option(ENABLE_GCOV "Coverage support" false)
	if(ENABLE_GCOV)
		set(CMAKE_C_FLAGS "-coverage ${CMAKE_C_FLAGS}")
	endif()
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
	add_definitions(-D_GNU_SOURCE)
	option(ENABLE_GCOV "Coverage support" false)
	if(ENABLE_GCOV)
		set(CMAKE_C_FLAGS "-coverage ${CMAKE_C_FLAGS}")
	endif()
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
	# XXX: Not sure why we need to use MATCHES instead of STREQUAL here.

	# /wd4819
	# Without BOM, Visual Studio does not treat source file as UTF-8
	# encoding, thus it will complain about invalid character. Use
	# /wd4819 can suppress this warning.
	set(CMAKE_C_FLAGS "/wd4819 ${CMAKE_C_FLAGS}")
	add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE)
	add_definitions(/Dsnprintf=_snprintf /D__func__=__FUNCTION__)
endif()

include(CheckCCompilerFlag)
check_c_compiler_flag(-fvisibility=hidden FVISIBILITY_HIDDEN)
if(${FVISIBILITY_HIDDEN})
	set(CMAKE_C_FLAGS "-fvisibility=hidden ${CMAKE_C_FLAGS}")
endif()

# automake compatibility
add_definitions(-DHAVE_CONFIG_H=1)

# binary data representation
option(USE_BINARY_DATA "Use binary representation for internal data manipulation" true)
if (USE_BINARY_DATA)
	add_definitions(-DUSE_BINARY_DATA=1)
endif()

# Feature probe
include(CheckTypeSize)
check_type_size(uint16_t UINT16_T)

{'fraction_non_alphanumeric': 0.10337263504250069, 'fraction_numerical': 0.015903482314230874, 'mean_word_length': 7.790361445783133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3546200', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1414, 'n_words': 268}