diff --git a/.ci/test_r_package_windows.ps1 b/.ci/test_r_package_windows.ps1 index 891c7cbd36e1..fc6fbc9ee4f3 100644 --- a/.ci/test_r_package_windows.ps1 +++ b/.ci/test_r_package_windows.ps1 @@ -132,13 +132,13 @@ Run-R-Code-Redirect-Stderr "options(install.packages.check.source = 'no'); insta # # MiKTeX always needs to be built to test a CRAN package. if (($env:COMPILER -eq "MINGW") -or ($env:R_BUILD_TYPE -eq "cran")) { - Download-File-With-Retries "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/miktexsetup-4.0-x64.zip" -destfile "miktexsetup-x64.zip" + Download-File-With-Retries "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/miktexsetup-5.2.0-x64.zip" -destfile "miktexsetup-x64.zip" Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory("miktexsetup-x64.zip", "miktex") Write-Output "Setting up MiKTeX" - .\miktex\miktexsetup.exe --remote-package-repository="$env:CTAN_PACKAGE_ARCHIVE" --local-package-repository=./miktex/download --package-set=essential --quiet download ; Check-Output $? + .\miktex\miktexsetup_standalone.exe --remote-package-repository="$env:CTAN_PACKAGE_ARCHIVE" --local-package-repository=./miktex/download --package-set=essential --quiet download ; Check-Output $? Write-Output "Installing MiKTeX" - .\miktex\download\miktexsetup.exe --remote-package-repository="$env:CTAN_PACKAGE_ARCHIVE" --portable="$env:R_LIB_PATH/miktex" --quiet install ; Check-Output $? + .\miktex\download\miktexsetup_standalone.exe --remote-package-repository="$env:CTAN_PACKAGE_ARCHIVE" --portable="$env:R_LIB_PATH/miktex" --quiet install ; Check-Output $? Write-Output "Done installing MiKTeX" Run-R-Code-Redirect-Stderr "result <- processx::run(command = 'initexmf', args = c('--set-config-value', '[MPM]AutoInstall=1'), echo = TRUE, windows_verbatim_args = TRUE, error_on_status = TRUE)" ; Check-Output $? diff --git a/CMakeLists.txt b/CMakeLists.txt index e313f58dd347..95610d557d05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,9 +132,26 @@ if(USE_CUDA) endif(USE_CUDA) if(USE_OPENMP) - find_package(OpenMP REQUIRED) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") -endif(USE_OPENMP) + if(APPLE) + find_package(OpenMP) + if(NOT OpenMP_FOUND) + # 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) + find_package(OpenMP REQUIRED) + endif() + else() + find_package(OpenMP REQUIRED) + endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") +endif() if(USE_GPU) SET(BOOST_COMPUTE_HEADER_DIR ${PROJECT_SOURCE_DIR}/external_libs/compute/include) diff --git a/R-package/configure b/R-package/configure index f94bf5831774..2b4951755c2f 100755 --- a/R-package/configure +++ b/R-package/configure @@ -1800,6 +1800,27 @@ if test `uname -s` = "Darwin" then OPENMP_CXXFLAGS='-Xclang -fopenmp' OPENMP_LIB='-lomp' + + # libomp 15.0+ from brew is keg-only (i.e. not symlinked into the standard paths search by the linker), + # so need to search in other locations. + # See https://github.com/Homebrew/homebrew-core/issues/112107#issuecomment-1278042927. + # + # If Homebrew is found and libomp was installed with it, this code adds the necessary + # flags for the compiler to find libomp headers and for the linker to find libomp.dylib. + HOMEBREW_LIBOMP_PREFIX="" + if command -v brew &> /dev/null; then + ac_brew_openmp=no + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether OpenMP was installed via Homebrew" >&5 +$as_echo_n "checking whether OpenMP was installed via Homebrew... " >&6; } + brew --prefix libomp &>/dev/null && ac_brew_openmp=yes + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_brew_openmp}" >&5 +$as_echo "${ac_brew_openmp}" >&6; } + if test "${ac_brew_openmp}" = yes; then + HOMEBREW_LIBOMP_PREFIX=`brew --prefix libomp` + OPENMP_CXXFLAGS="${OPENMP_CXXFLAGS} -I${HOMEBREW_LIBOMP_PREFIX}/include" + OPENMP_LIB="${OPENMP_LIB} -L${HOMEBREW_LIBOMP_PREFIX}/lib" + fi + fi ac_pkg_openmp=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether OpenMP will work in a package" >&5 $as_echo_n "checking whether OpenMP will work in a package... " >&6; } diff --git a/R-package/configure.ac b/R-package/configure.ac index ae8249cd659b..75ebbcf2a5e3 100644 --- a/R-package/configure.ac +++ b/R-package/configure.ac @@ -104,6 +104,25 @@ if test `uname -s` = "Darwin" then OPENMP_CXXFLAGS='-Xclang -fopenmp' OPENMP_LIB='-lomp' + + # libomp 15.0+ from brew is keg-only (i.e. not symlinked into the standard paths search by the linker), + # so need to search in other locations. + # See https://github.com/Homebrew/homebrew-core/issues/112107#issuecomment-1278042927. + # + # If Homebrew is found and libomp was installed with it, this code adds the necessary + # flags for the compiler to find libomp headers and for the linker to find libomp.dylib. + HOMEBREW_LIBOMP_PREFIX="" + if command -v brew &> /dev/null; then + ac_brew_openmp=no + AC_MSG_CHECKING([whether OpenMP was installed via Homebrew]) + brew --prefix libomp &>/dev/null && ac_brew_openmp=yes + AC_MSG_RESULT([${ac_brew_openmp}]) + if test "${ac_brew_openmp}" = yes; then + HOMEBREW_LIBOMP_PREFIX=`brew --prefix libomp` + OPENMP_CXXFLAGS="${OPENMP_CXXFLAGS} -I${HOMEBREW_LIBOMP_PREFIX}/include" + OPENMP_LIB="${OPENMP_LIB} -L${HOMEBREW_LIBOMP_PREFIX}/lib" + fi + fi ac_pkg_openmp=no AC_MSG_CHECKING([whether OpenMP will work in a package]) AC_LANG_CONFTEST(