Skip to content

Commit

Permalink
Update CMake search path for NVML lib and include
Browse files Browse the repository at this point in the history
  • Loading branch information
Syllo committed Apr 6, 2018
1 parent bf6c042 commit 0c6cf94
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ endif()
# DEPENDENCIES #
#///////////////////////////////////////////////////////////////////#

if(NVML_RETRIEVE_HEADER_ONLINE)
file(DOWNLOAD "https://raw.githubusercontent.com/NVIDIA/nvidia-settings/master/src/nvml.h" ${PROJECT_BINARY_DIR}/include/nvml.h)
endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)

find_package(NVML REQUIRED)
Expand Down
37 changes: 19 additions & 18 deletions cmake/modules/FindNVML.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Version 1.1
# Version 1.2
# Public Domain
# Written by Maxime SCHMITT <[email protected]>

Expand All @@ -19,29 +19,30 @@ if (NVML_INCLUDE_DIRS AND NVML_LIBRARIES)
endif()

# Headers
file(GLOB nvml_header_path_hint /usr/local/cuda*/include /opt/cuda*/include)
file(GLOB nvml_header_path_hint /usr/include/nvidia*/include /usr/local/cuda*/include /opt/cuda*/include)
find_path(NVML_INCLUDE_DIRS NAMES nvml.h
HINTS ${nvml_header_path_hint})
PATHS ${nvml_header_path_hint} ${PROJECT_BINARY_DIR}/include)

# library
find_library(NVML_LIBRARIES NAMES nvml nvidia-ml)
file(GLOB nvml_lib_path_hint /usr/lib*/nvidia*/)
find_library(NVML_LIBRARIES NAMES nvidia-ml libnvidia-ml.so.1
PATHS ${nvml_lib_path_hint})

# Version
set(filename "${NVML_INCLUDE_DIRS}/nvml.h")
if (NOT EXISTS ${filename} AND NOT quiet)
message(AUTHOR_WARNING "Unable to find ${filename}")
endif()
file(READ "${filename}" nvml_header)
set(nvml_api_version_match "NVML_API_VERSION")

string(REGEX REPLACE ".*#[ \t]*define[ \t]*${nvml_api_version_match}[ \t]*([0-9]+).*"
"\\1" nvml_api_version "${nvml_header}")

if (nvml_api_version STREQUAL nvml_header)
message(AUTHOR_WARNING "Unable to find nvml api version")
else()
set(NVML_API_VERSION "${nvml_api_version}")
endif()
if (EXISTS ${filename})
file(READ "${filename}" nvml_header)
set(nvml_api_version_match "NVML_API_VERSION")

string(REGEX REPLACE ".*#[ \t]*define[ \t]*${nvml_api_version_match}[ \t]*([0-9]+).*"
"\\1" nvml_api_version "${nvml_header}")

if (nvml_api_version STREQUAL nvml_header AND NOT quiet)
message(AUTHOR_WARNING "Unable to find nvml api version")
else()
set(NVML_API_VERSION "${nvml_api_version}")
endif()
endif(EXISTS ${filename})

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NVML
Expand Down

0 comments on commit 0c6cf94

Please sign in to comment.