diff --git a/R-package/CMakeLists.txt b/R-package/CMakeLists.txt index 003a635a5485..a19e56f4e6eb 100644 --- a/R-package/CMakeLists.txt +++ b/R-package/CMakeLists.txt @@ -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 $) diff --git a/R-package/src/Makevars.in b/R-package/src/Makevars.in index 9e7cbfed4c18..f42c94501b06 100644 --- a/R-package/src/Makevars.in +++ b/R-package/src/Makevars.in @@ -5,9 +5,12 @@ 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) @@ -15,9 +18,25 @@ ifeq ($(R_OSTYPE)$(WIN),windows) 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 \ diff --git a/R-package/src/Makevars.win b/R-package/src/Makevars.win index 7dfa415a43d1..1b620751f1d2 100644 --- a/R-package/src/Makevars.win +++ b/R-package/src/Makevars.win @@ -5,9 +5,12 @@ 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) @@ -15,9 +18,25 @@ ifeq ($(R_OSTYPE)$(WIN),windows) 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 \