~ubuntu-branches/ubuntu/trusty/libsoxr/trusty

« back to all changes in this revision

Viewing changes to cmake/Modules/FindOpenMP.cmake

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2013-01-19 13:59:15 UTC
  • Revision ID: package-import@ubuntu.com-20130119135915-ig85015j5zwtf0rp
Tags: upstream-0.1.0
Import upstream version 0.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# - Finds OpenMP support
 
2
# This module can be used to detect OpenMP support in a compiler.
 
3
# If the compiler supports OpenMP, the flags required to compile with
 
4
# openmp support are set.
 
5
#
 
6
# The following variables are set:
 
7
#   OpenMP_C_FLAGS - flags to add to the C compiler for OpenMP support
 
8
#   OPENMP_FOUND - true if openmp is detected
 
9
#
 
10
# Supported compilers can be found at http://openmp.org/wp/openmp-compilers/
 
11
#
 
12
# Modified for libsoxr not to rely on presence of C++ compiler.
 
13
#
 
14
#=============================================================================
 
15
# Copyright 2009 Kitware, Inc.
 
16
# Copyright 2008-2009 André Rigland Brodtkorb <Andre.Brodtkorb@ifi.uio.no>
 
17
#
 
18
# Redistribution and use in source and binary forms, with or without
 
19
# modification, are permitted provided that the following conditions are
 
20
# met:
 
21
#
 
22
#  * Redistributions of source code must retain the above copyright notice,
 
23
#    this list of conditions and the following disclaimer.
 
24
#
 
25
#  * Redistributions in binary form must reproduce the above copyright notice,
 
26
#    this list of conditions and the following disclaimer in the documentation
 
27
#    and/or other materials provided with the distribution.
 
28
#
 
29
#  * The names of Kitware, Inc., the Insight Consortium, or the names of
 
30
#    any consortium members, or of any contributors, may not be used to
 
31
#    endorse or promote products derived from this software without
 
32
#    specific prior written permission.
 
33
#
 
34
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
 
35
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
36
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
37
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
 
38
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
39
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
40
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
41
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
42
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
43
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
44
 
 
45
include (CheckCSourceCompiles)
 
46
include (FindPackageHandleStandardArgs)
 
47
 
 
48
set (OpenMP_C_FLAG_CANDIDATES
 
49
  #Gnu
 
50
  "-fopenmp"
 
51
  #Microsoft Visual Studio
 
52
  "/openmp"
 
53
  #Intel windows
 
54
  "-Qopenmp"
 
55
  #Intel
 
56
  "-openmp"
 
57
  #Empty, if compiler automatically accepts openmp
 
58
  " "
 
59
  #Sun
 
60
  "-xopenmp"
 
61
  #HP
 
62
  "+Oopenmp"
 
63
  #IBM XL C/c++
 
64
  "-qsmp"
 
65
  #Portland Group
 
66
  "-mp"
 
67
)
 
68
 
 
69
# sample openmp source code to test
 
70
set (OpenMP_C_TEST_SOURCE
 
71
"
 
72
#include <omp.h>
 
73
int main() {
 
74
#ifdef _OPENMP
 
75
  return 0;
 
76
#else
 
77
  breaks_on_purpose
 
78
#endif
 
79
}
 
80
")
 
81
# if these are set then do not try to find them again,
 
82
# by avoiding any try_compiles for the flags
 
83
if (DEFINED OpenMP_C_FLAGS)
 
84
  set (OpenMP_C_FLAG_CANDIDATES)
 
85
endif (DEFINED OpenMP_C_FLAGS)
 
86
 
 
87
# check c compiler
 
88
foreach (FLAG ${OpenMP_C_FLAG_CANDIDATES})
 
89
  set (SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
 
90
  set (CMAKE_REQUIRED_FLAGS "${FLAG}")
 
91
  unset (OpenMP_FLAG_DETECTED CACHE)
 
92
  message (STATUS "Try OpenMP C flag = [${FLAG}]")
 
93
  check_c_source_compiles ("${OpenMP_C_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
 
94
  set (CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
 
95
  if (OpenMP_FLAG_DETECTED)
 
96
    set (OpenMP_C_FLAGS_INTERNAL "${FLAG}")
 
97
    break ()
 
98
  endif (OpenMP_FLAG_DETECTED)
 
99
endforeach (FLAG ${OpenMP_C_FLAG_CANDIDATES})
 
100
 
 
101
set (OpenMP_C_FLAGS "${OpenMP_C_FLAGS_INTERNAL}"
 
102
  CACHE STRING "C compiler flags for OpenMP parallization")
 
103
 
 
104
# handle the standard arguments for find_package
 
105
find_package_handle_standard_args (OpenMP DEFAULT_MSG
 
106
  OpenMP_C_FLAGS OpenMP_C_FLAGS)
 
107
 
 
108
mark_as_advanced (OpenMP_C_FLAGS)