<commit_before>cmake_minimum_required(VERSION 2.8.8)
project(hipify-clang)

if (PARENT_SCOPE)
    set(BUILD_HIPIFY_CLANG 0 PARENT_SCOPE)
endif()

# Find LLVM package
find_package(LLVM 3.8 QUIET PATHS ${HIPIFY_CLANG_LLVM_DIR} NO_DEFAULT_PATH)
if (NOT ${LLVM_FOUND})
    find_package(LLVM 3.9 QUIET PATHS ${HIPIFY_CLANG_LLVM_DIR} NO_DEFAULT_PATH)
    if (NOT ${LLVM_FOUND})
        message(STATUS "hipify-clang will not be built. To build it please specify absolute path to LLVM 3.8 or LLVM 3.9 package/dist using -DHIPIFY_CLANG_LLVM_DIR")
    endif()
endif()

if (${LLVM_FOUND})
    list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR})
    include(AddLLVM)

    message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")

    include_directories(${LLVM_INCLUDE_DIRS})
    link_directories(${LLVM_LIBRARY_DIRS})
    add_definitions(${LLVM_DEFINITIONS})
    add_llvm_executable(hipify-clang src/Cuda2Hip.cpp)

    set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++)
    set(CMAKE_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)

    # Link against LLVM and CLANG libraries
    target_link_libraries(hipify-clang
        clangASTMatchers
        clangFrontend
        clangTooling
        clangParse
        clangSerialization
        clangSema
        clangEdit
        clangFormat
        clangLex
        clangAnalysis
        clangDriver
        clangAST
        clangToolingCore
        clangRewrite
        clangBasic
        LLVMProfileData
        LLVMSupport
        LLVMMCParser
        LLVMMC
        LLVMBitReader
        LLVMOption
        LLVMCore)

    if(WIN32)
        target_link_libraries(hipify-clang version)
    endif()

    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
    if(MSVC)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR- /EHs- /EHc-")
        set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} /SUBSYSTEM:WINDOWS")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -fno-rtti -fvisibility-inlines-hidden")
    endif()

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHIPIFY_CLANG_RES=\\\"${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}\\\"")

    install(TARGETS hipify-clang DESTINATION bin)

    if (HIPIFY_CLANG_TESTS)
        # tests
        set(Python_ADDITIONAL_VERSIONS 2.7)
        include(FindPythonInterp)
        if(NOT PYTHONINTERP_FOUND)
            message(FATAL_ERROR
                "Unable to find Python interpreter, required for builds and testing.\n\n"
                "Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
        endif()

        find_program(LIT_COMMAND lit)

        set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

        configure_file(
            ${CMAKE_SOURCE_DIR}/tests/hipify-clang/lit.site.cfg.in
            ${CMAKE_CURRENT_BINARY_DIR}/tests/hipify-clang/lit.site.cfg
            @ONLY)

        add_lit_testsuite(test-hipify "Running HIPify regression tests"
            ${CMAKE_SOURCE_DIR}/tests/hipify-clang
            PARAMS site_config=${CMAKE_CURRENT_BINARY_DIR}/tests/hipify-clang/lit.site.cfg
            DEPENDS hipify-clang lit
            )

        add_custom_target(test-hipify-clang)
        add_dependencies(test-hipify-clang test-hipify)
        set_target_properties(test-hipify-clang PROPERTIES FOLDER "Tests")
    endif()

    if (PARENT_SCOPE)
        set(BUILD_HIPIFY_CLANG 1 PARENT_SCOPE)
    endif()
endif()<commit_msg>Use early return to avoid indenting all of CMakeLists.txt<commit_after>cmake_minimum_required(VERSION 2.8.8)
project(hipify-clang)

if (PARENT_SCOPE)
    set(BUILD_HIPIFY_CLANG 0 PARENT_SCOPE)
endif()

# Find LLVM package
find_package(LLVM 3.8 QUIET PATHS ${HIPIFY_CLANG_LLVM_DIR} NO_DEFAULT_PATH)
if (NOT ${LLVM_FOUND})
    find_package(LLVM 3.9 QUIET PATHS ${HIPIFY_CLANG_LLVM_DIR} NO_DEFAULT_PATH)
    if (NOT ${LLVM_FOUND})
        message(STATUS "hipify-clang will not be built. To build it please specify absolute path to LLVM 3.8 or LLVM 3.9 package/dist using -DHIPIFY_CLANG_LLVM_DIR")
        return()
    endif()
endif()

list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR})
include(AddLLVM)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")

include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
add_definitions(${LLVM_DEFINITIONS})
add_llvm_executable(hipify-clang src/Cuda2Hip.cpp)

set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++)
set(CMAKE_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)

# Link against LLVM and CLANG libraries
target_link_libraries(hipify-clang
    clangASTMatchers
    clangFrontend
    clangTooling
    clangParse
    clangSerialization
    clangSema
    clangEdit
    clangFormat
    clangLex
    clangAnalysis
    clangDriver
    clangAST
    clangToolingCore
    clangRewrite
    clangBasic
    LLVMProfileData
    LLVMSupport
    LLVMMCParser
    LLVMMC
    LLVMBitReader
    LLVMOption
    LLVMCore)

if(WIN32)
    target_link_libraries(hipify-clang version)
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
if(MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR- /EHs- /EHc-")
    set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} /SUBSYSTEM:WINDOWS")
else()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -fno-rtti -fvisibility-inlines-hidden")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHIPIFY_CLANG_RES=\\\"${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}\\\"")

install(TARGETS hipify-clang DESTINATION bin)

if (HIPIFY_CLANG_TESTS)
    # tests
    set(Python_ADDITIONAL_VERSIONS 2.7)
    include(FindPythonInterp)
    if(NOT PYTHONINTERP_FOUND)
        message(FATAL_ERROR
            "Unable to find Python interpreter, required for builds and testing.\n\n"
            "Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
    endif()

    find_program(LIT_COMMAND lit)

    set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

    configure_file(
        ${CMAKE_SOURCE_DIR}/tests/hipify-clang/lit.site.cfg.in
        ${CMAKE_CURRENT_BINARY_DIR}/tests/hipify-clang/lit.site.cfg
        @ONLY)

    add_lit_testsuite(test-hipify "Running HIPify regression tests"
        ${CMAKE_SOURCE_DIR}/tests/hipify-clang
        PARAMS site_config=${CMAKE_CURRENT_BINARY_DIR}/tests/hipify-clang/lit.site.cfg
        DEPENDS hipify-clang lit
        )

    add_custom_target(test-hipify-clang)
    add_dependencies(test-hipify-clang test-hipify)
    set_target_properties(test-hipify-clang PROPERTIES FOLDER "Tests")
endif()

if (PARENT_SCOPE)
    set(BUILD_HIPIFY_CLANG 1 PARENT_SCOPE)
endif()
{'fraction_non_alphanumeric': 0.09417040358744394, 'fraction_numerical': 0.005979073243647235, 'mean_word_length': 3.6336565096952906, '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': '92521', 'n_tokens_mistral': 2618, 'n_tokens_neox': 2456, 'n_words': 403}