From 0b1e72fada9f624de09ea519efadc8b34f563982 Mon Sep 17 00:00:00 2001 From: "shiqiang.yu" Date: Wed, 10 Oct 2018 01:43:23 -0400 Subject: [PATCH] [CP] Fix compilation issues for ClearLinux integration(CL#806263) Fix compilation issues for ClearLinux integration 1. Auto detect libdrm 2. Auto detect systemd 3. Standard installation path 4. Explictly compile common module as static library 5. Add pkg-config file 6. Add shared library version Change-Id: Id9bb8d597cb260304f1aad7f8560ae729846cf7a --- CMakeLists.txt | 72 +++++++++++++++++----- README.md | 29 +++++---- common/CMakeLists.txt | 1 + config/{hdcpd.service => hdcpd.service.in} | 3 +- config/libhdcpsdk.pc.in | 10 +++ config/postinst | 4 +- config/systemdservice.cmake | 47 ++++++++++++++ daemon/CMakeLists.txt | 7 +-- sdk/CMakeLists.txt | 2 + 9 files changed, 139 insertions(+), 36 deletions(-) rename config/{hdcpd.service => hdcpd.service.in} (70%) create mode 100644 config/libhdcpsdk.pc.in create mode 100644 config/systemdservice.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 63491b9..6b01b5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,15 @@ cmake_minimum_required(VERSION 2.8.12) +add_definitions(-DLINUX) + +# Forbid in-tree building +if(${CMAKE_SOURCE_DIR} MATCHES ${CMAKE_BINARY_DIR}) + message(STATUS "Please do out-of-tree build") + message(FATAL_ERROR "In-tree-build detected!") +endif() + +# Set compile flags set(HDCP_COMMON_COMPILE_FLAGS -O2 -D_FORTIFY_SOURCE=2 @@ -36,9 +45,8 @@ set(HDCP_C_FLAGS ${HDCP_COMMON_COMPILE_FLAGS}) set(HDCP_CXX_FLAGS ${HDCP_COMMON_COMPILE_FLAGS} -std=c++11) set(HDCP_LD_FLAGS "-z noexecstack -z relro -z now -pie") -add_definitions(-DLINUX) - -if (DEFINED CMAKE_BUILD_TYPE AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") +# Set build type +if(DEFINED CMAKE_BUILD_TYPE AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") message(STATUS "cmake build type is DEBUG") set(HDCP_CXX_FLAGS ${HDCP_CXX_FLAGS} -g) @@ -47,20 +55,28 @@ if (DEFINED CMAKE_BUILD_TYPE AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") add_definitions(-DHDCP_USE_VERBOSE_LOGGING) add_definitions(-DHDCP_USE_FUNCTION_LOGGING) add_definitions(-DHDCP_USE_LINK_FUNCTION_LOGGING) -endif () +endif() -if (DEFINED CMAKE_BUILD_TYPE AND "${CMAKE_BUILD_TYPE}" STREQUAL "ReleaseInternal") +if(DEFINED CMAKE_BUILD_TYPE AND "${CMAKE_BUILD_TYPE}" STREQUAL "ReleaseInternal") message(STATUS "cmake build type is \"${CMAKE_BUILD_TYPE}\"") add_definitions(-DLOG_CONSOLE) add_definitions(-DHDCP_USE_VERBOSE_LOGGING) add_definitions(-DHDCP_USE_FUNCTION_LOGGING) -endif () +endif() -if (DEFINED CMAKE_BUILD_TYPE AND "${CMAKE_BUILD_TYPE}" STREQUAL "Release") +if(DEFINED CMAKE_BUILD_TYPE AND "${CMAKE_BUILD_TYPE}" STREQUAL "Release") message(STATUS "cmake build type is \"${CMAKE_BUILD_TYPE}\"") -endif () +endif() + +# Set version +set(HDCP_VERSION_MAJOR 0) +set(HDCP_VERSION_MINOR 1) +set(HDCP_VERSION_PATCH 1) +set(HDCP_VERSION + ${HDCP_VERSION_MAJOR}.${HDCP_VERSION_MINOR}.${HDCP_VERSION_PATCH}) +# Include sub project sdk daemon set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) @@ -69,17 +85,43 @@ add_subdirectory(common ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/common) add_subdirectory(sdk ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/sdk) add_subdirectory(daemon ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/daemon) -set(CMAKE_INSTALL_BINDIR /usr/bin) -set(CMAKE_INSTALL_LIBDIR /usr/lib/x86_64-linux-gnu) -set(CMAKE_SYSTEMD_INSTALL_DIR /etc/systemd/system) -install (PROGRAMS ${CMAKE_BINARY_DIR}/hdcpd DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT cp) -install (FILES ${CMAKE_BINARY_DIR}/libhdcpsdk.so DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT cp) -install (FILES ${CMAKE_SOURCE_DIR}/config/hdcpd.service DESTINATION ${CMAKE_SYSTEMD_INSTALL_DIR} COMPONENT cp) +configure_file(${CMAKE_SOURCE_DIR}/config/libhdcpsdk.pc.in + ${CMAKE_BINARY_DIR}/libhdcpsdk.pc + @ONLY) + +# Set install path +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "/usr/local") +endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + +set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include) +set(CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_PREFIX}/bin) +set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib) + +install(PROGRAMS ${CMAKE_BINARY_DIR}/hdcpd + DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT cp) +install(FILES ${CMAKE_SOURCE_DIR}/sdk/hdcpapi.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT cp) +install(FILES ${CMAKE_BINARY_DIR}/libhdcpsdk.so + DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT cp) +install(FILES ${CMAKE_BINARY_DIR}/libhdcpsdk.so.${HDCP_VERSION_MAJOR} + DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT cp) +install(FILES ${CMAKE_BINARY_DIR}/libhdcpsdk.so.${HDCP_VERSION} + DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT cp) +install(FILES ${CMAKE_BINARY_DIR}/libhdcpsdk.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT cp) + +include(${CMAKE_SOURCE_DIR}/config/systemdservice.cmake) + +message(STATUS "hdcpd install dir : ${CMAKE_INSTALL_BINDIR}") +message(STATUS "libhdcpsdk.so install dir : ${CMAKE_INSTALL_LIBDIR}") +# Set package information set(CPACK_GENERATOR "DEB") set(CPACK_PACKAGE_NAME "intel-uapi-hdcp") +set(CPACK_PACKAGE_VERSION ${HDCP_VERSION}) set(CPACK_PACKAGE_VENDOR "Intel") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "intel-uapi-hdcp deb package for internal usage only") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "intel unified hdcp deb package") SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_SOURCE_DIR}/config/postinst) set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel") diff --git a/README.md b/README.md index 6bdc25d..7fc365c 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,13 @@ The Intel(R) unified HDCP is dependent on kernel space HDCP implementation to pr 1. Obtain Linux kernel from https://github.com/freedesktop/drm-tip 2. Follow below steps to build and upgrade kernel: ``` -$ make ARCH=x86_64 defconfig   +$ make ARCH=x86_64 defconfig $ make ARCH=x86_64 menuconfig - # include device driver->Network device driver->USB Network Adapters->the corresponding adapter if you use usb adapter for network hub.   - # include drivers->misc drivers->Intel Management Engine Interface & ME Enabled Intel Chipsets & Intel Trusted Execution Enviroment with ME Interface to enable MEI_HDCP for HDCP 2.2  -$ make -j  -$ make modules   -$ sudo make modules_install   + # include device driver->Network device driver->USB Network Adapters->the corresponding adapter if you use usb adapter for network hub. + # include drivers->misc drivers->Intel Management Engine Interface & ME Enabled Intel Chipsets & Intel Trusted Execution Enviroment with ME Interface to enable MEI_HDCP for HDCP 2.2 +$ make -j +$ make modules +$ sudo make modules_install $ sudo make install ``` @@ -49,12 +49,13 @@ $ sudo make install |- sdk |- common |- CMakeLists.txt + ... ``` -3. +3. Create build folder, and generate targets in the directory ``` $ cd -$ cmake CMakeLists.txt \ - -DLIBDRM_INCLUDE_DIRS=/usr/local/include/libdrm +$ mkdir build; cd build +$ cmake ../ ``` 4. Then run ``` @@ -68,8 +69,12 @@ $ sudo make install ``` This will install the following files (e.g. on Ubuntu): ``` --- Installing: /usr/lib/x86_64-linux-gnu/libhdcpsdk.so --- Installing: /usr/bin/hdcpd +-- Installing: /usr/local/bin/hdcpd +-- Installing: /usr/local/include/hdcpapi.h +-- Installing: /usr/local/lib/libhdcpsdk.so +-- Installing: /usr/local/lib/pkgconfig/libhdcpsdk.pc +-- Installing: /lib/systemd/system/hdcpd.service +-- ... ``` @@ -123,4 +128,4 @@ You may follow below basic steps for HDCP enabling: 7. App finishes playing protected content. -8. App is finished and calls HDCPDestroy. HDCP SDK cleans up and destroys its session with the daemon. The daemon will remove the App from a list of active applications using the port. \ No newline at end of file +8. App is finished and calls HDCPDestroy. HDCP SDK cleans up and destroys its session with the daemon. The daemon will remove the App from a list of active applications using the port. diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 183dba0..33516ce 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -29,6 +29,7 @@ get_filename_component(HDCP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." REALPATH) include_directories(${HDCP_DIR}/sdk) add_library(${PROJECT_NAME} + STATIC clientsock.cpp gensock.cpp servsock.cpp diff --git a/config/hdcpd.service b/config/hdcpd.service.in similarity index 70% rename from config/hdcpd.service rename to config/hdcpd.service.in index 1c0ee05..cc8632b 100644 --- a/config/hdcpd.service +++ b/config/hdcpd.service.in @@ -3,8 +3,7 @@ Description=hdcp daemon [Service] Type=simple -ExecStart=/usr/bin/hdcpd -User=root +ExecStart=@CMAKE_INSTALL_BINDIR@/hdcpd [Install] WantedBy=multi-user.target diff --git a/config/libhdcpsdk.pc.in b/config/libhdcpsdk.pc.in new file mode 100644 index 0000000..ac259c9 --- /dev/null +++ b/config/libhdcpsdk.pc.in @@ -0,0 +1,10 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: @CMAKE_PROJECT_NAME@ +Description: Intel Unified HDCP SDK +Version: @HDCP_VERSION@ +Libs: -L${libdir} -lhdcpsdk +Cflags: -I${includedir} diff --git a/config/postinst b/config/postinst index 3d46827..714fa1e 100644 --- a/config/postinst +++ b/config/postinst @@ -1,4 +1,6 @@ #!/bin/bash +systemctl disable hdcpd.service systemctl enable hdcpd.service -systemctl start hdcpd.service \ No newline at end of file +systemctl stop hdcpd.service +systemctl start hdcpd.service diff --git a/config/systemdservice.cmake b/config/systemdservice.cmake new file mode 100644 index 0000000..9178025 --- /dev/null +++ b/config/systemdservice.cmake @@ -0,0 +1,47 @@ +# Copyright (c) 2018, Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +include(FindPkgConfig) + +pkg_check_modules(SYSTEMD "systemd") + +if (SYSTEMD_FOUND AND "${SYSTEMD_SERVICES_INSTALL_DIR}" STREQUAL "") + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} + --variable=systemdsystemunitdir systemd + OUTPUT_VARIABLE SYSTEMD_SERVICES_INSTALL_DIR) + string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_SERVICES_INSTALL_DIR + "${SYSTEMD_SERVICES_INSTALL_DIR}") + configure_file(${CMAKE_SOURCE_DIR}/config/hdcpd.service.in + ${CMAKE_BINARY_DIR}/hdcpd.service + @ONLY) + install(FILES ${CMAKE_BINARY_DIR}/hdcpd.service DESTINATION + ${SYSTEMD_SERVICES_INSTALL_DIR} COMPONENT cp) + +elseif (NOT SYSTEMD_FOUND AND SYSTEMD_SERVICES_INSTALL_DIR) + message (FATAL_ERROR "Variable SYSTEMD_SERVICES_INSTALL_DIR is\ + defined, but we can't find systemd using pkg-config") +endif() + +if (SYSTEMD_FOUND) + set(WITH_SYSTEMD "ON") + message(STATUS "systemd services install dir: ${SYSTEMD_SERVICES_INSTALL_DIR}") +else() + set(WITH_SYSTEMD "OFF") +endif (SYSTEMD_FOUND) diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 51a4ee8..2b3b66b 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -22,19 +22,14 @@ cmake_minimum_required(VERSION 2.8.12) project(hdcpd CXX) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/") - find_package(Threads REQUIRED) find_package(OpenSSL REQUIRED) -if ("${LIBDRM_INCLUDE_DIRS}" STREQUAL "") - Message(FATAL_ERROR "libdrm include directory is not specified") -endif () +pkg_check_modules(LIBDRM REQUIRED libdrm) get_filename_component(HDCP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." REALPATH) include_directories(${OPENSSL_INCLUDE_DIRS}) include_directories(${LIBDRM_INCLUDE_DIRS}) -include_directories(${LIBDRM_MODE_INCLUDE_DIRS}) include_directories(${HDCP_DIR}/common) include_directories(${HDCP_DIR}/sdk) include_directories(${HDCP_DIR}/daemon) diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index b9cb489..e03a690 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -36,6 +36,8 @@ add_library(${PROJECT_NAME} target_compile_options(${PROJECT_NAME} PRIVATE ${HDCP_CXX_FLAGS}) set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS ${HDCP_LD_FLAGS}) +set_target_properties(${PROJECT_NAME} PROPERTIES + VERSION ${HDCP_VERSION} SOVERSION ${HDCP_VERSION_MAJOR}) target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT}