Skip to content

Commit bf2f49f

Browse files
committed
CMake: Avoid mixed OpenMP linkage
1 parent c856ba6 commit bf2f49f

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ if (USE_OPENMP)
117117
set(CCOMMON_OPT "${CCOMMON_OPT} -DUSE_OPENMP")
118118
if (NOT NOFORTRAN)
119119
find_package(OpenMP COMPONENTS Fortran REQUIRED)
120+
# Avoid mixed OpenMP linkage
121+
get_target_property(OMP_C_LIB OpenMP::OpenMP_C INTERFACE_LINK_LIBRARIES)
122+
get_target_property(OMP_Fortran_LIB OpenMP::OpenMP_Fortran INTERFACE_LINK_LIBRARIES)
123+
if (NOT OMP_C_LIB STREQUAL OMP_Fortran_LIB)
124+
message(FATAL_ERROR "Multiple OpenMP runtime libraries detected. Mixed OpenMP runtime linkage is dangerous. You may pass -DOpenMP_LANG_LIB_NAMES and -DOpenMP_omp_LIBRARY to manually choose the OpenMP library.")
125+
endif()
120126
endif ()
121127
endif ()
122128

ctest/CMakeLists.txt

-16
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ else()
4444
c_${float_char}blas1.c)
4545
endif()
4646
target_link_libraries(x${float_char}cblat1 ${OpenBLAS_LIBNAME})
47-
if (USE_OPENMP AND (${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU) AND (${CMAKE_C_COMPILER_ID} STREQUAL Clang))
48-
string(REGEX REPLACE "-fopenmp" "" CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
49-
target_link_libraries(x${float_char}cblat1 omp pthread)
50-
endif()
5147
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "QNX")
5248
target_link_libraries(x${float_char}cblat1 m)
5349
endif()
@@ -73,10 +69,6 @@ else()
7369
constant.c)
7470
endif()
7571
target_link_libraries(x${float_char}cblat2 ${OpenBLAS_LIBNAME})
76-
if (USE_OPENMP AND (${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU) AND (${CMAKE_C_COMPILER_ID} STREQUAL Clang))
77-
string(REGEX REPLACE "-fopenmp" "" CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
78-
target_link_libraries(x${float_char}cblat2 omp pthread)
79-
endif()
8072
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "QNX")
8173
target_link_libraries(x${float_char}cblat2 m)
8274
endif()
@@ -124,20 +116,12 @@ else()
124116
endif()
125117
endif()
126118
target_link_libraries(x${float_char}cblat3 ${OpenBLAS_LIBNAME})
127-
if (USE_OPENMP AND (${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU) AND (${CMAKE_C_COMPILER_ID} STREQUAL Clang))
128-
string(REGEX REPLACE "-fopenmp" "" CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
129-
target_link_libraries(x${float_char}cblat3 omp pthread)
130-
endif()
131119
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "QNX")
132120
target_link_libraries(x${float_char}cblat3 m)
133121
endif()
134122
if (USE_GEMM3M)
135123
if ((${float_char} STREQUAL "c") OR (${float_char} STREQUAL "z"))
136124
target_link_libraries(x${float_char}cblat3_3m ${OpenBLAS_LIBNAME})
137-
if (USE_OPENMP AND (${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU) AND (${CMAKE_C_COMPILER_ID} STREQUAL Clang))
138-
string(REGEX REPLACE "-fopenmp" "" CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
139-
target_link_libraries(x${float_char}cblat3 omp pthread)
140-
endif()
141125
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "QNX")
142126
target_link_libraries(x${float_char}cblat3_3m m)
143127
endif()

test/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ endif ()
3434
foreach(test_bin ${OpenBLAS_Tests})
3535
add_executable(${test_bin} ${test_bin}.f)
3636
target_link_libraries(${test_bin} ${OpenBLAS_LIBNAME})
37-
if (USE_OPENMP AND (${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU) AND (${CMAKE_C_COMPILER_ID} STREQUAL Clang))
38-
string(REGEX REPLACE "-fopenmp" "" CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
39-
target_link_libraries(${test_bin} omp pthread)
40-
endif()
4137
endforeach()
4238

4339
# $1 exec, $2 input, $3 output_result

0 commit comments

Comments
 (0)