Skip to content

Commit

Permalink
Make the CMake command find_package(cudawrappers 0.3.0 REQUIRED cu nv…
Browse files Browse the repository at this point in the history
…rtc) work
  • Loading branch information
bouweandela authored Apr 21, 2022
2 parents 2aa998e + 86d60a4 commit 46acd21
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .cmake-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

# If a statement is wrapped to more than one line, than dangle the closing
# parenthesis on its own line.
dangle_parens = False
dangle_parens = True

# If the trailing parenthesis must be 'dangled' on its on line, then align it
# to this reference: `prefix`: the start of the statement, `prefix-indent`:
Expand Down
80 changes: 69 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,84 @@ project(
DESCRIPTION "C++ Wrappers for the CUDA Driver API"
VERSION 0.3.0
HOMEPAGE_URL https://github.com/nlesc-recruit/cudawrappers
LANGUAGES CUDA CXX)
LANGUAGES CXX
)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_BUILD_TYPE Release)
option(BUILD_SHARED_LIBS "Create shared libraries" True)

find_package(CUDAToolkit REQUIRED)
set(CUDA_MIN_VERSION 10.0)
find_package(CUDAToolkit ${CUDA_MIN_VERSION} REQUIRED)

# --- auto-ignore build directory
if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
file(WRITE ${PROJECT_BINARY_DIR}/.gitignore "*")
endif()
# Define components
set(COMPONENTS cu nvrtc)
set(LINK_cu CUDA::cuda_driver)
set(LINK_nvrtc CUDA::cuda_driver CUDA::nvrtc)

include(GNUInstallDirs)
foreach(component ${COMPONENTS})
# Create library
add_library(${component})
# Add a pretend namespace for use cases where the project in not installed
add_library(${PROJECT_NAME}::${component} ALIAS ${component})
# Add sources
target_sources(${component} PRIVATE src/${component}.cpp)
# Add headers
set_target_properties(
${component} PROPERTIES PUBLIC_HEADER include/${component}.hpp
)
# Add the project name as a prefix to the output libraries
set_target_properties(${component} PROPERTIES PREFIX ${PROJECT_NAME}-)
# Add includes
target_include_directories(
${component}
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE ${CUDAToolkit_INCLUDE_DIRS}
)
# Add links
target_link_libraries(${component} PUBLIC ${LINK_${component}})
# Install libraries and headers
install(
TARGETS ${component}
EXPORT ${component}-config # export component cmake targets
COMPONENT ${component}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
# Install component cmake targets
install(
EXPORT ${component}-config
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
endforeach()

set(SOURCE_FILES src/cu.cpp src/nvrtc.cpp)
# Install project cmake targets
include(CMakePackageConfigHelpers)

include_directories(./include/)
include_directories(${CUDAToolkit_INCLUDE_DIRS})
configure_file(
cmake/${PROJECT_NAME}-config.cmake.in ${PROJECT_NAME}-config.cmake @ONLY
)

add_library(cudawrappers SHARED ${SOURCE_FILES})
write_basic_package_version_file(
${PROJECT_NAME}-config-version.cmake
VERSION ${cudawrappers_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

# Including linters rules
include(cmake/linter-tools.cmake)

# Tests
add_subdirectory(tests)

# --- auto-ignore build directory
if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
file(WRITE ${PROJECT_BINARY_DIR}/.gitignore "*")
endif()
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ make -C build
This command will create a `build` folder, compile the code and generate the library `libcudawrappers.so` in the build directory.
For more details on the building requirements and on testing, check the [developer documentation](README.dev.md).

To install to `~/.local`, use
```shell
git clone https://github.com/nlesc-recruit/cudawrappers
cd cudawrappers
cmake -DCMAKE_INSTALL_PREFIX=$HOME/.local -S . -B build
make -C build
make -C build install
```

### Usage examples

You can include the cudawrappers library in your own projects in various ways. We have created a few repositories with example setups to get you started:
Expand Down
7 changes: 7 additions & 0 deletions cmake/cudawrappers-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include(CMakeFindDependencyMacro)

find_package(CUDAToolkit @CUDA_MIN_VERSION@ REQUIRED)

foreach(component ${@PROJECT_NAME@_FIND_COMPONENTS})
include(${CMAKE_CURRENT_LIST_DIR}/${component}-config.cmake)
endforeach()
1 change: 0 additions & 1 deletion cudawrappers-config.cmake

This file was deleted.

0 comments on commit 46acd21

Please sign in to comment.