Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 1 | # Copyright 2019 The IREE Authors |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 2 | # |
Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 3 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | # See https://llvm.org/LICENSE.txt for license information. |
| 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 6 | |
Lei Zhang | c4a945e | 2020-06-10 10:23:47 -0400 | [diff] [blame] | 7 | #------------------------------------------------------------------------------- |
Ben Vanik | 31c4dbb | 2020-11-14 12:11:16 -0800 | [diff] [blame] | 8 | # C/C++ options as used within IREE |
Ben Vanik | 246bc91 | 2019-09-19 15:22:12 -0700 | [diff] [blame] | 9 | #------------------------------------------------------------------------------- |
Ben Vanik | 31c4dbb | 2020-11-14 12:11:16 -0800 | [diff] [blame] | 10 | # |
| 11 | # ██ ██ █████ ██████ ███ ██ ██ ███ ██ ██████ |
| 12 | # ██ ██ ██ ██ ██ ██ ████ ██ ██ ████ ██ ██ |
| 13 | # ██ █ ██ ███████ ██████ ██ ██ ██ ██ ██ ██ ██ ██ ███ |
| 14 | # ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ |
| 15 | # ███ ███ ██ ██ ██ ██ ██ ████ ██ ██ ████ ██████ |
| 16 | # |
| 17 | # Everything here is added to *every* iree_cc_library/iree_cc_binary/etc. |
| 18 | # That includes both runtime and compiler components, and these may propagate |
| 19 | # out to user code interacting with either (such as custom modules). |
| 20 | # |
| 21 | # Be extremely judicious in the use of these flags. |
| 22 | # |
| 23 | # - Need to disable a warning? |
| 24 | # Usually these are encountered in compiler-specific code and can be disabled |
| 25 | # in a compiler-specific way. Only add global warning disables when it's clear |
| 26 | # that we never want them or that they'll show up in a lot of places. |
| 27 | # |
| 28 | # See: https://stackoverflow.com/questions/3378560/how-to-disable-gcc-warnings-for-a-few-lines-of-code |
| 29 | # |
| 30 | # - Need to add a linker dependency? |
| 31 | # First figure out if you *really* need it. If it's only required on specific |
| 32 | # platforms and in very specific files clang or msvc are used prefer |
| 33 | # autolinking. GCC is stubborn and doesn't have autolinking so additional |
| 34 | # flags may be required there. |
| 35 | # |
| 36 | # See: https://en.wikipedia.org/wiki/Auto-linking |
| 37 | # |
| 38 | # - Need to tweak a compilation mode setting (debug/asserts/etc)? |
| 39 | # Don't do that here, and in general *don't do that at all* unless it's behind |
| 40 | # a very specific IREE-prefixed cmake flag (like IREE_SIZE_OPTIMIZED). |
| 41 | # There's no one-size solution when we are dealing with cross-project and |
| 42 | # cross-compiled binaries - there's no safe way to set global options that |
| 43 | # won't cause someone to break, and you probably don't really need to do |
| 44 | # change that setting anyway. Follow the rule of least surprise: if the user |
| 45 | # has CMake's Debug configuration active then don't force things into release |
| 46 | # mode, etc. |
| 47 | # |
| 48 | # - Need to add an include directory? |
| 49 | # Don't do that here. Always prefer to fully-specify the path from the IREE |
| 50 | # workspace root when it's known that the compilation will be occuring using |
| 51 | # the files within the IREE checkout; for example, instead of adding a global |
| 52 | # include path to third_party/foo/ and #include <foo.h>'ing, just |
| 53 | # #include "third_party/foo/foo.h". This reduces build configuration, makes it |
| 54 | # easier for readers to find the files, etc. |
| 55 | # |
| 56 | # - Still think you need to add an include directory? (system includes, etc) |
| 57 | # Don't do that here, either. It's highly doubtful that every single target in |
| 58 | # all of IREE (both compiler and runtime) on all platforms (both host and |
| 59 | # cross-compilation targets) needs your special include directory. Add it on |
| 60 | # the COPTS of the target you are using it in and, ideally, private to that |
| 61 | # target (used in .c/cc files, not in a .h that leaks the include path |
| 62 | # requirements to all consumers of the API). |
Ben Vanik | 246bc91 | 2019-09-19 15:22:12 -0700 | [diff] [blame] | 63 | |
Lei Zhang | 6c5907b | 2020-06-02 09:06:08 -0700 | [diff] [blame] | 64 | set(IREE_CXX_STANDARD ${CMAKE_CXX_STANDARD}) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 65 | |
Ben Vanik | 3c082aa | 2020-11-16 04:03:11 -0800 | [diff] [blame] | 66 | # TODO(benvanik): fix these names (or remove entirely). |
Ben Vanik | 479ef30 | 2020-11-14 08:36:35 -0800 | [diff] [blame] | 67 | set(IREE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
Ben Vanik | 3c082aa | 2020-11-16 04:03:11 -0800 | [diff] [blame] | 68 | set(IREE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 69 | set(IREE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 70 | |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 71 | iree_select_compiler_opts(IREE_DEFAULT_COPTS |
Geoffrey Martin-Noble | d9ea501 | 2019-12-10 08:53:35 -0800 | [diff] [blame] | 72 | CLANG |
Geoffrey Martin-Noble | e86278d | 2020-07-16 10:10:51 -0700 | [diff] [blame] | 73 | # Set clang diagnostics. These largely match the set of warnings used within |
| 74 | # Google. They have not been audited super carefully by the IREE team but |
| 75 | # are generally thought to be a good set and consistency with those used |
Copybara-Service | 583c5ea | 2020-11-04 09:19:30 -0800 | [diff] [blame] | 76 | # internally is very useful when importing. If you feel that some of these |
Geoffrey Martin-Noble | e86278d | 2020-07-16 10:10:51 -0700 | [diff] [blame] | 77 | # should be different, please raise an issue! |
Geoffrey Martin-Noble | f822f92 | 2020-12-28 09:11:19 -0800 | [diff] [blame] | 78 | |
| 79 | # Please keep these in sync with build_tools/bazel/iree.bazelrc |
| 80 | |
Geoffrey Martin-Noble | e86278d | 2020-07-16 10:10:51 -0700 | [diff] [blame] | 81 | "-Wall" |
| 82 | |
| 83 | # Disable warnings we don't care about or that generally have a low |
| 84 | # signal/noise ratio. |
| 85 | "-Wno-ambiguous-member-template" |
| 86 | "-Wno-char-subscripts" |
Geoffrey Martin-Noble | 7a3b63d | 2021-03-01 13:10:33 -0800 | [diff] [blame] | 87 | "-Wno-deprecated-declarations" |
Geoffrey Martin-Noble | e86278d | 2020-07-16 10:10:51 -0700 | [diff] [blame] | 88 | "-Wno-extern-c-compat" # Matches upstream. Cannot impact due to extern C inclusion method. |
| 89 | "-Wno-gnu-alignof-expression" |
| 90 | "-Wno-gnu-variable-sized-type-not-at-end" |
| 91 | "-Wno-ignored-optimization-argument" |
| 92 | "-Wno-invalid-offsetof" # Technically UB but needed for intrusive ptrs |
| 93 | "-Wno-invalid-source-encoding" |
| 94 | "-Wno-mismatched-tags" |
| 95 | "-Wno-pointer-sign" |
| 96 | "-Wno-reserved-user-defined-literal" |
| 97 | "-Wno-return-type-c-linkage" |
| 98 | "-Wno-self-assign-overloaded" |
| 99 | "-Wno-sign-compare" |
| 100 | "-Wno-signed-unsigned-wchar" |
| 101 | "-Wno-strict-overflow" |
| 102 | "-Wno-trigraphs" |
| 103 | "-Wno-unknown-pragmas" |
| 104 | "-Wno-unknown-warning-option" |
| 105 | "-Wno-unused-command-line-argument" |
| 106 | "-Wno-unused-const-variable" |
| 107 | "-Wno-unused-function" |
| 108 | "-Wno-unused-local-typedef" |
| 109 | "-Wno-unused-private-field" |
| 110 | "-Wno-user-defined-warnings" |
| 111 | # Explicitly enable some additional warnings. |
| 112 | # Some of these aren't on by default, or under -Wall, or are subsets of |
| 113 | # warnings turned off above. |
| 114 | "-Wno-ambiguous-member-template" |
| 115 | "-Wctad-maybe-unsupported" |
| 116 | "-Wfloat-overflow-conversion" |
| 117 | "-Wfloat-zero-conversion" |
| 118 | "-Wfor-loop-analysis" |
| 119 | "-Wformat-security" |
| 120 | "-Wgnu-redeclared-enum" |
| 121 | "-Wimplicit-fallthrough" |
| 122 | "-Winfinite-recursion" |
| 123 | "-Wliteral-conversion" |
| 124 | "-Wnon-virtual-dtor" |
| 125 | "-Woverloaded-virtual" |
| 126 | "-Wself-assign" |
| 127 | "-Wstring-conversion" |
| 128 | "-Wtautological-overlap-compare" |
| 129 | "-Wthread-safety" |
| 130 | "-Wthread-safety-beta" |
| 131 | "-Wunused-comparison" |
Geoffrey Martin-Noble | e86278d | 2020-07-16 10:10:51 -0700 | [diff] [blame] | 132 | "-Wvla" |
Geoffrey Martin-Noble | e86278d | 2020-07-16 10:10:51 -0700 | [diff] [blame] | 133 | |
| 134 | # Turn off some additional warnings (CMake only) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 135 | "-Wno-strict-prototypes" |
| 136 | "-Wno-shadow-uncaptured-local" |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 137 | "-Wno-gnu-zero-variadic-macro-arguments" |
| 138 | "-Wno-shadow-field-in-constructor" |
| 139 | "-Wno-unreachable-code-return" |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 140 | "-Wno-missing-variable-declarations" |
| 141 | "-Wno-gnu-label-as-value" |
Geoffrey Martin-Noble | d9ea501 | 2019-12-10 08:53:35 -0800 | [diff] [blame] | 142 | CLANG_OR_GCC |
| 143 | "-Wno-unused-parameter" |
Ben Vanik | 31c4dbb | 2020-11-14 12:11:16 -0800 | [diff] [blame] | 144 | "-Wno-unused-variable" |
Geoffrey Martin-Noble | d9ea501 | 2019-12-10 08:53:35 -0800 | [diff] [blame] | 145 | "-Wno-undef" |
Lei Zhang | 6bd3b1d | 2020-08-25 21:31:28 -0400 | [diff] [blame] | 146 | "-fvisibility=hidden" |
Stella Laurenzo | 516178a | 2021-01-08 12:18:24 -0800 | [diff] [blame] | 147 | # NOTE: The RTTI setting must match what LLVM was compiled with (defaults |
| 148 | # to RTTI disabled). |
| 149 | "$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>" |
| 150 | "$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>" |
| 151 | |
Ben Vanik | b8fe086 | 2019-09-25 09:26:03 -0700 | [diff] [blame] | 152 | MSVC_OR_CLANG_CL |
Scott Todd | 9fa14f9 | 2021-03-09 10:43:38 -0800 | [diff] [blame] | 153 | # Default warning level (severe + significant + production quality). |
| 154 | # This does not include level 4, "informational", warnings or those that |
| 155 | # are off by default. |
| 156 | # https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level |
| 157 | # Note that we set CMake policy CMP0092 (if found), making this explicit: |
| 158 | # https://cmake.org/cmake/help/v3.15/policy/CMP0092.html |
| 159 | "/W3" |
| 160 | |
Ben Vanik | 31c4dbb | 2020-11-14 12:11:16 -0800 | [diff] [blame] | 161 | # Exclude a bunch of rarely-used APIs, such as crypto/DDE/shell. |
| 162 | # https://docs.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers |
| 163 | # NOTE: this is not really required anymore for build performance but does |
| 164 | # work around some issues that crop up with header version compatibility |
| 165 | # (abseil has issues with winsock versions). |
Ben Vanik | b8fe086 | 2019-09-25 09:26:03 -0700 | [diff] [blame] | 166 | "/DWIN32_LEAN_AND_MEAN" |
Ben Vanik | 31c4dbb | 2020-11-14 12:11:16 -0800 | [diff] [blame] | 167 | |
| 168 | # Don't allow windows.h to define MIN and MAX and conflict with the STL. |
| 169 | # There's no legit use for these macros as any code we are writing ourselves |
| 170 | # that we want a MIN/MAX in should be using an IREE-prefixed version |
| 171 | # instead: iree_min iree_max |
| 172 | # https://stackoverflow.com/a/4914108 |
| 173 | "/DNOMINMAX" |
| 174 | |
| 175 | # Adds M_PI and other constants to <math.h>/<cmath> (to match non-windows). |
| 176 | # https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants |
Scott Todd | f396022 | 2020-09-18 15:58:35 -0700 | [diff] [blame] | 177 | "/D_USE_MATH_DEFINES" |
Ben Vanik | 31c4dbb | 2020-11-14 12:11:16 -0800 | [diff] [blame] | 178 | |
Ben Vanik | b7c92bf | 2020-11-14 13:32:28 -0800 | [diff] [blame] | 179 | # Disable the "deprecation" warnings about CRT functions like strcpy. |
| 180 | # Though the secure versions *are* better, they aren't portable and as such |
| 181 | # just make cross-platform code annoying. One solution is to reimplement |
| 182 | # them in a portable fashion and use those - and that's what we try to do |
| 183 | # in certain places where we can get away with it. Other uses, like getenv, |
| 184 | # are fine as these are not intended for use in core runtime code that needs |
| 185 | # to be secure (friends don't let friends ship entire compiler stacks |
| 186 | # embedded inside security sensitive applications anyway :). |
| 187 | # https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt |
| 188 | "/D_CRT_SECURE_NO_WARNINGS" |
| 189 | |
| 190 | # With the above said about the "deprecated" functions; this useful flag |
| 191 | # will at least try to use them when possible without any change to user |
| 192 | # code. Note however because the new versions use templates they won't be |
| 193 | # activated in C code; that's fine. |
| 194 | # https://docs.microsoft.com/en-us/cpp/c-runtime-library/secure-template-overloads |
| 195 | "/D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES" |
| 196 | |
Stella Laurenzo | 516178a | 2021-01-08 12:18:24 -0800 | [diff] [blame] | 197 | # Configure RTTI generation. |
| 198 | # - /GR - Enable generation of RTTI (default) |
| 199 | # - /GR- - Disables generation of RTTI |
| 200 | # https://docs.microsoft.com/en-us/cpp/build/reference/gr-enable-run-time-type-information?view=msvc-160 |
| 201 | "/GR-" |
Ben Vanik | 31c4dbb | 2020-11-14 12:11:16 -0800 | [diff] [blame] | 202 | |
| 203 | # Default max section count is 64k, which is woefully inadequate for some of |
| 204 | # the insanely bloated tablegen outputs LLVM/MLIR produces. This cranks it |
| 205 | # up to 2^32. It's not great that we have to generate/link files like that |
| 206 | # but it's better to not get spurious failures during LTCG. |
| 207 | # https://docs.microsoft.com/en-us/cpp/build/reference/bigobj-increase-number-of-sections-in-dot-obj-file |
| 208 | "/bigobj" |
| 209 | |
Ben Vanik | b7c92bf | 2020-11-14 13:32:28 -0800 | [diff] [blame] | 210 | # "nonstandard extension used : zero-sized array in struct/union" |
| 211 | # This happens with unsized or zero-length arrays at the end of structs, |
| 212 | # which is completely valid in C where we do it and get this warning. Shut |
| 213 | # it up and rely on the better warnings from clang to catch if we try to |
| 214 | # use it where it really matters (on a class that has copy/move ctors, etc). |
| 215 | # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-levels-2-and-4-c4200 |
| 216 | "/wd4200" |
| 217 | |
Ben Vanik | c17659f | 2020-11-14 13:58:45 -0800 | [diff] [blame] | 218 | # "signed/unsigned mismatch in comparison" |
| 219 | # This is along the lines of a generic implicit conversion warning but tends |
| 220 | # to crop up in code that implicitly treats unsigned size_t values as if |
| 221 | # they were signed values instead of properly using ssize_t. In certain |
| 222 | # cases where the comparison being performed may be guarding access to |
| 223 | # memory this can cause unexpected behavior ("-1ull < 512ull, great let's |
Ben Vanik | 7f3a7e3 | 2020-11-14 14:16:07 -0800 | [diff] [blame] | 224 | # dereference buffer[-1ull]!"). |
Ben Vanik | c17659f | 2020-11-14 13:58:45 -0800 | [diff] [blame] | 225 | # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4018 |
| 226 | # |
Ben Vanik | 7f3a7e3 | 2020-11-14 14:16:07 -0800 | [diff] [blame] | 227 | # TODO(#3844): remove this (or make it per-file to iree/compiler, as LLVM |
Ben Vanik | c17659f | 2020-11-14 13:58:45 -0800 | [diff] [blame] | 228 | # tends to not care about these kind of things and it crops up there a lot). |
Ben Vanik | afd7abe | 2020-10-07 09:01:53 -0700 | [diff] [blame] | 229 | "/wd4018" |
Ben Vanik | c17659f | 2020-11-14 13:58:45 -0800 | [diff] [blame] | 230 | |
Ben Vanik | 7f3a7e3 | 2020-11-14 14:16:07 -0800 | [diff] [blame] | 231 | # Also common in LLVM is mismatching signed/unsigned math. That's even more |
| 232 | # dangerous than C4018: almost always these crop up in doing something with |
| 233 | # a size_t and a non-size_t value (usually int or something like it) and do |
| 234 | # you want out-of-bounds access exploits? Because that's how you get |
| 235 | # out-of-bounds access exploits. Before fuzzers took over finding code and |
| 236 | # trying to compile it with this warning forced to be an error was a way to |
| 237 | # narrow down the places to look for attack vectors. I lived through the |
| 238 | # Microsoft SAL/safe-int code red, and once you get used to using the safe |
| 239 | # buffer offset/size manipulation functions it eliminates all kinds of |
| 240 | # annoying bugs - as well as potential security issues. |
| 241 | # |
| 242 | # TODO(#3844): work to remove this class of errors from our code. It's |
| 243 | # almost entirely in LLVM related stuff so per-file iree/compiler/... would |
| 244 | # be fine. |
| 245 | "/wd4146" # operator applied to unsigned type, result still unsigned |
| 246 | "/wd4244" # possible loss of data |
| 247 | "/wd4267" # initializing: possible loss of data |
| 248 | |
Ben Vanik | c17659f | 2020-11-14 13:58:45 -0800 | [diff] [blame] | 249 | # Misc tweaks to better match reasonable clang/gcc behavior: |
| 250 | "/wd4005" # allow: macro redefinition |
| 251 | "/wd4065" # allow: switch statement contains 'default' but no 'case' labels |
| 252 | "/wd4141" # allow: inline used more than once |
| 253 | "/wd4624" # allow: destructor was implicitly defined as deleted |
| 254 | |
| 255 | # TODO(benvanik): confirm these are all still required and document: |
| 256 | "/wd4146" # operator applied to unsigned type, result still unsigned |
| 257 | "/wd4244" # possible loss of data |
| 258 | "/wd4267" # initializing: possible loss of data |
| 259 | "/wd5105" # allow: macro expansion producing 'defined' has undefined behavior |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 260 | ) |
Ben Vanik | 31c4dbb | 2020-11-14 12:11:16 -0800 | [diff] [blame] | 261 | |
Scott Todd | b8c3811 | 2021-03-09 10:46:10 -0800 | [diff] [blame] | 262 | # On MSVC, CMake sets /GR by default (enabling RTTI), but we set /GR- |
| 263 | # (disabling it) above. To avoid Command line warning D9025 which warns about |
| 264 | # overriding the flag value, we remove /GR from global CMake flags. |
| 265 | # |
| 266 | # Note: this may have ripple effects on downstream projects using IREE. If this |
| 267 | # is a problem for your project, please reach out to us and we'll figure out a |
| 268 | # compatible solution. |
| 269 | # |
| 270 | # See also: |
| 271 | # https://github.com/google/iree/issues/4665. |
| 272 | # https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878 |
| 273 | # https://gitlab.kitware.com/cmake/cmake/-/issues/20610 |
Lei Zhang | 3075d7b | 2021-04-22 17:03:55 -0400 | [diff] [blame] | 274 | if(CMAKE_CXX_FLAGS AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
| 275 | string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
Scott Todd | b8c3811 | 2021-03-09 10:46:10 -0800 | [diff] [blame] | 276 | endif() |
| 277 | |
Cindy Liu | 331946c | 2021-06-01 12:20:30 -0700 | [diff] [blame] | 278 | if(NOT ANDROID AND ${IREE_ENABLE_THREADING}) |
Ben Vanik | 36225a4 | 2020-11-14 12:34:04 -0800 | [diff] [blame] | 279 | iree_select_compiler_opts(_IREE_PTHREADS_LINKOPTS |
| 280 | CLANG_OR_GCC |
| 281 | "-lpthread" |
| 282 | ) |
| 283 | else() |
| 284 | # Android provides its own pthreads support with no linking required. |
| 285 | endif() |
| 286 | |
Kojo Acquah | 68c27a0 | 2021-04-08 16:28:48 -0700 | [diff] [blame] | 287 | if(ANDROID) |
| 288 | # logging.h on Android needs llog to link in Android logging. |
| 289 | iree_select_compiler_opts(_IREE_LOGGING_LINKOPTS |
| 290 | CLANG_OR_GCC |
| 291 | "-llog" |
| 292 | ) |
| 293 | endif() |
| 294 | |
Ben Vanik | 36225a4 | 2020-11-14 12:34:04 -0800 | [diff] [blame] | 295 | iree_select_compiler_opts(IREE_DEFAULT_LINKOPTS |
Ben Vanik | 36225a4 | 2020-11-14 12:34:04 -0800 | [diff] [blame] | 296 | CLANG_OR_GCC |
| 297 | # Required by all modern software, effectively: |
Ben Vanik | b70104b | 2021-05-02 11:19:22 -0700 | [diff] [blame] | 298 | "-lm" |
Ben Vanik | 36225a4 | 2020-11-14 12:34:04 -0800 | [diff] [blame] | 299 | ${_IREE_PTHREADS_LINKOPTS} |
Kojo Acquah | 68c27a0 | 2021-04-08 16:28:48 -0700 | [diff] [blame] | 300 | ${_IREE_LOGGING_LINKOPTS} |
Ben Vanik | b34a2e5 | 2021-06-01 15:31:35 -0700 | [diff] [blame] | 301 | MSVC |
| 302 | "-natvis:${CMAKE_SOURCE_DIR}/iree/iree.natvis" |
Ben Vanik | 36225a4 | 2020-11-14 12:34:04 -0800 | [diff] [blame] | 303 | ) |
Ben Vanik | 31c4dbb | 2020-11-14 12:11:16 -0800 | [diff] [blame] | 304 | |
Ben Vanik | 90faf21 | 2020-11-15 17:09:49 -0800 | [diff] [blame] | 305 | # Add to LINKOPTS on a binary to configure it for X/Wayland/Windows/etc |
| 306 | # depending on the target cross-compilation platform. |
| 307 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") |
| 308 | set(IREE_TARGET_GUI_LINKOPTS "-SUBSYSTEM:WINDOWS") |
| 309 | else() |
| 310 | set(IREE_TARGET_GUI_LINKOPTS "") |
| 311 | endif() |
| 312 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 313 | #------------------------------------------------------------------------------- |
Ben Vanik | 0bef300 | 2020-08-08 11:05:19 -0700 | [diff] [blame] | 314 | # Size-optimized build flags |
| 315 | #------------------------------------------------------------------------------- |
| 316 | |
| 317 | # TODO(#898): add a dedicated size-constrained configuration. |
| 318 | if(${IREE_SIZE_OPTIMIZED}) |
| 319 | iree_select_compiler_opts(IREE_SIZE_OPTIMIZED_DEFAULT_COPTS |
Ben Vanik | 4bb17bd | 2021-08-04 16:14:21 -0700 | [diff] [blame] | 320 | CLANG_OR_GCC |
| 321 | "-DIREE_STATUS_MODE=0" |
| 322 | "-DIREE_HAL_MODULE_STRING_UTIL_ENABLE=0" |
| 323 | "-DIREE_VM_EXT_I64_ENABLE=0" |
| 324 | "-DIREE_VM_EXT_F32_ENABLE=0" |
Ben Vanik | 0bef300 | 2020-08-08 11:05:19 -0700 | [diff] [blame] | 325 | MSVC_OR_CLANG_CL |
| 326 | "/GS-" |
| 327 | "/GL" |
| 328 | "/Gw" |
| 329 | "/Gy" |
| 330 | "/DNDEBUG" |
| 331 | "/DIREE_STATUS_MODE=0" |
Ben Vanik | 8e96578 | 2021-05-04 09:31:25 -0700 | [diff] [blame] | 332 | "/DIREE_FLAGS_ENABLE_CLI=0" |
| 333 | "/DIREE_HAL_MODULE_STRING_UTIL_ENABLE=0" |
| 334 | "/DIREE_VM_EXT_I64_ENABLE=0" |
| 335 | "/DIREE_VM_EXT_F32_ENABLE=0" |
Ben Vanik | dab0b28 | 2021-02-05 23:52:57 -0800 | [diff] [blame] | 336 | "/Os" |
| 337 | "/Oy" |
Ben Vanik | 8e96578 | 2021-05-04 09:31:25 -0700 | [diff] [blame] | 338 | "/Zi" |
| 339 | "/c" |
Ben Vanik | 0bef300 | 2020-08-08 11:05:19 -0700 | [diff] [blame] | 340 | ) |
| 341 | iree_select_compiler_opts(IREE_SIZE_OPTIMIZED_DEFAULT_LINKOPTS |
| 342 | MSVC_OR_CLANG_CL |
Ben Vanik | 8e96578 | 2021-05-04 09:31:25 -0700 | [diff] [blame] | 343 | "-DEBUG:FULL" |
Ben Vanik | dab0b28 | 2021-02-05 23:52:57 -0800 | [diff] [blame] | 344 | "-LTCG" |
| 345 | "-opt:ref,icf" |
Ben Vanik | 0bef300 | 2020-08-08 11:05:19 -0700 | [diff] [blame] | 346 | ) |
| 347 | # TODO(#898): make this only impact the runtime (IREE_RUNTIME_DEFAULT_...). |
| 348 | set(IREE_DEFAULT_COPTS |
| 349 | "${IREE_DEFAULT_COPTS}" |
| 350 | "${IREE_SIZE_OPTIMIZED_DEFAULT_COPTS}") |
| 351 | set(IREE_DEFAULT_LINKOPTS |
| 352 | "${IREE_DEFAULT_LINKOPTS}" |
| 353 | "${IREE_SIZE_OPTIMIZED_DEFAULT_LINKOPTS}") |
| 354 | endif() |
| 355 | |
| 356 | #------------------------------------------------------------------------------- |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 357 | # Compiler: Clang/LLVM |
| 358 | #------------------------------------------------------------------------------- |
| 359 | |
| 360 | # TODO(benvanik): Clang/LLVM options. |
| 361 | |
| 362 | #------------------------------------------------------------------------------- |
| 363 | # Compiler: GCC |
| 364 | #------------------------------------------------------------------------------- |
| 365 | |
| 366 | # TODO(benvanik): GCC options. |
| 367 | |
| 368 | #------------------------------------------------------------------------------- |
| 369 | # Compiler: MSVC |
| 370 | #------------------------------------------------------------------------------- |
| 371 | |
| 372 | # TODO(benvanik): MSVC options. |
| 373 | |
| 374 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 375 | # Third party: llvm-project |
Marius Brehler | 18152f1 | 2020-01-06 09:30:20 -0800 | [diff] [blame] | 376 | #------------------------------------------------------------------------------- |
| 377 | |
Lei Zhang | 1ff7061 | 2020-06-04 10:12:41 -0400 | [diff] [blame] | 378 | set(MLIR_TABLEGEN_EXE mlir-tblgen) |
| 379 | # iree-tblgen is not defined using the add_tablegen mechanism as other TableGen |
| 380 | # tools in LLVM. |
Lei Zhang | 486e707 | 2020-06-16 11:42:49 -0400 | [diff] [blame] | 381 | iree_get_executable_path(IREE_TABLEGEN_EXE iree-tblgen) |
Marius Brehler | 9a92463 | 2019-12-17 13:56:31 -0800 | [diff] [blame] | 382 | |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 383 | #------------------------------------------------------------------------------- |
Marius Brehler | ec38aa0 | 2020-07-29 13:18:45 -0700 | [diff] [blame] | 384 | # Third party: mlir-emitc |
| 385 | #------------------------------------------------------------------------------- |
| 386 | |
| 387 | if(IREE_ENABLE_EMITC) |
Marius Brehler | ec38aa0 | 2020-07-29 13:18:45 -0700 | [diff] [blame] | 388 | add_definitions(-DIREE_HAVE_EMITC_DIALECT) |
| 389 | endif() |