Skip to content

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

Closed
@MarelliF

Description

@MarelliF

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions