xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/Linux.cmake (revision 35ffd701415c9e32e53136d61a677a8d0a8fc4a5)
1*35ffd701SAndroid Build Coastguard Worker# Copyright(c) 2017 Intel Corporation
2*35ffd701SAndroid Build Coastguard Worker
3*35ffd701SAndroid Build Coastguard Worker# Permission is hereby granted, free of charge, to any person obtaining a
4*35ffd701SAndroid Build Coastguard Worker# copy of this software and associated documentation files(the "Software"),
5*35ffd701SAndroid Build Coastguard Worker# to deal in the Software without restriction, including without limitation
6*35ffd701SAndroid Build Coastguard Worker# the rights to use, copy, modify, merge, publish, distribute, sublicense,
7*35ffd701SAndroid Build Coastguard Worker# and / or sell copies of the Software, and to permit persons to whom the
8*35ffd701SAndroid Build Coastguard Worker# Software is furnished to do so, subject to the following conditions:
9*35ffd701SAndroid Build Coastguard Worker
10*35ffd701SAndroid Build Coastguard Worker# The above copyright notice and this permission notice shall be included
11*35ffd701SAndroid Build Coastguard Worker# in all copies or substantial portions of the Software.
12*35ffd701SAndroid Build Coastguard Worker
13*35ffd701SAndroid Build Coastguard Worker# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14*35ffd701SAndroid Build Coastguard Worker# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*35ffd701SAndroid Build Coastguard Worker# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16*35ffd701SAndroid Build Coastguard Worker# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17*35ffd701SAndroid Build Coastguard Worker# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18*35ffd701SAndroid Build Coastguard Worker# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19*35ffd701SAndroid Build Coastguard Worker# OTHER DEALINGS IN THE SOFTWARE.
20*35ffd701SAndroid Build Coastguard Worker
21*35ffd701SAndroid Build Coastguard Worker#this file should contain only compiler and linker flags
22*35ffd701SAndroid Build Coastguard Workerif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^aarch")
23*35ffd701SAndroid Build Coastguard Worker    SET (GMMLIB_COMPILER_FLAGS_COMMON
24*35ffd701SAndroid Build Coastguard Worker    #general warnings
25*35ffd701SAndroid Build Coastguard Worker    #-Wall
26*35ffd701SAndroid Build Coastguard Worker    -Winit-self
27*35ffd701SAndroid Build Coastguard Worker    -Winvalid-pch
28*35ffd701SAndroid Build Coastguard Worker    -Wpointer-arith
29*35ffd701SAndroid Build Coastguard Worker    -Wno-unused
30*35ffd701SAndroid Build Coastguard Worker    -Wno-unknown-pragmas
31*35ffd701SAndroid Build Coastguard Worker    -Wno-comments
32*35ffd701SAndroid Build Coastguard Worker    -Wno-narrowing
33*35ffd701SAndroid Build Coastguard Worker    -Wno-overflow
34*35ffd701SAndroid Build Coastguard Worker    -Wno-parentheses
35*35ffd701SAndroid Build Coastguard Worker    -Wno-missing-braces
36*35ffd701SAndroid Build Coastguard Worker    -Wno-sign-compare
37*35ffd701SAndroid Build Coastguard Worker    -Werror=address
38*35ffd701SAndroid Build Coastguard Worker    -Werror=format-security
39*35ffd701SAndroid Build Coastguard Worker    -Werror=return-type
40*35ffd701SAndroid Build Coastguard Worker
41*35ffd701SAndroid Build Coastguard Worker    # General optimization options
42*35ffd701SAndroid Build Coastguard Worker    -march=${GMMLIB_MARCH}
43*35ffd701SAndroid Build Coastguard Worker    -finline-functions
44*35ffd701SAndroid Build Coastguard Worker    -fno-short-enums
45*35ffd701SAndroid Build Coastguard Worker    -Wa,--noexecstack
46*35ffd701SAndroid Build Coastguard Worker    -fno-strict-aliasing
47*35ffd701SAndroid Build Coastguard Worker    # Common defines
48*35ffd701SAndroid Build Coastguard Worker    -DUSE_NEON
49*35ffd701SAndroid Build Coastguard Worker    # Other common flags
50*35ffd701SAndroid Build Coastguard Worker    -fstack-protector
51*35ffd701SAndroid Build Coastguard Worker    -fdata-sections
52*35ffd701SAndroid Build Coastguard Worker    -ffunction-sections
53*35ffd701SAndroid Build Coastguard Worker    -fmessage-length=0
54*35ffd701SAndroid Build Coastguard Worker    -fvisibility=hidden
55*35ffd701SAndroid Build Coastguard Worker    -fPIC
56*35ffd701SAndroid Build Coastguard Worker    -g
57*35ffd701SAndroid Build Coastguard Worker    )
58*35ffd701SAndroid Build Coastguard Workerelse()
59*35ffd701SAndroid Build Coastguard Worker    SET (GMMLIB_COMPILER_FLAGS_COMMON
60*35ffd701SAndroid Build Coastguard Worker    #general warnings
61*35ffd701SAndroid Build Coastguard Worker    -Wall
62*35ffd701SAndroid Build Coastguard Worker    -Winit-self
63*35ffd701SAndroid Build Coastguard Worker    -Winvalid-pch
64*35ffd701SAndroid Build Coastguard Worker    -Wpointer-arith
65*35ffd701SAndroid Build Coastguard Worker    -Wno-unused
66*35ffd701SAndroid Build Coastguard Worker    -Wno-unknown-pragmas
67*35ffd701SAndroid Build Coastguard Worker    -Wno-comments
68*35ffd701SAndroid Build Coastguard Worker    -Wno-narrowing
69*35ffd701SAndroid Build Coastguard Worker    -Wno-overflow
70*35ffd701SAndroid Build Coastguard Worker    -Wno-parentheses
71*35ffd701SAndroid Build Coastguard Worker    -Wno-missing-braces
72*35ffd701SAndroid Build Coastguard Worker    -Wno-sign-compare
73*35ffd701SAndroid Build Coastguard Worker    -Wno-enum-compare
74*35ffd701SAndroid Build Coastguard Worker    -Werror=address
75*35ffd701SAndroid Build Coastguard Worker    -Werror=format-security
76*35ffd701SAndroid Build Coastguard Worker    -Werror=return-type
77*35ffd701SAndroid Build Coastguard Worker
78*35ffd701SAndroid Build Coastguard Worker    # General optimization options
79*35ffd701SAndroid Build Coastguard Worker    -march=${GMMLIB_MARCH}
80*35ffd701SAndroid Build Coastguard Worker    -mpopcnt
81*35ffd701SAndroid Build Coastguard Worker    -msse
82*35ffd701SAndroid Build Coastguard Worker    -msse2
83*35ffd701SAndroid Build Coastguard Worker    -msse3
84*35ffd701SAndroid Build Coastguard Worker    -mssse3
85*35ffd701SAndroid Build Coastguard Worker    -msse4
86*35ffd701SAndroid Build Coastguard Worker    -msse4.1
87*35ffd701SAndroid Build Coastguard Worker    -msse4.2
88*35ffd701SAndroid Build Coastguard Worker    -mfpmath=sse
89*35ffd701SAndroid Build Coastguard Worker    -finline-functions
90*35ffd701SAndroid Build Coastguard Worker    -fno-short-enums
91*35ffd701SAndroid Build Coastguard Worker    -Wa,--noexecstack
92*35ffd701SAndroid Build Coastguard Worker    -fno-strict-aliasing
93*35ffd701SAndroid Build Coastguard Worker    # Common defines
94*35ffd701SAndroid Build Coastguard Worker    -DUSE_MMX
95*35ffd701SAndroid Build Coastguard Worker    -DUSE_SSE
96*35ffd701SAndroid Build Coastguard Worker    -DUSE_SSE2
97*35ffd701SAndroid Build Coastguard Worker    -DUSE_SSE3
98*35ffd701SAndroid Build Coastguard Worker    -DUSE_SSSE3
99*35ffd701SAndroid Build Coastguard Worker    # Other common flags
100*35ffd701SAndroid Build Coastguard Worker    -fstack-protector
101*35ffd701SAndroid Build Coastguard Worker    -fdata-sections
102*35ffd701SAndroid Build Coastguard Worker    -ffunction-sections
103*35ffd701SAndroid Build Coastguard Worker    -fmessage-length=0
104*35ffd701SAndroid Build Coastguard Worker    -fvisibility=hidden
105*35ffd701SAndroid Build Coastguard Worker    -fPIC
106*35ffd701SAndroid Build Coastguard Worker    -g
107*35ffd701SAndroid Build Coastguard Worker    # -m32 or -m64
108*35ffd701SAndroid Build Coastguard Worker    -m${GMMLIB_ARCH}
109*35ffd701SAndroid Build Coastguard Worker    )
110*35ffd701SAndroid Build Coastguard Workerendif()
111*35ffd701SAndroid Build Coastguard Worker
112*35ffd701SAndroid Build Coastguard Workerif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
113*35ffd701SAndroid Build Coastguard Worker#Gcc only flags
114*35ffd701SAndroid Build Coastguard Workerlist (APPEND GMMLIB_COMPILER_FLAGS_COMMON
115*35ffd701SAndroid Build Coastguard Worker    -funswitch-loops
116*35ffd701SAndroid Build Coastguard Worker    -Wl,--no-undefined
117*35ffd701SAndroid Build Coastguard Worker    -Wl,--no-as-needed
118*35ffd701SAndroid Build Coastguard Worker    -Wl,--gc-sections
119*35ffd701SAndroid Build Coastguard Worker    )
120*35ffd701SAndroid Build Coastguard Workerendif()
121*35ffd701SAndroid Build Coastguard Worker
122*35ffd701SAndroid Build Coastguard WorkerSET (GMMLIB_COMPILER_CXX_FLAGS_COMMON
123*35ffd701SAndroid Build Coastguard Worker    #cpp
124*35ffd701SAndroid Build Coastguard Worker    -Wno-reorder
125*35ffd701SAndroid Build Coastguard Worker    -Wsign-promo
126*35ffd701SAndroid Build Coastguard Worker    -Wnon-virtual-dtor
127*35ffd701SAndroid Build Coastguard Worker    -Wno-invalid-offsetof
128*35ffd701SAndroid Build Coastguard Worker    -fvisibility-inlines-hidden
129*35ffd701SAndroid Build Coastguard Worker    -fno-use-cxa-atexit
130*35ffd701SAndroid Build Coastguard Worker    -fno-rtti
131*35ffd701SAndroid Build Coastguard Worker    -fexceptions
132*35ffd701SAndroid Build Coastguard Worker    -fcheck-new
133*35ffd701SAndroid Build Coastguard Worker    -std=c++11
134*35ffd701SAndroid Build Coastguard Worker    -pthread
135*35ffd701SAndroid Build Coastguard Worker    -Werror=non-virtual-dtor
136*35ffd701SAndroid Build Coastguard Worker    )
137*35ffd701SAndroid Build Coastguard Worker
138*35ffd701SAndroid Build Coastguard WorkerSET (GMMLIB_COMPILER_FLAGS_DEBUG
139*35ffd701SAndroid Build Coastguard Worker    -O0
140*35ffd701SAndroid Build Coastguard Worker    -DINSTR_GTUNE_EXT
141*35ffd701SAndroid Build Coastguard Worker    )
142*35ffd701SAndroid Build Coastguard Worker
143*35ffd701SAndroid Build Coastguard WorkerSET (GMMLIB_COMPILER_FLAGS_RELEASE
144*35ffd701SAndroid Build Coastguard Worker    -O2
145*35ffd701SAndroid Build Coastguard Worker    -fno-omit-frame-pointer
146*35ffd701SAndroid Build Coastguard Worker    #-flto
147*35ffd701SAndroid Build Coastguard Worker    #-Wl,-flto
148*35ffd701SAndroid Build Coastguard Worker    )
149*35ffd701SAndroid Build Coastguard Worker
150*35ffd701SAndroid Build Coastguard Workerif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
151*35ffd701SAndroid Build Coastguard Worker
152*35ffd701SAndroid Build Coastguard Workerlist(APPEND GMMLIB_COMPILER_FLAGS_RELEASE
153*35ffd701SAndroid Build Coastguard Worker    -finline-limit=100
154*35ffd701SAndroid Build Coastguard Worker    )
155*35ffd701SAndroid Build Coastguard Worker
156*35ffd701SAndroid Build Coastguard Workerendif()
157*35ffd701SAndroid Build Coastguard Worker
158*35ffd701SAndroid Build Coastguard Worker#if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
159*35ffd701SAndroid Build Coastguard Worker    # For LTO support, use special wrappers around ar and ranlib commands:
160*35ffd701SAndroid Build Coastguard Worker    # ... and if using "nm", use gcc-nm
161*35ffd701SAndroid Build Coastguard Worker #   SET(CMAKE_AR "gcc-ar")
162*35ffd701SAndroid Build Coastguard Worker #   SET(CMAKE_RANLIB "gcc-ranlib")
163*35ffd701SAndroid Build Coastguard Worker#endif()
164*35ffd701SAndroid Build Coastguard Worker
165*35ffd701SAndroid Build Coastguard WorkerSET( GMMLIB_COMPILER_FLAGS_RELEASEINTERNAL  ${GMMLIB_COMPILER_FLAGS_RELEASE})
166*35ffd701SAndroid Build Coastguard Worker
167*35ffd701SAndroid Build Coastguard Worker#set predefined compiler flags set
168*35ffd701SAndroid Build Coastguard Workeradd_compile_options("${GMMLIB_COMPILER_FLAGS_COMMON}")
169*35ffd701SAndroid Build Coastguard Workeradd_compile_options("$<$<CONFIG:Debug>:${GMMLIB_COMPILER_FLAGS_DEBUG}>")
170*35ffd701SAndroid Build Coastguard Workeradd_compile_options("$<$<CONFIG:Release>:${GMMLIB_COMPILER_FLAGS_RELEASE}>")
171*35ffd701SAndroid Build Coastguard Workeradd_compile_options("$<$<CONFIG:ReleaseInternal>:${GMMLIB_COMPILER_FLAGS_RELEASEINTERNAL}>")
172*35ffd701SAndroid Build Coastguard Worker#cmake 3.3+, add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:${GMMLIB_COMPILER_CXX_FLAGS_COMMON}>")
173*35ffd701SAndroid Build Coastguard Workerforeach (flag ${GMMLIB_COMPILER_CXX_FLAGS_COMMON})
174*35ffd701SAndroid Build Coastguard Worker    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
175*35ffd701SAndroid Build Coastguard Workerendforeach()
176*35ffd701SAndroid Build Coastguard Worker
177*35ffd701SAndroid Build Coastguard Workerif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^aarch")
178*35ffd701SAndroid Build Coastguard Worker    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
179*35ffd701SAndroid Build Coastguard Worker    SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
180*35ffd701SAndroid Build Coastguard Workerelse()
181*35ffd701SAndroid Build Coastguard Worker    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m${GMMLIB_ARCH}")
182*35ffd701SAndroid Build Coastguard Worker    SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m${GMMLIB_ARCH}")
183*35ffd701SAndroid Build Coastguard Workerendif()
184