title: CUDA 5.0 separate compilation of library with cmake
body: <p>The buildtime of my cuda library is increasing and so I thought that separate compilation introduced in CUDA 5.0 might help me. I couldn't figure out how to achieve separate compilation with cmake. I looked into the NVCC documentation and found how to compile device object (using the -dc option) and how to link them (using the -dlink). My attempts to get it running using cmake failed. I'm using cmake 2.8.10.2 and the head of the trunk of the FindCUDA.cmake. I couldn't however find out how to specify which files should be compiled and how to link them into a library.
  Especially the syntax of the <code>function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file_var cuda_target options object_files source_files)
  </code> is unclear to me because I don't know what the <code>output_file_var</code> and the <code>cuda_target</code> are.
  Here the not working results of my attemps:</p>
  
  <pre><code>cuda_compile(DEVICEMANAGER_O devicemanager.cu OPTIONS -dc)
  cuda_compile(BLUB_O blub.cu OPTIONS -dc)
  CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS(TEST_O gpuacceleration
                                            ""  DEVICEMANGER_O BLUB_O)
  set(LIB_TYPE SHARED)
  #cuda_add_library(gpuacceleration ${LIB_TYPE} 
    #${gpuacc_SRCS} 
    #devicemanager.cu
    # blub.cu
    #DEVICEMANAGER_O
  #  TEST_O
  #)
  </code></pre>
  
  <p>Does anyone know how to compile and link a cuda library using cmake?
  Thanks in advance.</p>
  
  <p><strong>EDIT:</strong>
  After a friend consulted the developer of the FindCUDA.cmake, a bug got fixed in the example provided with FindCUDA.cmake (<a href="https://gforge.sci.utah.edu/gf/project/findcuda/scmsvn/?action=browse&amp;path=%2F">https://gforge.sci.utah.edu/gf/project/findcuda/scmsvn/?action=browse&amp;path=%2F</a><em>checkout</em>%2Ftrunk%2FFindCuda.html).
  I'm now able to build the example.
  In my project I can build the library as needed using the following (cmake 2.8.10 required):</p>
  
  <pre><code>set(LIB_TYPE SHARED)
  set(CUDA_SEPARABLE_COMPILATION ON)
  cuda_add_library(gpuacceleration ${LIB_TYPE} 
   blub.cu
   blab.cu
  )
  </code></pre>
  
  <p><strong>BUT:</strong>
  I cannot link against this library. When I builded the lib without separate compilation i was able to link against it.
  Now getting the following error:</p>
  
  <pre><code> undefined reference to `__cudaRegisterLinkedBinary_53_tmpxft_00005ab4_00000000_6_blub_cpp1_ii_d07d5695'
  </code></pre>
  
  <p>for every file with a function used in the interface. Seems strange since it builds without any warning etc.
  Any ideas how to get this working?</p>
  
  <p><strong>EDIT:</strong>
  I finally figured out how to do this. See @PHD's and my answer for details. </p>