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# C++ compiler flags 26function(libomp_get_cxxflags cxxflags) 27 set(flags_local) 28 29 # GCC silently accepts any -Wno-<foo> option, but warns about those options 30 # being unrecognized only if the compilation triggers other warnings to be 31 # printed. Therefore, check for whether the compiler supports options in the 32 # form -W<foo>, and if supported, add the corresponding -Wno-<foo> option. 33 34 libomp_append(flags_local -fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG) 35 libomp_append(flags_local -fno-rtti LIBOMP_HAVE_FNO_RTTI_FLAG) 36 libomp_append(flags_local -Wno-class-memaccess LIBOMP_HAVE_WCLASS_MEMACCESS_FLAG) 37 libomp_append(flags_local -Wno-covered-switch-default LIBOMP_HAVE_WCOVERED_SWITCH_DEFAULT_FLAG) 38 libomp_append(flags_local -Wno-frame-address LIBOMP_HAVE_WFRAME_ADDRESS_FLAG) 39 libomp_append(flags_local -Wno-strict-aliasing LIBOMP_HAVE_WSTRICT_ALIASING_FLAG) 40 libomp_append(flags_local -Wstringop-overflow=0 LIBOMP_HAVE_WSTRINGOP_OVERFLOW_FLAG) 41 libomp_append(flags_local -Wno-stringop-truncation LIBOMP_HAVE_WSTRINGOP_TRUNCATION_FLAG) 42 libomp_append(flags_local -Wno-switch LIBOMP_HAVE_WSWITCH_FLAG) 43 libomp_append(flags_local -Wno-uninitialized LIBOMP_HAVE_WUNINITIALIZED_FLAG) 44 libomp_append(flags_local -Wno-return-type-c-linkage LIBOMP_HAVE_WRETURN_TYPE_C_LINKAGE_FLAG) 45 libomp_append(flags_local -Wno-cast-qual LIBOMP_HAVE_WCAST_QUAL_FLAG) 46 libomp_append(flags_local -Wno-int-to-void-pointer-cast LIBOMP_HAVE_WINT_TO_VOID_POINTER_CAST_FLAG) 47 # libomp_append(flags_local -Wconversion LIBOMP_HAVE_WCONVERSION_FLAG) 48 libomp_append(flags_local /GS LIBOMP_HAVE_GS_FLAG) 49 libomp_append(flags_local /EHsc LIBOMP_HAVE_EHSC_FLAG) 50 libomp_append(flags_local /Oy- LIBOMP_HAVE_OY__FLAG) 51 if(${IA32} OR ${INTEL64}) 52 libomp_append(flags_local -mrtm LIBOMP_HAVE_MRTM_FLAG) 53 endif() 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(cxxflags_local ${flags_local} ${LIBOMP_CXXFLAGS}) 76 libomp_setup_flags(cxxflags_local) 77 set(${cxxflags} ${cxxflags_local} PARENT_SCOPE) 78endfunction() 79 80# Assembler flags 81function(libomp_get_asmflags asmflags) 82 set(asmflags_local) 83 # Architectural assembler flags 84 if(${IA32}) 85 if(CMAKE_SIZEOF_VOID_P EQUAL 8) 86 libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG) 87 endif() 88 libomp_append(asmflags_local /safeseh LIBOMP_HAVE_SAFESEH_MASM_FLAG) 89 libomp_append(asmflags_local /coff LIBOMP_HAVE_COFF_MASM_FLAG) 90 elseif(${MIC}) 91 libomp_append(asmflags_local -mmic LIBOMP_HAVE_MMIC_FLAG) 92 endif() 93 set(asmflags_local ${asmflags_local} ${LIBOMP_ASMFLAGS}) 94 libomp_setup_flags(asmflags_local) 95 set(${asmflags} ${asmflags_local} PARENT_SCOPE) 96endfunction() 97 98# Linker flags 99function(libomp_get_ldflags ldflags) 100 set(ldflags_local) 101 libomp_append(ldflags_local "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_LIB_NAME}.def" 102 IF_DEFINED CMAKE_LINK_DEF_FILE_FLAG) 103 libomp_append(ldflags_local "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR}" 104 IF_DEFINED CMAKE_C_OSX_CURRENT_VERSION_FLAG) 105 libomp_append(ldflags_local "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR}" 106 IF_DEFINED CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG) 107 libomp_append(ldflags_local -Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG) 108 libomp_append(ldflags_local "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG) 109 libomp_append(ldflags_local -static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG) 110 libomp_append(ldflags_local -Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG) 111 libomp_append(ldflags_local -no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG) 112 libomp_append(ldflags_local -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG) 113 libomp_append(ldflags_local /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG) 114 # Architectural linker flags 115 if(${IA32}) 116 if(CMAKE_SIZEOF_VOID_P EQUAL 8) 117 libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG) 118 endif() 119 libomp_append(ldflags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) 120 elseif(${MIC}) 121 libomp_append(ldflags_local -mmic LIBOMP_HAVE_MMIC_FLAG) 122 libomp_append(ldflags_local -Wl,-x LIBOMP_HAVE_X_FLAG) 123 endif() 124 set(ldflags_local ${ldflags_local} ${LIBOMP_LDFLAGS}) 125 libomp_setup_flags(ldflags_local) 126 set(${ldflags} ${ldflags_local} PARENT_SCOPE) 127endfunction() 128 129# Library flags 130function(libomp_get_libflags libflags) 131 set(libflags_local) 132 libomp_append(libflags_local "${CMAKE_THREAD_LIBS_INIT}") 133 libomp_append(libflags_local "${LIBOMP_HWLOC_LIBRARY}" LIBOMP_USE_HWLOC) 134 if(${IA32}) 135 libomp_append(libflags_local -lirc_pic LIBOMP_HAVE_IRC_PIC_LIBRARY) 136 endif() 137 if(MINGW) 138 libomp_append(libflags_local -lpsapi LIBOMP_HAVE_PSAPI) 139 endif() 140 if(LIBOMP_HAVE_SHM_OPEN_WITH_LRT) 141 libomp_append(libflags_local -lrt) 142 endif() 143 if(${CMAKE_SYSTEM_NAME} MATCHES "DragonFly|FreeBSD|OpenBSD") 144 libomp_append(libflags_local "-Wl,--no-as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG) 145 libomp_append(libflags_local "-lm") 146 libomp_append(libflags_local "-Wl,--as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG) 147 if (${CMAKE_SYSTEM_NAME} STREQUAL "DragonFly") 148 libomp_append(libflags_local "-lkvm") 149 endif() 150 elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD|SunOS") 151 libomp_append(libflags_local -lm) 152 if (${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") 153 libomp_append(libflags_local "-lproc") 154 endif() 155 endif() 156 set(libflags_local ${libflags_local} ${LIBOMP_LIBFLAGS}) 157 libomp_setup_flags(libflags_local) 158 libomp_string_to_list("${libflags_local}" libflags_local_list) 159 set(${libflags} ${libflags_local_list} PARENT_SCOPE) 160endfunction() 161 162# Fortran flags 163function(libomp_get_fflags fflags) 164 set(fflags_local) 165 if(${IA32}) 166 libomp_append(fflags_local -m32 LIBOMP_HAVE_M32_FORTRAN_FLAG) 167 endif() 168 set(fflags_local ${fflags_local} ${LIBOMP_FFLAGS}) 169 libomp_setup_flags(fflags_local) 170 set(${fflags} ${fflags_local} PARENT_SCOPE) 171endfunction() 172 173# Python generate-defs.py flags (For Windows only) 174function(libomp_get_gdflags gdflags) 175 set(gdflags_local) 176 if(${IA32}) 177 set(libomp_gdflag_arch arch_32) 178 libomp_append(gdflags_local "-D IS_IA_ARCH") 179 elseif(${INTEL64}) 180 set(libomp_gdflag_arch arch_32e) 181 libomp_append(gdflags_local "-D IS_IA_ARCH") 182 else() 183 set(libomp_gdflag_arch arch_${LIBOMP_ARCH}) 184 endif() 185 libomp_append(gdflags_local "-D ${libomp_gdflag_arch}") 186 libomp_append(gdflags_local "-D msvc_compat") 187 libomp_append(gdflags_local "-D norm" NORMAL_LIBRARY) 188 libomp_append(gdflags_local "-D prof" PROFILE_LIBRARY) 189 libomp_append(gdflags_local "-D stub" STUBS_LIBRARY) 190 libomp_append(gdflags_local "-D HAVE_QUAD" LIBOMP_USE_QUAD_PRECISION) 191 libomp_append(gdflags_local "-D USE_DEBUGGER" LIBOMP_USE_DEBUGGER) 192 if(${DEBUG_BUILD} OR ${RELWITHDEBINFO_BUILD}) 193 libomp_append(gdflags_local "-D KMP_DEBUG") 194 endif() 195 set(${gdflags} ${gdflags_local} PARENT_SCOPE) 196endfunction() 197