[vtkusers] CMake, UseVTK.cmake and CUDA incompatibility

Gregory Kramida algomorph at gmail.com
Fri Dec 18 12:55:24 EST 2015


Dear all,
I'm experiencing a CMake problem caused by UseVTK.cmake (VTK version 6.3 
release).
I have a large CMake project with multiple targets. Some use VTK, some 
use PCL (which uses VTK). One uses neither, but does use the Nvidia CUDA 
package. Here is what happens:

1) find_package(PCL) in my CMake code automatically runs PCLConfig.cmake.
2) PCLConfig.cmake includes UseVTK.cmake after find_package(VTK) is 
successful (note: this is the intended use, I'm assuming there is 
nothing wrong with this).
3) UseVTK.cmake adds a trainload of flags to CMAKE_C_FLAGS and 
CMAKE_CXX_FLAGS CMake variables directly (!!Something wrong with this 
schema -- discussed later!!).
4) Even though a certain target does not link/use VTK or PCL, the way 
the CMake default CUDA handling works is that these flags are passed to 
the nvcc compiler, i.e. here's what gets executed:

---------begin quote-----------
/usr/local/cuda/bin/nvcc -M -D__CUDACC__ 
/home/<omitted>/quickshift_gpu.cu -o 
/home/<omitted>/reco_segmentation_generated_quickshift_gpu.cu.o.NVCC-depend 
-ccbin /usr/bin/c++ -m64 -D_DEBUG -DvtkRenderingContext2D_AUTOINIT=1 ( 
vtkRenderingContextOpenGL ) -DvtkRenderingCore_AUTOINIT=3 ( 
vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL ) 
-DvtkRenderingVolume_AUTOINIT=1 ( vtkRenderingVolumeOpenGL ) 
-Dreco_segmentation_EXPORTS -Xcompiler 
,\"-Wall\",\"-std=c++11\",\"-fPIC\",\"-g\" -DNVCC 
-I/usr/local/cuda/include -I/usr/local/include/vtk-6.3 
-I/usr/local/cuda/include
---------end quote-------------

-- instead of simply:

---------begin quote-----------
/usr/local/cuda/bin/nvcc /home/<omitted>/quickshift_gpu.cu -c -o 
/home/<omitted>/reco_segmentation_generated_quickshift_gpu.cu.o -ccbin 
/usr/bin/c++ -m64 -D_DEBUG -Dreco_segmentation_EXPORTS -Xcompiler 
,\"-Wall\",\"-std=c++11\",\"-fPIC\",\"-g\" -DNVCC 
-I/usr/local/cuda/include -I/usr/local/cuda/include
---------end quote-------------

Whereas the latter command funs fine, the former fails with "nvcc 
fatal   : A single input file is required for a non-link phase when an 
outputfile is specified".

Now, syntax such as "set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} 
${VTK_REQUIRED_CXX_FLAGS}")" is not supposed to be used in UseXXX.CMake 
files, it is intended for CMake macros/functions(1). Clearly, it causes 
unintended problems. The modern way to do things like this is to add the 
flags to something like VTK_CXX_FLAGS, so that the user may use the 
target_compile_definitions(...) command (2) to add them to specific 
targets. Ideally, off course, the preprocessor definitions should be set 
in config header files that are configured by cmake *at the time of VTK 
CMake generation*, such as /Common/Core/vtkConfigure.h.in. This way they 
are defined when the target project includes the headers (which is done 
any way), and avoid the need for separate target_compile_definitions calls.

1) How do I get around this and get CUDA working on this target without 
losing PCL/VTK support for other targets?
2) Is there any rationale behind setting compiler flags in CMake instead 
of in header config files? Is there any rationale behind explicitly 
modifying the CMake flags variables in the UseVTK.cmake script?

Thanks,
Greg

[1] 
https://cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file
[2] 
https://cmake.org/cmake/help/v3.2/command/target_compile_definitions.html

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151218/4971c825/attachment.html>


More information about the vtkusers mailing list