<commit_before>#---------------------------------------------------------------------------
# Copyright 2011 The Open Source Electronic Health Record Agent
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#---------------------------------------------------------------------------

if(POLICY CMP0012)
  cmake_policy(SET CMP0012 NEW)
endif()

find_package(Java REQUIRED)
include(UseJava)

find_program(DOT_EXECUTABLE NAMES dot REQUIRED)

set(DOCUMENT_VISTA_M_DIR "" CACHE PATH
  "Path to the folder that contains the routines and globals from OSEHRA")
STRING(REGEX REPLACE "\\\\" "/" DOCUMENT_VISTA_M_DIR ${DOCUMENT_VISTA_M_DIR})
if(NOT EXISTS ${DOCUMENT_VISTA_M_DIR})
  message(WARNING "DOCUMENT_VISTA_M_DIR is required.")
endif()

set(DOCUMENT_VISTA_OUTPUT_DIR "" CACHE PATH
  "Path to the directory where ViViaN and DOX files will be generated")
STRING(REGEX REPLACE "\\\\" "/" DOCUMENT_VISTA_OUTPUT_DIR ${DOCUMENT_VISTA_OUTPUT_DIR})
file(MAKE_DIRECTORY "${DOCUMENT_VISTA_OUTPUT_DIR}")
if(NOT EXISTS ${DOCUMENT_VISTA_OUTPUT_DIR})
  message(WARNING "DOCUMENT_VISTA_OUTPUT_DIR is required.")
endif()

set(DOCUMENT_VISTA_ICR_OUTPUT_DIR "${DOCUMENT_VISTA_OUTPUT_DIR}/ICR")
set(ICR_FILE "" CACHE FILEPATH "ICR File from http://foia-vista.osehra.org/VistA_Integration_Agreement/")
if(NOT EXISTS ${ICR_FILE})
  message(WARNING "ICR_FILE is required.")
else()
  # Get file name without directory or longest extension
  get_filename_component(ICR_JSON_FILE ${ICR_FILE} NAME_WE)
  set(ICR_JSON_FILE "${DOCUMENT_VISTA_OUTPUT_DIR}/${ICR_JSON_FILE}.JSON")
  STRING(REGEX REPLACE "\\\\" "/" ICR_JSON_FILE ${ICR_JSON_FILE})
endif()

set(DOCUMENT_VISTA_DOX_OUTPUT_DIR "${DOCUMENT_VISTA_OUTPUT_DIR}/dox")
set(DOCUMENT_VISTA_PDF_OUTPUT_DIR "${DOCUMENT_VISTA_DOX_OUTPUT_DIR}/PDF")

set(PYTHONSCRIPTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/PythonScripts")
set(LOCAL_DOX_LINKS "FALSE" CACHE BOOL "Use a local links for DOX page connections")
set(GENERATE_DOX "TRUE" CACHE BOOL "Generate the DOX pages")
mark_as_advanced(GENERATE_DOX)

set(GENERATE_VIVIAN "TRUE" CACHE BOOL "Generate ViViaN data")
mark_as_advanced(GENERATE_VIVIAN)

set(GENERATE_PDF_BUNDLE "FALSE" CACHE BOOL "Generate PDF bundle")

if(GENERATE_PDF_BUNDLE)
  set(GENERATE_PDF "-pdf")
else()
  set(GENERATE_PDF "")
endif()

if(LOCAL_DOX_LINKS)
  set(LOCAL_VIVIAN_FILES_URL "" CACHE STRING "A local ViViaN/files URL to point to")
  if(NOT LOCAL_VIVIAN_FILES_URL)
    message(SEND_ERROR "Must supply a local ViViaN/files/ URL.")
  endif()
  set(GENERATE_LOCAL_LINKS "-local ${LOCAL_VIVIAN_FILES_URL}")
else()
  set(GENERATE_LOCAL_LINKS "")
endif()

if (NOT GENERATE_DOX AND NOT GENERATE_VIVIAN)
  message(SEND_ERROR "Must select GENERATE_DOX and/or GENERATE_VIVIAN.")
endif()

if (NOT GENERATE_DOX AND GENERATE_PDF_BUNDLE)
  message(SEND_ERROR "Must select GENERATE_DOX to generate PDF Bundle")
endif()

set(SCRIPT_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Docs/CallerGraph")
set(LOG_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Log")

# 0. Install the Enhanced XINDEX patch
if (GENERATE_DOX OR GENERATE_VIVIAN)
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XINDEXInstall.cmake.in ${SCRIPT_OUTPUT_DIR}/XINDEXInstall.cmake @ONLY)
  add_test(XINDEX_Install ${CMAKE_COMMAND} -P ${SCRIPT_OUTPUT_DIR}/XINDEXInstall.cmake)
endif()

# 1. Generate XINDEX based cross reference output used by:
#    GeneratePackageDep (ViViaN) and WebPageGenerator (DOX)
if (GENERATE_DOX OR GENERATE_VIVIAN)
  FindPackages(${VISTA_SOURCE_DIR})
  set(CALLER_GRAPH_LOG_DIR "${SCRIPT_OUTPUT_DIR}/Log")
  file(MAKE_DIRECTORY "${CALLER_GRAPH_LOG_DIR}")
  foreach(package_file_name ${PACKAGES})
    string(REPLACE  "_" " " packageDirName "${package_file_name}")
    FindPackageInfo(${VISTA_SOURCE_DIR} ${packageDirName})
    set(package "${DOCUMENT_VISTA_M_DIR}/Packages/${packageDirName}")
    if(IS_DIRECTORY ${package})
      file(GLOB routines "${package}/Routines/*.m")
      set(AllRoutines "")
      foreach(routine ${routines})
        get_filename_component(routine_name ${routine} NAME_WE)
        set(AllRoutines "${AllRoutines}AllRoutines.append(\"${routine_name}\")\n")
      endforeach()
      list(FIND PACKAGES ${package_file_name} PACKAGE_INDEX)
      list(GET PACKAGES_INTERNAL ${PACKAGE_INDEX} PACKAGE_INTERNAL_NAME)
      set(logfile "${CALLER_GRAPH_LOG_DIR}/${package_file_name}.log")
      #Configures the python script with the name of the routine
      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XindexCallerGraph.py.in
                     ${SCRIPT_OUTPUT_DIR}/${package_file_name}.py)

      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XindexCallerGraph.cmake.in
                     ${SCRIPT_OUTPUT_DIR}/${package_file_name}.cmake @ONLY)

      # Creates the command that will be called for the Test
      add_test(CALLERGRAPH_${package_file_name} ${CMAKE_COMMAND} -P ${SCRIPT_OUTPUT_DIR}/${package_file_name}.cmake)
      set_tests_properties(CALLERGRAPH_${package_file_name} PROPERTIES TIMEOUT 5000)
    endif()
  endforeach()
endif()

# 2. Generate Fileman Schema used by:
#    GeneratePackageDep (ViViaN) and WebPageGenerator (DOX)
if (GENERATE_DOX OR GENERATE_VIVIAN)<commit_msg>Use M directory packages.csv for Packages<commit_after>#---------------------------------------------------------------------------
# Copyright 2011 The Open Source Electronic Health Record Agent
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#---------------------------------------------------------------------------

if(POLICY CMP0012)
  cmake_policy(SET CMP0012 NEW)
endif()

find_package(Java REQUIRED)
include(UseJava)

find_program(DOT_EXECUTABLE NAMES dot REQUIRED)

set(DOCUMENT_VISTA_M_DIR "" CACHE PATH
  "Path to the folder that contains the routines and globals from OSEHRA")
STRING(REGEX REPLACE "\\\\" "/" DOCUMENT_VISTA_M_DIR ${DOCUMENT_VISTA_M_DIR})
if(NOT EXISTS ${DOCUMENT_VISTA_M_DIR})
  message(WARNING "DOCUMENT_VISTA_M_DIR is required.")
endif()

set(DOCUMENT_VISTA_OUTPUT_DIR "" CACHE PATH
  "Path to the directory where ViViaN and DOX files will be generated")
STRING(REGEX REPLACE "\\\\" "/" DOCUMENT_VISTA_OUTPUT_DIR ${DOCUMENT_VISTA_OUTPUT_DIR})
file(MAKE_DIRECTORY "${DOCUMENT_VISTA_OUTPUT_DIR}")
if(NOT EXISTS ${DOCUMENT_VISTA_OUTPUT_DIR})
  message(WARNING "DOCUMENT_VISTA_OUTPUT_DIR is required.")
endif()

set(DOCUMENT_VISTA_ICR_OUTPUT_DIR "${DOCUMENT_VISTA_OUTPUT_DIR}/ICR")
set(ICR_FILE "" CACHE FILEPATH "ICR File from http://foia-vista.osehra.org/VistA_Integration_Agreement/")
if(NOT EXISTS ${ICR_FILE})
  message(WARNING "ICR_FILE is required.")
else()
  # Get file name without directory or longest extension
  get_filename_component(ICR_JSON_FILE ${ICR_FILE} NAME_WE)
  set(ICR_JSON_FILE "${DOCUMENT_VISTA_OUTPUT_DIR}/${ICR_JSON_FILE}.JSON")
  STRING(REGEX REPLACE "\\\\" "/" ICR_JSON_FILE ${ICR_JSON_FILE})
endif()

set(DOCUMENT_VISTA_DOX_OUTPUT_DIR "${DOCUMENT_VISTA_OUTPUT_DIR}/dox")
set(DOCUMENT_VISTA_PDF_OUTPUT_DIR "${DOCUMENT_VISTA_DOX_OUTPUT_DIR}/PDF")

set(PYTHONSCRIPTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/PythonScripts")
set(LOCAL_DOX_LINKS "FALSE" CACHE BOOL "Use a local links for DOX page connections")
set(GENERATE_DOX "TRUE" CACHE BOOL "Generate the DOX pages")
mark_as_advanced(GENERATE_DOX)

set(GENERATE_VIVIAN "TRUE" CACHE BOOL "Generate ViViaN data")
mark_as_advanced(GENERATE_VIVIAN)

set(GENERATE_PDF_BUNDLE "FALSE" CACHE BOOL "Generate PDF bundle")

if(GENERATE_PDF_BUNDLE)
  set(GENERATE_PDF "-pdf")
else()
  set(GENERATE_PDF "")
endif()

if(LOCAL_DOX_LINKS)
  set(LOCAL_VIVIAN_FILES_URL "" CACHE STRING "A local ViViaN/files URL to point to")
  if(NOT LOCAL_VIVIAN_FILES_URL)
    message(SEND_ERROR "Must supply a local ViViaN/files/ URL.")
  endif()
  set(GENERATE_LOCAL_LINKS "-local ${LOCAL_VIVIAN_FILES_URL}")
else()
  set(GENERATE_LOCAL_LINKS "")
endif()

if (NOT GENERATE_DOX AND NOT GENERATE_VIVIAN)
  message(SEND_ERROR "Must select GENERATE_DOX and/or GENERATE_VIVIAN.")
endif()

if (NOT GENERATE_DOX AND GENERATE_PDF_BUNDLE)
  message(SEND_ERROR "Must select GENERATE_DOX to generate PDF Bundle")
endif()

set(SCRIPT_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Docs/CallerGraph")
set(LOG_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Log")

# 0. Install the Enhanced XINDEX patch
if (GENERATE_DOX OR GENERATE_VIVIAN)
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XINDEXInstall.cmake.in ${SCRIPT_OUTPUT_DIR}/XINDEXInstall.cmake @ONLY)
  add_test(XINDEX_Install ${CMAKE_COMMAND} -P ${SCRIPT_OUTPUT_DIR}/XINDEXInstall.cmake)
endif()

# 1. Generate XINDEX based cross reference output used by:
#    GeneratePackageDep (ViViaN) and WebPageGenerator (DOX)
if (GENERATE_DOX OR GENERATE_VIVIAN)
  FindPackages(${DOCUMENT_VISTA_M_DIR})
  set(CALLER_GRAPH_LOG_DIR "${SCRIPT_OUTPUT_DIR}/Log")
  file(MAKE_DIRECTORY "${CALLER_GRAPH_LOG_DIR}")
  foreach(package_file_name ${PACKAGES})
    string(REPLACE  "_" " " packageDirName "${package_file_name}")
    FindPackageInfo(${DOCUMENT_VISTA_M_DIR} ${packageDirName})
    set(package "${DOCUMENT_VISTA_M_DIR}/Packages/${packageDirName}")
    if(IS_DIRECTORY ${package})
      file(GLOB routines "${package}/Routines/*.m")
      set(AllRoutines "")
      foreach(routine ${routines})
        get_filename_component(routine_name ${routine} NAME_WE)
        set(AllRoutines "${AllRoutines}AllRoutines.append(\"${routine_name}\")\n")
      endforeach()
      list(FIND PACKAGES ${package_file_name} PACKAGE_INDEX)
      list(GET PACKAGES_INTERNAL ${PACKAGE_INDEX} PACKAGE_INTERNAL_NAME)
      set(logfile "${CALLER_GRAPH_LOG_DIR}/${package_file_name}.log")
      #Configures the python script with the name of the routine
      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XindexCallerGraph.py.in
                     ${SCRIPT_OUTPUT_DIR}/${package_file_name}.py)

      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XindexCallerGraph.cmake.in
                     ${SCRIPT_OUTPUT_DIR}/${package_file_name}.cmake @ONLY)

      # Creates the command that will be called for the Test
      add_test(CALLERGRAPH_${package_file_name} ${CMAKE_COMMAND} -P ${SCRIPT_OUTPUT_DIR}/${package_file_name}.cmake)
      set_tests_properties(CALLERGRAPH_${package_file_name} PROPERTIES TIMEOUT 5000)
    endif()
  endforeach()
endif()

# 2. Generate Fileman Schema used by:
#    GeneratePackageDep (ViViaN) and WebPageGenerator (DOX)
if (GENERATE_DOX OR GENERATE_VIVIAN)
{'fraction_non_alphanumeric': 0.12901212553495006, 'fraction_numerical': 0.004101283880171184, 'mean_word_length': 4.931782125859334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6316354', 'n_tokens_mistral': 4051, 'n_tokens_neox': 3821, 'n_words': 850}