Skip to content

Commit

Permalink
[CI] standardize endif() calls in CMake scripts (#9637)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored Oct 8, 2023
1 parent 799f848 commit db8d117
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 99 deletions.
104 changes: 52 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cmake_policy(SET CMP0063 NEW)

if ((${CMAKE_VERSION} VERSION_GREATER 3.13) OR (${CMAKE_VERSION} VERSION_EQUAL 3.13))
cmake_policy(SET CMP0077 NEW)
endif ((${CMAKE_VERSION} VERSION_GREATER 3.13) OR (${CMAKE_VERSION} VERSION_EQUAL 3.13))
endif()

message(STATUS "CMake version ${CMAKE_VERSION}")

Expand Down Expand Up @@ -88,80 +88,80 @@ option(ADD_PKGCONFIG "Add xgboost.pc into system." ON)
#-- Checks for building XGBoost
if (USE_DEBUG_OUTPUT AND (NOT (CMAKE_BUILD_TYPE MATCHES Debug)))
message(SEND_ERROR "Do not enable `USE_DEBUG_OUTPUT' with release build.")
endif (USE_DEBUG_OUTPUT AND (NOT (CMAKE_BUILD_TYPE MATCHES Debug)))
endif()
if (USE_NCCL AND NOT (USE_CUDA))
message(SEND_ERROR "`USE_NCCL` must be enabled with `USE_CUDA` flag.")
endif (USE_NCCL AND NOT (USE_CUDA))
endif()
if (USE_DEVICE_DEBUG AND NOT (USE_CUDA))
message(SEND_ERROR "`USE_DEVICE_DEBUG` must be enabled with `USE_CUDA` flag.")
endif (USE_DEVICE_DEBUG AND NOT (USE_CUDA))
endif()
if (BUILD_WITH_SHARED_NCCL AND (NOT USE_NCCL))
message(SEND_ERROR "Build XGBoost with -DUSE_NCCL=ON to enable BUILD_WITH_SHARED_NCCL.")
endif (BUILD_WITH_SHARED_NCCL AND (NOT USE_NCCL))
endif()
if (JVM_BINDINGS AND R_LIB)
message(SEND_ERROR "`R_LIB' is not compatible with `JVM_BINDINGS' as they both have customized configurations.")
endif (JVM_BINDINGS AND R_LIB)
endif()
if (R_LIB AND GOOGLE_TEST)
message(WARNING "Some C++ unittests will fail with `R_LIB` enabled,
as R package redirects some functions to R runtime implementation.")
endif (R_LIB AND GOOGLE_TEST)
endif()
if (PLUGIN_RMM AND NOT (USE_CUDA))
message(SEND_ERROR "`PLUGIN_RMM` must be enabled with `USE_CUDA` flag.")
endif (PLUGIN_RMM AND NOT (USE_CUDA))
endif()
if (PLUGIN_RMM AND NOT ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")))
message(SEND_ERROR "`PLUGIN_RMM` must be used with GCC or Clang compiler.")
endif (PLUGIN_RMM AND NOT ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")))
endif()
if (PLUGIN_RMM AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux"))
message(SEND_ERROR "`PLUGIN_RMM` must be used with Linux.")
endif (PLUGIN_RMM AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux"))
endif()
if (ENABLE_ALL_WARNINGS)
if ((NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
message(SEND_ERROR "ENABLE_ALL_WARNINGS is only available for Clang and GCC.")
endif ((NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
endif (ENABLE_ALL_WARNINGS)
endif()
endif()
if (BUILD_STATIC_LIB AND (R_LIB OR JVM_BINDINGS))
message(SEND_ERROR "Cannot build a static library libxgboost.a when R or JVM packages are enabled.")
endif (BUILD_STATIC_LIB AND (R_LIB OR JVM_BINDINGS))
endif()
if (PLUGIN_FEDERATED)
if (CMAKE_CROSSCOMPILING)
message(SEND_ERROR "Cannot cross compile with federated learning support")
endif ()
endif()
if (BUILD_STATIC_LIB)
message(SEND_ERROR "Cannot build static lib with federated learning support")
endif ()
endif()
if (R_LIB OR JVM_BINDINGS)
message(SEND_ERROR "Cannot enable federated learning support when R or JVM packages are enabled.")
endif ()
endif()
if (WIN32)
message(SEND_ERROR "Federated learning not supported for Windows platform")
endif ()
endif ()
endif()
endif()

#-- Removed options
if (USE_AVX)
message(SEND_ERROR "The option `USE_AVX` is deprecated as experimental AVX features have been removed from XGBoost.")
endif (USE_AVX)
endif()
if (PLUGIN_LZ4)
message(SEND_ERROR "The option `PLUGIN_LZ4` is removed from XGBoost.")
endif (PLUGIN_LZ4)
endif()
if (RABIT_BUILD_MPI)
message(SEND_ERROR "The option `RABIT_BUILD_MPI` has been removed from XGBoost.")
endif (RABIT_BUILD_MPI)
endif()
if (USE_S3)
message(SEND_ERROR "The option `USE_S3` has been removed from XGBoost")
endif (USE_S3)
endif()
if (USE_AZURE)
message(SEND_ERROR "The option `USE_AZURE` has been removed from XGBoost")
endif (USE_AZURE)
endif()
if (USE_HDFS)
message(SEND_ERROR "The option `USE_HDFS` has been removed from XGBoost")
endif (USE_HDFS)
endif()

#-- Sanitizer
if (USE_SANITIZER)
include(cmake/Sanitizer.cmake)
enable_sanitizers("${ENABLED_SANITIZERS}")
endif (USE_SANITIZER)
endif()

if (USE_CUDA)
set(USE_OPENMP ON CACHE BOOL "CUDA requires OpenMP" FORCE)
Expand All @@ -178,7 +178,7 @@ if (USE_CUDA)
add_subdirectory(${PROJECT_SOURCE_DIR}/gputreeshap)

find_package(CUDAToolkit REQUIRED)
endif (USE_CUDA)
endif()

if (FORCE_COLORED_OUTPUT AND (CMAKE_GENERATOR STREQUAL "Ninja") AND
((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
Expand All @@ -204,11 +204,11 @@ if (USE_OPENMP)
set(OpenMP_CXX_LIB_NAMES omp)
set(OpenMP_omp_LIBRARY ${HOMEBREW_LIBOMP_PREFIX}/lib/libomp.dylib)
find_package(OpenMP REQUIRED)
endif ()
endif()
else ()
find_package(OpenMP REQUIRED)
endif ()
endif (USE_OPENMP)
endif()
endif()
#Add for IBM i
if (${CMAKE_SYSTEM_NAME} MATCHES "OS400")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
Expand All @@ -217,21 +217,21 @@ endif()

if (USE_NCCL)
find_package(Nccl REQUIRED)
endif (USE_NCCL)
endif()

# dmlc-core
msvc_use_static_runtime()
if (FORCE_SHARED_CRT)
set(DMLC_FORCE_SHARED_CRT ON)
endif ()
endif()
add_subdirectory(${xgboost_SOURCE_DIR}/dmlc-core)

if (MSVC)
if (TARGET dmlc_unit_tests)
target_compile_options(dmlc_unit_tests PRIVATE
-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE)
endif (TARGET dmlc_unit_tests)
endif (MSVC)
endif()
endif()

# rabit
add_subdirectory(rabit)
Expand All @@ -243,12 +243,12 @@ target_link_libraries(objxgboost PUBLIC dmlc)
# Exports some R specific definitions and objects
if (R_LIB)
add_subdirectory(${xgboost_SOURCE_DIR}/R-package)
endif (R_LIB)
endif()

# This creates its own shared library `xgboost4j'.
if (JVM_BINDINGS)
add_subdirectory(${xgboost_SOURCE_DIR}/jvm-packages)
endif (JVM_BINDINGS)
endif()

# Plugin
add_subdirectory(${xgboost_SOURCE_DIR}/plugin)
Expand All @@ -264,14 +264,14 @@ if (PLUGIN_RMM)
list(APPEND rmm_link_libs CUDA::cudart_static)
set_target_properties(rmm::rmm PROPERTIES INTERFACE_LINK_LIBRARIES "${rmm_link_libs}")
get_target_property(rmm_link_libs rmm::rmm INTERFACE_LINK_LIBRARIES)
endif (PLUGIN_RMM)
endif()

#-- library
if (BUILD_STATIC_LIB)
add_library(xgboost STATIC)
else (BUILD_STATIC_LIB)
add_library(xgboost SHARED)
endif (BUILD_STATIC_LIB)
endif()
target_link_libraries(xgboost PRIVATE objxgboost)
target_include_directories(xgboost
INTERFACE
Expand All @@ -298,8 +298,8 @@ if (BUILD_DEPRECATED_CLI)
set_output_directory(runxgboost ${xgboost_BINARY_DIR})
else ()
set_output_directory(runxgboost ${xgboost_SOURCE_DIR})
endif (KEEP_BUILD_ARTIFACTS_IN_BINARY_DIR)
endif (BUILD_DEPRECATED_CLI)
endif()
endif()
#-- End CLI for xgboost

# Common setup for all targets
Expand All @@ -313,37 +313,37 @@ if (JVM_BINDINGS)
xgboost_target_properties(xgboost4j)
xgboost_target_link_libraries(xgboost4j)
xgboost_target_defs(xgboost4j)
endif (JVM_BINDINGS)
endif()

if (KEEP_BUILD_ARTIFACTS_IN_BINARY_DIR)
set_output_directory(xgboost ${xgboost_BINARY_DIR}/lib)
else ()
set_output_directory(xgboost ${xgboost_SOURCE_DIR}/lib)
endif ()
endif()

# Ensure these two targets do not build simultaneously, as they produce outputs with conflicting names
if (BUILD_DEPRECATED_CLI)
add_dependencies(xgboost runxgboost)
endif (BUILD_DEPRECATED_CLI)
endif()

#-- Installing XGBoost
if (R_LIB)
include(cmake/RPackageInstallTargetSetup.cmake)
set_target_properties(xgboost PROPERTIES PREFIX "")
if (APPLE)
set_target_properties(xgboost PROPERTIES SUFFIX ".so")
endif (APPLE)
endif()
setup_rpackage_install_target(xgboost "${CMAKE_CURRENT_BINARY_DIR}/R-package-install")
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/dummy_inst")
endif (R_LIB)
endif()
if (MINGW)
set_target_properties(xgboost PROPERTIES PREFIX "")
endif (MINGW)
endif()

if (BUILD_C_DOC)
include(cmake/Doc.cmake)
run_doxygen()
endif (BUILD_C_DOC)
endif()

include(CPack)

Expand All @@ -364,14 +364,14 @@ if (BUILD_STATIC_LIB)
set(INSTALL_TARGETS xgboost runxgboost objxgboost dmlc)
else()
set(INSTALL_TARGETS xgboost objxgboost dmlc)
endif (BUILD_DEPRECATED_CLI)
endif()
else (BUILD_STATIC_LIB)
if (BUILD_DEPRECATED_CLI)
set(INSTALL_TARGETS xgboost runxgboost)
else(BUILD_DEPRECATED_CLI)
set(INSTALL_TARGETS xgboost)
endif (BUILD_DEPRECATED_CLI)
endif (BUILD_STATIC_LIB)
endif()
endif()

install(TARGETS ${INSTALL_TARGETS}
EXPORT XGBoostTargets
Expand Down Expand Up @@ -428,8 +428,8 @@ if (GOOGLE_TEST)
set_tests_properties(TestXGBoostCLI
PROPERTIES
PASS_REGULAR_EXPRESSION ".*test-rmse:0.087.*")
endif (BUILD_DEPRECATED_CLI)
endif (GOOGLE_TEST)
endif()
endif()

# For MSVC: Call msvc_use_static_runtime() once again to completely
# replace /MD with /MT. See https://github.com/dmlc/xgboost/issues/4462
Expand All @@ -443,4 +443,4 @@ if (ADD_PKGCONFIG)
install(
FILES ${xgboost_BINARY_DIR}/xgboost.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif (ADD_PKGCONFIG)
endif()
2 changes: 1 addition & 1 deletion cmake/Doc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function (run_doxygen)

if (NOT DOXYGEN_DOT_FOUND)
message(FATAL_ERROR "Command `dot` not found. Please install graphviz.")
endif (NOT DOXYGEN_DOT_FOUND)
endif()

configure_file(
${xgboost_SOURCE_DIR}/doc/Doxyfile.in
Expand Down
2 changes: 1 addition & 1 deletion cmake/Sanitizer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ macro(enable_sanitizer sanitizer)
set(SAN_COMPILE_FLAGS "${SAN_COMPILE_FLAGS} -fsanitize=thread")
if (TSan_FOUND)
link_libraries(${TSan_LIBRARY})
endif (TSan_FOUND)
endif()

elseif(${sanitizer} MATCHES "leak")
find_package(LSan)
Expand Down
Loading

0 comments on commit db8d117

Please sign in to comment.