From 8110bb219a190ec56b5c651c6ec0855a44687485 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Mon, 6 Sep 2021 12:33:17 +0800 Subject: [PATCH] fix(cmake/env): fix a bug about env set in cmake build mode GitOrigin-RevId: 492eaf428a1ab1f8c671730af139fa12cedae3f7 --- CMakeLists.txt | 12 ++++++++++++ cmake/aclrt.cmake | 8 ++------ cmake/cndev.cmake | 8 ++------ cmake/cnml.cmake | 8 ++------ cmake/cnrt.cmake | 8 ++------ cmake/cudnn.cmake | 12 ++++-------- cmake/tensorrt.cmake | 12 ++++-------- scripts/cmake-build/BUILD_README.md | 4 ++++ 8 files changed, 32 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1722a7cd..5e63420c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,18 @@ set_property(CACHE MGE_ARCH PROPERTY STRINGS AUTO ) set (MGE_EXPORT_TARGETS MegEngine-targets) +if(NOT "$ENV{LD_LIBRARY_PATH}" STREQUAL "") + string(REPLACE ":" ";" ALTER_LD_LIBRARY_PATHS $ENV{LD_LIBRARY_PATH}) +else() + set(ALTER_LD_LIBRARY_PATHS "") +endif() + +if(NOT "$ENV{LIBRARY_PATH}" STREQUAL "") + string(REPLACE ":" ";" ALTER_LIBRARY_PATHS $ENV{LIBRARY_PATH}) +else() + set(ALTER_LIBRARY_PATHS "") +endif() + option(MGE_WITH_JIT "Build MegEngine with JIT." ON) option(MGE_WITH_JIT_MLIR "Build MegEngine with MLIR JIT." OFF) option(MGE_WITH_HALIDE "Build MegEngine with Halide JIT" OFF) diff --git a/cmake/aclrt.cmake b/cmake/aclrt.cmake index c25d3e18c..d9d3d190b 100644 --- a/cmake/aclrt.cmake +++ b/cmake/aclrt.cmake @@ -1,11 +1,7 @@ -if($ENV{LIBRARY_PATH}) - string(REPLACE ":" ";" SYSTEM_LIBRARY_PATHS $ENV{LIBRARY_PATH}) -endif() - find_library(ACLRT_LIBRARY NAMES libascendcl.so - PATHS $ENV{LD_LIBRARY_PATH} "$ENV{ACLRT_HOME}/lib64/stub" ${CMAKE_INSTALL_PREFIX} - HINTS ${SYSTEM_LIBRARY_PATHS} + PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{ACLRT_HOME}/lib64/stub" ${CMAKE_INSTALL_PREFIX} + HINTS ${ALTER_LIBRARY_PATHS} PATH_SUFFIXES stub DOC "ACL library." ) diff --git a/cmake/cndev.cmake b/cmake/cndev.cmake index 422912b05..ae7cdadbc 100644 --- a/cmake/cndev.cmake +++ b/cmake/cndev.cmake @@ -1,11 +1,7 @@ -if($ENV{LIBRARY_PATH}) - string(REPLACE ":" ";" SYSTEM_LIBRARY_PATHS $ENV{LIBRARY_PATH}) -endif() - find_library(CNDEV_LIBRARY NAMES libcndev.so - PATHS $ENV{LD_LIBRARY_PATH} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX} - HINTS ${SYSTEM_LIBRARY_PATHS} + PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX} + HINTS ${ALTER_LIBRARY_PATHS} PATH_SUFFIXES lib lib64 DOC "CNDEV library." ) diff --git a/cmake/cnml.cmake b/cmake/cnml.cmake index 388f1b762..1956129b0 100644 --- a/cmake/cnml.cmake +++ b/cmake/cnml.cmake @@ -1,11 +1,7 @@ -if($ENV{LIBRARY_PATH}) - string(REPLACE ":" ";" SYSTEM_LIBRARY_PATHS $ENV{LIBRARY_PATH}) -endif() - find_library(CNML_LIBRARY NAMES libcnml.so - PATHS $ENV{LD_LIBRARY_PATH} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX} - HINTS ${SYSTEM_LIBRARY_PATHS} + PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX} + HINTS ${ALTER_LIBRARY_PATHS} PATH_SUFFIXES lib lib64 DOC "CNML library." ) diff --git a/cmake/cnrt.cmake b/cmake/cnrt.cmake index 4319ef3d2..fc458d75c 100644 --- a/cmake/cnrt.cmake +++ b/cmake/cnrt.cmake @@ -1,11 +1,7 @@ -if($ENV{LIBRARY_PATH}) - string(REPLACE ":" ";" SYSTEM_LIBRARY_PATHS $ENV{LIBRARY_PATH}) -endif() - find_library(CNRT_LIBRARY NAMES libcnrt.so - PATHS $ENV{LD_LIBRARY_PATH} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX} - HINTS ${SYSTEM_LIBRARY_PATHS} + PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX} + HINTS ${ALTER_LIBRARY_PATHS} PATH_SUFFIXES lib lib64 DOC "CNRT library." ) diff --git a/cmake/cudnn.cmake b/cmake/cudnn.cmake index 3b037c3cc..cf18b4a29 100644 --- a/cmake/cudnn.cmake +++ b/cmake/cudnn.cmake @@ -3,10 +3,6 @@ if(${PkgConfig_FOUND}) pkg_check_modules(PC_CUDNN QUIET CUDNN) endif() -if(NOT "$ENV{LIBRARY_PATH}" STREQUAL "") - string(REPLACE ":" ";" SYSTEM_LIBRARY_PATHS $ENV{LIBRARY_PATH}) -endif() - if("${CUDNN_ROOT_DIR}" STREQUAL "" AND NOT "$ENV{CUDNN_ROOT_DIR}" STREQUAL "") set(CUDNN_ROOT_DIR $ENV{CUDNN_ROOT_DIR}) endif() @@ -14,15 +10,15 @@ endif() if(MGE_CUDA_USE_STATIC AND NOT MGE_WITH_CUDNN_SHARED) find_library(CUDNN_LIBRARY NAMES libcudnn_static.a cudnn.lib - PATHS $ENV{LD_LIBRARY_PATH} ${CUDNN_ROOT_DIR} ${PC_CUDNN_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX} - HINTS ${SYSTEM_LIBRARY_PATHS} + PATHS ${ALTER_LD_LIBRARY_PATHS} ${CUDNN_ROOT_DIR} ${PC_CUDNN_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX} + HINTS ${ALTER_LIBRARY_PATHS} PATH_SUFFIXES lib lib64 DOC "CUDNN library." ) else() find_library(CUDNN_LIBRARY NAMES libcudnn.so libcudnn.dylib cudnn64.dll - PATHS $ENV{LD_LIBRARY_PATH} ${CUDNN_ROOT_DIR} ${PC_CUDNN_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX} - HINTS ${SYSTEM_LIBRARY_PATHS} + PATHS ${ALTER_LD_LIBRARY_PATHS} ${CUDNN_ROOT_DIR} ${PC_CUDNN_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX} + HINTS ${ALTER_LIBRARY_PATHS} PATH_SUFFIXES lib lib64 DOC "CUDNN library." ) endif() diff --git a/cmake/tensorrt.cmake b/cmake/tensorrt.cmake index 1958a643d..e5dee682b 100644 --- a/cmake/tensorrt.cmake +++ b/cmake/tensorrt.cmake @@ -1,7 +1,3 @@ -if(NOT "$ENV{LIBRARY_PATH}" STREQUAL "") - string(REPLACE ":" ";" SYSTEM_LIBRARY_PATHS $ENV{LIBRARY_PATH}) -endif() - if("${TRT_ROOT_DIR}" STREQUAL "" AND NOT "$ENV{TRT_ROOT_DIR}" STREQUAL "") set(TRT_ROOT_DIR $ENV{TRT_ROOT_DIR}) endif() @@ -9,15 +5,15 @@ endif() if(MGE_CUDA_USE_STATIC) find_library(TRT_LIBRARY NAMES libnvinfer_static.a nvinfer.lib - PATHS $ENV{LD_LIBRARY_PATH} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} - HINTS ${SYSTEM_LIBRARY_PATHS} + PATHS ${ALTER_LD_LIBRARY_PATHS} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} + HINTS ${ALTER_LIBRARY_PATHS} PATH_SUFFIXES lib lib64 DOC "TRT library." ) else() find_library(TRT_LIBRARY NAMES libnvinfer.so libnvinfer.dylib nvinfer.dll - PATHS $ENV{LD_LIBRARY_PATH} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} - HINTS ${SYSTEM_LIBRARY_PATHS} + PATHS ${ALTER_LD_LIBRARY_PATHS} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} + HINTS ${ALTER_LIBRARY_PATHS} PATH_SUFFIXES lib lib64 DOC "TRT library." ) endif() diff --git a/scripts/cmake-build/BUILD_README.md b/scripts/cmake-build/BUILD_README.md index 6e673a9f0..26af6f147 100755 --- a/scripts/cmake-build/BUILD_README.md +++ b/scripts/cmake-build/BUILD_README.md @@ -75,6 +75,10 @@ 2: install gcc/g++, which version >= 6, (gcc/g++ >= 7, if need build training mode) 3: install build-essential git git-lfs gfortran libgfortran-6-dev autoconf gnupg flex bison gperf curl zlib1g-dev gcc-multilib g++-multilib lib32ncurses5-dev libxml2-utils xsltproc unzip libtool librdmacm-dev rdmacm-utils python3-dev python3-numpy texinfo 4: CUDA env(if enable CUDA), version detail refer to README.md +recommend set env about cuda/cudnn/tensorrt as followed: +export CUDA_ROOT_DIR=/path/to/cuda/lib +export CUDNN_ROOT_DIR=/path/to/cudnn/lib +export TRT_ROOT_DIR=/path/to/tensorrt/lib ``` ### MacOS host build -- GitLab