Debian Codegraph @

Tools/bldsys/include/utils.cmake

raw
1 # *****************************************************************************
2 # Copyright (c) 2017 Intel Corporation
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
10 #
11 # The above copyright notice and this permission notice shall be included in all
12 # copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
21 # *****************************************************************************
22
23 # utility functions for cmake
24
25 if(NOT DEFINED _bs_include_utils)
26 set(_bs_include_utils TRUE)
27
28 include(${BUILD_SYS_INC}/bs_base_utils.cmake)
29
30
31 # macro to setup output name to OUTPUT_NAME
32 # and turn on position independent code. This
33 # was pulled in to cover the separate hooks
34 # that each component was using to a standard macro
35 # for Linux builds only. Can be extended to
36 # cover other OS targets without the need to update
37 # individual component lists.
38 macro(bs_set_post_target)
39 if (${PLATFORM} STREQUAL linux)
40 set_property(TARGET ${LIB_NAME} PROPERTY OUTPUT_NAME ${OUTPUT_NAME})
41 set_property(TARGET ${LIB_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
42 endif(${PLATFORM} STREQUAL linux)
43 endmacro()
44
45 # macro to setup standard defines This
46 # was pulled in to cover the separate v2c hooks
47 # that each component was using to a standard macro
48 # Can be extended to cover more OS targets without the need to update
49 # individual component lists.
50 macro(bs_set_defines)
51 if (${PLATFORM} STREQUAL "ghs")
52 # LANGUAGE "CXX" alone is not enough for GHS compiler
53 # as both CC and CXX execs point to the same binary
54 add_definitions(-dotciscxx)
55 endif (${PLATFORM} STREQUAL "ghs")
56
57 if(NOT ${PLATFORM} STREQUAL "qnx")
58 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
59 endif()
60
61 if (${PLATFORM} STREQUAL linux)
62 add_definitions(-D__STDC_LIMIT_MACROS)
63 add_definitions(-D__STDC_CONSTANT_MACROS)
64 endif (${PLATFORM} STREQUAL linux)
65 endmacro()
66
67 # macro to properly setup the target_link_libraries
68 # for both INTERNAL_LIBS and EXTERNAL_LIBS.
69 macro(bs_ufo_link_libraries TARGET_NAME INTERNAL_LIBS EXTERNAL_LIBS)
70
71 string(REPLACE " " ";" INTERNAL_LIBS_LIST "${INTERNAL_LIBS}")
72 string(REPLACE " " ";" EXTERNAL_LIBS_LIST "${EXTERNAL_LIBS}")
73
74 set(CMAKE_EXE_LINKER_FLAGS_RELEASE )
75
76 target_link_libraries(
77 ${TARGET_NAME}
78 -Wl,-Bsymbolic
79 -Wl,--no-undefined
80 )
81
82 foreach(lib ${INTERNAL_LIBS_LIST})
83 # work around an undef (DeleteGHAL3DRegInfo) when linking with external projects
84 if(NOT lib MATCHES "glsl_fe_link")
85 target_link_libraries(${TARGET_NAME} -Wl,--whole-archive ${lib})
86 endif()
87 endforeach()
88
89 target_link_libraries(
90 ${TARGET_NAME}
91 -Wl,--no-whole-archive
92 )
93
94 foreach(lib ${EXTERNAL_LIBS_LIST})
95 target_link_libraries(${TARGET_NAME} ${lib})
96 endforeach()
97
98 endmacro()
99 macro(bs_ufo_link_libraries_noBsymbolic TARGET_NAME INTERNAL_LIBS EXTERNAL_LIBS)
100
101 string(REPLACE " " ";" INTERNAL_LIBS_LIST "${INTERNAL_LIBS}")
102 string(REPLACE " " ";" EXTERNAL_LIBS_LIST "${EXTERNAL_LIBS}")
103
104 set(CMAKE_EXE_LINKER_FLAGS_RELEASE )
105
106 target_link_libraries(
107 ${TARGET_NAME}
108 -Wl,--no-undefined
109 )
110
111 foreach(lib ${INTERNAL_LIBS_LIST})
112 # work around an undef (DeleteGHAL3DRegInfo) when linking with external projects
113 if(NOT lib MATCHES "glsl_fe_link")
114 target_link_libraries(${TARGET_NAME} -Wl,--whole-archive ${lib})
115 endif()
116 endforeach()
117
118 target_link_libraries(
119 ${TARGET_NAME}
120 -Wl,--no-whole-archive
121 )
122
123 foreach(lib ${EXTERNAL_LIBS_LIST})
124 target_link_libraries(${TARGET_NAME} ${lib})
125 endforeach()
126
127 endmacro()
128 # macro to setup forced exceptions for Linux
129 # builds only. Should be extended for other
130 # targets that require forced exceptions.
131 macro(bs_set_force_exceptions)
132 if (${PLATFORM} STREQUAL "linux")
133 string(REPLACE "no-exceptions" "exceptions" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
134 string(REPLACE "no-exceptions" "exceptions" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
135 string(REPLACE "no-exceptions" "exceptions" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
136 string(REPLACE "no-exceptions" "exceptions" CMAKE_C_FLAGS_RELEASEINTERNAL "${CMAKE_C_FLAGS_RELEASEINTERNAL}")
137
138 string(REPLACE "no-exceptions" "exceptions" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
139 string(REPLACE "no-exceptions" "exceptions" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
140 string(REPLACE "no-exceptions" "exceptions" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
141 string(REPLACE "no-exceptions" "exceptions" CMAKE_CXX_FLAGS_RELEASEINTERNAL "${CMAKE_CXX_FLAGS_RELEASEINTERNAL}")
142
143 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
144 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
145 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
146 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_C_FLAGS_RELEASEINERNAL "${CMAKE_C_FLAGS_RELEASEINERNAL}")
147
148 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
149 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
150 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
151 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_CXX_FLAGS_RELEASEINTERNAL "${CMAKE_CXX_FLAGS_RELEASEINTERNAL}")
152 endif()
153 endmacro()
154
155 # function to force an error if a variable if it is not
156 # defined
157 function(bs_fatal_if_undefined)
158 string(REPLACE " " ";" _var_names "${ARGV}")
159 set(_undef_seen FALSE)
160 foreach(_varnam ${_var_names})
161 if(NOT DEFINED ${_varnam})
162 message(SEND_ERROR "Required variable not defined: ${_varnam}")
163 set(_undef_seen TRUE)
164 endif()
165 endforeach()
166 if(_undef_seen)
167 message(FATAL_ERROR "Stopping due to undefined variables")
168 endif(_undef_seen)
169 endfunction(bs_fatal_if_undefined)
170
171 # macro to return the llvm directory path
172 # for host and target builds.
173 macro(bs_get_llvm_dir)
174 set(LLVM_DIR ${DUMP_DIR}/igc/llvm/${LLVM_INT_DIR})
175 set(CODEGEN_DIR ${DUMP_DIR}/codegen)
176 endmacro()
177
178 # macro to add common includes used by multiple components.
179 macro(bs_add_some_common_includes)
180 bs_fatal_if_undefined(PLATFORM)
181 if (${PLATFORM} STREQUAL linux)
182 bs_get_llvm_dir()
183 bs_fatal_if_undefined(CODEGEN_DIR LLVM_DIR GFX_DEVELOPMENT_DIR)
184 include_directories(${CODEGEN_DIR})
185 include_directories(${LLVM_DIR}/include)
186 include_directories(${GFX_DEVELOPMENT_DIR}/Source/OpenGL/source/os/linux/oskl)
187
188 if(NOT "${LIBDRM_SRC}" STREQUAL "")
189 message("using LIBDRM_SRC=${LIBDRM_SRC}")
190 include_directories(${LIBDRM_SRC})
191 include_directories(${LIBDRM_SRC}/include/drm)
192 include_directories(${LIBDRM_SRC}/intel)
193 else()
194 include_directories(${BS_DIR_OPENGL}/source/os/linux/oskl/drm_intel)
195 include_directories(${BS_DIR_INSTRUMENTATION}/driver/linux/drm_intel)
196 endif()
197 set(DRM_LIB_PATH drm)
198 set(DRM_INTEL_LIB_PATH drm_intel)
199 endif()
200 endmacro()
201
202 # macro to allow setting a list of extra compile
203 # definitions.
204 macro(bs_set_extra_target_properties targ propValues)
205 string(REPLACE " " ";" PROP_VALUES "${ARGV}")
206 if(TARGET "${targ}")
207 foreach(prop ${PROP_VALUES})
208 if (${prop} STREQUAL ${targ})
209 continue()
210 endif()
211 set_property(TARGET "${targ}" APPEND PROPERTY COMPILE_DEFINITIONS
212 ${prop}
213 )
214 endforeach()
215 endif(TARGET "${targ}")
216 endmacro()
217
218 endif(NOT DEFINED _bs_include_utils)