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# utility functions for cmake 22 23if(NOT DEFINED _bs_include_utils) 24set(_bs_include_utils TRUE) 25 26include(${BUILD_SYS_INC}/bs_base_utils.cmake) 27 28 29# macro bs_assignments_from_file - Execute a file of assignments. 30# This must be a macro and not a function so as to not provide an 31# additional level of symbol scope. 32# 33# For an example, see file include/bs_enable.mk . 34# 35# Example file content: 36# # A comment looks like this. Assignments follow: 37# BS_ENABLE_gmmlib = 0 38# BS_ENABLE_igc = 0 39macro(bs_assignments_from_file file_path) 40 file(STRINGS "${file_path}" bsa_list) 41 bs_assignments_from_string("${bsa_list}") 42endmacro(bs_assignments_from_file) 43 44 45# Function to capitalize SourceString and return 46# the result on ResultString 47function(_bs_capitalize SourceString ResultString) 48 string(SUBSTRING ${SourceString} 0 1 FIRST_LETTER) 49 string(TOUPPER ${FIRST_LETTER} FIRST_LETTER) 50 string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" CapString "${SourceString}") 51 set(${ResultString} ${CapString} PARENT_SCOPE) 52endfunction(_bs_capitalize) 53 54# Function to return the canonical string for gen 55# Ex: gen7.5 becomes gen75 56function(bs_canonicalize_string_gen SourceGen AllGens) 57 if ( ${SourceGen} MATCHES "[0-9].[0-9]") 58 STRING(REPLACE "." "" tempstr ${SourceGen}) 59 else() 60 set(tempstr "${SourceGen}0") 61 endif() 62 set(${AllGens} ${tempstr} PARENT_SCOPE) 63endfunction(bs_canonicalize_string_gen) 64 65# bs_list_to_string - Convert a cmake list to a string. 66macro(bs_list_to_string varnam) 67 string(REPLACE ";" " " ${varnam} "${${varnam}}") 68endmacro(bs_list_to_string) 69 70# bs_string_to_list - Convert a string to a cmake list. 71macro(bs_string_to_list varnam) 72 string(REPLACE " " ";" ${varnam} "${${varnam}}") 73endmacro(bs_string_to_list) 74 75# Macro to find the xsltproc installed on 76# the system. 77macro(bs_find_xsltproc) 78 if (NOT ${PLATFORM} STREQUAL Windows) 79 find_program(XSLTPROC xsltproc) 80 else() 81 find_program(XSLTPROC NAMES xslt msxsl msxsl.exe PATHS "${BS_DIR_INSTRUMENTATION}/tools") 82 endif() 83endmacro(bs_find_xsltproc) 84 85# Macro to find the python installed on 86# the system. 87macro(bs_find_python) 88 if (NOT ${PLATFORM} STREQUAL Windows) 89 find_program(PYTHON python) 90 else() 91 find_program(PYTHON NAMES python.exe PATHS "${GFX_DEVELOPMENT_DIR}/Tools/Build/scripts/deps/python27" NO_DEFAULT_PATH) 92 endif() 93 message("python is ${PYTHON}") 94endmacro(bs_find_python) 95 96# Macro to find the flex installed on 97# the system. 98macro(bs_find_flex) 99 if (NOT ${PLATFORM} STREQUAL Windows) 100 find_program(FLEX flex) 101 else() 102 find_program(FLEX NAMES flex flex.exe PATHS "${GFX_DEVELOPMENT_DIR}/Tools//OpenGL/BisonFlex/win") 103 endif() 104endmacro(bs_find_flex) 105 106# Macro to find the bison installed on 107# the system. 108macro(bs_find_bison) 109 if (NOT ${PLATFORM} STREQUAL Windows) 110 find_program(BISON bison) 111 else() 112 find_program(BISON NAMES bison bison.exe PATHS "${GFX_DEVELOPMENT_DIR}/Tools//OpenGL/BisonFlex/win") 113 endif() 114endmacro(bs_find_bison) 115 116# Macro to find the patch installed on 117# the system. 118macro(bs_find_patch) 119 find_program(PATCH NAMES patch patch.exe) 120endmacro() 121 122macro(bs_find_7z) 123 if (NOT ${PLATFORM} STREQUAL Windows) 124 find_program(7Z NAMES 7za 7z) 125 else() 126 find_program(7Z NAMES 7z.exe PATHS "${GFX_DEVELOPMENT_DIR}/Tools/Build/scripts/deps/7zip") 127 endif() 128endmacro() 129 130 131function(bs_check_component_enable component_name enable_flag_name) 132 set(_component_enable "${BS_ENABLE_${component_name}}") 133 if("${_component_enable}" STREQUAL "1") 134 set(_enable_flag 1) 135 elseif("${_component_enable}" STREQUAL "W") 136 if("${PLATFORM}" STREQUAL "Windows") 137 set(_enable_flag 1) 138 else() 139 set(_enable_flag 0) 140 endif() 141 elseif("${_component_enable}" STREQUAL "NW") 142 if(NOT "${PLATFORM}" STREQUAL "Windows") 143 set(_enable_flag 1) 144 else() 145 set(_enable_flag 0) 146 endif() 147 elseif("${_component_enable}" STREQUAL "0") 148 set(_enable_flag 0) 149 elseif("${_component_enable}" STREQUAL "t") 150 set(_enable_flag 0) 151 message(WARNING "${CMAKE_CURRENT_LIST_FILE}: warning: Obsolete component enable flag, now same as 0: ${component_name}: \"${_component_enable}\"") 152 else() 153 set(_enable_flag 0) 154 message(SEND_ERROR "${CMAKE_CURRENT_LIST_FILE}: error: Invalid component enable flag: ${component_name}: \"${_component_enable}\"") 155 endif() 156 if("${_enable_flag}") 157 message("${CMAKE_CURRENT_LIST_FILE}: component enabled (${_component_enable}): ${component_name}") 158 else() 159 message("${CMAKE_CURRENT_LIST_FILE}: component disabled: ${component_name}") 160 endif() 161 set(${enable_flag_name} ${_enable_flag} PARENT_SCOPE) 162endfunction(bs_check_component_enable) 163 164 165# macro to setup output name to OUTPUT_NAME 166# and turn on position independent code. This 167# was pulled in to cover the separate v2c hooks 168# that each component was using to a standard macro 169# for Linux builds only. Can be extended to 170# cover other OS targets without the need to update 171# individual component lists. 172macro(bs_set_post_target) 173 if (${PLATFORM} STREQUAL linux) 174 set_property(TARGET ${LIB_NAME} PROPERTY OUTPUT_NAME ${OUTPUT_NAME}) 175 set_property(TARGET ${LIB_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) 176 endif(${PLATFORM} STREQUAL linux) 177endmacro() 178 179# macro to setup standard defines This 180# was pulled in to cover the separate v2c hooks 181# that each component was using to a standard macro 182# Can be extended to cover more OS targets without the need to update 183# individual component lists. 184macro(bs_set_defines) 185 if (${PLATFORM} STREQUAL linux) 186 add_definitions(-D__STDC_LIMIT_MACROS) 187 add_definitions(-D__STDC_CONSTANT_MACROS) 188 endif (${PLATFORM} STREQUAL linux) 189endmacro() 190 191# macro to setup forced exceptions for Linux 192# builds only. Should be extended for other 193# targets that require forced exceptions. 194macro(bs_set_force_exceptions) 195 if (${PLATFORM} STREQUAL "linux") 196 string(REPLACE "no-exceptions" "exceptions" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") 197 string(REPLACE "no-exceptions" "exceptions" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") 198 string(REPLACE "no-exceptions" "exceptions" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") 199 string(REPLACE "no-exceptions" "exceptions" CMAKE_C_FLAGS_RELEASEINTERNAL "${CMAKE_C_FLAGS_RELEASEINTERNAL}") 200 201 string(REPLACE "no-exceptions" "exceptions" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 202 string(REPLACE "no-exceptions" "exceptions" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") 203 string(REPLACE "no-exceptions" "exceptions" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") 204 string(REPLACE "no-exceptions" "exceptions" CMAKE_CXX_FLAGS_RELEASEINTERNAL "${CMAKE_CXX_FLAGS_RELEASEINTERNAL}") 205 206 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") 207 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") 208 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") 209 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_C_FLAGS_RELEASEINERNAL "${CMAKE_C_FLAGS_RELEASEINERNAL}") 210 211 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 212 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") 213 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") 214 string(REPLACE "-DNO_EXCEPTION_HANDLING" "" CMAKE_CXX_FLAGS_RELEASEINTERNAL "${CMAKE_CXX_FLAGS_RELEASEINTERNAL}") 215 endif() 216endmacro() 217 218# function to force an error if a variable if it is not 219# defined 220function(bs_fatal_if_undefined) 221 string(REPLACE " " ";" _var_names "${ARGV}") 222 set(_undef_seen FALSE) 223 foreach(_varnam ${_var_names}) 224 if(NOT DEFINED ${_varnam}) 225 message(SEND_ERROR "Required variable not defined: ${_varnam}") 226 set(_undef_seen TRUE) 227 endif() 228 endforeach() 229 if(_undef_seen) 230 message(FATAL_ERROR "Stopping due to undefined variables") 231 endif(_undef_seen) 232endfunction(bs_fatal_if_undefined) 233 234# macro to return the llvm directory path 235# for host and target builds. 236macro(bs_get_llvm_dir) 237 set(LLVM_DIR ${DUMP_DIR}/igc/llvm/${LLVM_INT_DIR}) 238 set(CODEGEN_DIR ${DUMP_DIR}/codegen) 239endmacro() 240 241# macro to add common includes used by multiple components. 242macro(bs_add_some_common_includes) 243 bs_fatal_if_undefined(PLATFORM) 244 if (${PLATFORM} STREQUAL linux) 245 bs_get_llvm_dir() 246 bs_fatal_if_undefined(CODEGEN_DIR LLVM_DIR GFX_DEVELOPMENT_DIR) 247 include_directories(${CODEGEN_DIR}) 248 include_directories(${LLVM_DIR}/include) 249 include_directories(${GFX_DEVELOPMENT_DIR}/Source/OpenGL/source/os/linux/oskl) 250 251 if(NOT "${LIBDRM_SRC}" STREQUAL "") 252 message("using LIBDRM_SRC=${LIBDRM_SRC}") 253 include_directories(${LIBDRM_SRC}) 254 include_directories(${LIBDRM_SRC}/include/drm) 255 include_directories(${LIBDRM_SRC}/intel) 256 else() 257 include_directories(${BS_DIR_OPENGL}/source/os/linux/oskl/drm_intel) 258 include_directories(${BS_DIR_INSTRUMENTATION}/driver/linux/drm_intel) 259 endif() 260 set(DRM_LIB_PATH drm) 261 set(DRM_INTEL_LIB_PATH drm_intel) 262 endif() 263endmacro() 264 265# macro to allow setting a list of extra compile 266# definitions. 267macro(bs_set_extra_target_properties targ propValues) 268 string(REPLACE " " ";" PROP_VALUES "${ARGV}") 269 if(TARGET "${targ}") 270 foreach(prop ${PROP_VALUES}) 271 if (${prop} STREQUAL ${targ}) 272 continue() 273 endif() 274 set_property(TARGET "${targ}" APPEND PROPERTY COMPILE_DEFINITIONS 275 ${prop} 276 ) 277 endforeach() 278 endif(TARGET "${targ}") 279endmacro() 280 281 282# 283# Macro to help find libraries when they are build as external projects. 284# 285macro(bs_external_add_library names paths target_name shared) 286 find_library(_LIB NAMES ${names} PATHS ${paths}) 287 288 if(_LIB AND NOT TARGET ${target_name}) 289 message("importing external library ${target_name}") 290 if(${shared} MATCHES y) 291 add_library(${target_name} SHARED IMPORTED GLOBAL) 292 else() 293 add_library(${target_name} STATIC IMPORTED GLOBAL) 294 endif() 295 set_target_properties(${target_name} PROPERTIES IMPORTED_LOCATION "${_LIB}") 296 endif() 297endmacro() 298 299 300 301 302 303 304endif(NOT DEFINED _bs_include_utils) 305