<commit_before>cmake_minimum_required(VERSION 3.1)
include(ExternalProject)


set(Python_ADDITIONAL_VERSIONS 2.7 2.7.6 3.4 3.5 3.6 3.7)
if (NOT ${PYTHON_VERSION} STREQUAL "")
  find_package(PythonLibs ${PYTHON_VERSION} EXACT)

  if (NOT PythonLibs_FOUND)
    find_package(PythonLibs ${PYTHON_VERSION})
  endif()

  set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}")
  if (NOT PythonLibs_FOUND)
    # WARNING: DIRTY HACK
    # ^^^^^^^^^^^^^^^^^^^
    if ((${PYTHON_VERSION} VERSION_GREATER "3") OR (${PYTHON_VERSION} VERSION_EQUAL "3"))
      if (UNIX)
        set(PYTHON_LIBRARY /usr/lib/libpython${PYTHON_VERSION}.so)
        if(EXISTS "/usr/include/python${PYTHON_VERSION}" AND IS_DIRECTORY "/usr/include/python${PYTHON_VERSION}")
          set(PYTHON_INCLUDE_DIR /usr/include/python${PYTHON_VERSION})
          set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}")
        elseif(EXISTS "/usr/include/python${PYTHON_VERSION}m" AND IS_DIRECTORY "/usr/include/python${PYTHON_VERSION}m")
          set(PYTHON_INCLUDE_DIR /usr/include/python${PYTHON_VERSION}m)
          set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}m")
        endif()
      endif()
    endif()
  endif()
else()
  find_package(PythonLibs REQUIRED)
endif()


message(STATUS "Python version: ${PYTHONLIBS_VERSION_STRING}")
message(STATUS "Python lib:     ${PYTHON_LIBRARY}")
message(STATUS "Python include: ${PYTHON_INCLUDE_DIR}")


set(PYBIND11_GIT_URL "https://github.com/pybind/pybind11.git" CACHE STRING "URL to the Pybind11 repo")
ExternalProject_Add(pybind11
  GIT_REPOSITORY ${PYBIND11_GIT_URL}
  GIT_TAG           v2.1.0
  CONFIGURE_COMMAND ""
  BUILD_COMMAND     ""
  INSTALL_COMMAND   "")
ExternalProject_get_property(pybind11 SOURCE_DIR)
set(PYBIND11_SOURCE_DIR "${SOURCE_DIR}")


# Define source files
set(LIEF_PYTHON_SRC
  "${CMAKE_CURRENT_SOURCE_DIR}/pyLIEF.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/pyUtils.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/pyJson.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/pyIterators.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/pyExceptions.cpp"

  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/init.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyBinary.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyHeader.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pySection.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyParser.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pySymbol.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/pyEnums.cpp"
)


add_library(pyLIEF SHARED ${LIEF_PYTHON_SRC})


target_include_directories(pyLIEF PUBLIC
  "${CMAKE_CURRENT_SOURCE_DIR}/"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract"
  "${PYTHON_INCLUDE_DIR}"
  "${PYBIND11_SOURCE_DIR}/include")

add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)

if(LIEF_ELF)
  include("${CMAKE_CURRENT_SOURCE_DIR}/ELF/CMakeLists.txt")
endif()

if(LIEF_PE)
  include("${CMAKE_CURRENT_SOURCE_DIR}/PE/CMakeLists.txt")
endif()

if(LIEF_MACHO)
  include("${CMAKE_CURRENT_SOURCE_DIR}/MachO/CMakeLists.txt")
endif()


target_compile_features(pyLIEF PRIVATE cxx_attribute_deprecated)

set_property(TARGET pyLIEF PROPERTY CXX_STANDARD          11)
set_property(TARGET pyLIEF PROPERTY CXX_STANDARD_REQUIRED ON)

if (MSVC)
  target_compile_options(pyLIEF PUBLIC /FIiso646.h)
	set_property(TARGET pyLIEF PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT)
endif()

set_target_properties(pyLIEF PROPERTIES PYTHON_VERSION ${PYTHONLIBS_VERSION_STRING})
set(PYLIEF_DEPS_LIBRARIES LIB_LIEF_STATIC)

if(LIEF_COVERAGE)
  target_compile_options(pyLIEF PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage)
  set(PYLIEF_DEPS_LIBRARIES ${PYLIEF_DEPS_LIBRARIES} gcov)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  target_compile_options(pyLIEF PRIVATE -Wall -Wextra -Wpedantic -Wno-macro-redefined)
endif()

set_target_properties(pyLIEF PROPERTIES PREFIX "" OUTPUT_NAME "lief")
add_dependencies(pyLIEF pybind11)

if(APPLE)
    set_target_properties(pyLIEF PROPERTIES MACOSX_RPATH ".")<commit_msg>Disable '-Wno-macro-redefined' when not available<commit_after>cmake_minimum_required(VERSION 3.1)
include(ExternalProject)
include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)


set(Python_ADDITIONAL_VERSIONS 2.7 2.7.6 3.4 3.5 3.6 3.7)
if (NOT ${PYTHON_VERSION} STREQUAL "")
  find_package(PythonLibs ${PYTHON_VERSION} EXACT)

  if (NOT PythonLibs_FOUND)
    find_package(PythonLibs ${PYTHON_VERSION})
  endif()

  set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}")
  if (NOT PythonLibs_FOUND)
    # WARNING: DIRTY HACK
    # ^^^^^^^^^^^^^^^^^^^
    if ((${PYTHON_VERSION} VERSION_GREATER "3") OR (${PYTHON_VERSION} VERSION_EQUAL "3"))
      if (UNIX)
        set(PYTHON_LIBRARY /usr/lib/libpython${PYTHON_VERSION}.so)
        if(EXISTS "/usr/include/python${PYTHON_VERSION}" AND IS_DIRECTORY "/usr/include/python${PYTHON_VERSION}")
          set(PYTHON_INCLUDE_DIR /usr/include/python${PYTHON_VERSION})
          set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}")
        elseif(EXISTS "/usr/include/python${PYTHON_VERSION}m" AND IS_DIRECTORY "/usr/include/python${PYTHON_VERSION}m")
          set(PYTHON_INCLUDE_DIR /usr/include/python${PYTHON_VERSION}m)
          set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}m")
        endif()
      endif()
    endif()
  endif()
else()
  find_package(PythonLibs REQUIRED)
endif()


message(STATUS "Python version: ${PYTHONLIBS_VERSION_STRING}")
message(STATUS "Python lib:     ${PYTHON_LIBRARY}")
message(STATUS "Python include: ${PYTHON_INCLUDE_DIR}")


set(PYBIND11_GIT_URL "https://github.com/pybind/pybind11.git" CACHE STRING "URL to the Pybind11 repo")
ExternalProject_Add(pybind11
  GIT_REPOSITORY ${PYBIND11_GIT_URL}
  GIT_TAG           v2.1.0
  CONFIGURE_COMMAND ""
  BUILD_COMMAND     ""
  INSTALL_COMMAND   "")
ExternalProject_get_property(pybind11 SOURCE_DIR)
set(PYBIND11_SOURCE_DIR "${SOURCE_DIR}")


# Define source files
set(LIEF_PYTHON_SRC
  "${CMAKE_CURRENT_SOURCE_DIR}/pyLIEF.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/pyUtils.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/pyJson.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/pyIterators.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/pyExceptions.cpp"

  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/init.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyBinary.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyHeader.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pySection.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyParser.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pySymbol.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract/pyEnums.cpp"
)


add_library(pyLIEF SHARED ${LIEF_PYTHON_SRC})


target_include_directories(pyLIEF PUBLIC
  "${CMAKE_CURRENT_SOURCE_DIR}/"
  "${CMAKE_CURRENT_SOURCE_DIR}/Abstract"
  "${PYTHON_INCLUDE_DIR}"
  "${PYBIND11_SOURCE_DIR}/include")

add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)

if(LIEF_ELF)
  include("${CMAKE_CURRENT_SOURCE_DIR}/ELF/CMakeLists.txt")
endif()

if(LIEF_PE)
  include("${CMAKE_CURRENT_SOURCE_DIR}/PE/CMakeLists.txt")
endif()

if(LIEF_MACHO)
  include("${CMAKE_CURRENT_SOURCE_DIR}/MachO/CMakeLists.txt")
endif()


target_compile_features(pyLIEF PRIVATE cxx_attribute_deprecated)

set_property(TARGET pyLIEF PROPERTY CXX_STANDARD          11)
set_property(TARGET pyLIEF PROPERTY CXX_STANDARD_REQUIRED ON)

if (MSVC)
  target_compile_options(pyLIEF PUBLIC /FIiso646.h)
	set_property(TARGET pyLIEF PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT)
endif()

set_target_properties(pyLIEF PROPERTIES PYTHON_VERSION ${PYTHONLIBS_VERSION_STRING})
set(PYLIEF_DEPS_LIBRARIES LIB_LIEF_STATIC)

if(LIEF_COVERAGE)
  target_compile_options(pyLIEF PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage)
  set(PYLIEF_DEPS_LIBRARIES ${PYLIEF_DEPS_LIBRARIES} gcov)
endif()

set(PYLIEF_COMPILE_FLAGS)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  CHECK_CXX_COMPILER_FLAG("-Wno-macro-redefined" HAS_NO_MACRO_REDEFINED)
  set(PYLIEF_COMPILE_FLAGS ${PYLIEF_COMPILE_FLAGS} -Wall -Wextra -Wpedantic)
  if (HAS_NO_MACRO_REDEFINED)
    set(PYLIEF_COMPILE_FLAGS ${PYLIEF_COMPILE_FLAGS} -Wno-macro-redefined)
  endif()

  target_compile_options(pyLIEF PRIVATE ${PYLIEF_COMPILE_FLAGS})
endif()

set_target_properties(pyLIEF PROPERTIES PREFIX "" OUTPUT_NAME "lief")
add_dependencies(pyLIEF pybind11)

if(APPLE)
    set_target_properties(pyLIEF PROPERTIES MACOSX_RPATH ".")
{'fraction_non_alphanumeric': 0.12098411560969784, 'fraction_numerical': 0.010509972530753612, 'mean_word_length': 6.256499133448873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5076933', 'n_tokens_mistral': 3366, 'n_tokens_neox': 3273, 'n_words': 423}