blob: 8133040188248bf30608b960ee36f818fc683660 [file] [log] [blame]
Jaswant Panchumartieb93d8c2024-06-22 10:51:37 +00001# Copyright 2024 The Dawn & Tint Authors
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are met:
5#
6# 1. Redistributions of source code must retain the above copyright notice, this
7# list of conditions and the following disclaimer.
8#
9# 2. Redistributions in binary form must reproduce the above copyright notice,
10# this list of conditions and the following disclaimer in the documentation
11# and/or other materials provided with the distribution.
12#
13# 3. Neither the name of the copyright holder nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28if (${DAWN_ENABLE_TSAN})
29 add_compile_options(-stdlib=libc++)
30 add_link_options(-stdlib=libc++)
31endif ()
32
33################################################################################
34# common_compile_options - sets compiler and linker options common for dawn
35################################################################################
36function(common_compile_options target)
37 if (COMPILER_IS_LIKE_GNU)
38 target_compile_options(${target}
39 PRIVATE
40 "-fno-exceptions"
41 "-fno-rtti"
42
43 "-Wno-deprecated-builtins"
44 "-Wno-unknown-warning-option"
45 "-Wno-switch-default"
46 )
47 if (${DAWN_WERROR})
48 target_compile_options(${target}
49 PRIVATE "-Werror")
50 endif ()
51 endif ()
52
53 if (MSVC)
54 target_compile_options(${target}
55 PUBLIC "/utf-8")
56 endif ()
57
58 if (COMPILER_IS_LIKE_GNU)
59 set(SANITIZER_OPTIONS "")
60 if (${DAWN_ENABLE_MSAN})
61 list(APPEND SANITIZER_OPTIONS "-fsanitize=memory")
62 endif ()
63 if (${DAWN_ENABLE_ASAN})
64 list(APPEND SANITIZER_OPTIONS "-fsanitize=address")
65 endif ()
66 if (${DAWN_ENABLE_TSAN})
67 list(APPEND SANITIZER_OPTIONS "-fsanitize=thread")
68 endif ()
69 if (${DAWN_ENABLE_UBSAN})
70 list(APPEND SANITIZER_OPTIONS
71 "-fsanitize=undefined"
72 "-fsanitize=float-divide-by-zero")
73 endif ()
74 if (SANITIZER_OPTIONS)
75 target_compile_options(${target}
76 PUBLIC ${SANITIZER_OPTIONS})
77 target_link_options(${target}
78 PUBLIC ${SANITIZER_OPTIONS})
79 endif ()
80 endif ()
81
82 option(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF)
83 if (DAWN_EMIT_COVERAGE)
84 target_compile_definitions(${target}
85 PRIVATE "DAWN_EMIT_COVERAGE")
86 if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
87 target_compile_options(${target}
88 PRIVATE "--coverage")
89 target_link_options(${target}
90 PRIVATE "gcov")
91 elseif (COMPILER_IS_CLANG OR COMPILER_IS_CLANG_CL)
92 target_compile_options(${target}
93 PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
94 target_link_options(${target}
95 PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
96 else()
97 message(FATAL_ERROR
98 "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain")
99 endif ()
100 endif ()
101endfunction()