1#
2#//===----------------------------------------------------------------------===//
3#//
4#//                     The LLVM Compiler Infrastructure
5#//
6#// This file is dual licensed under the MIT and the University of Illinois Open
7#// Source Licenses. See LICENSE.txt for details.
8#//
9#//===----------------------------------------------------------------------===//
10#
11
12# Setup the flags correctly for cmake (covert to string)
13# Pretty them up (STRIP any beginning and trailing whitespace,
14# remove duplicates, remove empty entries)
15macro(libomp_setup_flags flags)
16  if(NOT "${${flags}}" STREQUAL "") # if flags are empty, don't do anything
17    set(flags_local)
18    list(REMOVE_DUPLICATES ${flags}) # remove duplicates
19    list(REMOVE_ITEM ${flags} "") # remove empty items
20    libomp_list_to_string("${${flags}}" flags_local)
21    string(STRIP "${flags_local}" flags_local)
22    set(${flags} "${flags_local}")
23  endif()
24endmacro()
25
26# Gets flags common to both the C and C++ compiler
27function(libomp_get_c_and_cxxflags_common flags)
28  set(flags_local)
29  libomp_append(flags_local -fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG)
30  libomp_append(flags_local -fno-rtti LIBOMP_HAVE_FNO_RTTI_FLAG)
31  if(${OPENMP_STANDALONE_BUILD})
32    libomp_append(flags_local -Wsign-compare LIBOMP_HAVE_WNO_SIGN_COMPARE_FLAG)
33    libomp_append(flags_local -Wunused-function LIBOMP_HAVE_WNO_UNUSED_FUNCTION_FLAG)
34    libomp_append(flags_local -Wunused-local-typedef LIBOMP_HAVE_WNO_UNUSED_LOCAL_TYPEDEF_FLAG)
35    libomp_append(flags_local -Wunused-value LIBOMP_HAVE_WNO_UNUSED_VALUE_FLAG)
36    libomp_append(flags_local -Wunused-variable LIBOMP_HAVE_WNO_UNUSED_VARIABLE_FLAG)
37    libomp_append(flags_local -Wdeprecated-register LIBOMP_HAVE_WNO_DEPRECATED_REGISTER_FLAG)
38    libomp_append(flags_local -Wunknown-pragmas LIBOMP_HAVE_WNO_UNKNOWN_PRAGMAS_FLAG)
39    libomp_append(flags_local -Wcomment LIBOMP_HAVE_WNO_COMMENT_FLAG)
40    libomp_append(flags_local -Wself-assign LIBOMP_HAVE_WNO_SELF_ASSIGN_FLAG)
41    libomp_append(flags_local -Wformat-pedantic LIBOMP_HAVE_WNO_FORMAT_PEDANTIC_FLAG)
42  endif()
43  libomp_append(flags_local -Wno-switch LIBOMP_HAVE_WNO_SWITCH_FLAG)
44  libomp_append(flags_local -Wno-covered-switch-default LIBOMP_HAVE_WNO_COVERED_SWITCH_DEFAULT_FLAG)
45  libomp_append(flags_local -Wno-gnu-anonymous-struct LIBOMP_HAVE_WNO_GNU_ANONYMOUS_STRUCT_FLAG)
46  libomp_append(flags_local -Wno-missing-field-initializers LIBOMP_HAVE_WNO_MISSING_FIELD_INITIALIZERS_FLAG)
47  libomp_append(flags_local -Wno-missing-braces LIBOMP_HAVE_WNO_MISSING_BRACES_FLAG)
48  libomp_append(flags_local -Wno-vla-extension LIBOMP_HAVE_WNO_VLA_EXTENSION_FLAG)
49  libomp_append(flags_local -Wstringop-overflow=0 LIBOMP_HAVE_WSTRINGOP_OVERFLOW_FLAG)
50  libomp_append(flags_local /GS LIBOMP_HAVE_GS_FLAG)
51  libomp_append(flags_local /EHsc LIBOMP_HAVE_EHSC_FLAG)
52  libomp_append(flags_local /Oy- LIBOMP_HAVE_OY__FLAG)
53  libomp_append(flags_local -mrtm LIBOMP_HAVE_MRTM_FLAG)
54  # Intel(R) C Compiler flags
55  libomp_append(flags_local /Qsafeseh LIBOMP_HAVE_QSAFESEH_FLAG)
56  libomp_append(flags_local -Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG)
57  libomp_append(flags_local -Qlong_double LIBOMP_HAVE_LONG_DOUBLE_FLAG)
58  libomp_append(flags_local -Qdiag-disable:177 LIBOMP_HAVE_DIAG_DISABLE_177_FLAG)
59  if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD})
60    libomp_append(flags_local -Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG)
61  endif()
62  # Architectural C and C++ flags
63  if(${IA32})
64    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
65      libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG)
66    endif()
67    libomp_append(flags_local /arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG)
68    libomp_append(flags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG)
69    libomp_append(flags_local -falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG)
70  elseif(${MIC})
71    libomp_append(flags_local -mmic LIBOMP_HAVE_MMIC_FLAG)
72    libomp_append(flags_local -ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG)
73    libomp_append(flags_local "-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG)
74  endif()
75  set(${flags} ${flags_local} PARENT_SCOPE)
76endfunction()
77
78# C compiler flags
79function(libomp_get_cflags cflags)
80  set(cflags_local)
81  libomp_get_c_and_cxxflags_common(cflags_local)
82  # flags only for the C Compiler
83  libomp_append(cflags_local /TP LIBOMP_HAVE_TP_FLAG)
84  libomp_append(cflags_local "-x c++" LIBOMP_HAVE_X_CPP_FLAG)
85  set(cflags_local ${cflags_local} ${LIBOMP_CFLAGS})
86  libomp_setup_flags(cflags_local)
87  set(${cflags} ${cflags_local} PARENT_SCOPE)
88endfunction()
89
90# C++ compiler flags
91function(libomp_get_cxxflags cxxflags)
92  set(cxxflags_local)
93  libomp_get_c_and_cxxflags_common(cxxflags_local)
94  if(${OPENMP_STANDALONE_BUILD})
95      libomp_append(cxxflags_local -Wcast-qual LIBOMP_HAVE_WCAST_QUAL_FLAG)
96  endif()
97  set(cxxflags_local ${cxxflags_local} ${LIBOMP_CXXFLAGS})
98  libomp_setup_flags(cxxflags_local)
99  set(${cxxflags} ${cxxflags_local} PARENT_SCOPE)
100endfunction()
101
102# Assembler flags
103function(libomp_get_asmflags asmflags)
104  set(asmflags_local)
105  libomp_append(asmflags_local "-x assembler-with-cpp" LIBOMP_HAVE_X_ASSEMBLER_WITH_CPP_FLAG)
106  # Architectural assembler flags
107  if(${IA32})
108    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
109      libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG)
110    endif()
111    libomp_append(asmflags_local /safeseh LIBOMP_HAVE_SAFESEH_MASM_FLAG)
112    libomp_append(asmflags_local /coff LIBOMP_HAVE_COFF_MASM_FLAG)
113  elseif(${MIC})
114    libomp_append(asmflags_local -mmic LIBOMP_HAVE_MMIC_FLAG)
115  endif()
116  set(asmflags_local ${asmflags_local} ${LIBOMP_ASMFLAGS})
117  libomp_setup_flags(asmflags_local)
118  set(${asmflags} ${asmflags_local} PARENT_SCOPE)
119endfunction()
120
121# Linker flags
122function(libomp_get_ldflags ldflags)
123  set(ldflags_local)
124  libomp_append(ldflags_local "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_LIB_NAME}.def"
125    IF_DEFINED CMAKE_LINK_DEF_FILE_FLAG)
126  libomp_append(ldflags_local "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR}"
127    IF_DEFINED CMAKE_C_OSX_CURRENT_VERSION_FLAG)
128  libomp_append(ldflags_local "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR}"
129    IF_DEFINED CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG)
130  libomp_append(ldflags_local -Wl,--warn-shared-textrel LIBOMP_HAVE_WARN_SHARED_TEXTREL_FLAG)
131  libomp_append(ldflags_local -Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG)
132  libomp_append(ldflags_local "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
133  libomp_append(ldflags_local -static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG)
134  libomp_append(ldflags_local -Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG)
135  libomp_append(ldflags_local -Wl,-fini=__kmp_internal_end_fini LIBOMP_HAVE_FINI_FLAG)
136  libomp_append(ldflags_local -no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG)
137  libomp_append(ldflags_local -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG)
138  libomp_append(ldflags_local /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG)
139  # Architectural linker flags
140  if(${IA32})
141    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
142      libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG)
143    endif()
144    libomp_append(ldflags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG)
145  elseif(${MIC})
146    libomp_append(ldflags_local -mmic LIBOMP_HAVE_MMIC_FLAG)
147    libomp_append(ldflags_local -Wl,-x LIBOMP_HAVE_X_FLAG)
148  endif()
149  set(ldflags_local ${ldflags_local} ${LIBOMP_LDFLAGS})
150  libomp_setup_flags(ldflags_local)
151  set(${ldflags} ${ldflags_local} PARENT_SCOPE)
152endfunction()
153
154# Library flags
155function(libomp_get_libflags libflags)
156  set(libflags_local)
157  libomp_append(libflags_local "${CMAKE_THREAD_LIBS_INIT}")
158  libomp_append(libflags_local "${LIBOMP_HWLOC_LIBRARY}" LIBOMP_USE_HWLOC)
159  if(${IA32})
160    libomp_append(libflags_local -lirc_pic LIBOMP_HAVE_IRC_PIC_LIBRARY)
161  endif()
162  IF(${CMAKE_SYSTEM_NAME} MATCHES "DragonFly")
163    libomp_append(libflags_local "-Wl,--no-as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
164    libomp_append(libflags_local "-lm")
165    libomp_append(libflags_local "-Wl,--as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
166  ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "DragonFly")
167  IF(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
168    libomp_append(libflags_local -lm)
169  ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
170  set(libflags_local ${libflags_local} ${LIBOMP_LIBFLAGS})
171  libomp_setup_flags(libflags_local)
172  set(${libflags} ${libflags_local} PARENT_SCOPE)
173endfunction()
174
175# Fortran flags
176function(libomp_get_fflags fflags)
177  set(fflags_local)
178  if(${IA32})
179    libomp_append(fflags_local -m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
180  endif()
181  set(fflags_local ${fflags_local} ${LIBOMP_FFLAGS})
182  libomp_setup_flags(fflags_local)
183  set(${fflags} ${fflags_local} PARENT_SCOPE)
184endfunction()
185
186# Perl generate-defs.pl flags (For Windows only)
187function(libomp_get_gdflags gdflags)
188  set(gdflags_local)
189  if(${IA32})
190    set(libomp_gdflag_arch arch_32)
191  elseif(${INTEL64})
192    set(libomp_gdflag_arch arch_32e)
193  else()
194    set(libomp_gdflag_arch arch_${LIBOMP_ARCH})
195  endif()
196  libomp_append(gdflags_local "-D ${libomp_gdflag_arch}")
197  libomp_append(gdflags_local "-D msvc_compat")
198  libomp_append(gdflags_local "-D norm" NORMAL_LIBRARY)
199  libomp_append(gdflags_local "-D prof" PROFILE_LIBRARY)
200  libomp_append(gdflags_local "-D stub" STUBS_LIBRARY)
201  libomp_append(gdflags_local "-D HAVE_QUAD" LIBOMP_USE_QUAD_PRECISION)
202  libomp_append(gdflags_local "-D USE_DEBUGGER" LIBOMP_USE_DEBUGGER)
203  if(${LIBOMP_OMP_VERSION} GREATER 50 OR ${LIBOMP_OMP_VERSION} EQUAL 50)
204    libomp_append(gdflags_local "-D OMP_50")
205  endif()
206  if(${LIBOMP_OMP_VERSION} GREATER 45 OR ${LIBOMP_OMP_VERSION} EQUAL 45)
207    libomp_append(gdflags_local "-D OMP_45")
208  endif()
209  if(${LIBOMP_OMP_VERSION} GREATER 40 OR ${LIBOMP_OMP_VERSION} EQUAL 40)
210    libomp_append(gdflags_local "-D OMP_40")
211  endif()
212  if(${LIBOMP_OMP_VERSION} GREATER 30 OR ${LIBOMP_OMP_VERSION} EQUAL 30)
213    libomp_append(gdflags_local "-D OMP_30")
214  endif()
215  if(${DEBUG_BUILD} OR ${RELWITHDEBINFO_BUILD})
216    libomp_append(gdflags_local "-D KMP_DEBUG")
217  endif()
218  set(${gdflags} ${gdflags_local} PARENT_SCOPE)
219endfunction()
220