FindOpenMP: try the most likely flags first

Since we know which compiler we have we can test those OpenMP flags first that
are likely to be correct. This doesn't make any difference for GNU compilers,
but it should avoid useless try_compiles and output cluttering for all others.
This commit is contained in:
Rolf Eike Beer 2012-02-08 19:23:38 +01:00
parent 81228e9d1d
commit 6f573ac9ee
1 changed files with 67 additions and 32 deletions

View File

@ -13,6 +13,7 @@
#============================================================================= #=============================================================================
# Copyright 2009 Kitware, Inc. # Copyright 2009 Kitware, Inc.
# Copyright 2008-2009 André Rigland Brodtkorb <Andre.Brodtkorb@ifi.uio.no> # Copyright 2008-2009 André Rigland Brodtkorb <Andre.Brodtkorb@ifi.uio.no>
# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
# #
# Distributed under the OSI-approved BSD License (the "License"); # Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details. # see accompanying file Copyright.txt for details.
@ -31,14 +32,15 @@ unset(_ENABLED_LANGUAGES)
set(_OPENMP_REQUIRED_VARS) set(_OPENMP_REQUIRED_VARS)
set(OpenMP_C_FLAG_CANDIDATES function(_OPENMP_FLAG_CANDIDATES LANG)
#Gnu set(OpenMP_FLAG_CANDIDATES
#GNU
"-fopenmp" "-fopenmp"
#Microsoft Visual Studio #Microsoft Visual Studio
"/openmp" "/openmp"
#Intel windows #Intel windows
"-Qopenmp" "-Qopenmp"
#Intel #PathScale, Intel
"-openmp" "-openmp"
#Empty, if compiler automatically accepts openmp #Empty, if compiler automatically accepts openmp
" " " "
@ -48,10 +50,34 @@ set(OpenMP_C_FLAG_CANDIDATES
"+Oopenmp" "+Oopenmp"
#IBM XL C/c++ #IBM XL C/c++
"-qsmp" "-qsmp"
#Portland Group #Portland Group, MIPSpro
"-mp" "-mp"
) )
set(OpenMP_CXX_FLAG_CANDIDATES ${OpenMP_C_FLAG_CANDIDATES})
set(OMP_FLAG_GNU "-fopenmp")
set(OMP_FLAG_HP "+Oopenmp")
if(WIN32)
set(OMP_FLAG_Intel "-Qopenmp")
else()
set(OMP_FLAG_Intel "-openmp")
endif()
set(OMP_FLAG_MIPSpro "-mp")
set(OMP_FLAG_MSVC "/openmp")
set(OMP_FLAG_PathScale "-openmp")
set(OMP_FLAG_PGI "-mp")
set(OMP_FLAG_SunPro "-xopenmp")
set(OMP_FLAG_XL "-qsmp")
# Move the flag that matches the compiler to the head of the list,
# this is faster and doesn't clutter the output that much. If that
# flag doesn't work we will still try all.
if(OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID})
list(REMOVE_ITEM OpenMP_FLAG_CANDIDATES "${OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID}}")
list(INSERT OpenMP_FLAG_CANDIDATES 0 "${OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID}}")
endif()
set(OpenMP_${LANG}_FLAG_CANDIDATES "${OpenMP_FLAG_CANDIDATES}" PARENT_SCOPE)
endfunction(_OPENMP_FLAG_CANDIDATES)
# sample openmp source code to test # sample openmp source code to test
set(OpenMP_C_TEST_SOURCE set(OpenMP_C_TEST_SOURCE
@ -65,16 +91,17 @@ int main() {
#endif #endif
} }
") ")
# 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)
set(OpenMP_C_FLAG_CANDIDATES)
set(OpenMP_CXX_FLAG_CANDIDATES)
endif(DEFINED OpenMP_C_FLAGS AND DEFINED OpenMP_CXX_FLAGS)
# check c compiler # check c compiler
if(NOT _HAVE_LANGUAGE_C EQUAL -1) if(NOT _HAVE_LANGUAGE_C EQUAL -1)
# if these are set then do not try to find them again,
# by avoiding any try_compiles for the flags
if(OpenMP_C_FLAGS)
unset(OpenMP_C_FLAG_CANDIDATES)
else()
_OPENMP_FLAG_CANDIDATES("C")
include(CheckCSourceCompiles) include(CheckCSourceCompiles)
endif()
foreach(FLAG ${OpenMP_C_FLAG_CANDIDATES}) foreach(FLAG ${OpenMP_C_FLAG_CANDIDATES})
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
@ -98,9 +125,17 @@ endif()
# check cxx compiler # check cxx compiler
if(NOT _HAVE_LANGUAGE_CXX EQUAL -1) if(NOT _HAVE_LANGUAGE_CXX EQUAL -1)
# if these are set then do not try to find them again,
# by avoiding any try_compiles for the flags
if(OpenMP_CXX_FLAGS)
unset(OpenMP_CXX_FLAG_CANDIDATES)
else()
_OPENMP_FLAG_CANDIDATES("CXX")
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
# use the same source for CXX as C for now # use the same source for CXX as C for now
set(OpenMP_CXX_TEST_SOURCE ${OpenMP_C_TEST_SOURCE}) set(OpenMP_CXX_TEST_SOURCE ${OpenMP_C_TEST_SOURCE})
endif()
foreach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES}) foreach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES})
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")