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