diff options
author | Christian Pfeiffer <cpfeiffer@live.de> | 2017-10-13 14:17:08 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-10-17 13:53:57 (GMT) |
commit | f4cc71099a0e71bc8b141d5ada97d8841e5194ac (patch) | |
tree | a6485adda8a19bd8fb0f3ced62c9064405e86b5a /Modules/FindOpenMP.cmake | |
parent | e25d88ecb9925af45d990d47132bd45f86e20485 (diff) | |
download | CMake-f4cc71099a0e71bc8b141d5ada97d8841e5194ac.zip CMake-f4cc71099a0e71bc8b141d5ada97d8841e5194ac.tar.gz CMake-f4cc71099a0e71bc8b141d5ada97d8841e5194ac.tar.bz2 |
FindOpenMP: Improve OMP libraries search
This supports libraries given as full path and filters libraries given
in CMAKE_<LANG>_STANDARD_LIBRARIES.
Fixes: #17351
Diffstat (limited to 'Modules/FindOpenMP.cmake')
-rw-r--r-- | Modules/FindOpenMP.cmake | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake index 720db68..d3e6782 100644 --- a/Modules/FindOpenMP.cmake +++ b/Modules/FindOpenMP.cmake @@ -211,13 +211,27 @@ function(_OPENMP_GET_FLAGS LANG FLAG_MODE OPENMP_FLAG_VAR OPENMP_LIB_NAMES_VAR) unset(_OPENMP_LIB_NAMES) foreach(_OPENMP_IMPLICIT_LIB IN LISTS OpenMP_${LANG}_IMPLICIT_LIBRARIES) - if(NOT "${_OPENMP_IMPLICIT_LIB}" IN_LIST CMAKE_${LANG}_IMPLICIT_LINK_LIBRARIES) - find_library(OpenMP_${_OPENMP_IMPLICIT_LIB}_LIBRARY - NAMES "${_OPENMP_IMPLICIT_LIB}" - HINTS ${OpenMP_${LANG}_IMPLICIT_LINK_DIRS} - ) - mark_as_advanced(OpenMP_${_OPENMP_IMPLICIT_LIB}_LIBRARY) - list(APPEND _OPENMP_LIB_NAMES ${_OPENMP_IMPLICIT_LIB}) + get_filename_component(_OPENMP_IMPLICIT_LIB_DIR "${_OPENMP_IMPLICIT_LIB}" DIRECTORY) + get_filename_component(_OPENMP_IMPLICIT_LIB_NAME "${_OPENMP_IMPLICIT_LIB}" NAME) + get_filename_component(_OPENMP_IMPLICIT_LIB_PLAIN "${_OPENMP_IMPLICIT_LIB}" NAME_WE) + string(REGEX REPLACE "([][+.*?()^$])" "\\\\\\1" _OPENMP_IMPLICIT_LIB_PLAIN_ESC "${_OPENMP_IMPLICIT_LIB_PLAIN}") + string(REGEX REPLACE "([][+.*?()^$])" "\\\\\\1" _OPENMP_IMPLICIT_LIB_PATH_ESC "${_OPENMP_IMPLICIT_LIB}") + if(NOT ( "${_OPENMP_IMPLICIT_LIB}" IN_LIST CMAKE_${LANG}_IMPLICIT_LINK_LIBRARIES + OR "${CMAKE_${LANG}_STANDARD_LIBRARIES}" MATCHES "(^| )(-Wl,)?(-l)?(${_OPENMP_IMPLICIT_LIB_PLAIN_ESC}|${_OPENMP_IMPLICIT_LIB_PATH_ESC})( |$)" + OR "${CMAKE_${LANG}_LINK_EXECUTABLE}" MATCHES "(^| )(-Wl,)?(-l)?(${_OPENMP_IMPLICIT_LIB_PLAIN_ESC}|${_OPENMP_IMPLICIT_LIB_PATH_ESC})( |$)" ) ) + if(_OPENMP_IMPLICIT_LIB_DIR) + set(OpenMP_${_OPENMP_IMPLICIT_LIB_PLAIN}_LIBRARY "${_OPENMP_IMPLICIT_LIB}" CACHE FILEPATH + "Path to the ${_OPENMP_IMPLICIT_LIB_PLAIN} library for OpenMP") + else() + find_library(OpenMP_${_OPENMP_IMPLICIT_LIB_PLAIN}_LIBRARY + NAMES "${_OPENMP_IMPLICIT_LIB_NAME}" + DOC "Path to the ${_OPENMP_IMPLICIT_LIB_PLAIN} library for OpenMP" + HINTS ${OpenMP_${LANG}_IMPLICIT_LINK_DIRS} + CMAKE_FIND_ROOT_PATH_BOTH + ) + endif() + mark_as_advanced(OpenMP_${_OPENMP_IMPLICIT_LIB_PLAIN}_LIBRARY) + list(APPEND _OPENMP_LIB_NAMES ${_OPENMP_IMPLICIT_LIB_PLAIN}) endif() endforeach() set("${OPENMP_LIB_NAMES_VAR}" "${_OPENMP_LIB_NAMES}" PARENT_SCOPE) |