<commit_before>cmake_minimum_required(VERSION 2.8.11)

project(Zopfli)

# Check if being built standalone
set(zopfli_standalone FALSE)
get_directory_property(zopfli_parent_directory PARENT_DIRECTORY)
if("${zopfli_parent_directory}" STREQUAL "")
  set(zopfli_standalone TRUE)
endif()
unset(zopfli_parent_directory)

#
# Options
#

# Default to BUILD_SHARED_LIBS if set, but allow overriding it
set(zopfli_shared_default OFF)
if(DEFINED BUILD_SHARED_LIBS)
  set(zopfli_shared_default ${BUILD_SHARED_LIBS})
endif()
option(ZOPFLI_BUILD_SHARED "Build Zopfli with shared libraries" ${zopfli_shared_default})
unset(zopfli_shared_default)

# If standalone or shared subproject, default to building install
if(zopfli_standalone OR ZOPFLI_BUILD_SHARED)
  option(ZOPFLI_BUILD_INSTALL "Add Zopfli install target" ON)
else()
  option(ZOPFLI_BUILD_INSTALL "Add Zopfli install target" OFF)
endif()

#
# Library version
#
set(ZOPFLI_VERSION_MAJOR 1)
set(ZOPFLI_VERSION_MINOR 0)
set(ZOPFLI_VERSION_PATCH 2)
set(ZOPFLI_VERSION "${ZOPFLI_VERSION_MAJOR}.${ZOPFLI_VERSION_MINOR}.${ZOPFLI_VERSION_PATCH}")

if(zopfli_standalone)
  if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
    message(STATUS "Zopfli build type is default (CMAKE_BUILD_TYPE empty)")
  endif()
endif()

if(ZOPFLI_BUILD_SHARED)
  set(zopfli_library_type SHARED)
else()
  set(zopfli_library_type STATIC)
endif()

set(zopflilib_src
  src/zopfli/blocksplitter.c
  src/zopfli/cache.c
  src/zopfli/deflate.c
  src/zopfli/gzip_container.c
  src/zopfli/hash.c
  src/zopfli/katajainen.c
  src/zopfli/lz77.c
  src/zopfli/squeeze.c
  src/zopfli/tree.c
  src/zopfli/util.c
  src/zopfli/zlib_container.c
  src/zopfli/zopfli_lib.c
)

set(zopflipnglib_src
  src/zopflipng/zopflipng_lib.cc
)

set (lodepng_src
  src/zopflipng/lodepng/lodepng.cpp
  src/zopflipng/lodepng/lodepng_util.cpp
)

#
# libzopfli object files shared by both libraries
#
add_library(zopflilib_obj OBJECT
  ${zopflilib_src}
)
if(ZOPFLI_BUILD_SHARED)
  set_property(TARGET zopflilib_obj PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()

#
# libzopfli
#
add_library(libzopfli ${zopfli_library_type}
  $<TARGET_OBJECTS:zopflilib_obj>
)
target_include_directories(libzopfli INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src/zopfli")
set_target_properties(libzopfli PROPERTIES
  OUTPUT_NAME zopfli
  VERSION ${ZOPFLI_VERSION}
  SOVERSION ${ZOPFLI_VERSION_MAJOR}
)
if(UNIX)
  target_link_libraries(libzopfli m)
endif()

#
# libzopflipng
#
add_library(libzopflipng ${zopfli_library_type}
  ${zopflipnglib_src}
  ${lodepng_src}
  $<TARGET_OBJECTS:zopflilib_obj>
)
target_include_directories(libzopflipng INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src/zopflipng")
set_target_properties(libzopflipng PROPERTIES
  OUTPUT_NAME zopflipng
  VERSION ${ZOPFLI_VERSION}
  SOVERSION ${ZOPFLI_VERSION_MAJOR}
)

#
# zopfli
#
add_executable(zopfli src/zopfli/zopfli_bin.c)
target_link_libraries(zopfli libzopfli)
if(MSVC)
  target_compile_definitions(zopfli PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

#
# zopflipng
#
add_executable(zopflipng src/zopflipng/zopflipng_bin.cc)
target_link_libraries(zopflipng libzopflipng)
if(MSVC)
  target_compile_definitions(zopflipng PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

#
# Install
#
if(ZOPFLI_BUILD_INSTALL)
  include(GNUInstallDirs)
  install(TARGETS libzopfli libzopflipng zopfli zopflipng
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  )
  install(FILES include/zopfli.h include/zopflipng_lib.h
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  )
endif()
<commit_msg>Add workaround for MSVC building DLL<commit_after>cmake_minimum_required(VERSION 2.8.11)

project(Zopfli)

# Check if being built standalone
set(zopfli_standalone FALSE)
get_directory_property(zopfli_parent_directory PARENT_DIRECTORY)
if("${zopfli_parent_directory}" STREQUAL "")
  set(zopfli_standalone TRUE)
endif()
unset(zopfli_parent_directory)

#
# Options
#

# Default to BUILD_SHARED_LIBS if set, but allow overriding it
set(zopfli_shared_default OFF)
if(DEFINED BUILD_SHARED_LIBS)
  set(zopfli_shared_default ${BUILD_SHARED_LIBS})
endif()
option(ZOPFLI_BUILD_SHARED "Build Zopfli with shared libraries" ${zopfli_shared_default})
unset(zopfli_shared_default)

# If standalone or shared subproject, default to building install
if(zopfli_standalone OR ZOPFLI_BUILD_SHARED)
  option(ZOPFLI_BUILD_INSTALL "Add Zopfli install target" ON)
else()
  option(ZOPFLI_BUILD_INSTALL "Add Zopfli install target" OFF)
endif()

#
# Library version
#
set(ZOPFLI_VERSION_MAJOR 1)
set(ZOPFLI_VERSION_MINOR 0)
set(ZOPFLI_VERSION_PATCH 2)
set(ZOPFLI_VERSION "${ZOPFLI_VERSION_MAJOR}.${ZOPFLI_VERSION_MINOR}.${ZOPFLI_VERSION_PATCH}")

if(zopfli_standalone)
  if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
    message(STATUS "Zopfli build type is default (CMAKE_BUILD_TYPE empty)")
  endif()
endif()

if(ZOPFLI_BUILD_SHARED)
  set(zopfli_library_type SHARED)
else()
  set(zopfli_library_type STATIC)
endif()

set(zopflilib_src
  src/zopfli/blocksplitter.c
  src/zopfli/cache.c
  src/zopfli/deflate.c
  src/zopfli/gzip_container.c
  src/zopfli/hash.c
  src/zopfli/katajainen.c
  src/zopfli/lz77.c
  src/zopfli/squeeze.c
  src/zopfli/tree.c
  src/zopfli/util.c
  src/zopfli/zlib_container.c
  src/zopfli/zopfli_lib.c
)

set(zopflipnglib_src
  src/zopflipng/zopflipng_lib.cc
)

set (lodepng_src
  src/zopflipng/lodepng/lodepng.cpp
  src/zopflipng/lodepng/lodepng_util.cpp
)

#
# libzopfli object files shared by both libraries
#
add_library(zopflilib_obj OBJECT
  ${zopflilib_src}
)
if(ZOPFLI_BUILD_SHARED)
  set_property(TARGET zopflilib_obj PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()

#
# libzopfli
#
add_library(libzopfli ${zopfli_library_type}
  $<TARGET_OBJECTS:zopflilib_obj>
)
target_include_directories(libzopfli INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src/zopfli")
set_target_properties(libzopfli PROPERTIES
  OUTPUT_NAME zopfli
  VERSION ${ZOPFLI_VERSION}
  SOVERSION ${ZOPFLI_VERSION_MAJOR}
)
if(UNIX)
  target_link_libraries(libzopfli m)
endif()

#
# libzopflipng
#
add_library(libzopflipng ${zopfli_library_type}
  ${zopflipnglib_src}
  ${lodepng_src}
  $<TARGET_OBJECTS:zopflilib_obj>
)
target_include_directories(libzopflipng INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src/zopflipng")
set_target_properties(libzopflipng PROPERTIES
  OUTPUT_NAME zopflipng
  VERSION ${ZOPFLI_VERSION}
  SOVERSION ${ZOPFLI_VERSION_MAJOR}
)

# MSVC does not export symbols by default when building a DLL, this is a
# workaround for recent versions of CMake
if(MSVC AND ZOPFLI_BUILD_SHARED)
  if(CMAKE_VERSION VERSION_LESS 3.4)
    message(WARNING "Automatic export of all symbols to DLL not supported until CMake 3.4")
  else()
    set_target_properties(libzopfli PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
    set_target_properties(libzopflipng PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
  endif()
endif()

#
# zopfli
#
add_executable(zopfli src/zopfli/zopfli_bin.c)
target_link_libraries(zopfli libzopfli)
if(MSVC)
  target_compile_definitions(zopfli PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

#
# zopflipng
#
add_executable(zopflipng src/zopflipng/zopflipng_bin.cc)
target_link_libraries(zopflipng libzopflipng)
if(MSVC)
  target_compile_definitions(zopflipng PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

#
# Install
#
if(ZOPFLI_BUILD_INSTALL)
  include(GNUInstallDirs)
  install(TARGETS libzopfli libzopflipng zopfli zopflipng
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  )
  install(FILES include/zopfli.h include/zopflipng_lib.h
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  )
endif()

{'fraction_non_alphanumeric': 0.08549797676543532, 'fraction_numerical': 0.0028716877692207283, 'mean_word_length': 6.939896373056995, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4574443', 'n_tokens_mistral': 3391, 'n_tokens_neox': 3148, 'n_words': 489}