Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the process of using NVTX in another CMake project #94

Open
alliepiper opened this issue May 2, 2024 · 1 comment
Open

Simplify the process of using NVTX in another CMake project #94

alliepiper opened this issue May 2, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@alliepiper
Copy link

Rather than requesting users use a custom include(...) file to consume imported CMake targets, it is possible to detect whether NVTX is being built stand-alone or as part of another project. The common pattern for detecting this is to add a top-level CMakeLists.txt file with:

In a new NVTX/CMakeLists.txt file:

# ...normal project setup here...

# Check if standalone or part of another project:
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}")
  set(NVTX_TOPLEVEL_PROJECT ON)
endif()

# using `option` instead of `set` lets users change this using `ccmake` or `cmake -D....`.
# When built as part of another project, NVTX_TOPLEVEL_PROJECT will be unset and default to false.
# When built stand-alone, NVTX_TOPLEVEL_PROJECT will be truthy and disable imported targets.
option(NVTX3_TARGETS_NOT_USING_IMPORTED "<doc string>" ${NVTX_TOPLEVEL_PROJECT})

# The `set(...NOT_USING_IMPORTED...)` in c/CMakeLists.txt should be removed in favor of the option above.
add_subdirectory(c)

For an example of how we use this pattern in CCCL, see: https://github.com/NVIDIA/cccl/blob/main/CMakeLists.txt#L10-L14

By making this change (and adding a top-level CMakeLists.txt file to the NVTX repo per the suggestion above), CPM usage would be simplified to:

CPMAddPackage("gh:NVIDIA/NVTX@release-v3")

for most users. Currently, we must do

CPMAddPackage(
  NAME NVTX
  GITHUB_REPOSITORY NVIDIA/NVTX
  GIT_TAG release-v3
  DOWNLOAD_ONLY
  SYSTEM
)
include("${NVTX_SOURCE_DIR}/c/nvtxImportedTargets.cmake")

for the common case of wanting imported targets.

@alliepiper
Copy link
Author

I'd be willing to push a PR with these changes if they sound agreeable to the NVTX team.

@evanramos-nvidia evanramos-nvidia added the enhancement New feature or request label Oct 30, 2024
@evanramos-nvidia evanramos-nvidia self-assigned this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants