From d1a2140a9455d3364e2b2d6860e4e7333ac9c6ca Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Sun, 10 Mar 2024 01:51:24 +0700 Subject: [PATCH] Fix CMakeLists.txt --- CMakeLists.txt | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git CMakeLists.txt CMakeLists.txt index 1ff289b9..43f6bcea 100644 --- CMakeLists.txt +++ CMakeLists.txt @@ -35,11 +35,7 @@ project(lightgbm LANGUAGES C CXX) -if(BUILD_CPP_TEST) - set(CMAKE_CXX_STANDARD 14) -else() - set(CMAKE_CXX_STANDARD 11) -endif() +set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules") @@ -115,19 +111,16 @@ endif() endif() -set(EIGEN_DIR "${PROJECT_SOURCE_DIR}/external_libs/eigen") +find_package(fmt REQUIRED) +include_directories(${LIBFMT_DIR}) + +find_package(Eigen3 REQUIRED NO_MODULE) include_directories(${EIGEN_DIR}) # See https://gitlab.com/libeigen/eigen/-/blob/master/COPYING.README add_definitions(-DEIGEN_MPL2_ONLY) add_definitions(-DEIGEN_DONT_PARALLELIZE) -set(FAST_DOUBLE_PARSER_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/external_libs/fast_double_parser/include") -include_directories(${FAST_DOUBLE_PARSER_INCLUDE_DIR}) - -set(FMT_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/external_libs/fmt/include") -include_directories(${FMT_INCLUDE_DIR}) - if(__BUILD_FOR_R) find_package(LibR REQUIRED) message(STATUS "LIBR_EXECUTABLE: ${LIBR_EXECUTABLE}") @@ -159,26 +152,7 @@ endif() if(USE_OPENMP) - if(APPLE) - find_package(OpenMP) - if(NOT OpenMP_FOUND) - if(USE_HOMEBREW_FALLBACK) - # libomp 15.0+ from brew is keg-only, so have to search in other locations. - # See https://github.com/Homebrew/homebrew-core/issues/112107#issuecomment-1278042927. - execute_process(COMMAND brew --prefix libomp - OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX - OUTPUT_STRIP_TRAILING_WHITESPACE) - set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include") - set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include") - set(OpenMP_C_LIB_NAMES omp) - set(OpenMP_CXX_LIB_NAMES omp) - set(OpenMP_omp_LIBRARY ${HOMEBREW_LIBOMP_PREFIX}/lib/libomp.dylib) - endif() - find_package(OpenMP REQUIRED) - endif() - else() - find_package(OpenMP REQUIRED) - endif() + find_package(OpenMP REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") endif() @@ -689,90 +663,6 @@ set(CMAKE_INSTALL_PREFIX "lightgbm") endif() -# The macOS linker puts an absolute path to linked libraries in lib_lightgbm.dylib. -# This block overrides that information for LightGBM's OpenMP dependency, to allow -# finding that library in more places. -# -# This reduces the risk of runtime issues resulting from multiple {libgomp,libiomp,libomp}.dylib being loaded. -# -if(APPLE AND USE_OPENMP) - # store path to {libgomp,libiomp,libomp}.dylib found at build time in a variable - get_target_property( - OpenMP_LIBRARY_LOCATION - OpenMP::OpenMP_CXX - INTERFACE_LINK_LIBRARIES - ) - # get just the filename of that path - # (to deal with the possibility that it might be 'libomp.dylib' or 'libgomp.dylib' or 'libiomp.dylib') - get_filename_component( - OpenMP_LIBRARY_NAME - ${OpenMP_LIBRARY_LOCATION} - NAME - ) - # get directory of that path - get_filename_component( - OpenMP_LIBRARY_DIR - ${OpenMP_LIBRARY_LOCATION} - DIRECTORY - ) - # get exact name of the library in a variable - get_target_property( - __LIB_LIGHTGBM_OUTPUT_NAME - _lightgbm - OUTPUT_NAME - ) - if(NOT __LIB_LIGHTGBM_OUTPUT_NAME) - set(__LIB_LIGHTGBM_OUTPUT_NAME "lib_lightgbm") - endif() - - if(CMAKE_SHARED_LIBRARY_SUFFIX_CXX) - set( - __LIB_LIGHTGBM_FILENAME "${__LIB_LIGHTGBM_OUTPUT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX_CXX}" - CACHE INTERNAL "lightgbm shared library filename" - ) - else() - set( - __LIB_LIGHTGBM_FILENAME "${__LIB_LIGHTGBM_OUTPUT_NAME}.dylib" - CACHE INTERNAL "lightgbm shared library filename" - ) - endif() - - # Override the absolute path to OpenMP with a relative one using @rpath. - # - # This also ensures that if a {libgomp,libiomp,libomp}.dylib has already been loaded, it'll just use that. - add_custom_command( - TARGET _lightgbm - POST_BUILD - COMMAND - install_name_tool - -change - ${OpenMP_LIBRARY_LOCATION} - "@rpath/${OpenMP_LIBRARY_NAME}" - "${__LIB_LIGHTGBM_FILENAME}" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Replacing hard-coded OpenMP install_name with '@rpath/${OpenMP_LIBRARY_NAME}'..." - ) - # add RPATH entries to ensure the loader looks in the following, in the following order: - # - # - ${OpenMP_LIBRARY_DIR} (wherever find_package(OpenMP) found OpenMP at build time) - # - /opt/homebrew/opt/libomp/lib (where 'brew install' / 'brew link' puts libomp.dylib) - # - /opt/local/lib/libomp (where 'port install' puts libomp.dylib) - # - set_target_properties( - _lightgbm - PROPERTIES - BUILD_WITH_INSTALL_RPATH TRUE - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # with clang, libomp doesn't ship with the compiler and might be supplied separately - INSTALL_RPATH "${OpenMP_LIBRARY_DIR};/opt/homebrew/opt/libomp/lib;/opt/local/lib/libomp;" - else() - # with other compilers, OpenMP ships with the compiler (e.g. libgomp with gcc) - INSTALL_RPATH "${OpenMP_LIBRARY_DIR}" - endif() - INSTALL_RPATH_USE_LINK_PATH FALSE - ) -endif() - install( TARGETS _lightgbm RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin @@ -785,13 +675,4 @@ DIRECTORY ${LightGBM_HEADER_DIR}/LightGBM DESTINATION ${CMAKE_INSTALL_PREFIX}/include ) - install( - FILES ${FAST_DOUBLE_PARSER_INCLUDE_DIR}/fast_double_parser.h - DESTINATION ${CMAKE_INSTALL_PREFIX}/include/LightGBM/utils - ) - install( - DIRECTORY ${FMT_INCLUDE_DIR}/ - DESTINATION ${CMAKE_INSTALL_PREFIX}/include/LightGBM/utils - FILES_MATCHING PATTERN "*.h" - ) endif()