[vtk-developers] How to write CMakeLists.txt for a library using CUDA?

Mingcheng Chen linyufly at gmail.com
Mon Mar 17 17:21:25 EDT 2014


Hi Kenneth,

Thanks a lot for your advice!

I followed your advice and successfully built *.so and *.a for the same
library, and my following code can use *.so library successfully!

I have two follower questions:
(1) I have link error if I want to compile something using my *.a library,
but the CMakeLists.txt is almost the same as the one using *.so library. I
use target_link_libraries(myApp ${VTK_SOURCE_DIR}/myLib.a) and
target_link_libraries(myApp ${VTK_SOURCE_DIR}/myLib.so) for both. Is there
anything I should consider for *.a library?

(2) The CMakeLists.txt that works in Ubuntu does not work in Visual Studio.
The *.sln it creates is not a CUDA project. How to solve that problem?

Thanks again!

Best regards,
Mingcheng Chen
March 17th, 2014


On Mon, Mar 17, 2014 at 12:59 PM, Moreland, Kenneth <kmorel at sandia.gov>wrote:

>   This question is really more applicable to the VTK users list, so I'm
> responding to there as well.
>
>  The short answer is that if you add the command "find_package(CUDA
> REQUIRED)" to your CMakeLists.txt, that will load the CMake code to find
> the CUDA install. Then you replace add_library with cuda_add_library. You
> also have to use a .cu extension for your C or C++ files that use CUDA
> instead of .c or .cxx or .cpp. The cuda_add_library will only use the
> requisite nvcc compiler on files with a .cu extension.
>
>  For more information, try this command prompt command: "cmake
> --help-module FindCUDA | less". You can also find several examples on the
> web.
>
>  -Ken
>
>   From: Mingcheng Chen <linyufly at gmail.com>
> Date: Sunday, March 16, 2014 11:36 AM
> To: "vtk-developers at vtk.org" <vtk-developers at vtk.org>
> Subject: [EXTERNAL] [vtk-developers] How to write CMakeLists.txt for a
> library using CUDA?
>
>   Hi everyone,
>
>  Thanks for your time!
>
>  I write a class which uses VTK and CUDA, and I want to write a
> CMakeLists.txt for others to build my library. I only know how to write
> CMakeLists.txt for executables. Could anybody please show me how to write
> for a library?
>
>  Thanks!
>
>  Best regards,
> Mingcheng Chen
> March 16th, 2014
>
>  --
>  Research Assistant in Graphics Group
>  University of Illinois at Urbana-Champaign
> http://mingchengchen.org
>



-- 
Research Assistant in Graphics Group
University of Illinois at Urbana-Champaign
http://mingchengchen.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20140317/8bc539e3/attachment-0002.html>


More information about the vtk-developers mailing list