Skip to content

Commit

Permalink
link OpenMP explicitly; help CMake actually find it
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Jul 8, 2024
1 parent 0ca728c commit 590e3ce
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
10 changes: 10 additions & 0 deletions recipe/bld.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@echo on
SetLocal EnableDelayedExpansion

:: show CPU arch to detect slow CI agents early (rather than wait for 6h timeout)
python -c "import numpy; numpy.show_config()"
Expand All @@ -9,6 +10,14 @@ copy %BUILD_PREFIX%\Library\bin\flang-new.exe %BUILD_PREFIX%\Library\bin\flang.e
mkdir build
cd build

if "%USE_OPENMP%"=="1" (
REM https://discourse.cmake.org/t/how-to-find-openmp-with-clang-on-macos/8860
set "CMAKE_EXTRA=-DOpenMP_ROOT=%LIBRARY_LIB%"
REM not picked up by `find_package(OpenMP)` for some reason
set "CMAKE_EXTRA=-DOpenMP_Fortran_FLAGS=-fopenmp -DOpenMP_Fortran_LIB_NAMES=libomp"
set "FFLAGS=%FFLAGS% -I%LIBRARY_INC%"
)

:: millions of lines of warnings with clang-19
set "CFLAGS=%CFLAGS% -w"

Expand All @@ -23,6 +32,7 @@ cmake -G "Ninja" ^
-DNUM_THREADS=128 ^
-DBUILD_SHARED_LIBS=on ^
-DUSE_OPENMP=%USE_OPENMP% ^
!CMAKE_EXTRA! ^
%SRC_DIR%
if %ERRORLEVEL% neq 0 exit 1

Expand Down
2 changes: 2 additions & 0 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package:
source:
url: https://github.com/OpenMathLib/OpenBLAS/archive/v{{ version }}.tar.gz
sha256: aa2d68b1564fe2b13bc292672608e9cdeeeb6dc34995512e65c3b10f4599e897
patches:
- patches/0001-explicitly-link-to-OpenMP.patch

build:
number: {{ build_number }}
Expand Down
51 changes: 51 additions & 0 deletions recipe/patches/0001-explicitly-link-to-OpenMP.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
From 4cab116c4e811f977c816f3027df57d1fba3bd0c Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
Date: Mon, 1 Jul 2024 09:05:00 +1100
Subject: [PATCH] explicitly link to OpenMP

bump CMake minimum to adopt CMP0074 for checking OpenMP_ROOT, see
https://cmake.org/cmake/help/latest/policy/CMP0074.html
---
CMakeLists.txt | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 096ca88b3..ef505f70d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@
## Author: Hank Anderson <hank@statease.com>
##

-cmake_minimum_required(VERSION 2.8.5)
+cmake_minimum_required(VERSION 3.12)

project(OpenBLAS C ASM)

@@ -100,6 +100,10 @@ endif()

message(WARNING "CMake support is experimental. It does not yet support all build options and may not produce the same Makefiles that OpenBLAS ships with.")

+if (USE_OPENMP)
+ find_package(OpenMP REQUIRED)
+endif ()
+
include("${PROJECT_SOURCE_DIR}/cmake/utils.cmake")
include("${PROJECT_SOURCE_DIR}/cmake/system.cmake")

@@ -256,6 +260,15 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "AIX|Android|Linux|FreeBSD|OpenBSD|NetBSD|Drago
endif()
endif()

+if (USE_OPENMP)
+ if(BUILD_STATIC_LIBS)
+ target_link_libraries(${OpenBLAS_LIBNAME}_static OpenMP::OpenMP_C)
+ endif()
+ if(BUILD_SHARED_LIBS)
+ target_link_libraries(${OpenBLAS_LIBNAME}_shared OpenMP::OpenMP_C)
+ endif()
+endif()
+
# Seems that this hack doesn't required since macOS 11 Big Sur
if (APPLE AND BUILD_SHARED_LIBS AND CMAKE_HOST_SYSTEM_VERSION VERSION_LESS 20)
set (CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1)

0 comments on commit 590e3ce

Please sign in to comment.