install.libs.R 1.7 KB
Newer Older
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
use_gpu <- FALSE
use_mingw <- FALSE
source_dir <- paste0(R_PACKAGE_SOURCE, '/src')
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, will disable GPU build")
      use_gpu <- FALSE
    }
  }
  if(!file.copy("./../../CMakeLists.txt", "./", overwrite=TRUE, recursive=TRUE)){
    stop("cannot find file LightGBM/CMakeLists.txt")
  }
}

build_dir <- paste0(source_dir, "/build")
dir.create(build_dir, recursive = TRUE, showWarnings = FALSE)
setwd(build_dir)

cmake_cmd <- "cmake"
build_cmd <- "make -j"
lib_folder <- paste0(R_PACKAGE_SOURCE, '/src')

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"
    lib_folder <- paste0(R_PACKAGE_SOURCE, '/src/Release')
  }
}

if(use_gpu) {
  cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=1 ")
}

system(paste0(cmake_cmd, " .."))
system(build_cmd)
dest <- file.path(R_PACKAGE_DIR, paste0('libs', R_ARCH))
dir.create(dest, recursive = TRUE, showWarnings = FALSE)
src <- paste0(lib_folder, '/lib_lightgbm', SHLIB_EXT)
if(file.exists(src)){
  print(paste0("find library file: ", src))
  file.copy(src, dest, overwrite = TRUE)
} else {
  stop("cannot find lib_lightgbm.dll")
}