xref: /aosp_15_r20/external/intel-media-driver/cmrtlib/linux/cmrt_utils.cmake (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
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# Idempotent include implementation
22set_property( GLOBAL PROPERTY USE_FOLDERS ON)
23set(BUILD_FUNCTIONS_INC ON)
24
25# Functions to add custom build configurations: release, release internal, debug
26# Assumption is that there is only one of these per target (otherwise the custom target breaks)
27function(custom_build_add configName copyConfigName)
28  string(TOUPPER "${configName}" _configName)
29  string(TOUPPER "${copyConfigName}" _copyConfigName)
30
31  set("CMAKE_CXX_FLAGS_${_configName}"           "${CMAKE_CXX_FLAGS_${_copyConfigName}}"           CACHE STRING "C++ compilder flags used during \"${configName}\" builds.")
32  set("CMAKE_C_FLAGS_${_configName}"             "${CMAKE_C_FLAGS_${_copyConfigName}}"             CACHE STRING "Flags used during \"${configName}\" builds.")
33  set("CMAKE_EXE_LINKER_FLAGS_${_configName}"    "${CMAKE_EXE_LINKER_FLAGS_${_copyConfigName}}"    CACHE STRING "Linker flags used during \"${configName}\" builds for executables.")
34  set("CMAKE_MODULE_LINKER_FLAGS_${_configName}" "${CMAKE_MODULE_LINKER_FLAGS_${_copyConfigName}}" CACHE STRING "Linker flags used during \"${configName}\" builds for modules.")
35  set("CMAKE_SHARED_LINKER_FLAGS_${_configName}" "${CMAKE_SHARED_LINKER_FLAGS_${_copyConfigName}}" CACHE STRING "Linker flags used during \"${configName}\" builds for shared libraries.")
36  set("CMAKE_STATIC_LINKER_FLAGS_${_configName}" "${CMAKE_STATIC_LINKER_FLAGS_${_copyConfigName}}" CACHE STRING "Linker flags used during \"${configName}\" builds for static libraries.")
37  mark_as_advanced(
38      "CMAKE_CXX_FLAGS_${_configName}"
39      "CMAKE_C_FLAGS_${_configName}"
40      "CMAKE_EXE_LINKER_FLAGS_${_configName}"
41      "CMAKE_MODULE_LINKER_FLAGS_${_configName}"
42      "CMAKE_SHARED_LINKER_FLAGS_${_configName}"
43      "CMAKE_STATIC_LINKER_FLAGS_${_configName}"
44    )
45
46endfunction()
47
48function( setup_configurations )
49    set(CMAKE_CONFIGURATION_TYPES
50        "Debug"
51        "ReleaseInternal"
52        "Release"
53      )
54    custom_build_add("ReleaseInternal"       "Release")
55    set(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES} CACHE STRING "Available build configurations." FORCE)
56endfunction( setup_configurations )
57
58# If you update this function - make sure you also update the copy of this for the IGC build that is
59# hard-coded into the CM_jitter CMakeLists.txt
60function ( setup_library target src_list shared actual_name)
61  if ( ${shared} )
62    add_library(${target} SHARED ${src_list})
63  else ( ${shared} )
64    add_library(${target} ${src_list})
65  endif ( ${shared} )
66endfunction( setup_library )
67
68# get the major and minor versions from the cm_rt header file
69macro ( get_cmrt_versions cmrt_major_version cmrt_minor_version cmrt_patch_version)
70  file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/../agnostic/share/cm_rt.h version_line REGEX "#define __INTEL_CM" LIMIT_COUNT 1)
71  string(REGEX MATCH "CM_([0-9]+)_([0-9]+)" version_line ${version_line})
72  string(REPLACE "CM_" "" version_line ${version_line})
73  string(REPLACE "_" ";" version_list ${version_line})
74  list(GET version_list 0 major)
75  list(GET version_list 1 minor)
76
77  set(${cmrt_major_version} ${major})
78  set(${cmrt_minor_version} ${minor})
79  set(${cmrt_patch_version} 0)
80endmacro()
81
82# Only can include subdirectory which has a cmrt_srcs.cmake
83# the effect is like include(${CMAKE_CURRENT_LIST_DIR}/<subd>/cmrt_srcs.cmake)
84macro(cmrt_include_subdirectory subd)
85    if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${subd}/cmrt_srcs.cmake)
86        include(${CMAKE_CURRENT_LIST_DIR}/${subd}/cmrt_srcs.cmake)
87    else()
88        message("-- ${CMAKE_CURRENT_LIST_DIR}/${subd}/cmrt_srcs.cmake doesn't exist, macro(cmrt_include_subdirectory) just does nothing")
89    endif()
90endmacro()
91
92# Only can include subdirectory which has a cmrt_srcs.cmake
93# the effect is like include(${CMAKE_CURRENT_LIST_DIR}/<subd>/cmrt_srcs.cmake)
94macro(cmrt_include_directory dir)
95    if(EXISTS ${dir}/cmrt_srcs.cmake)
96        include(${dir}/cmrt_srcs.cmake)
97    else()
98        message("-- ${dir}/cmrt_srcs.cmake doesn't exist, macro(cmrt_include_subdirectory) just does nothing")
99    endif()
100endmacro()
101