Skip to content

Instantly share code, notes, and snippets.

@JayKickliter
Last active April 11, 2018 19:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayKickliter/06d0e7c4f84ef7ccc7a9 to your computer and use it in GitHub Desktop.
Save JayKickliter/06d0e7c4f84ef7ccc7a9 to your computer and use it in GitHub Desktop.
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
Copy link

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

@JayKickliter
Copy link
Author

@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
Copy link

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

JuliaLang/julia@7927ba1

@mmmm1998
Copy link

mmmm1998 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