Skip to content

Commit

Permalink
[R] reformat build scripts (#9540)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored Sep 4, 2023
1 parent 419e052 commit d159ee8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 25 deletions.
39 changes: 26 additions & 13 deletions R-package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
find_package(LibR REQUIRED)
message(STATUS "LIBR_CORE_LIBRARY " ${LIBR_CORE_LIBRARY})

file(GLOB_RECURSE R_SOURCES
file(
GLOB_RECURSE R_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/*.cc
${CMAKE_CURRENT_LIST_DIR}/src/*.c)
${CMAKE_CURRENT_LIST_DIR}/src/*.c
)

# Use object library to expose symbols
add_library(xgboost-r OBJECT ${R_SOURCES})
if (ENABLE_ALL_WARNINGS)

if(ENABLE_ALL_WARNINGS)
target_compile_options(xgboost-r PRIVATE -Wall -Wextra)
endif (ENABLE_ALL_WARNINGS)
target_compile_definitions(xgboost-r
PUBLIC
endif()

target_compile_definitions(
xgboost-r PUBLIC
-DXGBOOST_STRICT_R_MODE=1
-DXGBOOST_CUSTOMIZE_GLOBAL_PRNG=1
-DDMLC_LOG_BEFORE_THROW=0
-DDMLC_DISABLE_STDIN=1
-DDMLC_LOG_CUSTOMIZE=1
-DRABIT_STRICT_CXX98_)
target_include_directories(xgboost-r
PRIVATE
-DRABIT_STRICT_CXX98_
)

target_include_directories(
xgboost-r PRIVATE
${LIBR_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/dmlc-core/include
${PROJECT_SOURCE_DIR}/rabit/include)
${PROJECT_SOURCE_DIR}/rabit/include
)

target_link_libraries(xgboost-r PUBLIC ${LIBR_CORE_LIBRARY})
if (USE_OPENMP)

if(USE_OPENMP)
find_package(OpenMP REQUIRED)
target_link_libraries(xgboost-r PUBLIC OpenMP::OpenMP_CXX OpenMP::OpenMP_C)
endif (USE_OPENMP)
endif()

set_target_properties(
xgboost-r PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON)
POSITION_INDEPENDENT_CODE ON
)

# Get compilation and link flags of xgboost-r and propagate to objxgboost
target_link_libraries(objxgboost PUBLIC xgboost-r)

# Add all objects of xgboost-r to objxgboost
target_sources(objxgboost INTERFACE $<TARGET_OBJECTS:xgboost-r>)

Expand Down
31 changes: 25 additions & 6 deletions R-package/src/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,38 @@ ENABLE_STD_THREAD=1

CXX_STD = CXX17

XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0\
-DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) -DDMLC_DISABLE_STDIN=1\
-DDMLC_LOG_CUSTOMIZE=1
XGB_RFLAGS = \
-DXGBOOST_STRICT_R_MODE=1 \
-DDMLC_LOG_BEFORE_THROW=0 \
-DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) \
-DDMLC_DISABLE_STDIN=1 \
-DDMLC_LOG_CUSTOMIZE=1

# disable the use of thread_local for 32 bit windows:
ifeq ($(R_OSTYPE)$(WIN),windows)
XGB_RFLAGS += -DDMLC_CXX11_THREAD_LOCAL=0
endif
$(foreach v, $(XGB_RFLAGS), $(warning $(v)))

PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(PKGROOT)/dmlc-core/include -I$(PKGROOT)/rabit/include -I$(PKGROOT) $(XGB_RFLAGS)
PKG_CXXFLAGS= @OPENMP_CXXFLAGS@ @ENDIAN_FLAG@ -pthread $(CXX_VISIBILITY)
PKG_LIBS = @OPENMP_CXXFLAGS@ @OPENMP_LIB@ @ENDIAN_FLAG@ @BACKTRACE_LIB@ -pthread
PKG_CPPFLAGS = \
-I$(PKGROOT)/include \
-I$(PKGROOT)/dmlc-core/include \
-I$(PKGROOT)/rabit/include \
-I$(PKGROOT) \
$(XGB_RFLAGS)

PKG_CXXFLAGS = \
@OPENMP_CXXFLAGS@ \
@ENDIAN_FLAG@ \
-pthread \
$(CXX_VISIBILITY)

PKG_LIBS = \
@OPENMP_CXXFLAGS@ \
@OPENMP_LIB@ \
@ENDIAN_FLAG@ \
@BACKTRACE_LIB@ \
-pthread

OBJECTS= \
./xgboost_R.o \
Expand Down
31 changes: 25 additions & 6 deletions R-package/src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,38 @@ ENABLE_STD_THREAD=0

CXX_STD = CXX17

XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0\
-DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) -DDMLC_DISABLE_STDIN=1\
-DDMLC_LOG_CUSTOMIZE=1
XGB_RFLAGS = \
-DXGBOOST_STRICT_R_MODE=1 \
-DDMLC_LOG_BEFORE_THROW=0 \
-DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) \
-DDMLC_DISABLE_STDIN=1 \
-DDMLC_LOG_CUSTOMIZE=1

# disable the use of thread_local for 32 bit windows:
ifeq ($(R_OSTYPE)$(WIN),windows)
XGB_RFLAGS += -DDMLC_CXX11_THREAD_LOCAL=0
endif
$(foreach v, $(XGB_RFLAGS), $(warning $(v)))

PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(PKGROOT)/dmlc-core/include -I$(PKGROOT)/rabit/include -I$(PKGROOT) $(XGB_RFLAGS)
PKG_CXXFLAGS= $(SHLIB_OPENMP_CXXFLAGS) -DDMLC_CMAKE_LITTLE_ENDIAN=1 $(SHLIB_PTHREAD_FLAGS) $(CXX_VISIBILITY)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) -DDMLC_CMAKE_LITTLE_ENDIAN=1 $(SHLIB_PTHREAD_FLAGS) -lwsock32 -lws2_32
PKG_CPPFLAGS = \
-I$(PKGROOT)/include \
-I$(PKGROOT)/dmlc-core/include \
-I$(PKGROOT)/rabit/include \
-I$(PKGROOT) \
$(XGB_RFLAGS)

PKG_CXXFLAGS = \
$(SHLIB_OPENMP_CXXFLAGS) \
-DDMLC_CMAKE_LITTLE_ENDIAN=1 \
$(SHLIB_PTHREAD_FLAGS) \
$(CXX_VISIBILITY)

PKG_LIBS = \
$(SHLIB_OPENMP_CXXFLAGS) \
-DDMLC_CMAKE_LITTLE_ENDIAN=1 \
$(SHLIB_PTHREAD_FLAGS) \
-lwsock32 \
-lws2_32

OBJECTS= \
./xgboost_R.o \
Expand Down

0 comments on commit d159ee8

Please sign in to comment.