"src/vscode:/vscode.git/clone" did not exist on "7c503ba3710b7e298006195c6ccb90db00e4d8e1"
install.libs.R 2.66 KB
Newer Older
Laurae's avatar
Laurae committed
1
2
# User options
use_precompile <- FALSE
3
4
use_gpu <- FALSE
use_mingw <- FALSE
Laurae's avatar
Laurae committed
5
6
7
8
9

# Check for precompilation
if (!use_precompile) {

  # Check repository content
10
  source_dir <- paste0(R_PACKAGE_SOURCE, "/src/")
Laurae's avatar
Laurae committed
11
12
13
14
15
16
  setwd(source_dir)
  
  if (!file.exists("_IS_FULL_PACKAGE")) {
    if (!file.copy("./../../include", "./", overwrite = TRUE, recursive = TRUE)) {
      stop("Cannot find folder LightGBM/include")
    }
17
18
19
20
    if (!file.copy("./../../src", "./", overwrite = TRUE, recursive = TRUE)) {
      stop("Cannot find folder LightGBM/src")
    }
    if (use_gpu) {
Laurae's avatar
Laurae committed
21
22
23
24
25
26
27
28
      if (!file.copy("./../../compute", "./", overwrite = TRUE, recursive = TRUE)) {
        print("Cannot find folder LightGBM/compute, disabling GPU build.")
        use_gpu <- FALSE
      }
    }
    if (!file.copy("./../../CMakeLists.txt", "./", overwrite = TRUE, recursive = TRUE)) {
  	  stop("Cannot find file LightGBM/CMakeLists.txt")
    }
29
  }
Laurae's avatar
Laurae committed
30
31
  
  # Prepare building package
32
  build_dir <- paste0(source_dir, "build/")
Laurae's avatar
Laurae committed
33
34
35
  dir.create(build_dir, recursive = TRUE, showWarnings = FALSE)
  setwd(build_dir)
  
36
  # Prepare installation steps
Laurae's avatar
Laurae committed
37
38
  cmake_cmd <- "cmake"
  build_cmd <- "make -j"
39
  lib_folder <- paste0(R_PACKAGE_SOURCE, "/src/")
Laurae's avatar
Laurae committed
40
  
41
  # Check if Windows installation (for gcc vs Visual Studio)
Laurae's avatar
Laurae committed
42
43
44
45
46
47
48
  if (WINDOWS) {
    if (use_mingw) {
      cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ")
      build_cmd <- "mingw32-make.exe -j"
    } else {
      cmake_cmd <- paste0(cmake_cmd, " -DCMAKE_GENERATOR_PLATFORM=x64 ")
      build_cmd <- "cmake --build . --target _lightgbm  --config Release"
49
      lib_folder <- paste0(R_PACKAGE_SOURCE, "/src/Release/")
50
51
    }
  }
Laurae's avatar
Laurae committed
52
53
54
  
  if (use_gpu) {
    cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=1 ")
55
  }
Laurae's avatar
Laurae committed
56
57
58
59
  
  # Install
  system(paste0(cmake_cmd, " .."))
  system(build_cmd)
60
  src <- paste0(lib_folder, "lib_lightgbm", SHLIB_EXT)
Laurae's avatar
Laurae committed
61
62
  
} else {
63

Laurae's avatar
Laurae committed
64
65
66
67
  # Has precompiled package
  lib_folder <- paste0(R_PACKAGE_SOURCE, "/../")
  if (file.exists(paste0(lib_folder, "lib_lightgbm", SHLIB_EXT))) {
    src <- paste0(lib_folder, "lib_lightgbm", SHLIB_EXT)
68
69
  } else if (file.exists(paste0(lib_folder, "Release/lib_lightgbm", SHLIB_EXT))){
    src <- paste0(lib_folder, "Release/lib_lightgbm", SHLIB_EXT) 
Laurae's avatar
Laurae committed
70
  } else {
71
    src <- paste0(lib_folder, "windows/x64/DLL/lib_lightgbm", SHLIB_EXT) # Expected result: installation will fail if it is not here or any other
72
  }
Laurae's avatar
Laurae committed
73
  
74
75
}

Laurae's avatar
Laurae committed
76
77
# Check installation correctness
dest <- file.path(R_PACKAGE_DIR, paste0("libs", R_ARCH))
78
dir.create(dest, recursive = TRUE, showWarnings = FALSE)
Laurae's avatar
Laurae committed
79
80
if (file.exists(src)) {
  cat("Found library file: ", src, " to move to ", dest, sep = "")
81
82
  file.copy(src, dest, overwrite = TRUE)
} else {
Laurae's avatar
Laurae committed
83
  stop(paste0("Cannot find lib_lightgbm", SHLIB_EXT))
84
}