<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Dear all,<br>
I'm experiencing a CMake problem caused by UseVTK.cmake (VTK version
6.3 release).<br>
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:<br>
<br>
1) find_package(PCL) in my CMake code automatically runs
PCLConfig.cmake.<br>
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).<br>
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!!).<br>
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:<br>
<br>
---------begin quote-----------<br>
/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<br>
---------end quote-------------<br>
<br>
-- instead of simply:<br>
<br>
---------begin quote-----------<br>
/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<br>
---------end quote-------------<br>
<br>
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".<br>
<br>
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.
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<br>
<br>
1) How do I get around this and get CUDA working on this target
without losing PCL/VTK support for other targets?<br>
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?<br>
<br>
Thanks,<br>
Greg<br>
<br>
[1]
<a class="moz-txt-link-freetext" href="https://cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file">https://cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file</a><br>
[2]
<a class="moz-txt-link-freetext" href="https://cmake.org/cmake/help/v3.2/command/target_compile_definitions.html">https://cmake.org/cmake/help/v3.2/command/target_compile_definitions.html</a><br>
<br>
</body>
</html>