xref: /aosp_15_r20/external/deqp/framework/delibs/cmake/CFlags.cmake (revision 35238bce31c2a825756842865a792f8cf7f89930)
1#-------------------------------------------------------------------------
2# drawElements CMake utilities
3# ----------------------------
4#
5# Copyright 2014 The Android Open Source Project
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11#      http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19#-------------------------------------------------------------------------
20
21set(DE_COVERAGE_BUILD "OFF" CACHE STRING "Build with coverage instrumentation with GCC (ON/OFF)")
22
23if (NOT DE_DEFS)
24	message(FATAL_ERROR "Defs.cmake is not included")
25endif ()
26
27if (DE_COMPILER_IS_GCC OR DE_COMPILER_IS_CLANG)
28	# Compiler flags for GCC/Clang
29
30	set(TARGET_FLAGS "")
31
32	if (DE_COVERAGE_BUILD)
33		if (not DE_COMPILER_IS_GCC)
34			message(FATAL_ERROR "Coverage build requires GCC")
35		endif ()
36
37		add_definitions("-DDE_COVERAGE_BUILD")
38		set(TARGET_FLAGS	"-fprofile-arcs -ftest-coverage")
39		set(LINK_FLAGS		"${LINK_FLAGS} -lgcov")
40	endif ()
41
42	# \note Remove -Wno-sign-conversion for more warnings
43	set(WARNING_FLAGS			"-Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion -Wno-sign-conversion")
44
45	# Need to specify c++ standard version through CMAKE_C_STANDARD and CMAKE_CXX_STANDARD
46	# Avoids incorrect addition of argument -std=gnu++XX that may result in build failure to usage of features in
47	# greater standard version than the one specified
48	set(CMAKE_C_STANDARD 99)
49	set(CMAKE_CXX_STANDARD 17)
50	set(CMAKE_C_FLAGS			"${TARGET_FLAGS} ${WARNING_FLAGS} ${CMAKE_C_FLAGS} -pedantic ")
51	set(CMAKE_CXX_FLAGS			"${TARGET_FLAGS} ${WARNING_FLAGS} ${CMAKE_CXX_FLAGS}")
52
53	# Set _FILE_OFFSET_BITS=64 on 32-bit build on Linux to enable output log files to exceed 2GB
54	if ((DE_CPU_X86) AND (DE_OS_UNIX))
55		set(CMAKE_C_FLAGS		"${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64")
56		set(CMAKE_CXX_FLAGS		"${CMAKE_CXX_FLAGS} -D_FILE_OFFSET_BITS=64")
57	endif ()
58
59	# Force compiler to generate code where integers have well defined overflow
60	# Turn on -Wstrict-overflow=5 and check all warnings before removing
61	set(CMAKE_C_FLAGS			"${CMAKE_C_FLAGS} -fwrapv")
62	set(CMAKE_CXX_FLAGS			"${CMAKE_CXX_FLAGS} -fwrapv")
63
64	# Force compiler to not export any symbols.
65	# Any static libraries build are linked into the standalone executable binaries.
66	set(CMAKE_C_FLAGS			"${CMAKE_C_FLAGS} -fvisibility=hidden")
67	set(CMAKE_CXX_FLAGS			"${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
68
69	# For 3rd party sw disable all warnings
70	set(DE_3RD_PARTY_C_FLAGS	"${CMAKE_C_FLAGS} ${TARGET_FLAGS} -w")
71	set(DE_3RD_PARTY_CXX_FLAGS	"${CMAKE_CXX_FLAGS} ${TARGET_FLAGS} -w")
72elseif (DE_COMPILER_IS_MSC)
73	# Compiler flags for msc
74
75	# \note Following unnecessary nagging warnings are disabled:
76	# 4820: automatic padding added after data
77	# 4255: no function prototype given (from system headers)
78	# 4668: undefined identifier in preprocessor expression (from system headers)
79	# 4738: storing 32-bit float result in memory
80	# 4711: automatic inline expansion
81	set(MSC_BASE_FLAGS "/DWIN32 /D_WINDOWS /D_CRT_SECURE_NO_WARNINGS")
82	set(MSC_WARNING_FLAGS "/W3 /wd4820 /wd4255 /wd4668 /wd4738 /wd4711")
83
84	set(CMAKE_C_FLAGS			"${CMAKE_C_FLAGS} ${MSC_BASE_FLAGS} ${MSC_WARNING_FLAGS}")
85	set(CMAKE_CXX_FLAGS			"${CMAKE_CXX_FLAGS} ${MSC_BASE_FLAGS} /EHsc ${MSC_WARNING_FLAGS} /std:c++17")
86
87	# For 3rd party sw disable all warnings
88	set(DE_3RD_PARTY_C_FLAGS	"${CMAKE_C_FLAGS} ${MSC_BASE_FLAGS} /W0")
89	set(DE_3RD_PARTY_CXX_FLAGS	"${CMAKE_CXX_FLAGS} ${MSC_BASE_FLAGS} /EHsc /W0")
90else ()
91	message(FATAL_ERROR "DE_COMPILER is not valid")
92endif ()
93
94if (DE_MINGW AND DE_PTR_SIZE EQUAL 8)
95	# Pass -mbig-obj to mingw gas on Win64. COFF has a 2**16 section limit, and
96	# on Win64, every COMDAT function creates at least 3 sections: .text, .pdata,
97	# and .xdata.
98	# Enable static libgcc and libstdc++ also to avoid needing to have
99	# Windows builds of the standard libraries distributed.
100	set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Wa,-mbig-obj -static -static-libgcc")
101	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj -static -static-libgcc -static-libstdc++")
102endif()
103