Skip to content

Commit

Permalink
Improve Julia cmake build system
Browse files Browse the repository at this point in the history
Summary: Update `FindJulia.cmake` according new version of [this](https://gist.github.com/JayKickliter/06d0e7c4f84ef7ccc7a9), add small change (change `Sys` to `Libdl` accroding [this](JuliaLang/julia#10328)) and add checking of existing dev files of julia, because you can have julia, but haven't include files. Also fix some problems in `juliabackends` cmake files, related with case sensivity of cmake variables.

Reviewers: #cantor, asemke

Reviewed By: #cantor, asemke

Subscribers: #cantor, #kde_edu

Tags: #kde_edu, #cantor

Differential Revision: https://phabricator.kde.org/D12121
  • Loading branch information
mmmm1998 authored and asemke committed May 7, 2018
1 parent 5f2a5eb commit 87bccf4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 41 deletions.
103 changes: 65 additions & 38 deletions cmake/FindJulia.cmake
Original file line number Diff line number Diff line change
@@ -1,56 +1,83 @@
if(Julia_FOUND)
if(JULIA_FOUND)
return()
endif()

# Find julia executable
find_program(JULIA_EXECUTABLE julia DOC "Julia executable")

# Looking for Julia executable
find_program(Julia_EXECUTABLE julia DOC "Julia executable")
if(NOT Julia_EXECUTABLE)
if(NOT JULIA_EXECUTABLE)
return()
endif()

# Getting Julia version



#
# Julia version
#
execute_process(
COMMAND ${Julia_EXECUTABLE} --version
OUTPUT_VARIABLE Julia_VERSION_STRING
RESULT_VARIABLE RETURN_CODE
COMMAND ${JULIA_EXECUTABLE} --version
OUTPUT_VARIABLE JULIA_VERSION_STRING
RESULT_VARIABLE RESULT
)
if(RETURN_CODE EQUAL 0)
string(
REGEX REPLACE ".*([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1"
Julia_VERSION_STRING ${Julia_VERSION_STRING}
)
else()
return()
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 "JULIA_HOME"
OUTPUT_VARIABLE Julia_INCLUDE_DIRS
RESULT_VARIABLE RETURN_CODE
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(RETURN_CODE EQUAL 0)
set(
Julia_INCLUDE_DIRS
"${Julia_INCLUDE_DIRS}/../include/julia"
)
string(REGEX REPLACE "(\"|\n)" "" Julia_INCLUDE_DIRS ${Julia_INCLUDE_DIRS})
string(STRIP Julia_INCLUDE_DIRS ${Julia_INCLUDE_DIRS})
set(
Julia_INCLUDE_DIRS ${Julia_INCLUDE_DIRS}
CACHE PATH "Location of Julia include files"
)
else()
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()

string(CONCAT JULIA_INCLUDE_TEST_FILE ${JULIA_INCLUDE_DIRS} "/julia_version.h")
string(REGEX REPLACE "\n" "" JULIA_INCLUDE_TEST_FILE ${JULIA_INCLUDE_TEST_FILE})
IF (NOT EXISTS ${JULIA_INCLUDE_TEST_FILE})
message(STATUS "Julia found, but include files are missing")
return()
endif()

# Checking existance of main header. Some distos provide packages without actual includes
find_path(Julia_MAIN_HEADER julia.h HINTS ${Julia_INCLUDE_DIRS})
find_library(Julia_LIBRARY julia HINTS ${Julia_INCLUDE_DIRS}/../../lib)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Julia
REQUIRED_VARS Julia_EXECUTABLE Julia_MAIN_HEADER Julia_INCLUDE_DIRS
VERSION_VAR Julia_VERSION_STRING
FAIL_MESSAGE "Julia not found"
#
# Julia library location
#
execute_process(
COMMAND ${JULIA_EXECUTABLE} -E "abspath(dirname(Libdl.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"
)
4 changes: 2 additions & 2 deletions src/backends/julia/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include_directories(${Julia_INCLUDE_DIRS})
include_directories(${JULIA_INCLUDE_DIRS})

add_subdirectory(juliaserver)
if(BUILD_TESTING)
Expand All @@ -20,7 +20,7 @@ ki18n_wrap_ui(JuliaBackend_SRCS settings.ui)

add_backend(juliabackend ${JuliaBackend_SRCS})

target_link_libraries(cantor_juliabackend Qt5::DBus ${Julia_LIBRARY})
target_link_libraries(cantor_juliabackend Qt5::DBus ${JULIA_LIBRARY})

install(FILES juliabackend.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
file(GLOB scripts "${CMAKE_CURRENT_SOURCE_DIR}/scripts/*.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/backends/julia/juliaserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(JuliaServer_SRCS
add_executable(cantor_juliaserver ${JuliaServer_SRCS})

target_link_libraries(cantor_juliaserver
${Julia_LIBRARY}
${JULIA_LIBRARY}
Qt5::Widgets
Qt5::DBus
)
Expand Down

0 comments on commit 87bccf4

Please sign in to comment.