## -*- mode: CMake -*-
##
## Copyright (c) 2012, 2013, 2014, 2015, 2016, 2018, 2019 The University of Utah
## All rights reserved.
##
## This file is distributed under the University of Illinois Open Source
## License.  See the file COPYING for details.

###############################################################################

cmake_minimum_required(VERSION 3.14)

project(cvise_python)

###############################################################################

# find_package(LLVM) is done by the topmost "CMakeLists.txt" file.

###############################################################################

# Check for the run-time prerequisites of C-Vise.  We only warn the user when
# these are not found at configure time.  Let the user install the dependencies
# later.
#
if(CLANG_FORMAT)
  find_program(CLANG_FORMAT_PATH
    "${CLANG_FORMAT}"
    PATHS "${LLVM_TOOLS_BINARY_DIR}"
  )
else()
  find_program(CLANG_FORMAT_PATH
    "clang-format${CMAKE_EXECUTABLE_SUFFIX}"
    PATHS "${LLVM_TOOLS_BINARY_DIR}"
    )
endif()

if(NOT CLANG_FORMAT_PATH)
  message(STATUS "`clang-format${CMAKE_EXECUTABLE_SUFFIX}' was not found")
  message("You must install `clang-format' before running C-Vise.")
  set(CLANG_FORMAT_PATH "clang-format" CACHE FILEPATH
      "Path for clang-format executable" FORCE)
else()
  message(STATUS "Using clang-format in ${CLANG_FORMAT_PATH}")
endif()

###############################################################################

# Generate file "cvise.py".
#
configure_file("${cvise_python_SOURCE_DIR}/cvise.py"
  "${cvise_python_BINARY_DIR}/cvise.py"
)

###############################################################################

# Copy the Python modules into the build tree so that we can run C-Vise there.
#
function(configure_one_file path)
  configure_file(
    "${cvise_python_SOURCE_DIR}/${path}"
    "${cvise_python_BINARY_DIR}/${path}"
    COPYONLY
  )
endfunction(configure_one_file)

set(SOURCE_FILES
  "__init__.py"
  "pass_groups/all.json"
  "pass_groups/no-interleaving.json"
  "pass_groups/opencl-120.json"
  "pass_groups/delta.json"
  "pass_groups/binary.json"
  "passes/__init__.py"
  "passes/abstract.py"
  "passes/balanced.py"
  "passes/blank.py"
  "passes/clang.py"
  "passes/clangbinarysearch.py"
  "passes/clanghints.py"
  "passes/clangincludegraph.py"
  "passes/clangmodulemap.py"
  "passes/clex.py"
  "passes/clexhints.py"
  "passes/comments.py"
  "passes/gcdabinary.py"
  "passes/hint_based.py"
  "passes/ifs.py"
  "passes/includeincludes.py"
  "passes/includes.py"
  "passes/indent.py"
  "passes/inlineincludes.py"
  "passes/ints.py"
  "passes/line_markers.py"
  "passes/lines.py"
  "passes/makefile.py"
  "passes/peep.py"
  "passes/rmunusedfiles.py"
  "passes/special.py"
  "passes/ternary.py"
  "passes/treesitter.py"
  "passes/unifdef.py"
  "tests/__init__.py"
  "tests/testabstract.py"
  "tests/test_balanced.py"
  "tests/test_blank.py"
  "tests/test_cache.py"
  "tests/test_clanghints.py"
  "tests/test_clangincludegraph.py"
  "tests/test_clangmodulemap.py"
  "tests/test_clexhints.py"
  "tests/test_comments.py"
  "tests/test_fileutil.py"
  "tests/test_folding.py"
  "tests/test_hint.py"
  "tests/test_hint_based.py"
  "tests/test_ifs.py"
  "tests/test_inlineincludes.py"
  "tests/test_ints.py"
  "tests/test_line_markers.py"
  "tests/test_lines.py"
  "tests/test_makefile.py"
  "tests/test_nestedmatcher.py"
  "tests/test_peep.py"
  "tests/test_process.py"
  "tests/test_rmunusedfiles.py"
  "tests/test_sigmonitor.py"
  "tests/test_special.py"
  "tests/test_ternary.py"
  "tests/test_test_manager.py"
  "tests/test_treesitter.py"
  "utils/__init__.py"
  "utils/cache.py"
  "utils/error.py"
  "utils/externalprograms.py"
  "utils/fileutil.py"
  "utils/folding.py"
  "utils/hint.py"
  "utils/makefileparser.py"
  "utils/mplogging.py"
  "utils/nestedmatcher.py"
  "utils/process.py"
  "utils/readkey_posix.py"
  "utils/readkey_windows.py"
  "utils/readkey.py"
  "utils/sigmonitor.py"
  "utils/statistics.py"
  "utils/testing.py"
)

foreach(file IN LISTS SOURCE_FILES)
  configure_one_file(${file})
endforeach()

###############################################################################

install(DIRECTORY "${cvise_python_BINARY_DIR}/"
  DESTINATION "${CMAKE_INSTALL_DATADIR}/${cvise_PACKAGE}"
  FILES_MATCHING
  PATTERN "*.py"
  PATTERN "*.json"
  PATTERN "__pycache__" EXCLUDE
  PATTERN "CMakeFiles" EXCLUDE
)

###############################################################################

## End of file.
