<commit_before>CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)
PROJECT(Skia-C)

OPTION(TREAT_WARNINGS_AS_ERRORS "Treat compiler warnings as errors. We use the highest warnings levels for compilers." OFF)

IF(MSVC)
	SET(MSVC_INSTALL_PATH "${PROJECT_SOURCE_DIR}/Windows")
	SET(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${MSVC_INSTALL_PATH}")

	IF(MSVC10)
		SET(MSVC_VERSION_STRING vc100)
	ELSEIF(MSVC11)
		SET(MSVC_VERSION_STRING vc110)
	ELSEIF(MSVC90)
		SET(MSVC_VERSION_STRING vc90)
	ELSEIF(MSVC80)
		SET(MSVC_VERSION_STRING vc80)
	ENDIF()

	# !FIXME! Actually detect compiler architecture version....
	IF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
		SET(MSVC_ARCHITECTURE_STRING x64)
	ELSE()
		SET(MSVC_ARCHITECTURE_STRING x86)
	ENDIF()

	SET(MSVC_LIB_DIR "${MSVC_INSTALL_PATH}/lib/${MSVC_ARCHITECTURE_STRING}/${MSVC_VERSION_STRING}")
	SET(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH};${MSVC_LIB_DIR}")

  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

ELSEIF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)

  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fms-extensions")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fms-extensions")

ENDIF(MSVC)

IF(TREAT_WARNINGS_AS_ERRORS)
  IF(MSVC)
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
  ELSEIF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
  ENDIF(MSVC)
ENDIF(TREAT_WARNINGS_AS_ERRORS)

FIND_PACKAGE(OpenGL)
IF(NOT OPENGL_FOUND)
  MESSAGE("OpenGL not found... skipping GPU build")
ENDIF()

FIND_PACKAGE(Freetype)
IF(NOT FREETYPE_FOUND)
  MESSAGE(FATAL_ERROR "FreeType library not found...")
ENDIF()

FIND_PACKAGE(PNG)
IF(NOT PNG_FOUND)
  MESSAGE(FATAL_ERROR "PNG library not found...")
ENDIF()

FIND_PACKAGE(GIF)
IF(NOT GIF_FOUND)
  MESSAGE(FATAL_ERROR "GIF library not found...")
ENDIF()

#######
## FontConfig
find_path(FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h)

find_library(FONTCONFIG_LIBRARY NAMES fontconfig)

# handle the QUIETLY and REQUIRED arguments and set FONTCONFIG_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FontConfig DEFAULT_MSG
  FONTCONFIG_LIBRARY  FONTCONFIG_INCLUDE_DIR)

if(FONTCONFIG_FOUND)
  set( FONTCONFIG_LIBRARIES ${FONTCONFIG_LIBRARY} )
endif()

mark_as_advanced(FONTCONFIG_INCLUDE_DIR FONTCONFIG_LIBRARY FONTCONFIG_LIBRARIES)

IF(NOT FONTCONFIG_FOUND)
  MESSAGE(FATAL_ERROR "FontConfig library not found...")
ENDIF()

########

SET(SKIA_DIRECTORY "" CACHE PATH "Path containing skia source code")
IF("${SKIA_DIRECTORY}" STREQUAL "")
  MESSAGE(FATAL_ERROR "Must specify path for skia directory")
ENDIF()

IF(NOT EXISTS "${SKIA_DIRECTORY}/")
  MESSAGE(FATAL_ERROR "Skia directory not found")
ENDIF()

SET(ENV{SKIA_OUT} ${Skia-C_SOURCE_DIR})
SET(ENV{GYP_GENERATORS} cmake)
EXECUTE_PROCESS(COMMAND ${SKIA_DIRECTORY}/gyp_skia WORKING_DIRECTORY ${Skia-C_SOURCE_DIR})

SET(OLD_CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR})
SET(CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/${CMAKE_BUILD_TYPE})
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR})
SET(CMAKE_SOURCE_DIR ${OLD_CMAKE_SOURCE_DIR})

SET(BUILD_SKIA_DEBUGGER OFF CACHE BOOL "Builds the Qt based Skia debugger")
IF(NOT BUILD_SKIA_DEBUGGER)
  set_target_properties(debugger PROPERTIES EXCLUDE_FROM_ALL ON)
  set_target_properties(debugger_qt_mocs PROPERTIES EXCLUDE_FROM_ALL ON)
  set_target_properties(debugger_qt_mocs__generate_moc PROPERTIES EXCLUDE_FROM_ALL ON)
ENDIF()


GET_TARGET_PROPERTY(SKIA_COMPILE_DEFS core COMPILE_DEFINITIONS)
GET_TARGET_PROPERTY(SKIA_COMPILE_FLAGS core COMPILE_FLAGS)
GET_TARGET_PROPERTY(SKIA_LINK_FLAGS core LINK_FLAGS)

ADD_LIBRARY(cskia src/skia.cpp)
INCLUDE_DIRECTORIES(${Skia-C_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/config)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/core)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/effects)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/src/core)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/images)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/gpu)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/utils)

SET_TARGET_PROPERTIES(cskia PROPERTIES COMPILE_DEFINITIONS "${SKIA_COMPILE_DEFS}")
SET_TARGET_PROPERTIES(cskia PROPERTIES COMPILE_FLAGS "${SKIA_COMPILE_FLAGS}")
SET_TARGET_PROPERTIES(cskia PROPERTIES LINK_FLAGS "${SKIA_LINK_FLAGS}")

SET(SKIA_LIBS ${SKIA_LIBS} core)
SET(SKIA_LIBS ${SKIA_LIBS} opts)
SET(SKIA_LIBS ${SKIA_LIBS} opts_sse4)
SET(SKIA_LIBS ${SKIA_LIBS} opts_ssse3)
SET(SKIA_LIBS ${SKIA_LIBS} images)
SET(SKIA_LIBS ${SKIA_LIBS} animator)
SET(SKIA_LIBS ${SKIA_LIBS} effects)
SET(SKIA_LIBS ${SKIA_LIBS} pdf)
SET(SKIA_LIBS ${SKIA_LIBS} ports)
SET(SKIA_LIBS ${SKIA_LIBS} sfnt)
SET(SKIA_LIBS ${SKIA_LIBS} views)
SET(SKIA_LIBS ${SKIA_LIBS} skgpu)
SET(SKIA_LIBS ${SKIA_LIBS} utils)
SET(SKIA_LIBS ${SKIA_LIBS} libetc1)
SET(SKIA_LIBS ${SKIA_LIBS} libSkKTX)
SET(SKIA_LIBS ${SKIA_LIBS} libwebp_enc)
SET(SKIA_LIBS ${SKIA_LIBS} libwebp_dec)
SET(SKIA_LIBS ${SKIA_LIBS} libwebp_demux)
SET(SKIA_LIBS ${SKIA_LIBS} libwebp_utils)
SET(SKIA_LIBS ${SKIA_LIBS} libwebp_dsp)
SET(SKIA_LIBS ${SKIA_LIBS} libjpeg)

FOREACH(TGT ${SKIA_LIBS})
  IF(TARGET ${TGT})
  ELSE()
    MESSAGE(FATAL_ERROR "Could not find target: " ${TGT})
  ENDIF()
ENDFOREACH()

SET(SKIA_LIBS ${SKIA_LIBS} ${FREETYPE_LIBRARIES})
SET(SKIA_LIBS ${SKIA_LIBS} ${FONTCONFIG_LIBRARIES})
SET(SKIA_LIBS ${SKIA_LIBS} ${PNG_LIBRARIES})
SET(SKIA_LIBS ${SKIA_LIBS} ${GIF_LIBRARIES})
SET(SKIA_LIBS ${SKIA_LIBS} ${OPENGL_LIBRARIES})

TARGET_LINK_LIBRARIES(cskia -Wl,--start-group ${SKIA_LIBS} -Wl,--end-group)

ADD_EXECUTABLE(cskia_test tests/test_libskia.c include/skia.h)
TARGET_LINK_LIBRARIES(cskia_test cskia)

SET_TARGET_PROPERTIES(cskia_test PROPERTIES COMPILE_DEFINITIONS "${SKIA_COMPILE_DEFS}")
SET_TARGET_PROPERTIES(cskia_test PROPERTIES LINK_FLAGS "${SKIA_LINK_FLAGS}")
<commit_msg>Add the option of building a shared library<commit_after>CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)
PROJECT(Skia-C)

OPTION(TREAT_WARNINGS_AS_ERRORS "Treat compiler warnings as errors. We use the highest warnings levels for compilers." OFF)

IF(MSVC)
	SET(MSVC_INSTALL_PATH "${PROJECT_SOURCE_DIR}/Windows")
	SET(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${MSVC_INSTALL_PATH}")

	IF(MSVC10)
		SET(MSVC_VERSION_STRING vc100)
	ELSEIF(MSVC11)
		SET(MSVC_VERSION_STRING vc110)
	ELSEIF(MSVC90)
		SET(MSVC_VERSION_STRING vc90)
	ELSEIF(MSVC80)
		SET(MSVC_VERSION_STRING vc80)
	ENDIF()

	# !FIXME! Actually detect compiler architecture version....
	IF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
		SET(MSVC_ARCHITECTURE_STRING x64)
	ELSE()
		SET(MSVC_ARCHITECTURE_STRING x86)
	ENDIF()

	SET(MSVC_LIB_DIR "${MSVC_INSTALL_PATH}/lib/${MSVC_ARCHITECTURE_STRING}/${MSVC_VERSION_STRING}")
	SET(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH};${MSVC_LIB_DIR}")

  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

ELSEIF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)

  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fms-extensions")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fms-extensions")

ENDIF(MSVC)

IF(TREAT_WARNINGS_AS_ERRORS)
  IF(MSVC)
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
  ELSEIF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
  ENDIF(MSVC)
ENDIF(TREAT_WARNINGS_AS_ERRORS)

FIND_PACKAGE(OpenGL)
IF(NOT OPENGL_FOUND)
  MESSAGE("OpenGL not found... skipping GPU build")
ENDIF()

FIND_PACKAGE(Freetype)
IF(NOT FREETYPE_FOUND)
  MESSAGE(FATAL_ERROR "FreeType library not found...")
ENDIF()

FIND_PACKAGE(PNG)
IF(NOT PNG_FOUND)
  MESSAGE(FATAL_ERROR "PNG library not found...")
ENDIF()

FIND_PACKAGE(GIF)
IF(NOT GIF_FOUND)
  MESSAGE(FATAL_ERROR "GIF library not found...")
ENDIF()

#######
## FontConfig
find_path(FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h)

find_library(FONTCONFIG_LIBRARY NAMES fontconfig)

# handle the QUIETLY and REQUIRED arguments and set FONTCONFIG_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FontConfig DEFAULT_MSG
  FONTCONFIG_LIBRARY  FONTCONFIG_INCLUDE_DIR)

if(FONTCONFIG_FOUND)
  set( FONTCONFIG_LIBRARIES ${FONTCONFIG_LIBRARY} )
endif()

mark_as_advanced(FONTCONFIG_INCLUDE_DIR FONTCONFIG_LIBRARY FONTCONFIG_LIBRARIES)

IF(NOT FONTCONFIG_FOUND)
  MESSAGE(FATAL_ERROR "FontConfig library not found...")
ENDIF()

########

SET(SKIA_DIRECTORY "" CACHE PATH "Path containing skia source code")
IF("${SKIA_DIRECTORY}" STREQUAL "")
  MESSAGE(FATAL_ERROR "Must specify path for skia directory")
ENDIF()

IF(NOT EXISTS "${SKIA_DIRECTORY}/")
  MESSAGE(FATAL_ERROR "Skia directory not found")
ENDIF()

SET(BUILD_SHARED_LIB OFF CACHE BOOL "Builds a shared library that links to the generated skia libs")

IF(BUILD_SHARED_LIB)
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
ENDIF()

SET(ENV{SKIA_OUT} ${Skia-C_SOURCE_DIR})
SET(ENV{GYP_GENERATORS} cmake)
EXECUTE_PROCESS(COMMAND ${SKIA_DIRECTORY}/gyp_skia WORKING_DIRECTORY ${Skia-C_SOURCE_DIR})

SET(OLD_CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR})
SET(CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/${CMAKE_BUILD_TYPE})
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR})
SET(CMAKE_SOURCE_DIR ${OLD_CMAKE_SOURCE_DIR})

SET(BUILD_SKIA_DEBUGGER OFF CACHE BOOL "Builds the Qt based Skia debugger")
IF(NOT BUILD_SKIA_DEBUGGER)
  set_target_properties(debugger PROPERTIES EXCLUDE_FROM_ALL ON)
  set_target_properties(debugger_qt_mocs PROPERTIES EXCLUDE_FROM_ALL ON)
  set_target_properties(debugger_qt_mocs__generate_moc PROPERTIES EXCLUDE_FROM_ALL ON)
ENDIF()

GET_TARGET_PROPERTY(SKIA_COMPILE_DEFS core COMPILE_DEFINITIONS)
GET_TARGET_PROPERTY(SKIA_COMPILE_FLAGS core COMPILE_FLAGS)
GET_TARGET_PROPERTY(SKIA_LINK_FLAGS core LINK_FLAGS)

IF(BUILD_SHARED_LIB)
  ADD_LIBRARY(cskia SHARED src/skia.cpp)
ELSE()
  ADD_LIBRARY(cskia STATIC src/skia.cpp)
ENDIF()

INCLUDE_DIRECTORIES(${Skia-C_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/config)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/core)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/effects)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/src/core)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/images)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/gpu)
INCLUDE_DIRECTORIES(${SKIA_DIRECTORY}/include/utils)

SET_TARGET_PROPERTIES(cskia PROPERTIES COMPILE_DEFINITIONS "${SKIA_COMPILE_DEFS}")
SET_TARGET_PROPERTIES(cskia PROPERTIES COMPILE_FLAGS "${SKIA_COMPILE_FLAGS}")
SET_TARGET_PROPERTIES(cskia PROPERTIES LINK_FLAGS "${SKIA_LINK_FLAGS}")

SET(SKIA_LIBS ${SKIA_LIBS} core)
SET(SKIA_LIBS ${SKIA_LIBS} opts)
SET(SKIA_LIBS ${SKIA_LIBS} opts_sse4)
SET(SKIA_LIBS ${SKIA_LIBS} opts_ssse3)
SET(SKIA_LIBS ${SKIA_LIBS} images)
SET(SKIA_LIBS ${SKIA_LIBS} animator)
SET(SKIA_LIBS ${SKIA_LIBS} effects)
SET(SKIA_LIBS ${SKIA_LIBS} pdf)
SET(SKIA_LIBS ${SKIA_LIBS} ports)
SET(SKIA_LIBS ${SKIA_LIBS} sfnt)
SET(SKIA_LIBS ${SKIA_LIBS} views)
SET(SKIA_LIBS ${SKIA_LIBS} skgpu)
SET(SKIA_LIBS ${SKIA_LIBS} utils)
SET(SKIA_LIBS ${SKIA_LIBS} libetc1)
SET(SKIA_LIBS ${SKIA_LIBS} libSkKTX)
SET(SKIA_LIBS ${SKIA_LIBS} libwebp_enc)
SET(SKIA_LIBS ${SKIA_LIBS} libwebp_dec)
SET(SKIA_LIBS ${SKIA_LIBS} libwebp_demux)
SET(SKIA_LIBS ${SKIA_LIBS} libwebp_utils)
SET(SKIA_LIBS ${SKIA_LIBS} libwebp_dsp)
SET(SKIA_LIBS ${SKIA_LIBS} libjpeg)

FOREACH(TGT ${SKIA_LIBS})
  IF(TARGET ${TGT})
  ELSE()
    MESSAGE(FATAL_ERROR "Could not find target: " ${TGT})
  ENDIF()
ENDFOREACH()

SET(SKIA_LIBS ${SKIA_LIBS} ${FREETYPE_LIBRARIES})
SET(SKIA_LIBS ${SKIA_LIBS} ${FONTCONFIG_LIBRARIES})
SET(SKIA_LIBS ${SKIA_LIBS} ${PNG_LIBRARIES})
SET(SKIA_LIBS ${SKIA_LIBS} ${GIF_LIBRARIES})
SET(SKIA_LIBS ${SKIA_LIBS} ${OPENGL_LIBRARIES})

TARGET_LINK_LIBRARIES(cskia -Wl,--start-group ${SKIA_LIBS} -Wl,--end-group)

ADD_EXECUTABLE(cskia_test tests/test_libskia.c include/skia.h)
TARGET_LINK_LIBRARIES(cskia_test cskia)

SET_TARGET_PROPERTIES(cskia_test PROPERTIES COMPILE_DEFINITIONS "${SKIA_COMPILE_DEFS}")
SET_TARGET_PROPERTIES(cskia_test PROPERTIES LINK_FLAGS "${SKIA_LINK_FLAGS}")

{'fraction_non_alphanumeric': 0.11293769521617623, 'fraction_numerical': 0.004931777083675818, 'mean_word_length': 8.875811688311689, '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': '1945440', 'n_tokens_mistral': 5365, 'n_tokens_neox': 5061, 'n_words': 795}