Skip to content

Commit

Permalink
lightgbm: restore patches for the Clang OpenMP support fix
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Nov 17, 2023
1 parent 228a656 commit 1e3e729
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
13 changes: 13 additions & 0 deletions recipes/lightgbm/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,16 @@ sources:
"3.3.2":
url: "https://github.com/microsoft/LightGBM/archive/refs/tags/v3.3.2.tar.gz"
sha256: "d7c0f842e94165578d5a0c046ca942838d1574149f98c84400ce511239d17b9f"
patches:
"4.1.0":
- patch_file: "patches/4.1.0-0001-fix-openmp-clang.patch"
patch_type: "portability"
patch_description: "Fix OpenMP support for Clang"
"3.3.5":
- patch_file: "patches/3.3.5-0001-fix-openmp-clang.patch"
patch_type: "portability"
patch_description: "Fix OpenMP support for Clang"
"3.3.2":
- patch_file: "patches/3.3.2-0001-fix-openmp-clang.patch"
patch_type: "portability"
patch_description: "Fix OpenMP support for Clang"
8 changes: 5 additions & 3 deletions recipes/lightgbm/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, replace_in_file, save
from conan.tools.files import copy, get, replace_in_file, save, export_conandata_patches, apply_conandata_patches
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version

Expand Down Expand Up @@ -36,6 +36,9 @@ class LightGBMConan(ConanFile):
"with_openmp": True,
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand Down Expand Up @@ -74,9 +77,8 @@ def generate(self):
tc.generate()

def _patch_sources(self):
apply_conandata_patches(self)
cmakelists_path = os.path.join(self.source_folder, "CMakeLists.txt")
# Fix OpenMP detection for Clang
replace_in_file(self, cmakelists_path, "AppleClang", "Clang|AppleClang")
# Fix vendored dependency includes
common_h = os.path.join(self.source_folder, "include", "LightGBM", "utils", "common.h")
for lib in ["fmt", "fast_double_parser"]:
Expand Down
13 changes: 13 additions & 0 deletions recipes/lightgbm/all/patches/3.3.2-0001-fix-openmp-clang.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 109a252d..e5d46bce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -415,7 +415,7 @@ if(USE_MPI)
endif(USE_MPI)

if(USE_OPENMP)
- if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
+ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
TARGET_LINK_LIBRARIES(lightgbm OpenMP::OpenMP_CXX)
TARGET_LINK_LIBRARIES(_lightgbm OpenMP::OpenMP_CXX)
endif()
13 changes: 13 additions & 0 deletions recipes/lightgbm/all/patches/3.3.5-0001-fix-openmp-clang.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 95610d55..2b48507d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -444,7 +444,7 @@ if(USE_MPI)
endif(USE_MPI)

if(USE_OPENMP)
- if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
+ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
TARGET_LINK_LIBRARIES(lightgbm OpenMP::OpenMP_CXX)
TARGET_LINK_LIBRARIES(_lightgbm OpenMP::OpenMP_CXX)
endif()
11 changes: 11 additions & 0 deletions recipes/lightgbm/all/patches/4.1.0-0001-fix-openmp-clang.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -526,7 +526,7 @@
endif()

if(USE_OPENMP)
- if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang|AppleClang")
target_link_libraries(lightgbm_objs PUBLIC OpenMP::OpenMP_CXX)
# c_api headers also includes OpenMP headers, thus compiling
# lightgbm_capi_objs needs include directory for OpenMP.

0 comments on commit 1e3e729

Please sign in to comment.