Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
if(JULIA_FOUND)
return()
endif()
# Find 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 RESULT
)
if(RESULT EQUAL 0)
string(REGEX REPLACE ".*([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1"
JULIA_VERSION_STRING ${JULIA_VERSION_STRING})
endif()
#
# Julia includes
#
execute_process(
COMMAND ${JULIA_EXECUTABLE} -E "joinpath(match(r\"(.*)(bin)\",JULIA_HOME).captures[1],\"include\",\"julia\")"
OUTPUT_VARIABLE JULIA_INCLUDE_DIRS
# COMMAND ${JULIA_EXECUTABLE} -E "abspath(joinpath(JULIA_HOME, \"../..\", \"src\"))"
# OUTPUT_VARIABLE JULIA_INCLUDE_DIRS
RESULT_VARIABLE RESULT
)
if(RESULT 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")
endif()
#
# Julia library location
#
execute_process(
COMMAND ${JULIA_EXECUTABLE} -E "abspath(dirname(Sys.dlpath(\"libjulia\")))"
OUTPUT_VARIABLE JULIA_LIBRARY_DIR
RESULT_VARIABLE RESULT
)
if(RESULT 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")
endif()
find_library( JULIA_LIBRARY
NAMES julia
PATHS ${JULIA_LIBRARY_DIR}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Julia
REQUIRED_VARS JULIA_LIBRARY JULIA_LIBRARY_DIR JULIA_INCLUDE_DIRS
VERSION_VAR JULIA_VERSION_STRING
FAIL_MESSAGE "Julia not found"
)
@filipesaraiva

This comment has been minimized.

Copy link

commented Aug 25, 2016

Hi Jay, we would like to use it in Cantor, a software of KDE Applications. Which license are you using for this code?

@JayKickliter

This comment has been minimized.

Copy link
Owner Author

commented Dec 2, 2016

@filipesaraiva I somehow didn't get notified or didn't notice your comment. If you still want to know, you can use it however you want.

@rongcuid

This comment has been minimized.

Copy link

commented May 10, 2017

Hello,
For newer version of Julia, it seems that you need abspath(dirname(Libdl.dlpath("libjulia"))) instead of Sys

JuliaLang/julia@7927ba1

@mmmm1998

This comment has been minimized.

Copy link

commented Apr 11, 2018

Hello.
Maybe add checking for existings of include path of Julia? Something like that:

IF (NOT EXISTS JULIA_INCLUDE_DIRS)
    message(STATUS "Julia found, but include files are missing")
    return()
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.