install.libs.R 2.59 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
17
18
19
20
21
22
23
24
25
26
27
28
  setwd(source_dir)
  
  if (!file.exists("_IS_FULL_PACKAGE")) {
    if (!file.copy("./../../include", "./", overwrite = TRUE, recursive = TRUE)) {
      stop("Cannot find folder LightGBM/include")
    }
	  if (!file.copy("./../../src", "./", overwrite = TRUE, recursive = TRUE)) {
		  stop("Cannot find folder LightGBM/src")
	  }
	  if (use_gpu) {
      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
36
37
38
  dir.create(build_dir, recursive = TRUE, showWarnings = FALSE)
  setwd(build_dir)
  
  # Prepare installatio nsteps
  cmake_cmd <- "cmake"
  build_cmd <- "make -j"
39
  lib_folder <- paste0(R_PACKAGE_SOURCE, "/src/")
Laurae's avatar
Laurae committed
40
41
42
43
44
45
46
47
  
  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"
48
      lib_folder <- paste0(R_PACKAGE_SOURCE, "src/Release/")
49
50
    }
  }
Laurae's avatar
Laurae committed
51
52
53
  
  if (use_gpu) {
    cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=1 ")
54
  }
Laurae's avatar
Laurae committed
55
56
57
58
  
  # Install
  system(paste0(cmake_cmd, " .."))
  system(build_cmd)
59
  src <- paste0(lib_folder, "lib_lightgbm", SHLIB_EXT)
Laurae's avatar
Laurae committed
60
61
  
} else {
62

Laurae's avatar
Laurae committed
63
64
65
66
  # 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)
67
68
  } 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
69
  } else {
70
    src <- paste0(lib_folder, "windows/x64/DLL/lib_lightgbm", SHLIB_EXT) # Expected result: installation will fail if it is not here or any other
71
  }
Laurae's avatar
Laurae committed
72
  
73
74
}

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