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