Fix mingw build with R. (#5918)

This commit is contained in:
Jiaming Yuan 2020-07-22 02:56:49 +08:00 committed by GitHub
parent 8d7702766a
commit 9b688aca3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -15,8 +15,8 @@
# R_VERSION (for win) # R_VERSION (for win)
# R_ARCH (for win 64 when want 32 bit build) # R_ARCH (for win 64 when want 32 bit build)
# #
# TODO: # TODO:
# - someone to verify OSX detection, # - someone to verify OSX detection,
# - possibly, add OSX detection based on current R in PATH or LIBR_EXECUTABLE # - possibly, add OSX detection based on current R in PATH or LIBR_EXECUTABLE
# - improve registry-based R_HOME detection in Windows (from a set of R_VERSION's) # - improve registry-based R_HOME detection in Windows (from a set of R_VERSION's)
@ -37,8 +37,8 @@ endif()
# Creates R.lib and R.def in the build directory for linking with MSVC # Creates R.lib and R.def in the build directory for linking with MSVC
function(create_rlib_for_msvc) function(create_rlib_for_msvc)
# various checks and warnings # various checks and warnings
if(NOT WIN32 OR NOT MSVC) if(NOT WIN32 OR (NOT MSVC AND NOT MINGW))
message(FATAL_ERROR "create_rlib_for_msvc() can only be used with MSVC") message(FATAL_ERROR "create_rlib_for_msvc() can only be used with MSVC or MINGW")
endif() endif()
if(NOT EXISTS "${LIBR_LIB_DIR}") if(NOT EXISTS "${LIBR_LIB_DIR}")
message(FATAL_ERROR "LIBR_LIB_DIR was not set!") message(FATAL_ERROR "LIBR_LIB_DIR was not set!")
@ -90,7 +90,7 @@ if(APPLE)
set(LIBR_INCLUDE_DIRS "${LIBR_HOME}/include" CACHE PATH "R include directory") set(LIBR_INCLUDE_DIRS "${LIBR_HOME}/include" CACHE PATH "R include directory")
set(LIBR_LIB_DIR "${LIBR_HOME}/lib" CACHE PATH "R lib directory") set(LIBR_LIB_DIR "${LIBR_HOME}/lib" CACHE PATH "R lib directory")
endif() endif()
# detection for UNIX & Win32 # detection for UNIX & Win32
else() else()
@ -98,7 +98,7 @@ else()
if(NOT LIBR_EXECUTABLE) if(NOT LIBR_EXECUTABLE)
find_program(LIBR_EXECUTABLE NAMES R R.exe) find_program(LIBR_EXECUTABLE NAMES R R.exe)
endif() endif()
if(UNIX) if(UNIX)
if(NOT LIBR_EXECUTABLE) if(NOT LIBR_EXECUTABLE)
@ -124,7 +124,7 @@ else()
# Windows # Windows
else() else()
# ask R for R_HOME # ask R for R_HOME
if(LIBR_EXECUTABLE) if(LIBR_EXECUTABLE)
execute_process( execute_process(
COMMAND ${LIBR_EXECUTABLE} "--slave" "--no-save" "-e" "cat(normalizePath(R.home(),winslash='/'))" COMMAND ${LIBR_EXECUTABLE} "--slave" "--no-save" "-e" "cat(normalizePath(R.home(),winslash='/'))"
@ -147,7 +147,7 @@ else()
# set other R paths based on home path # set other R paths based on home path
set(LIBR_INCLUDE_DIRS "${LIBR_HOME}/include") set(LIBR_INCLUDE_DIRS "${LIBR_HOME}/include")
set(LIBR_LIB_DIR "${LIBR_HOME}/bin/${R_ARCH}") set(LIBR_LIB_DIR "${LIBR_HOME}/bin/${R_ARCH}")
message(STATUS "LIBR_HOME [${LIBR_HOME}]") message(STATUS "LIBR_HOME [${LIBR_HOME}]")
message(STATUS "LIBR_EXECUTABLE [${LIBR_EXECUTABLE}]") message(STATUS "LIBR_EXECUTABLE [${LIBR_EXECUTABLE}]")
message(STATUS "LIBR_INCLUDE_DIRS [${LIBR_INCLUDE_DIRS}]") message(STATUS "LIBR_INCLUDE_DIRS [${LIBR_INCLUDE_DIRS}]")
@ -158,7 +158,7 @@ message(STATUS "LIBR_CORE_LIBRARY [${LIBR_CORE_LIBRARY}]")
endif() endif()
if(WIN32 AND MSVC) if((WIN32 AND MSVC) OR (WIN32 AND MINGW))
# create a local R.lib import library for R.dll if it doesn't exist # create a local R.lib import library for R.dll if it doesn't exist
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/R.lib") if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/R.lib")
create_rlib_for_msvc() create_rlib_for_msvc()

View File

@ -94,7 +94,7 @@ TEST(GPUPredictor, ExternalMemoryTest) {
gpu_predictor->Configure({}); gpu_predictor->Configure({});
LearnerModelParam param; LearnerModelParam param;
param.num_feature = 2; param.num_feature = 5;
const int n_classes = 3; const int n_classes = 3;
param.num_output_group = n_classes; param.num_output_group = n_classes;
param.base_score = 0.5; param.base_score = 0.5;