<commit_before>cmake_minimum_required(VERSION 3.2)

project(yara C)

set(PACKAGE "yara")
set(VERSION_MAJOR 3)
set(VERSION_MINOR 5)
set(VERSION_PATCH 0)
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(PACKAGE_VERSION ${VERSION})
set(PACKAGE_URL "")
set(PACKAGE_TARNAME ${PACKAGE})
set(PACKAGE_STRING "${PACKAGE} ${PACKAGE_VERSION}")
set(PACKAGE_NAME ${PACKAGE})
set(PACKAGE_BUGREPORT "<EMAIL>")

macro(yara_option OPTION_NAME OPTION_TEXT OPTION_DEFAULT)
    option(${OPTION_NAME} ${OPTION_TEXT} ${OPTION_DEFAULT})
    if(DEFINED ENV{${OPTION_NAME}})
        set(${OPTION_NAME} $ENV{${OPTION_NAME}})
    endif()
    if(${OPTION_NAME})
        add_definitions(-D${OPTION_NAME})
    endif()
    message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}")
endmacro()

macro(yara_nodef_option OPTION_NAME OPTION_TEXT OPTION_DEFAULT)
    option(${OPTION_NAME} ${OPTION_TEXT} ${OPTION_DEFAULT})
    message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}")
endmacro()

macro(yara_append_library LIST_NAME OPTION_NAME LIBRARY_NAME)
    if(${OPTION_NAME})
        list(APPEND ${LIST_NAME} ${${LIBRARY_NAME}})
    else()
        message(FATAL_ERROR "Missing ${LIBRARY_NAME} library")
    endif()
endmacro()


message(STATUS "Yara CMake Options")
message(STATUS "===================================================")
yara_nodef_option(LIBYARA_SHARED "Build libyara as shared library" OFF)
yara_option(HASH_MODULE "Build with Hash Module" ON)
yara_option(CUCKOO_MODULE "Build with Cuckoo Module" OFF)
yara_option(MAGIC_MODULE "Build with Magic Module" OFF)
yara_option(DOTNET_MODULE "Build with Dotnet Module" ON)
yara_nodef_option(BUILD_TESTS "Build Yara tests" OFF)
yara_nodef_option(BUILD_EXECUTABLE "Build Yara executable" ON)
yara_nodef_option(BUILD_COMPILER "Build Yara compiler" ON)
yara_option(PROFILING_ENABLED "Enable profiling support" OFF)
yara_option(DMALLOC "Enable dmalloc to debug heap-related issues" OFF)
yara_nodef_option(YARA_PACKAGE_RPM "When packaging, package Yara binaries into RPM" ON)
message(STATUS "===================================================")

set(LIBYARA_INCLUDES "")
set(LIBYARA_LIBRARIES "")

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
yara_append_library(LIBYARA_LIBRARIES CMAKE_THREAD_LIBS_INIT CMAKE_THREAD_LIBS_INIT)
set(HAVE_PTHREAD 1)

find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
set(YYTEXT_POINTER 1)

if(HASH_MODULE)
    if(NOT OPENSSL_FOUND)
        find_package(OpenSSL REQUIRED)
    endif()
    list(APPEND LIBYARA_INCLUDES ${OPENSSL_INCLUDES})
    yara_append_library(LIBYARA_LIBRARIES OPENSSL_FOUND OPENSSL_LIBRARIES)
    set(HAVE_LIBCRYPTO 1)
endif()

include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckLibraryExists)

CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H)
CHECK_INCLUDE_FILES(memory.h HAVE_MEMORY_H)
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H)
CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)
CHECK_INCLUDE_FILES(string.h HAVE_STRING_H)
CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
CHECK_FUNCTION_EXISTS(strlcpy HAVE_STRLCPY)
CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
CHECK_FUNCTION_EXISTS(memmem HAVE_MEMMEM)
CHECK_FUNCTION_EXISTS(timegm HAVE_TIMEGM)

CHECK_LIBRARY_EXISTS(m isnan "" HAVE_LIBM)
if(HAVE_LIBM)
    CHECK_LIBRARY_EXISTS(m log2 "" HAVE_LIBM)
endif()
if(NOT HAVE_LIBM)
    message(FATAL_ERROR "Missing m library")
endif()
list(APPEND LIBYARA_LIBRARIES m)

if(DMALLOC)
    CHECK_LIBRARY_EXISTS(dmalloc dmalloc_malloc "" HAVE_LIBDMALLOC)
    yara_append_library(LIBYARA_LIBRARIES HAVE_LIBDMALLOC dmalloc)
endif()

if(CUCKOO_MODULE)
    CHECK_LIBRARY_EXISTS(jansson json_loadb "" HAVE_LIBJANSSON)
    yara_append_library(LIBYARA_LIBRARIES HAVE_LIBJANSSON jansson)
endif()

if(MAGIC_MODULE)
    CHECK_LIBRARY_EXISTS(magic magic_open "" HAVE_LIBMAGIC)
    yara_append_library(LIBYARA_LIBRARIES HAVE_LIBMAGIC magic)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in.cmake
               ${CMAKE_CURRENT_BINARY_DIR}/config.h)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

add_definitions(-DHAVE_CONFIG_H)

add_subdirectory(libyara)

set(YARA_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/libyara/include
    CACHE PATH "Yara include directory")

include_directories(${YARA_INCLUDES})

if (BUILD_TESTS)
    enable_testing()
    add_subdirectory(tests)
endif()

if(BUILD_EXECUTABLE)
    set(YARA_SOURCES args.c threading.c yara.c)
    add_executable(yara ${YARA_SOURCES})
    target_link_libraries(yara libyara)
    install(TARGETS yara DESTINATION bin)
endif()

if(BUILD_COMPILER)
    set(YARAC_SOURCES args.c yarac.c)
    add_executable(yarac ${YARAC_SOURCES})
    target_link_libraries(yarac libyara)
    install(TARGETS yarac DESTINATION bin)
endif()

set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_PACKAGE_NAME ${PACKAGE_NAME})
set(CPACK_PACKAGE_VENDOR "")

if(YARA_PACKAGE_RPM)
    find_program(RPMBUILD NAMES rpmbuild PATHS "/usr/bin" "/usr/local/bin")
    if(RPMBUILD)
        set(RPMBUILD_FOUND ON)
        get_filename_component(RPMBUILD_PATH ${RPMBUILD} ABSOLUTE)
        message(STATUS "Found rpmbuild: ${RPMBUILD_PATH}")
    else()
        set(RPMBUILD_FOUND OFF)
        message(WARNING "Couldn't find rpmbuild")
    endif()

    if(RPMBUILD_FOUND)
        set(CPACK_GENERATOR RPM)
        set(CPACK_RPM_PACKAGE_SUMMARY "Yara")
    else()
        message(WARNING "Couldn't build RPM package")<commit_msg>Renamed some options to have YARA_* prefix.<commit_after>cmake_minimum_required(VERSION 3.2)

project(yara C)

set(PACKAGE "yara")
set(VERSION_MAJOR 3)
set(VERSION_MINOR 5)
set(VERSION_PATCH 0)
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(PACKAGE_VERSION ${VERSION})
set(PACKAGE_URL "")
set(PACKAGE_TARNAME ${PACKAGE})
set(PACKAGE_STRING "${PACKAGE} ${PACKAGE_VERSION}")
set(PACKAGE_NAME ${PACKAGE})
set(PACKAGE_BUGREPORT "<EMAIL>")

macro(yara_option OPTION_NAME OPTION_TEXT OPTION_DEFAULT)
    option(${OPTION_NAME} ${OPTION_TEXT} ${OPTION_DEFAULT})
    if(DEFINED ENV{${OPTION_NAME}})
        set(${OPTION_NAME} $ENV{${OPTION_NAME}})
    endif()
    if(${OPTION_NAME})
        add_definitions(-D${OPTION_NAME})
    endif()
    message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}")
endmacro()

macro(yara_nodef_option OPTION_NAME OPTION_TEXT OPTION_DEFAULT)
    option(${OPTION_NAME} ${OPTION_TEXT} ${OPTION_DEFAULT})
    message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}")
endmacro()

macro(yara_append_library LIST_NAME OPTION_NAME LIBRARY_NAME)
    if(${OPTION_NAME})
        list(APPEND ${LIST_NAME} ${${LIBRARY_NAME}})
    else()
        message(FATAL_ERROR "Missing ${LIBRARY_NAME} library")
    endif()
endmacro()


message(STATUS "Yara CMake Options")
message(STATUS "===================================================")
yara_nodef_option(LIBYARA_SHARED "Build libyara as shared library" OFF)
yara_option(HASH_MODULE "Build with Hash Module" ON)
yara_option(CUCKOO_MODULE "Build with Cuckoo Module" OFF)
yara_option(MAGIC_MODULE "Build with Magic Module" OFF)
yara_option(DOTNET_MODULE "Build with Dotnet Module" ON)
yara_nodef_option(YARA_BUILD_TESTS "Build Yara tests" OFF)
yara_nodef_option(YARA_BUILD_EXECUTABLE "Build Yara executable" ON)
yara_nodef_option(YARA_BUILD_COMPILER "Build Yara compiler" ON)
yara_option(PROFILING_ENABLED "Enable profiling support" OFF)
yara_option(DMALLOC "Enable dmalloc to debug heap-related issues" OFF)
yara_nodef_option(YARA_PACKAGE_RPM "When packaging, package Yara binaries into RPM" ON)
message(STATUS "===================================================")

set(LIBYARA_INCLUDES "")
set(LIBYARA_LIBRARIES "")

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
yara_append_library(LIBYARA_LIBRARIES CMAKE_THREAD_LIBS_INIT CMAKE_THREAD_LIBS_INIT)
set(HAVE_PTHREAD 1)

find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
set(YYTEXT_POINTER 1)

if(HASH_MODULE)
    if(NOT OPENSSL_FOUND)
        find_package(OpenSSL REQUIRED)
    endif()
    list(APPEND LIBYARA_INCLUDES ${OPENSSL_INCLUDES})
    yara_append_library(LIBYARA_LIBRARIES OPENSSL_FOUND OPENSSL_LIBRARIES)
    set(HAVE_LIBCRYPTO 1)
endif()

include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckLibraryExists)

CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H)
CHECK_INCLUDE_FILES(memory.h HAVE_MEMORY_H)
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H)
CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)
CHECK_INCLUDE_FILES(string.h HAVE_STRING_H)
CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
CHECK_FUNCTION_EXISTS(strlcpy HAVE_STRLCPY)
CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
CHECK_FUNCTION_EXISTS(memmem HAVE_MEMMEM)
CHECK_FUNCTION_EXISTS(timegm HAVE_TIMEGM)

CHECK_LIBRARY_EXISTS(m isnan "" HAVE_LIBM)
if(HAVE_LIBM)
    CHECK_LIBRARY_EXISTS(m log2 "" HAVE_LIBM)
endif()
if(NOT HAVE_LIBM)
    message(FATAL_ERROR "Missing m library")
endif()
list(APPEND LIBYARA_LIBRARIES m)

if(DMALLOC)
    CHECK_LIBRARY_EXISTS(dmalloc dmalloc_malloc "" HAVE_LIBDMALLOC)
    yara_append_library(LIBYARA_LIBRARIES HAVE_LIBDMALLOC dmalloc)
endif()

if(CUCKOO_MODULE)
    CHECK_LIBRARY_EXISTS(jansson json_loadb "" HAVE_LIBJANSSON)
    yara_append_library(LIBYARA_LIBRARIES HAVE_LIBJANSSON jansson)
endif()

if(MAGIC_MODULE)
    CHECK_LIBRARY_EXISTS(magic magic_open "" HAVE_LIBMAGIC)
    yara_append_library(LIBYARA_LIBRARIES HAVE_LIBMAGIC magic)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in.cmake
               ${CMAKE_CURRENT_BINARY_DIR}/config.h)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

add_definitions(-DHAVE_CONFIG_H)

add_subdirectory(libyara)

set(YARA_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/libyara/include
    CACHE PATH "Yara include directory")

include_directories(${YARA_INCLUDES})

if (YARA_BUILD_TESTS)
    enable_testing()
    add_subdirectory(tests)
endif()

if(YARA_BUILD_EXECUTABLE)
    set(YARA_SOURCES args.c threading.c yara.c)
    add_executable(yara ${YARA_SOURCES})
    target_link_libraries(yara libyara)
    install(TARGETS yara DESTINATION bin)
endif()

if(YARA_BUILD_COMPILER)
    set(YARAC_SOURCES args.c yarac.c)
    add_executable(yarac ${YARAC_SOURCES})
    target_link_libraries(yarac libyara)
    install(TARGETS yarac DESTINATION bin)
endif()

set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_PACKAGE_NAME ${PACKAGE_NAME})
set(CPACK_PACKAGE_VENDOR "")

if(YARA_PACKAGE_RPM)
    find_program(RPMBUILD NAMES rpmbuild PATHS "/usr/bin" "/usr/local/bin")
    if(RPMBUILD)
        set(RPMBUILD_FOUND ON)
        get_filename_component(RPMBUILD_PATH ${RPMBUILD} ABSOLUTE)
        message(STATUS "Found rpmbuild: ${RPMBUILD_PATH}")
    else()
        set(RPMBUILD_FOUND OFF)
        message(WARNING "Couldn't find rpmbuild")
    endif()

    if(RPMBUILD_FOUND)
        set(CPACK_GENERATOR RPM)
        set(CPACK_RPM_PACKAGE_SUMMARY "Yara")
    else()
        message(WARNING "Couldn't build RPM package")
{'fraction_non_alphanumeric': 0.11531811894882435, 'fraction_numerical': 0.0015560165975103733, 'mean_word_length': 7.124297752808989, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1492381', 'n_tokens_mistral': 4570, 'n_tokens_neox': 4307, 'n_words': 693}