From 14b0c5585ad47c0ae3cd2c545022eb28a4c92cbc Mon Sep 17 00:00:00 2001 From: FindHao Date: Mon, 20 Mar 2023 16:30:58 -0400 Subject: [PATCH] update cubin_filter --- cubin_filter/CMakeLists.txt | 17 ++++++++- cubin_filter/FindLibElf.cmake | 66 ++++++++++++++++++++++++++++++++++ cubin_filter/FindMbedTLS.cmake | 40 +++++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 cubin_filter/FindLibElf.cmake create mode 100644 cubin_filter/FindMbedTLS.cmake diff --git a/cubin_filter/CMakeLists.txt b/cubin_filter/CMakeLists.txt index 76ffb1a..90e5635 100644 --- a/cubin_filter/CMakeLists.txt +++ b/cubin_filter/CMakeLists.txt @@ -34,13 +34,23 @@ else () endif () enable_language(CUDA) +include(FindLibElf.cmake) +include(FindMbedTLS.cmake) -set(SANITIZER_PATH ${CUDAToolkit_TARGET_DIR}/compute-sanitizer) +message(INFO "==========") +message(STATUS ${LIBELF_INCLUDE_DIRS}) +message(STATUS ${LIBELF_LIBRARIES_PATH}) +message(STATUS ${MBEDTLS_INCLUDE_DIRS}) +message(STATUS ${MBEDCRYPTO_LIBRARY_PATH}) +set(SANITIZER_PATH ${CUDAToolkit_TARGET_DIR}/compute-sanitizer) +find_library(mbedcrypto_lib NAMES libmbedcrypto.so) include_directories(${SANITIZER_PATH}/include/ ${CUDAToolkit_TARGET_DIR}/include/ ${CMAKE_CURRENT_LIST_DIR}/include/ ${CMAKE_CURRENT_LIST_DIR}/src/ + ${LIBELF_INCLUDE_DIRS} + ${MBEDTLS_INCLUDE_DIRS} ) message(INFO ${SANITIZER_PATH} ${CUDAToolkit_NVCC_EXECUTABLE}) add_link_options(-L${SANITIZER_PATH} -fPIC -shared) @@ -49,6 +59,11 @@ aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/ cubin_filter_src) file(GLOB cubin_filter_head CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/*.h" ) + +add_link_options(-L${LIBELF_LIBRARIES_PATH} -L${MBEDTLS_LIBRARY_PATH} -L${MBEDCRYPTO_LIBRARY_PATH}) + +message(INFO ${mbedcrypto_lib}) + add_library(cubin_filter SHARED ${cubin_filter_src} ) target_link_libraries(cubin_filter PUBLIC diff --git a/cubin_filter/FindLibElf.cmake b/cubin_filter/FindLibElf.cmake new file mode 100644 index 0000000..ae12505 --- /dev/null +++ b/cubin_filter/FindLibElf.cmake @@ -0,0 +1,66 @@ +# - Try to find libelf +# Once done this will define +# +# LIBELF_FOUND - system has libelf +# LIBELF_INCLUDE_DIRS - the libelf include directory +# LIBELF_LIBRARIES - Link these to use libelf +# LIBELF_DEFINITIONS - Compiler switches required for using libelf +# +# Copyright (c) 2008 Bernhard Walle +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +if (LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS) + set (LibElf_FIND_QUIETLY TRUE) +endif (LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS) + +find_path (LIBELF_INCLUDE_DIRS + NAMES + libelf.h + PATHS + /usr/include + /usr/include/libelf + /usr/local/include + /usr/local/include/libelf + /opt/local/include + /opt/local/include/libelf + /sw/include + /sw/include/libelf + ENV CPATH) + +find_library (LIBELF_LIBRARIES + NAMES + elf + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ENV LIBRARY_PATH + ENV LD_LIBRARY_PATH) + +get_filename_component(LIBELF_LIBRARIES_PATH ${LIBELF_LIBRARIES} DIRECTORY) + +include (FindPackageHandleStandardArgs) + + +# handle the QUIETLY and REQUIRED arguments and set LIBELF_FOUND to TRUE if all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibElf DEFAULT_MSG + LIBELF_LIBRARIES + LIBELF_INCLUDE_DIRS) + +SET(CMAKE_REQUIRED_LIBRARIES elf) +INCLUDE(CheckCXXSourceCompiles) +CHECK_CXX_SOURCE_COMPILES("#include +int main() { + Elf *e = (Elf*)0; + size_t sz; + elf_getshdrstrndx(e, &sz); + return 0; +}" ELF_GETSHDRSTRNDX) + +mark_as_advanced(LIBELF_INCLUDE_DIRS LIBELF_LIBRARIES ELF_GETSHDRSTRNDX) diff --git a/cubin_filter/FindMbedTLS.cmake b/cubin_filter/FindMbedTLS.cmake new file mode 100644 index 0000000..7957026 --- /dev/null +++ b/cubin_filter/FindMbedTLS.cmake @@ -0,0 +1,40 @@ +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) 1998 - 2022, Daniel Stenberg, , et al. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at https://curl.se/docs/copyright.html. +# +# You may opt to use, copy, modify, merge, publish, distribute and/or sell +# copies of the Software, and permit persons to whom the Software is +# furnished to do so, under the terms of the COPYING file. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +# SPDX-License-Identifier: curl +# +########################################################################### +find_path(MBEDTLS_INCLUDE_DIRS mbedtls/md5.h) + +find_library(MBEDTLS_LIBRARY mbedtls) +# find_library(MBEDX509_LIBRARY mbedx509) +find_library(MBEDCRYPTO_LIBRARY mbedcrypto) + +get_filename_component(MBEDCRYPTO_LIBRARY_PATH ${MBEDCRYPTO_LIBRARY} DIRECTORY) +get_filename_component(MBEDTLS_LIBRARY_PATH ${MBEDTLS_LIBRARY} DIRECTORY) + + +set(MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MbedTLS DEFAULT_MSG + MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) + +mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)