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

Cmake modernization #102

Merged
merged 8 commits into from
Mar 21, 2019
Merged

Cmake modernization #102

merged 8 commits into from
Mar 21, 2019

Conversation

codecircuit
Copy link
Contributor

Main features:

  • Export of build directory (use in external projects without installing cuda-api-wrappers)
  • Installation of build tree independent export set. This is important if cuda-api-wrappers is used by other CMake projects and cuda-api-wrappers was installed somewhere.
  • Fix of library include directories

See

This enhanced my personal work with CMake a lot.

I do not care if you merge all the commits into one commit. I just did it that way to keep the changes understandable.

#60 (comment)

So here is a smaller PR.

- fix of generator expression syntax
- `INTERFACE` should only be used with header
  only libraries
See https://cmake.org/cmake/help/v3.12/command/export.html

"""
The file created by this command is specific to the build tree and should never be installed. See the install(EXPORT) command to export targets from an installation tree.
"""
See https://cmake.org/cmake/help/v3.12/command/install.html#command:install

"""
Note that the values specified for this option only apply to options listed AFTER the CONFIGURATIONS
"""
This enables users to use the
`find_package(cuda-api-wrappers)` function in their
`CMakeLists.txt`.
It is good practice to give the export set a different
name (in comparison to the project and target names).
This enables the external use without the installation
of the project. Thus in an external project one can use

```
find_package(cuda-api-wrappers)
```

because CMake finds the package in the local CMake package
registry (often `~/.cmake/packages`)
Copy link
Owner

@eyalroz eyalroz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to accept this soon, one way or another... but please answer these questions.

CMakeLists.txt Outdated
@@ -150,19 +157,38 @@ add_dependencies(examples examples_by_runtime_api_module modified_cuda_samples)

install(
TARGETS cuda-api-wrappers
EXPORT cuda-api-wrappers
EXPORT cuda-api-wrappersExport
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a particular reason you're using "Export" rather than _export as a suffix? cuda-api-wrappers_export makes sense to me, or CudaApiWrappersExport, or CUDAAPIWrappersExport but not this particular choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No there is no particular reason. I just think it is reasonable to give the export not the name of a target or the project.

CMakeLists.txt Outdated Show resolved Hide resolved
DESTINATION "share/cmake/${PROJECT_NAME}"
NAMESPACE "${PROJECT_NAME}::"
# In this CMake config file no dependencies are considered. But since we
# do not use any `find_package` call here this approach is sufficient.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the CUDA dependency? Can we ignore that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, everything works fine if you use the CUDA compiler nvcc from the CUDA toolkit. In future it might be more relevant to distinguish between a CUDA compiler and the CUDA libraries, like the runtime libraries or CUBLAS etc. I think it is right now not worth it to write CMake find modules by ourselves for the CUDA libraries. Moreover this problem is not introduced by my PR, but already exists in basically every project with CMake and CUDA libraries.

CMakeLists.txt Outdated Show resolved Hide resolved

export(
EXPORT ${PROJECT_NAME}Export
NAMESPACE "${PROJECT_NAME}::"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what's actually going to be inside that namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every target, which has been added at the installation to the export set. So right now only cuda-api-wrappers.

NAMESPACE "${PROJECT_NAME}::"
# In this CMake config file no dependencies are considered. But since we
# do not use any `find_package` call here this approach is sufficient.
FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
Copy link
Owner

@eyalroz eyalroz Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, shouldn't this be either cuda-api-wrappers_config or CudaApiWrappersConfig.cmake?

Copy link
Contributor Author

@codecircuit codecircuit Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you want the user to add the dependency to this project. I think the most intuitive way would be (this is how it is working right now):

find_package(cuda-api-wrappers)
...
target_link_libraries(
  foo
  cuda-api-wrappers::cuda-api-wrappers
)

If you name this file CudaApiWrappersConfig.cmake it would be

find_package(CudaApiWrappers)
...
target_link_libraries(
  foo
  cuda-api-wrappers::cuda-api-wrappers
)

and if you name this file cuda-api-wrappers_config it is useless, because CMake expects -config or Config suffix.

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants