浏览代码

FindOpenMP: Do not overwrite user-set FLAGS, LIB_NAMES

Since commit 2dbff623f9 (FindOpenMP: Save flags/libs in cache entries
each time they are detected, 2020-02-07, v3.17.0-rc1~10^2~1) we replace
both `OpenMP_${LANG}_FLAGS` and `OpenMP_${LANG}_LIB_NAMES` with detected
flags if either one is not set.  That can overwrite user-provided flags.

Update the logic for C, CXX, and Fortran to initialize each
`OpenMP_${LANG}_{FLAGS,LIB_NAMES}` variable only if it has not already
been set by the user.

Fixes: #23743
Balthasar Reuter 3 年之前
父节点
当前提交
878655384e
共有 1 个文件被更改,包括 24 次插入13 次删除
  1. 24 13
      Modules/FindOpenMP.cmake

+ 24 - 13
Modules/FindOpenMP.cmake

@@ -477,10 +477,14 @@ foreach(LANG IN ITEMS C CXX)
     if(NOT DEFINED OpenMP_${LANG}_FLAGS OR "${OpenMP_${LANG}_FLAGS}" STREQUAL "NOTFOUND"
       OR NOT DEFINED OpenMP_${LANG}_LIB_NAMES OR "${OpenMP_${LANG}_LIB_NAMES}" STREQUAL "NOTFOUND")
       _OPENMP_GET_FLAGS("${LANG}" "${LANG}" OpenMP_${LANG}_FLAGS_WORK OpenMP_${LANG}_LIB_NAMES_WORK)
-      set(OpenMP_${LANG}_FLAGS "${OpenMP_${LANG}_FLAGS_WORK}"
-        CACHE STRING "${LANG} compiler flags for OpenMP parallelization" FORCE)
-      set(OpenMP_${LANG}_LIB_NAMES "${OpenMP_${LANG}_LIB_NAMES_WORK}"
-        CACHE STRING "${LANG} compiler libraries for OpenMP parallelization" FORCE)
+      if(NOT DEFINED OpenMP_${LANG}_FLAGS OR "${OpenMP_${LANG}_FLAGS}" STREQUAL "NOTFOUND")
+        set(OpenMP_${LANG}_FLAGS "${OpenMP_${LANG}_FLAGS_WORK}"
+          CACHE STRING "${LANG} compiler flags for OpenMP parallelization" FORCE)
+      endif()
+      if(NOT DEFINED OpenMP_${LANG}_LIB_NAMES OR "${OpenMP_${LANG}_LIB_NAMES}" STREQUAL "NOTFOUND")
+        set(OpenMP_${LANG}_LIB_NAMES "${OpenMP_${LANG}_LIB_NAMES_WORK}"
+          CACHE STRING "${LANG} compiler libraries for OpenMP parallelization" FORCE)
+      endif()
       mark_as_advanced(OpenMP_${LANG}_FLAGS OpenMP_${LANG}_LIB_NAMES)
     endif()
   endif()
@@ -496,10 +500,14 @@ if(CMAKE_Fortran_COMPILER_LOADED)
       set(OpenMP_Fortran_HAVE_OMPLIB_MODULE TRUE CACHE BOOL INTERNAL "")
     endif()
 
-    set(OpenMP_Fortran_FLAGS "${OpenMP_Fortran_FLAGS_WORK}"
-      CACHE STRING "Fortran compiler flags for OpenMP parallelization")
-    set(OpenMP_Fortran_LIB_NAMES "${OpenMP_Fortran_LIB_NAMES_WORK}"
-      CACHE STRING "Fortran compiler libraries for OpenMP parallelization")
+    if(NOT DEFINED OpenMP_Fortran_FLAGS OR "${OpenMP_Fortran_FLAGS}" STREQUAL "NOTFOUND")
+      set(OpenMP_Fortran_FLAGS "${OpenMP_Fortran_FLAGS_WORK}"
+        CACHE STRING "Fortran compiler flags for OpenMP parallelization" FORCE)
+    endif()
+    if(NOT DEFINED OpenMP_Fortran_LIB_NAMES OR "${OpenMP_Fortran_LIB_NAMES}" STREQUAL "NOTFOUND")
+      set(OpenMP_Fortran_LIB_NAMES "${OpenMP_Fortran_LIB_NAMES_WORK}"
+        CACHE STRING "Fortran compiler libraries for OpenMP parallelization" FORCE)
+    endif()
     mark_as_advanced(OpenMP_Fortran_FLAGS OpenMP_Fortran_LIB_NAMES)
   endif()
 
@@ -512,11 +520,14 @@ if(CMAKE_Fortran_COMPILER_LOADED)
       set(OpenMP_Fortran_HAVE_OMPLIB_HEADER TRUE CACHE BOOL INTERNAL "")
     endif()
 
-    set(OpenMP_Fortran_FLAGS "${OpenMP_Fortran_FLAGS_WORK}"
-      CACHE STRING "Fortran compiler flags for OpenMP parallelization")
-
-    set(OpenMP_Fortran_LIB_NAMES "${OpenMP_Fortran_LIB_NAMES}"
-      CACHE STRING "Fortran compiler libraries for OpenMP parallelization")
+    if(NOT DEFINED OpenMP_Fortran_FLAGS OR "${OpenMP_Fortran_FLAGS}" STREQUAL "NOTFOUND")
+      set(OpenMP_Fortran_FLAGS "${OpenMP_Fortran_FLAGS_WORK}"
+        CACHE STRING "Fortran compiler flags for OpenMP parallelization" FORCE)
+    endif()
+    if(NOT DEFINED OpenMP_Fortran_LIB_NAMES OR "${OpenMP_Fortran_LIB_NAMES}" STREQUAL "NOTFOUND")
+      set(OpenMP_Fortran_LIB_NAMES "${OpenMP_Fortran_LIB_NAMES_WORK}"
+        CACHE STRING "Fortran compiler libraries for OpenMP parallelization" FORCE)
+    endif()
   endif()
 
   if(OpenMP_Fortran_HAVE_OMPLIB_MODULE)