-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFindJulia.cmake
133 lines (105 loc) · 4 KB
/
FindJulia.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
if(Julia_FOUND)
return()
endif()
####################
# Julia Executable #
####################
find_program(Julia_EXECUTABLE julia DOC "Julia executable")
MESSAGE(STATUS "Julia_EXECUTABLE: ${Julia_EXECUTABLE}")
#################
# Julia Version #
#################
execute_process(
COMMAND "${Julia_EXECUTABLE}" --startup-file=no --version
OUTPUT_VARIABLE Julia_VERSION_STRING
)
string(
REGEX REPLACE ".*([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1"
Julia_VERSION_STRING "${Julia_VERSION_STRING}"
)
MESSAGE(STATUS "Julia_VERSION_STRING: ${Julia_VERSION_STRING}")
##################
# Julia Includes #
##################
if(DEFINED ENV{JULIA_INCLUDE_DIRS})
set(Julia_INCLUDE_DIRS $ENV{JULIA_INCLUDE_DIRS}
CACHE STRING "Location of Julia include files")
else()
execute_process(
COMMAND ${Julia_EXECUTABLE} --startup-file=no -E "julia_include_dir = joinpath(match(r\"(.*)(bin)\",Sys.BINDIR).captures[1],\"include\",\"julia\")\n
if !isdir(julia_include_dir) # then we're running directly from build\n
julia_base_dir_aux = splitdir(splitdir(Sys.BINDIR)[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
)
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")
endif()
MESSAGE(STATUS "Julia_INCLUDE_DIRS: ${Julia_INCLUDE_DIRS}")
###################
# Julia Libraries #
###################
execute_process(
COMMAND ${Julia_EXECUTABLE} --startup-file=no -E "using Libdl; abspath(dirname(Libdl.dlpath(\"libjulia\")))"
OUTPUT_VARIABLE Julia_LIBRARY_DIR
)
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")
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .a)
find_library(Julia_LIBRARY
NAMES libjulia.dll.a
PATHS ${Julia_LIBRARY_DIR}//..//lib
NO_DEFAULT_PATH
)
else()
find_library(Julia_LIBRARY
NAMES julia libjulia
PATHS ${Julia_LIBRARY_DIR}
NO_DEFAULT_PATH
)
endif()
MESSAGE(STATUS "Julia_LIBRARY_DIR: ${Julia_LIBRARY_DIR}")
MESSAGE(STATUS "Julia_LIBRARY: ${Julia_LIBRARY}")
##############
# Sys.BINDIR #
##############
execute_process(
COMMAND ${Julia_EXECUTABLE} --startup-file=no -E "Sys.BINDIR"
OUTPUT_VARIABLE Sys.BINDIR
)
string(REGEX REPLACE "\"" "" Sys.BINDIR "${Sys.BINDIR}")
string(REGEX REPLACE "\n" "" Sys.BINDIR "${Sys.BINDIR}")
MESSAGE(STATUS "Sys.BINDIR: ${Sys.BINDIR}")
###################
# libLLVM version #
###################
execute_process(
COMMAND ${Julia_EXECUTABLE} --startup-file=no -E "Base.libllvm_version"
OUTPUT_VARIABLE Julia_LLVM_VERSION
)
string(REGEX REPLACE "\"" "" Julia_LLVM_VERSION "${Julia_LLVM_VERSION}")
string(REGEX REPLACE "\n" "" Julia_LLVM_VERSION "${Julia_LLVM_VERSION}")
##################################
# Check for Existence of Headers #
##################################
find_path(Julia_MAIN_HEADER julia.h HINTS ${Julia_INCLUDE_DIRS})
MESSAGE(STATUS "Julia_LLVM_VERSION: ${Julia_LLVM_VERSION}")
###########################
# FindPackage Boilerplate #
###########################
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Julia
REQUIRED_VARS Julia_LIBRARY Julia_LIBRARY_DIR Julia_INCLUDE_DIRS Julia_MAIN_HEADER
VERSION_VAR Julia_VERSION_STRING
FAIL_MESSAGE "Julia not found"
)