summaryrefslogtreecommitdiffstats
path: root/Modules/FindOpenMP.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/FindOpenMP.cmake')
-rw-r--r--Modules/FindOpenMP.cmake112
1 files changed, 69 insertions, 43 deletions
diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake
index 652803c..ceac8d2 100644
--- a/Modules/FindOpenMP.cmake
+++ b/Modules/FindOpenMP.cmake
@@ -24,9 +24,12 @@
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
-include(CheckCSourceCompiles)
-include(CheckCXXSourceCompiles)
-include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+get_property(_ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
+list(FIND _ENABLED_LANGUAGES "C" _HAVE_LANGUAGE_C)
+list(FIND _ENABLED_LANGUAGES "CXX" _HAVE_LANGUAGE_CXX)
+unset(_ENABLED_LANGUAGES)
+
+set(_OPENMP_REQUIRED_VARS)
set(OpenMP_C_FLAG_CANDIDATES
#Gnu
@@ -62,8 +65,6 @@ int main() {
#endif
}
")
-# use the same source for CXX as C for now
-set(OpenMP_CXX_TEST_SOURCE ${OpenMP_C_TEST_SOURCE})
# if these are set then do not try to find them again,
# by avoiding any try_compiles for the flags
if(DEFINED OpenMP_C_FLAGS AND DEFINED OpenMP_CXX_FLAGS)
@@ -72,43 +73,68 @@ if(DEFINED OpenMP_C_FLAGS AND DEFINED OpenMP_CXX_FLAGS)
endif(DEFINED OpenMP_C_FLAGS AND DEFINED OpenMP_CXX_FLAGS)
# check c compiler
-foreach(FLAG ${OpenMP_C_FLAG_CANDIDATES})
- set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_REQUIRED_FLAGS "${FLAG}")
- unset(OpenMP_FLAG_DETECTED CACHE)
- message(STATUS "Try OpenMP C flag = [${FLAG}]")
- check_c_source_compiles("${OpenMP_CXX_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
- set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
- if(OpenMP_FLAG_DETECTED)
- set(OpenMP_C_FLAGS_INTERNAL "${FLAG}")
- break()
- endif(OpenMP_FLAG_DETECTED)
-endforeach(FLAG ${OpenMP_C_FLAG_CANDIDATES})
+if(NOT _HAVE_LANGUAGE_C EQUAL -1)
+ include(CheckCSourceCompiles)
+
+ foreach(FLAG ${OpenMP_C_FLAG_CANDIDATES})
+ set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
+ set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+ unset(OpenMP_FLAG_DETECTED CACHE)
+ message(STATUS "Try OpenMP C flag = [${FLAG}]")
+ check_c_source_compiles("${OpenMP_C_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
+ set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
+ if(OpenMP_FLAG_DETECTED)
+ set(OpenMP_C_FLAGS_INTERNAL "${FLAG}")
+ break()
+ endif(OpenMP_FLAG_DETECTED)
+ endforeach(FLAG ${OpenMP_C_FLAG_CANDIDATES})
+
+ set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS_INTERNAL}"
+ CACHE STRING "C compiler flags for OpenMP parallization")
+
+ list(APPEND _OPENMP_REQUIRED_VARS OpenMP_C_FLAGS)
+ unset(OpenMP_C_FLAG_CANDIDATES)
+endif()
# check cxx compiler
-foreach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES})
- set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_REQUIRED_FLAGS "${FLAG}")
- unset(OpenMP_FLAG_DETECTED CACHE)
- message(STATUS "Try OpenMP CXX flag = [${FLAG}]")
- check_cxx_source_compiles("${OpenMP_C_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
- set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
- if(OpenMP_FLAG_DETECTED)
- set(OpenMP_CXX_FLAGS_INTERNAL "${FLAG}")
- break()
- endif(OpenMP_FLAG_DETECTED)
-endforeach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES})
-
-set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS_INTERNAL}"
- CACHE STRING "C compiler flags for OpenMP parallization")
-
-set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS_INTERNAL}"
- CACHE STRING "C++ compiler flags for OpenMP parallization")
-# handle the standard arguments for find_package
-find_package_handle_standard_args(OpenMP DEFAULT_MSG
- OpenMP_C_FLAGS OpenMP_CXX_FLAGS )
-
-mark_as_advanced(
- OpenMP_C_FLAGS
- OpenMP_CXX_FLAGS
-)
+if(NOT _HAVE_LANGUAGE_CXX EQUAL -1)
+ include(CheckCXXSourceCompiles)
+ # use the same source for CXX as C for now
+ set(OpenMP_CXX_TEST_SOURCE ${OpenMP_C_TEST_SOURCE})
+
+ foreach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES})
+ set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
+ set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+ unset(OpenMP_FLAG_DETECTED CACHE)
+ message(STATUS "Try OpenMP CXX flag = [${FLAG}]")
+ check_cxx_source_compiles("${OpenMP_CXX_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
+ set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
+ if(OpenMP_FLAG_DETECTED)
+ set(OpenMP_CXX_FLAGS_INTERNAL "${FLAG}")
+ break()
+ endif(OpenMP_FLAG_DETECTED)
+ endforeach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES})
+
+ set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS_INTERNAL}"
+ CACHE STRING "C++ compiler flags for OpenMP parallization")
+
+ list(APPEND _OPENMP_REQUIRED_VARS OpenMP_CXX_FLAGS)
+ unset(OpenMP_CXX_FLAG_CANDIDATES)
+ unset(OpenMP_CXX_TEST_SOURCE)
+endif()
+
+unset(_HAVE_LANGUAGE_C)
+unset(_HAVE_LANGUAGE_CXX)
+
+if(_OPENMP_REQUIRED_VARS)
+ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+ find_package_handle_standard_args(OpenMP
+ REQUIRED_VARS ${_OPENMP_REQUIRED_VARS})
+
+ mark_as_advanced(${_OPENMP_REQUIRED_VARS})
+
+ unset(_OPENMP_REQUIRED_VARS)
+else()
+ message(SEND_ERROR "FindOpenMP requires C or CXX language to be enabled")
+endif()