install.libs.R 2.87 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 <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/")
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 <- file.path(source_dir, "build", fsep = "/")
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 <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/")
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 <- file.path(R_PACKAGE_SOURCE, "src/Release", fsep = "/")
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 <- file.path(lib_folder, paste0("lib_lightgbm", SHLIB_EXT), fsep = "/")
Laurae's avatar
Laurae committed
61
62
  
} else {
63

Laurae's avatar
Laurae committed
64
  # Has precompiled package
65
66
67
68
69
  lib_folder <- file.path(R_PACKAGE_SOURCE, "../", fsep = "/")
  if (file.exists(file.path(lib_folder, paste0("lib_lightgbm", SHLIB_EXT), fsep = "/"))) {
    src <- file.path(lib_folder, paste0("lib_lightgbm", SHLIB_EXT), fsep = "/")
  } else if (file.exists(file.path(lib_folder, paste0("Release/lib_lightgbm", SHLIB_EXT), fsep = "/"))) {
    src <- file.path(lib_folder, paste0("Release/lib_lightgbm", SHLIB_EXT), fsep = "/") 
Laurae's avatar
Laurae committed
70
  } else {
71
    src <- file.path(lib_folder, paste0("/windows/x64/DLL/lib_lightgbm", SHLIB_EXT), fsep = "/") # 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
# Check installation correctness
77
dest <- file.path(R_PACKAGE_DIR, paste0("libs", R_ARCH), fsep = "/")
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
}