Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 1 | # |
| 2 | #//===----------------------------------------------------------------------===// |
| 3 | #// |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 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) |
| 14 | macro(libomp_setup_flags flags) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 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() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 23 | endmacro() |
| 24 | |
Jonas Hahnfeld | dc23c83 | 2019-08-15 13:11:50 +0000 | [diff] [blame] | 25 | # C++ compiler flags |
| 26 | function(libomp_get_cxxflags cxxflags) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 27 | set(flags_local) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 28 | libomp_append(flags_local -fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG) |
Jonathan Peyton | 1cdd87a | 2016-11-14 21:08:35 +0000 | [diff] [blame] | 29 | libomp_append(flags_local -fno-rtti LIBOMP_HAVE_FNO_RTTI_FLAG) |
Jonas Hahnfeld | dc23c83 | 2019-08-15 13:11:50 +0000 | [diff] [blame] | 30 | libomp_append(flags_local -Wno-class-memaccess LIBOMP_HAVE_WNO_CLASS_MEMACCESS_FLAG) |
Chandler Carruth | 5145156 | 2015-07-18 03:14:02 +0000 | [diff] [blame] | 31 | libomp_append(flags_local -Wno-covered-switch-default LIBOMP_HAVE_WNO_COVERED_SWITCH_DEFAULT_FLAG) |
Jonas Hahnfeld | dc23c83 | 2019-08-15 13:11:50 +0000 | [diff] [blame] | 32 | libomp_append(flags_local -Wno-frame-address LIBOMP_HAVE_WNO_FRAME_ADDRESS_FLAG) |
Jonas Hahnfeld | dc23c83 | 2019-08-15 13:11:50 +0000 | [diff] [blame] | 33 | libomp_append(flags_local -Wno-strict-aliasing LIBOMP_HAVE_WNO_STRICT_ALIASING_FLAG) |
Jonas Hahnfeld | f985f98 | 2018-07-30 18:16:22 +0000 | [diff] [blame] | 34 | libomp_append(flags_local -Wstringop-overflow=0 LIBOMP_HAVE_WSTRINGOP_OVERFLOW_FLAG) |
Jonas Hahnfeld | dc23c83 | 2019-08-15 13:11:50 +0000 | [diff] [blame] | 35 | libomp_append(flags_local -Wno-stringop-truncation LIBOMP_HAVE_WNO_STRINGOP_TRUNCATION_FLAG) |
| 36 | libomp_append(flags_local -Wno-switch LIBOMP_HAVE_WNO_SWITCH_FLAG) |
| 37 | libomp_append(flags_local -Wno-uninitialized LIBOMP_HAVE_WNO_UNINITIALIZED_FLAG) |
| 38 | libomp_append(flags_local -Wno-unused-but-set-variable LIBOMP_HAVE_WNO_UNUSED_BUT_SET_VARIABLE_FLAG) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 39 | libomp_append(flags_local /GS LIBOMP_HAVE_GS_FLAG) |
| 40 | libomp_append(flags_local /EHsc LIBOMP_HAVE_EHSC_FLAG) |
| 41 | libomp_append(flags_local /Oy- LIBOMP_HAVE_OY__FLAG) |
Andrey Churbanov | f700e9e | 2018-12-10 13:45:00 +0000 | [diff] [blame] | 42 | libomp_append(flags_local -mrtm LIBOMP_HAVE_MRTM_FLAG) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 43 | # Intel(R) C Compiler flags |
| 44 | libomp_append(flags_local /Qsafeseh LIBOMP_HAVE_QSAFESEH_FLAG) |
| 45 | libomp_append(flags_local -Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG) |
| 46 | libomp_append(flags_local -Qlong_double LIBOMP_HAVE_LONG_DOUBLE_FLAG) |
| 47 | libomp_append(flags_local -Qdiag-disable:177 LIBOMP_HAVE_DIAG_DISABLE_177_FLAG) |
| 48 | if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD}) |
| 49 | libomp_append(flags_local -Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG) |
| 50 | endif() |
| 51 | # Architectural C and C++ flags |
| 52 | if(${IA32}) |
| 53 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 54 | libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 55 | endif() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 56 | libomp_append(flags_local /arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG) |
| 57 | libomp_append(flags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) |
| 58 | libomp_append(flags_local -falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG) |
| 59 | elseif(${MIC}) |
| 60 | libomp_append(flags_local -mmic LIBOMP_HAVE_MMIC_FLAG) |
| 61 | libomp_append(flags_local -ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG) |
| 62 | libomp_append(flags_local "-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG) |
| 63 | endif() |
Jonas Hahnfeld | dc23c83 | 2019-08-15 13:11:50 +0000 | [diff] [blame] | 64 | set(cxxflags_local ${flags_local} ${LIBOMP_CXXFLAGS}) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 65 | libomp_setup_flags(cxxflags_local) |
| 66 | set(${cxxflags} ${cxxflags_local} PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 67 | endfunction() |
| 68 | |
| 69 | # Assembler flags |
| 70 | function(libomp_get_asmflags asmflags) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 71 | set(asmflags_local) |
| 72 | libomp_append(asmflags_local "-x assembler-with-cpp" LIBOMP_HAVE_X_ASSEMBLER_WITH_CPP_FLAG) |
| 73 | # Architectural assembler flags |
| 74 | if(${IA32}) |
| 75 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 76 | libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 77 | endif() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 78 | libomp_append(asmflags_local /safeseh LIBOMP_HAVE_SAFESEH_MASM_FLAG) |
| 79 | libomp_append(asmflags_local /coff LIBOMP_HAVE_COFF_MASM_FLAG) |
| 80 | elseif(${MIC}) |
| 81 | libomp_append(asmflags_local -mmic LIBOMP_HAVE_MMIC_FLAG) |
| 82 | endif() |
| 83 | set(asmflags_local ${asmflags_local} ${LIBOMP_ASMFLAGS}) |
| 84 | libomp_setup_flags(asmflags_local) |
| 85 | set(${asmflags} ${asmflags_local} PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 86 | endfunction() |
| 87 | |
| 88 | # Linker flags |
| 89 | function(libomp_get_ldflags ldflags) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 90 | set(ldflags_local) |
| 91 | libomp_append(ldflags_local "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_LIB_NAME}.def" |
| 92 | IF_DEFINED CMAKE_LINK_DEF_FILE_FLAG) |
Jonathan Peyton | c0225ca | 2015-08-28 18:42:10 +0000 | [diff] [blame] | 93 | libomp_append(ldflags_local "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR}" |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 94 | IF_DEFINED CMAKE_C_OSX_CURRENT_VERSION_FLAG) |
Jonathan Peyton | c0225ca | 2015-08-28 18:42:10 +0000 | [diff] [blame] | 95 | libomp_append(ldflags_local "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR}" |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 96 | IF_DEFINED CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG) |
| 97 | libomp_append(ldflags_local -Wl,--warn-shared-textrel LIBOMP_HAVE_WARN_SHARED_TEXTREL_FLAG) |
| 98 | libomp_append(ldflags_local -Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG) |
| 99 | libomp_append(ldflags_local "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG) |
| 100 | libomp_append(ldflags_local -static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG) |
| 101 | libomp_append(ldflags_local -Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 102 | libomp_append(ldflags_local -no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG) |
| 103 | libomp_append(ldflags_local -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG) |
| 104 | libomp_append(ldflags_local /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG) |
| 105 | # Architectural linker flags |
| 106 | if(${IA32}) |
| 107 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 108 | libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 109 | endif() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 110 | libomp_append(ldflags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) |
| 111 | elseif(${MIC}) |
| 112 | libomp_append(ldflags_local -mmic LIBOMP_HAVE_MMIC_FLAG) |
| 113 | libomp_append(ldflags_local -Wl,-x LIBOMP_HAVE_X_FLAG) |
| 114 | endif() |
| 115 | set(ldflags_local ${ldflags_local} ${LIBOMP_LDFLAGS}) |
| 116 | libomp_setup_flags(ldflags_local) |
| 117 | set(${ldflags} ${ldflags_local} PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 118 | endfunction() |
| 119 | |
| 120 | # Library flags |
| 121 | function(libomp_get_libflags libflags) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 122 | set(libflags_local) |
| 123 | libomp_append(libflags_local "${CMAKE_THREAD_LIBS_INIT}") |
Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 124 | libomp_append(libflags_local "${LIBOMP_HWLOC_LIBRARY}" LIBOMP_USE_HWLOC) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 125 | if(${IA32}) |
| 126 | libomp_append(libflags_local -lirc_pic LIBOMP_HAVE_IRC_PIC_LIBRARY) |
| 127 | endif() |
Andrey Churbanov | f34271d | 2019-10-08 12:23:25 +0000 | [diff] [blame] | 128 | if(${CMAKE_SYSTEM_NAME} MATCHES "DragonFly|FreeBSD") |
Kamil Rytarowski | a56ac94 | 2018-12-09 16:40:33 +0000 | [diff] [blame] | 129 | libomp_append(libflags_local "-Wl,--no-as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG) |
| 130 | libomp_append(libflags_local "-lm") |
| 131 | libomp_append(libflags_local "-Wl,--as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG) |
Andrey Churbanov | f34271d | 2019-10-08 12:23:25 +0000 | [diff] [blame] | 132 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") |
Joerg Sonnenberger | 8abf7c8 | 2015-09-21 20:21:02 +0000 | [diff] [blame] | 133 | libomp_append(libflags_local -lm) |
Dimitry Andric | 956168c | 2019-04-03 18:11:36 +0000 | [diff] [blame] | 134 | endif() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 135 | set(libflags_local ${libflags_local} ${LIBOMP_LIBFLAGS}) |
| 136 | libomp_setup_flags(libflags_local) |
| 137 | set(${libflags} ${libflags_local} PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 138 | endfunction() |
| 139 | |
| 140 | # Fortran flags |
| 141 | function(libomp_get_fflags fflags) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 142 | set(fflags_local) |
| 143 | if(${IA32}) |
| 144 | libomp_append(fflags_local -m32 LIBOMP_HAVE_M32_FORTRAN_FLAG) |
| 145 | endif() |
| 146 | set(fflags_local ${fflags_local} ${LIBOMP_FFLAGS}) |
| 147 | libomp_setup_flags(fflags_local) |
| 148 | set(${fflags} ${fflags_local} PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 149 | endfunction() |
| 150 | |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 151 | # Perl generate-defs.pl flags (For Windows only) |
| 152 | function(libomp_get_gdflags gdflags) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 153 | set(gdflags_local) |
| 154 | if(${IA32}) |
| 155 | set(libomp_gdflag_arch arch_32) |
| 156 | elseif(${INTEL64}) |
| 157 | set(libomp_gdflag_arch arch_32e) |
| 158 | else() |
| 159 | set(libomp_gdflag_arch arch_${LIBOMP_ARCH}) |
| 160 | endif() |
| 161 | libomp_append(gdflags_local "-D ${libomp_gdflag_arch}") |
| 162 | libomp_append(gdflags_local "-D msvc_compat") |
| 163 | libomp_append(gdflags_local "-D norm" NORMAL_LIBRARY) |
| 164 | libomp_append(gdflags_local "-D prof" PROFILE_LIBRARY) |
| 165 | libomp_append(gdflags_local "-D stub" STUBS_LIBRARY) |
| 166 | libomp_append(gdflags_local "-D HAVE_QUAD" LIBOMP_USE_QUAD_PRECISION) |
Jonathan Peyton | 3c4dd1c | 2015-08-06 15:16:54 +0000 | [diff] [blame] | 167 | libomp_append(gdflags_local "-D USE_DEBUGGER" LIBOMP_USE_DEBUGGER) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 168 | if(${DEBUG_BUILD} OR ${RELWITHDEBINFO_BUILD}) |
| 169 | libomp_append(gdflags_local "-D KMP_DEBUG") |
| 170 | endif() |
| 171 | set(${gdflags} ${gdflags_local} PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 172 | endfunction() |