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
21project( media )
22
23find_package(PkgConfig)
24find_package(X11)
25
26bs_set_if_undefined(LIB_NAME iHD_drv_video)
27
28option (MEDIA_RUN_TEST_SUITE "run google test module after install" ON)
29include(${MEDIA_DRIVER_CMAKE}/media_gen_flags.cmake)
30include(${MEDIA_DRIVER_CMAKE}/media_feature_flags.cmake)
31
32
33if(NOT DEFINED SKIP_GMM_CHECK)
34    # checking dependencies
35    pkg_check_modules(LIBGMM igdgmm)
36
37    if(LIBGMM_FOUND)
38        include_directories(BEFORE ${LIBGMM_INCLUDE_DIRS})
39        # link_directories() should appear before add_library and the like
40        # otherwise it will not take effect
41        link_directories(${LIBGMM_LIBRARY_DIRS})
42    endif()
43endif(NOT DEFINED SKIP_GMM_CHECK)
44
45message("-- media -- PLATFORM = ${PLATFORM}")
46message("-- media -- ARCH = ${ARCH}")
47message("-- media -- CMAKE_CURRENT_LIST_DIR = ${CMAKE_CURRENT_LIST_DIR}")
48message("-- media -- INCLUDED_LIBS = ${INCLUDED_LIBS}")
49message("-- media -- LIB_NAME = ${LIB_NAME}")
50message("-- media -- OUTPUT_NAME = ${OUTPUT_NAME}")
51message("-- media -- BUILD_TYPE/UFO_BUILD_TYPE/CMAKE_BUILD_TYPE = ${BUILD_TYPE}/${UFO_BUILD_TYPE}/${CMAKE_BUILD_TYPE}")
52message("-- media -- LIBVA_INSTALL_PATH = ${LIBVA_INSTALL_PATH}")
53message("-- media -- MEDIA_VERSION = ${MEDIA_VERSION}")
54if(X11_FOUND)
55message("-- media -- X11 Found")
56endif()
57
58set(LIB_NAME_OBJ    "${LIB_NAME}_OBJ")
59set(LIB_NAME_STATIC "${LIB_NAME}_STATIC")
60set(SOURCES_ "")
61
62# add source
63media_include_subdirectory(agnostic)
64media_include_subdirectory(linux)
65media_include_subdirectory(${MEDIA_EXT}/media_driver_next)
66include(${MEDIA_EXT}/media_srcs_ext.cmake OPTIONAL)
67
68include(${MEDIA_DRIVER_CMAKE}/media_include_paths.cmake)
69
70include(${MEDIA_DRIVER_CMAKE}/media_compile_flags.cmake)
71
72#
73# set platform specific defines
74#
75bs_set_defines()
76
77set_source_files_properties(${SOURCES_} PROPERTIES LANGUAGE "CXX")
78
79add_library(${LIB_NAME_OBJ} OBJECT ${SOURCES_})
80set_property(TARGET ${LIB_NAME_OBJ} PROPERTY POSITION_INDEPENDENT_CODE 1)
81
82add_library(${LIB_NAME}        SHARED $<TARGET_OBJECTS:${LIB_NAME_OBJ}>)
83add_library(${LIB_NAME_STATIC} STATIC $<TARGET_OBJECTS:${LIB_NAME_OBJ}>)
84set_target_properties(${LIB_NAME_STATIC} PROPERTIES OUTPUT_NAME ${LIB_NAME})
85
86option(MEDIA_BUILD_FATAL_WARNINGS "Turn compiler warnings into fatal errors" ON)
87if(MEDIA_BUILD_FATAL_WARNINGS)
88    set_target_properties(${LIB_NAME_OBJ} PROPERTIES COMPILE_FLAGS "-Werror")
89endif()
90
91set_target_properties(${LIB_NAME} PROPERTIES LINK_FLAGS "-Wl,--no-as-needed -Wl,--gc-sections -z relro -z now -fstack-protector -fPIC")
92set_target_properties(${LIB_NAME}        PROPERTIES PREFIX "")
93set_target_properties(${LIB_NAME_STATIC} PROPERTIES PREFIX "")
94
95MediaAddCommonTargetDefines(${LIB_NAME_OBJ})
96
97pkg_check_modules (PKG_PCIACCESS REQUIRED pciaccess)
98include_directories (BEFORE ${PKG_PCIACCESS_INCLUDE_DIRS})
99link_directories (${PKG_PCIACCESS_LIBRARY_DIRS})
100
101bs_ufo_link_libraries_noBsymbolic(
102    ${LIB_NAME}
103    "${INCLUDED_LIBS}"
104    "${PKG_PCIACCESS_LIBRARIES} m pthread dl rt"
105)
106
107if (NOT DEFINED INCLUDED_LIBS OR "${INCLUDED_LIBS}" STREQUAL "")
108    # dep libs (gmmlib for now) can be passed through INCLUDED_LIBS, but if not, we need try to setup dep through including dep projects
109    if(NOT LIBGMM_FOUND)
110        # If we failed to setup dependency from gmmlib via pkg-config we will try to
111        # add gmmlib as a target from sources. We need to do this here, after
112        # add_library() for iHD driver since gmmlib needs this information.
113        if (NOT TARGET igfx_gmmumd_dll)
114            add_subdirectory("${BS_DIR_GMMLIB}" "${CMAKE_BINARY_DIR}/gmmlib")
115        endif()
116        if (NOT TARGET igfx_gmmumd_dll)
117            message(FATAL_ERROR "gmm library not found on the system")
118        endif()
119        set(LIBGMM_CFLAGS_OTHER -DGMM_LIB_DLL)
120        set(LIBGMM_LIBRARIES igfx_gmmumd_dll)
121    endif()
122
123    target_compile_options( ${LIB_NAME} PUBLIC ${LIBGMM_CFLAGS_OTHER})
124    target_link_libraries ( ${LIB_NAME} ${LIBGMM_LIBRARIES})
125
126    include(${MEDIA_EXT_CMAKE}/ext/media_feature_include_ext.cmake OPTIONAL)
127
128endif(NOT DEFINED INCLUDED_LIBS OR "${INCLUDED_LIBS}" STREQUAL "")
129
130# post target attributes
131bs_set_post_target()
132
133if(MEDIA_RUN_TEST_SUITE AND ENABLE_KERNELS AND ENABLE_NONFREE_KERNELS)
134    add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/linux/ult)
135    include(${MEDIA_EXT}/media_driver_next/ult/ult_top_cmake.cmake OPTIONAL)
136endif()
137