<commit_before>
if(Julia_FOUND)
    return()
endif()

#################### 
# Julia Executable #
####################

find_program(Julia_EXECUTABLE julia DOC "Julia executable")
if(NOT Julia_EXECUTABLE)
    return()
endif()

################# 
# Julia Version #
################# 

execute_process(
    COMMAND ${Julia_EXECUTABLE} --version
    OUTPUT_VARIABLE Julia_VERSION_STRING
    RESULT_VARIABLE RETURN_CODE
)
if(RETURN_CODE EQUAL 0)
    string(
      REGEX REPLACE ".*([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1"
        Julia_VERSION_STRING ${Julia_VERSION_STRING}
    )
else()
    return()
endif()

################## 
# Julia Includes #
################## 

execute_process(
    COMMAND ${Julia_EXECUTABLE} -E "joinpath(match(r\"(.*)(bin)\",JULIA_HOME).captures[1],\"include\",\"julia\")"
    OUTPUT_VARIABLE Julia_INCLUDE_DIRS
    RESULT_VARIABLE RETURN_CODE
)
if(RETURN_CODE EQUAL 0)
    string(REGEX REPLACE "\"" "" Julia_INCLUDE_DIRS ${Julia_INCLUDE_DIRS})
    set(Julia_INCLUDE_DIRS ${Julia_INCLUDE_DIRS}
        CACHE PATH "Location of Julia include files")
else()
    return()
endif()

################### 
# Julia Libraries #
################### 

execute_process(
    COMMAND ${Julia_EXECUTABLE} -E "abspath(dirname(Libdl.dlpath(\"libjulia\")))"
    OUTPUT_VARIABLE Julia_LIBRARY_DIR
    RESULT_VARIABLE RETURN_CODE
)
if(RETURN_CODE EQUAL 0)
    string(REGEX REPLACE "\"" "" Julia_LIBRARY_DIR ${Julia_LIBRARY_DIR})
    string(STRIP ${Julia_LIBRARY_DIR} Julia_LIBRARY_DIR)
    set(Julia_LIBRARY_DIR ${Julia_LIBRARY_DIR}
        CACHE PATH "Julia library directory")
else()
    return()
endif()

find_library(Julia_LIBRARY
    NAMES julia
    PATHS ${Julia_LIBRARY_DIR}
)

############## 
# JULIA_HOME #
############## 

execute_process(
    COMMAND ${Julia_EXECUTABLE} -E "JULIA_HOME"
    OUTPUT_VARIABLE JULIA_HOME
    RESULT_VARIABLE RETURN_CODE
)
<commit_msg>Improve FindJulia to support in-build usage<commit_after>
if(Julia_FOUND)
    return()
endif()

#################### 
# Julia Executable #
####################

find_program(Julia_EXECUTABLE julia DOC "Julia executable")
if(NOT Julia_EXECUTABLE)
    return()
endif()

################# 
# Julia Version #
################# 

execute_process(
    COMMAND ${Julia_EXECUTABLE} --version
    OUTPUT_VARIABLE Julia_VERSION_STRING
    RESULT_VARIABLE RETURN_CODE
)
if(RETURN_CODE EQUAL 0)
    string(
      REGEX REPLACE ".*([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1"
        Julia_VERSION_STRING ${Julia_VERSION_STRING}
    )
else()
    return()
endif()

################## 
# Julia Includes #
################## 

execute_process(
    COMMAND ${Julia_EXECUTABLE} -E "julia_include_dir = joinpath(match(r\"(.*)(bin)\",JULIA_HOME).captures[1],\"include\",\"julia\")\n
        if !isdir(julia_include_dir)  # then we're running directly from build\n
          julia_base_dir_aux = splitdir(splitdir(JULIA_HOME)[1])[1]  # useful for running-from-build\n
          julia_include_dir = joinpath(julia_base_dir_aux, \"usr\", \"include\" )\n
          julia_include_dir *= \";\" * joinpath(julia_base_dir_aux, \"src\", \"support\" )\n
          julia_include_dir *= \";\" * joinpath(julia_base_dir_aux, \"src\" )\n
        end\n
        julia_include_dir"
    OUTPUT_VARIABLE Julia_INCLUDE_DIRS
    RESULT_VARIABLE RETURN_CODE
)
if(RETURN_CODE EQUAL 0)
    string(REGEX REPLACE "\"" "" Julia_INCLUDE_DIRS ${Julia_INCLUDE_DIRS})
    string(REGEX REPLACE "\n" "" Julia_INCLUDE_DIRS ${Julia_INCLUDE_DIRS})
    set(Julia_INCLUDE_DIRS ${Julia_INCLUDE_DIRS}
        CACHE PATH "Location of Julia include files")
else()
    return()
endif()

################### 
# Julia Libraries #
################### 

execute_process(
    COMMAND ${Julia_EXECUTABLE} -E "abspath(dirname(Libdl.dlpath(\"libjulia\")))"
    OUTPUT_VARIABLE Julia_LIBRARY_DIR
    RESULT_VARIABLE RETURN_CODE
)
if(RETURN_CODE EQUAL 0)
    string(REGEX REPLACE "\"" "" Julia_LIBRARY_DIR ${Julia_LIBRARY_DIR})
    string(REGEX REPLACE "\n" "" Julia_LIBRARY_DIR ${Julia_LIBRARY_DIR})
    string(STRIP ${Julia_LIBRARY_DIR} Julia_LIBRARY_DIR)
    set(Julia_LIBRARY_DIR ${Julia_LIBRARY_DIR}
        CACHE PATH "Julia library directory")
else()
    return()
endif()

find_library(Julia_LIBRARY
    NAMES julia
    PATHS ${Julia_LIBRARY_DIR}
)

############## 
# JULIA_HOME #
############## 

execute_process(
    COMMAND ${Julia_EXECUTABLE} -E "JULIA_HOME"
    OUTPUT_VARIABLE JULIA_HOME
    RESULT_VARIABLE RETURN_CODE
)

{'fraction_non_alphanumeric': 0.19299435028248588, 'fraction_numerical': 0.005423728813559322, 'mean_word_length': 4.417380660954712, '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': '5868019', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1583, 'n_words': 273}