Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame^] | 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) |
| 15 | macro(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() |
| 24 | endmacro() |
| 25 | |
| 26 | # Gets flags common to both the C and C++ compiler |
| 27 | function(libomp_get_c_and_cxxflags_common flags) |
| 28 | set(flags_local) |
| 29 | libomp_append(flags_local -std=c++11 LIBOMP_HAVE_STD_CPP11_FLAG) |
| 30 | libomp_append(flags_local -fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG) |
| 31 | libomp_append(flags_local -Wsign-compare LIBOMP_HAVE_WSIGN_COMPARE_FLAG) |
| 32 | libomp_append(flags_local -Wno-unused-value LIBOMP_HAVE_WNO_UNUSED_VALUE_FLAG) |
| 33 | libomp_append(flags_local -Wno-switch LIBOMP_HAVE_WNO_SWITCH_FLAG) |
| 34 | libomp_append(flags_local -Wno-deprecated-register LIBOMP_HAVE_WNO_DEPRECATED_REGISTER_FLAG) |
| 35 | libomp_append(flags_local /GS LIBOMP_HAVE_GS_FLAG) |
| 36 | libomp_append(flags_local /EHsc LIBOMP_HAVE_EHSC_FLAG) |
| 37 | libomp_append(flags_local /Oy- LIBOMP_HAVE_OY__FLAG) |
| 38 | # Intel(R) C Compiler flags |
| 39 | libomp_append(flags_local /Qsafeseh LIBOMP_HAVE_QSAFESEH_FLAG) |
| 40 | libomp_append(flags_local -Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG) |
| 41 | libomp_append(flags_local -Qlong_double LIBOMP_HAVE_LONG_DOUBLE_FLAG) |
| 42 | libomp_append(flags_local -Qdiag-disable:177 LIBOMP_HAVE_DIAG_DISABLE_177_FLAG) |
| 43 | if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD}) |
| 44 | libomp_append(flags_local -Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG) |
| 45 | endif() |
| 46 | # Architectural C and C++ flags |
| 47 | if(${IA32}) |
| 48 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 49 | libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG) |
| 50 | endif() |
| 51 | libomp_append(flags_local /arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG) |
| 52 | libomp_append(flags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) |
| 53 | libomp_append(flags_local -falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG) |
| 54 | elseif(${MIC}) |
| 55 | libomp_append(flags_local -mmic LIBOMP_HAVE_MMIC_FLAG) |
| 56 | libomp_append(flags_local -ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG) |
| 57 | libomp_append(flags_local "-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG) |
| 58 | endif() |
| 59 | set(${flags} ${flags_local} PARENT_SCOPE) |
| 60 | endfunction() |
| 61 | |
| 62 | # C compiler flags |
| 63 | function(libomp_get_cflags cflags) |
| 64 | set(cflags_local) |
| 65 | libomp_get_c_and_cxxflags_common(cflags_local) |
| 66 | # flags only for the C Compiler |
| 67 | libomp_append(cflags_local /TP LIBOMP_HAVE_TP_FLAG) |
| 68 | libomp_append(cflags_local "-x c++" LIBOMP_HAVE_X_CPP_FLAG) |
| 69 | set(cflags_local ${cflags_local} ${LIBOMP_CFLAGS}) |
| 70 | libomp_setup_flags(cflags_local) |
| 71 | set(${cflags} ${cflags_local} PARENT_SCOPE) |
| 72 | endfunction() |
| 73 | |
| 74 | # C++ compiler flags |
| 75 | function(libomp_get_cxxflags cxxflags) |
| 76 | set(cxxflags_local) |
| 77 | libomp_get_c_and_cxxflags_common(cxxflags_local) |
| 78 | set(cxxflags_local ${cxxflags_local} ${LIBOMP_CXXFLAGS}) |
| 79 | libomp_setup_flags(cxxflags_local) |
| 80 | set(${cxxflags} ${cxxflags_local} PARENT_SCOPE) |
| 81 | endfunction() |
| 82 | |
| 83 | # Assembler flags |
| 84 | function(libomp_get_asmflags asmflags) |
| 85 | set(asmflags_local) |
| 86 | libomp_append(asmflags_local "-x assembler-with-cpp" LIBOMP_HAVE_X_ASSEMBLER_WITH_CPP_FLAG) |
| 87 | # Architectural assembler flags |
| 88 | if(${IA32}) |
| 89 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 90 | libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG) |
| 91 | endif() |
| 92 | libomp_append(asmflags_local /safeseh LIBOMP_HAVE_SAFESEH_MASM_FLAG) |
| 93 | libomp_append(asmflags_local /coff LIBOMP_HAVE_COFF_MASM_FLAG) |
| 94 | elseif(${MIC}) |
| 95 | libomp_append(asmflags_local -mmic LIBOMP_HAVE_MMIC_FLAG) |
| 96 | endif() |
| 97 | set(asmflags_local ${asmflags_local} ${LIBOMP_ASMFLAGS}) |
| 98 | libomp_setup_flags(asmflags_local) |
| 99 | set(${asmflags} ${asmflags_local} PARENT_SCOPE) |
| 100 | endfunction() |
| 101 | |
| 102 | # Linker flags |
| 103 | function(libomp_get_ldflags ldflags) |
| 104 | set(ldflags_local) |
| 105 | libomp_append(ldflags_local "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_LIB_NAME}.def" |
| 106 | IF_DEFINED CMAKE_LINK_DEF_FILE_FLAG) |
| 107 | libomp_append(ldflags_local "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}${LIBOMP_VERSION}.0" |
| 108 | IF_DEFINED CMAKE_C_OSX_CURRENT_VERSION_FLAG) |
| 109 | libomp_append(ldflags_local "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}${LIBOMP_VERSION}.0" |
| 110 | IF_DEFINED CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG) |
| 111 | libomp_append(ldflags_local -Wl,--warn-shared-textrel LIBOMP_HAVE_WARN_SHARED_TEXTREL_FLAG) |
| 112 | libomp_append(ldflags_local -Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG) |
| 113 | libomp_append(ldflags_local "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG) |
| 114 | libomp_append(ldflags_local -static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG) |
| 115 | libomp_append(ldflags_local -Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG) |
| 116 | libomp_append(ldflags_local -Wl,-fini=__kmp_internal_end_fini LIBOMP_HAVE_FINI_FLAG) |
| 117 | libomp_append(ldflags_local -no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG) |
| 118 | libomp_append(ldflags_local -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG) |
| 119 | libomp_append(ldflags_local /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG) |
| 120 | # Architectural linker flags |
| 121 | if(${IA32}) |
| 122 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 123 | libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG) |
| 124 | endif() |
| 125 | libomp_append(ldflags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) |
| 126 | elseif(${MIC}) |
| 127 | libomp_append(ldflags_local -mmic LIBOMP_HAVE_MMIC_FLAG) |
| 128 | libomp_append(ldflags_local -Wl,-x LIBOMP_HAVE_X_FLAG) |
| 129 | endif() |
| 130 | set(ldflags_local ${ldflags_local} ${LIBOMP_LDFLAGS}) |
| 131 | libomp_setup_flags(ldflags_local) |
| 132 | set(${ldflags} ${ldflags_local} PARENT_SCOPE) |
| 133 | endfunction() |
| 134 | |
| 135 | # Library flags |
| 136 | function(libomp_get_libflags libflags) |
| 137 | set(libflags_local) |
| 138 | libomp_append(libflags_local "${CMAKE_THREAD_LIBS_INIT}") |
| 139 | if(${IA32}) |
| 140 | libomp_append(libflags_local -lirc_pic LIBOMP_HAVE_IRC_PIC_LIBRARY) |
| 141 | endif() |
| 142 | set(libflags_local ${libflags_local} ${LIBOMP_LIBFLAGS}) |
| 143 | libomp_setup_flags(libflags_local) |
| 144 | set(${libflags} ${libflags_local} PARENT_SCOPE) |
| 145 | endfunction() |
| 146 | |
| 147 | # Fortran flags |
| 148 | function(libomp_get_fflags fflags) |
| 149 | set(fflags_local) |
| 150 | if(${IA32}) |
| 151 | libomp_append(fflags_local -m32 LIBOMP_HAVE_M32_FORTRAN_FLAG) |
| 152 | endif() |
| 153 | set(fflags_local ${fflags_local} ${LIBOMP_FFLAGS}) |
| 154 | libomp_setup_flags(fflags_local) |
| 155 | set(${fflags} ${fflags_local} PARENT_SCOPE) |
| 156 | endfunction() |
| 157 | |
| 158 | # Perl expand-vars.pl flags |
| 159 | function(libomp_get_evflags evflags) |
| 160 | set(evflags_local) |
| 161 | libomp_append(evflags_local "-D KMP_TYPE=\"${LIBOMP_LEGAL_TYPE}\"") |
| 162 | libomp_append(evflags_local "-D KMP_ARCH=\"${LIBOMP_LEGAL_ARCH}\"") |
| 163 | libomp_append(evflags_local "-D KMP_VERSION_MAJOR=${LIBOMP_VERSION}") |
| 164 | libomp_append(evflags_local "-D KMP_VERSION_MINOR=0") |
| 165 | libomp_append(evflags_local "-D KMP_VERSION_BUILD=${LIBOMP_BUILD_NUMBER}") |
| 166 | libomp_append(evflags_local "-D KMP_BUILD_DATE=\"${LIBOMP_DATE}\"") |
| 167 | if(${DEBUG_BUILD} OR ${RELWITHDEBINFO_BUILD}) |
| 168 | libomp_append(evflags_local "-D KMP_DIAG=1") |
| 169 | libomp_append(evflags_local "-D KMP_DEBUG_INFO=1") |
| 170 | else() |
| 171 | libomp_append(evflags_local "-D KMP_DIAG=0") |
| 172 | libomp_append(evflags_local "-D KMP_DEBUG_INFO=0") |
| 173 | endif() |
| 174 | if(${LIBOMP_OMP_VERSION} EQUAL 40 OR ${LIBOMP_OMP_VERSION} GREATER 40) |
| 175 | libomp_append(evflags_local "-D OMP_VERSION=201307") |
| 176 | elseif(${LIBOMP_OMP_VERSION} EQUAL 30 OR ${LIBOMP_OMP_VERSION} GREATER 30) |
| 177 | libomp_append(evflags_local "-D OMP_VERSION=201107") |
| 178 | else() |
| 179 | libomp_append(evflags_local "-D OMP_VERSION=200505") |
| 180 | endif() |
| 181 | set(${evflags} ${evflags_local} PARENT_SCOPE) |
| 182 | endfunction() |
| 183 | |
| 184 | # Perl generate-defs.pl flags (For Windows only) |
| 185 | function(libomp_get_gdflags gdflags) |
| 186 | set(gdflags_local) |
| 187 | if(${IA32}) |
| 188 | set(libomp_gdflag_arch arch_32) |
| 189 | elseif(${INTEL64}) |
| 190 | set(libomp_gdflag_arch arch_32e) |
| 191 | else() |
| 192 | set(libomp_gdflag_arch arch_${LIBOMP_ARCH}) |
| 193 | endif() |
| 194 | libomp_append(gdflags_local "-D ${libomp_gdflag_arch}") |
| 195 | libomp_append(gdflags_local "-D msvc_compat") |
| 196 | libomp_append(gdflags_local "-D norm" NORMAL_LIBRARY) |
| 197 | libomp_append(gdflags_local "-D prof" PROFILE_LIBRARY) |
| 198 | libomp_append(gdflags_local "-D stub" STUBS_LIBRARY) |
| 199 | libomp_append(gdflags_local "-D HAVE_QUAD" LIBOMP_USE_QUAD_PRECISION) |
| 200 | if(${LIBOMP_OMP_VERSION} GREATER 41 OR ${LIBOMP_OMP_VERSION} EQUAL 41) |
| 201 | libomp_append(gdflags_local "-D OMP_41") |
| 202 | endif() |
| 203 | if(${LIBOMP_OMP_VERSION} GREATER 40 OR ${LIBOMP_OMP_VERSION} EQUAL 40) |
| 204 | libomp_append(gdflags_local "-D OMP_40") |
| 205 | endif() |
| 206 | if(${LIBOMP_OMP_VERSION} GREATER 30 OR ${LIBOMP_OMP_VERSION} EQUAL 30) |
| 207 | libomp_append(gdflags_local "-D OMP_30") |
| 208 | endif() |
| 209 | if(${DEBUG_BUILD} OR ${RELWITHDEBINFO_BUILD}) |
| 210 | libomp_append(gdflags_local "-D KMP_DEBUG") |
| 211 | endif() |
| 212 | set(${gdflags} ${gdflags_local} PARENT_SCOPE) |
| 213 | endfunction() |