[CMake] FindCUDA ignores project dependencies when separable compilation is on

Irwin Zaid irwin.zaid at physics.ox.ac.uk
Mon Jan 5 15:57:55 EST 2015


Hi James,

Thanks for the quick reply! As I mentioned, we've hit two issues. The 
first is the project dependencies one, which I'll try and describe more 
a bit below. I'm not a CMake expert, so please bear with me.

The second is what I've put under 2).

> The only CMake build dependency changes when doing separable compilation
> are found in CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS. Basically what
> this does is create a new rule to build an intermediate link file. For
> everything but some versions of MSVC generators it adds a custom command
> to generate this intermediate link file. The other case adds a custom
> command that runs as a PRE_LINK command to generate the object file (the
> reasons for this is a bug in VS custom command dependency scanning), but
> this should happen during link phase and not compile phase.
>
> Nothing in here should change what happens before the target is built,
> though.

1) Okay, I understand that, but I do think we saw a different behaviour 
when we switched to separable compilation. Let me describe what we are 
doing.

We generate part of our library from a simple program (call the simple 
program 'gen', which generates a source file 'gen.hpp') that we want to 
execute before compiling our library (call our library 'main'). We set 
this up with the following:

- add_executable(...) is called for 'gen'
- add_custom_command(...) sets up a command that executes 'gen'
- set_source_files_properties(...) is called to set 'gen.hpp' as having 
the PROPERTY of GENERATED
- add_dependencies(main gen) is called to establish 'main' depends on 'gen'

So far, this has only failed for CUDA with separable compilation. (It 
has worked for all of our other configurations. including CUDA without 
separable compilation.)

Have we done something wrong? Is there some additional information we 
can look at to figure out what's going on?

2) A second problem we've run into is an error when trying to link a 
CUDA shared library with separable compilation. This is specifically a 
Linux problem, on Mac it is fine. A static library is also fine, working 
for both Linux and Mac.

The particular error is "relocation R_X86_64_32S against 
`__nv_module_id' can not be used when making a shared object; recompile 
with -fPIC". However, we are already compiling with -fPIC. I can confirm 
that -fPIC appears to be passed to both the host compiler for non-CUDA 
source and via -Xcompiler -fPIC for CUDA source.

This error occurs when trying to link all the different object files 
together of our library.

Do you have any idea of what this could be?

--

Thanks for all of your help.

Cheers,

Irwin


More information about the CMake mailing list