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

CXX flags passed to nvcc using CMake make compilation fail #1991

Closed
MarelliF opened this issue Nov 18, 2019 · 2 comments · Fixed by #2338
Closed

CXX flags passed to nvcc using CMake make compilation fail #1991

MarelliF opened this issue Nov 18, 2019 · 2 comments · Fixed by #2338

Comments

@MarelliF
Copy link

Issue description

Compilation fails when using CMake and pybind11_add_module for project containing CUDA code. The -flto flag is passed to NVCC and causes the following output:
nvcc fatal : Unknown option 'flto'

Reproducible example code

In CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(projectname LANGUAGES CXX CUDA)
find_package(pybind11 REQUIRED)

pybind11_add_module(modulename src/cpp_source.cpp src/cuda_source.cu)

Possible solution

In pybind11/tools/pybind11Tools.cmake, line 104:
-use $<$<COMPILE_LANGUAGE:CXX>: to set the flag only for GCC
-pass it to nvcc as -Xcompiler=-flto

@YannickJadoul
Copy link
Collaborator

It might be even better to add this as a case to this if-block?

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")

Feel free to submit a PR. Otherwise, we'll put it on the backlog of "things to get to at some point".

@bstaletic
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants