FindJulia.cmake 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # Original FindJulia.cmake from https://github.com/QuantStack/xtensor-julia-cookiecutter/blob/master/%7B%7Bcookiecutter.github_project_name%7D%7D/cmake/FindJulia.cmake
  2. if(Julia_FOUND)
  3. return()
  4. endif()
  5. ####################
  6. # Julia Executable #
  7. ####################
  8. find_program(Julia_EXECUTABLE julia DOC "Julia executable")
  9. #################
  10. # Julia Version #
  11. #################
  12. if(Julia_EXECUTABLE)
  13. message(STATUS "Found Julia executable: " ${Julia_EXECUTABLE})
  14. execute_process(
  15. COMMAND "${Julia_EXECUTABLE}" --startup-file=no --version
  16. OUTPUT_VARIABLE Julia_VERSION_STRING
  17. )
  18. else()
  19. return()
  20. endif()
  21. string(
  22. REGEX REPLACE ".*([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1"
  23. Julia_VERSION_STRING "${Julia_VERSION_STRING}"
  24. )
  25. MESSAGE(STATUS "Julia_VERSION_STRING: ${Julia_VERSION_STRING}")
  26. ##################
  27. # Julia Includes #
  28. ##################
  29. set(JULIA_HOME_NAME "Sys.BINDIR")
  30. if(${Julia_VERSION_STRING} VERSION_LESS "0.7.0")
  31. set(JULIA_HOME_NAME "JULIA_HOME")
  32. else()
  33. set(USING_LIBDL "using Libdl")
  34. endif()
  35. if(DEFINED ENV{JULIA_INCLUDE_DIRS})
  36. set(Julia_INCLUDE_DIRS $ENV{JULIA_INCLUDE_DIRS}
  37. CACHE STRING "Location of Julia include files")
  38. elseif(Julia_EXECUTABLE)
  39. execute_process(
  40. COMMAND ${Julia_EXECUTABLE} --startup-file=no -E "julia_include_dir = joinpath(match(r\"(.*)(bin)\",${JULIA_HOME_NAME}).captures[1],\"include\",\"julia\")\n
  41. if !isdir(julia_include_dir) # then we're running directly from build\n
  42. julia_base_dir_aux = splitdir(splitdir(${JULIA_HOME_NAME})[1])[1] # useful for running-from-build\n
  43. julia_include_dir = joinpath(julia_base_dir_aux, \"usr\", \"include\" )\n
  44. julia_include_dir *= \";\" * joinpath(julia_base_dir_aux, \"src\", \"support\" )\n
  45. julia_include_dir *= \";\" * joinpath(julia_base_dir_aux, \"src\" )\n
  46. end\n
  47. julia_include_dir"
  48. OUTPUT_VARIABLE Julia_INCLUDE_DIRS
  49. )
  50. string(REGEX REPLACE "\"" "" Julia_INCLUDE_DIRS "${Julia_INCLUDE_DIRS}")
  51. string(REGEX REPLACE "\n" "" Julia_INCLUDE_DIRS "${Julia_INCLUDE_DIRS}")
  52. set(Julia_INCLUDE_DIRS ${Julia_INCLUDE_DIRS}
  53. CACHE PATH "Location of Julia include files")
  54. elseif(Julia_PREFIX)
  55. set(Julia_INCLUDE_DIRS ${Julia_PREFIX}/include/julia)
  56. endif()
  57. MESSAGE(STATUS "Julia_INCLUDE_DIRS: ${Julia_INCLUDE_DIRS}")
  58. ###################
  59. # Julia Libraries #
  60. ###################
  61. if(WIN32)
  62. set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .a)
  63. endif()
  64. if(Julia_EXECUTABLE)
  65. execute_process(
  66. COMMAND ${Julia_EXECUTABLE} --startup-file=no -E "${USING_LIBDL}\nabspath(Libdl.dlpath((ccall(:jl_is_debugbuild, Cint, ()) != 0) ? \"libjulia-debug\" : \"libjulia\"))"
  67. OUTPUT_VARIABLE Julia_LIBRARY
  68. )
  69. string(REGEX REPLACE "\"" "" Julia_LIBRARY "${Julia_LIBRARY}")
  70. string(REGEX REPLACE "\n" "" Julia_LIBRARY "${Julia_LIBRARY}")
  71. string(STRIP "${Julia_LIBRARY}" Julia_LIBRARY)
  72. if(WIN32)
  73. get_filename_component(Julia_LIBRARY_DIR ${Julia_LIBRARY} DIRECTORY)
  74. get_filename_component(Julia_LIBRARY_DIR ${Julia_LIBRARY_DIR} DIRECTORY)
  75. find_library(win_Julia_LIBRARY
  76. NAMES libjulia.dll.a
  77. PATHS "${Julia_LIBRARY_DIR}/lib"
  78. NO_DEFAULT_PATH
  79. )
  80. set(Julia_LIBRARY "${win_Julia_LIBRARY}")
  81. endif()
  82. set(Julia_LIBRARY "${Julia_LIBRARY}"
  83. CACHE PATH "Julia library")
  84. else()
  85. find_library(Julia_LIBRARY NAMES libjulia.${Julia_VERSION_STRING}.dylib julia libjulia libjulia.dll.a CMAKE_FIND_ROOT_PATH_BOTH)
  86. endif()
  87. get_filename_component(Julia_LIBRARY_DIR ${Julia_LIBRARY} DIRECTORY)
  88. MESSAGE(STATUS "Julia_LIBRARY_DIR: ${Julia_LIBRARY_DIR}")
  89. MESSAGE(STATUS "Julia_LIBRARY: ${Julia_LIBRARY}")
  90. ##############
  91. # JULIA_HOME #
  92. ##############
  93. if(Julia_EXECUTABLE)
  94. execute_process(
  95. COMMAND ${Julia_EXECUTABLE} --startup-file=no -E "${JULIA_HOME_NAME}"
  96. OUTPUT_VARIABLE JULIA_HOME
  97. )
  98. string(REGEX REPLACE "\"" "" JULIA_HOME "${JULIA_HOME}")
  99. string(REGEX REPLACE "\n" "" JULIA_HOME "${JULIA_HOME}")
  100. MESSAGE(STATUS "JULIA_HOME: ${JULIA_HOME}")
  101. ###################
  102. # libLLVM version #
  103. ###################
  104. execute_process(
  105. COMMAND ${Julia_EXECUTABLE} --startup-file=no -E "Base.libllvm_version"
  106. OUTPUT_VARIABLE Julia_LLVM_VERSION
  107. )
  108. string(REGEX REPLACE "\"" "" Julia_LLVM_VERSION "${Julia_LLVM_VERSION}")
  109. string(REGEX REPLACE "\n" "" Julia_LLVM_VERSION "${Julia_LLVM_VERSION}")
  110. MESSAGE(STATUS "Julia_LLVM_VERSION: ${Julia_LLVM_VERSION}")
  111. endif()
  112. ##################################
  113. # Check for Existence of Headers #
  114. ##################################
  115. find_path(Julia_MAIN_HEADER julia.h HINTS ${Julia_INCLUDE_DIRS})
  116. #######################################
  117. # Determine if we are on 32 or 64 bit #
  118. #######################################
  119. if(Julia_EXECUTABLE)
  120. execute_process(
  121. COMMAND ${Julia_EXECUTABLE} --startup-file=no -E "Sys.WORD_SIZE"
  122. OUTPUT_VARIABLE Julia_WORD_SIZE
  123. )
  124. string(REGEX REPLACE "\n" "" Julia_WORD_SIZE "${Julia_WORD_SIZE}")
  125. MESSAGE(STATUS "Julia_WORD_SIZE: ${Julia_WORD_SIZE}")
  126. endif()
  127. ###########################
  128. # FindPackage Boilerplate #
  129. ###########################
  130. include(FindPackageHandleStandardArgs)
  131. find_package_handle_standard_args(Julia
  132. REQUIRED_VARS Julia_LIBRARY Julia_LIBRARY_DIR Julia_INCLUDE_DIRS Julia_MAIN_HEADER Julia_EXECUTABLE
  133. VERSION_VAR Julia_VERSION_STRING
  134. FAIL_MESSAGE "Julia not found"
  135. )