Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use COMPONENTS when finding VTK to avoid linking agains unnecessary modules #3140

Merged
merged 6 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,28 @@ endif()
# Find VTK
option(WITH_VTK "Build VTK-Visualizations" TRUE)
if(WITH_VTK AND NOT ANDROID)
find_package(VTK)
set(PCL_VTK_COMPONENTS
vtkChartsCore
vtkCommonCore
vtkCommonDataModel
vtkCommonExecutionModel
vtkFiltersCore
vtkFiltersExtraction
vtkFiltersModeling
vtkImagingCore
vtkImagingSources
vtkInteractionStyle
vtkInteractionWidgets
vtkIOCore
vtkIOGeometry
vtkIOImage
vtkIOLegacy
vtkIOPLY
vtkRenderingAnnotation
vtkRenderingLOD
vtkViewsContext2D
)
find_package(VTK COMPONENTS ${PCL_VTK_COMPONENTS})
if(VTK_FOUND AND ("${VTK_VERSION}" VERSION_LESS 6.2))
message(WARNING "The minimum required version of VTK is 6.2, but found ${VTK_VERSION}")
set(VTK_FOUND FALSE)
Expand All @@ -367,17 +388,28 @@ if(WITH_VTK AND NOT ANDROID)
# safe to assume OpenGL backend
set(VTK_RENDERING_BACKEND "OpenGL")
endif()
list(APPEND PCL_VTK_COMPONENTS vtkRenderingContext${VTK_RENDERING_BACKEND})

if(WITH_QT)
if(";${VTK_MODULES_ENABLED};" MATCHES ";vtkGUISupportQt;" AND ";${VTK_MODULES_ENABLED};" MATCHES ";vtkRenderingQt;")
set(QVTK_FOUND ON)
list(APPEND PCL_VTK_COMPONENTS vtkRenderingQt vtkGUISupportQt)
else()
unset(QVTK_FOUND)
endif()
endif()

find_package(VTK COMPONENTS ${PCL_VTK_COMPONENTS})

message(STATUS "VTK_MAJOR_VERSION ${VTK_MAJOR_VERSION}, rendering backend: ${VTK_RENDERING_BACKEND}")
Copy link
Contributor

@SunBlack SunBlack Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include(${VTK_USE_FILE}) will be only called in case (PCL_SHARED_LIBS OR (NOT (PCL_SHARED_LIBS) AND NOT (VTK_BUILD_SHARED_LIBS))) returns true., Shouldn't it be always? (You removed some other calls to this include, so it could be an issue now).

//Edit: Just didn't noticed else tree of this code, that VTKwill be disabled otherwise. Nevertheless this whole code block should be checked. E.g. HAVE_VTK is undefined in case WITH_VTK is true, but VTK was not found.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g. HAVE_VTK is undefined in case WITH_VTK is true, but VTK was not found.

I think this is okay because undefined variables evaluate to false in conditionals.

if(PCL_SHARED_LIBS OR (NOT (PCL_SHARED_LIBS) AND NOT (VTK_BUILD_SHARED_LIBS)))
set(VTK_FOUND TRUE)
find_package(QVTK)
if(VTK_USE_FILE)
include(${VTK_USE_FILE})
endif()
message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, lib: ${VTK_LIBRARIES}")
message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, libs: ${VTK_LIBRARIES}")
if(APPLE)
option(VTK_USE_COCOA "Use Cocoa for VTK render windows" ON)
mark_as_advanced(VTK_USE_COCOA)
option(VTK_USE_COCOA "Use Cocoa for VTK render windows" ON)
mark_as_advanced(VTK_USE_COCOA)
endif()
if(${VTK_RENDERING_BACKEND} STREQUAL "OpenGL")
set(VTK_RENDERING_BACKEND_OPENGL_VERSION "1")
Expand Down
5 changes: 4 additions & 1 deletion PCLConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ macro(find_VTK)
set(VTK_DIR "@VTK_DIR@" CACHE PATH "The directory containing VTKConfig.cmake")
endif()
if(NOT ANDROID)
find_package(VTK ${QUIET_})
find_package(VTK ${QUIET_} COMPONENTS ${PCL_VTK_COMPONENTS})
endif()
endmacro()

Expand Down Expand Up @@ -435,6 +435,9 @@ list(LENGTH pcl_all_components PCL_NB_COMPONENTS)

@PCLCONFIG_OPTIONAL_DEPENDENCIES@

# VTK components required by PCL
set(PCL_VTK_COMPONENTS "@PCL_VTK_COMPONENTS@")

set(pcl_header_only_components 2d cuda_common geometry gpu_tracking modeler in_hand_scanner point_cloud_editor cloud_composer)

include(FindPackageHandleStandardArgs)
Expand Down
12 changes: 6 additions & 6 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ if(VTK_FOUND)
PCL_ADD_EXECUTABLE(pcl_stereo_ground_segmentation COMPONENT ${SUBSYS_NAME} SOURCES src/stereo_ground_segmentation.cpp)
target_link_libraries(pcl_stereo_ground_segmentation pcl_common pcl_io pcl_filters pcl_visualization pcl_segmentation pcl_features pcl_stereo)

if(Qt5_FOUND AND VTK_USE_QVTK)
if(Qt5_FOUND AND QVTK_FOUND)
# Manual registration demo
QT5_WRAP_UI(manual_registration_ui src/manual_registration/manual_registration.ui)
QT5_WRAP_CPP(manual_registration_moc include/pcl/apps/manual_registration.h OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
PCL_ADD_EXECUTABLE(pcl_manual_registration COMPONENT ${SUBSYS_NAME} SOURCES ${manual_registration_ui} ${manual_registration_moc} src/manual_registration/manual_registration.cpp BUNDLE)
target_link_libraries(pcl_manual_registration pcl_common pcl_io pcl_visualization pcl_segmentation pcl_features pcl_surface ${QVTK_LIBRARY} Qt5::Widgets)
target_link_libraries(pcl_manual_registration pcl_common pcl_io pcl_visualization pcl_segmentation pcl_features pcl_surface Qt5::Widgets)

QT5_WRAP_UI(pcd_video_player_ui src/pcd_video_player/pcd_video_player.ui)
QT5_WRAP_CPP(pcd_video_player_moc include/pcl/apps/pcd_video_player.h OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
PCL_ADD_EXECUTABLE(pcl_pcd_video_player COMPONENT ${SUBSYS_NAME} SOURCES ${pcd_video_player_ui} ${pcd_video_player_moc} src/pcd_video_player/pcd_video_player.cpp BUNDLE)
target_link_libraries(pcl_pcd_video_player pcl_common pcl_io pcl_visualization pcl_segmentation pcl_features pcl_surface ${QVTK_LIBRARY} Qt5::Widgets)
target_link_libraries(pcl_pcd_video_player pcl_common pcl_io pcl_visualization pcl_segmentation pcl_features pcl_surface Qt5::Widgets)
endif()

if(WITH_OPENNI)
Expand Down Expand Up @@ -137,18 +137,18 @@ if(VTK_FOUND)
PCL_ADD_EXECUTABLE(pcl_openni_face_detector COMPONENT ${SUBSYS_NAME} SOURCES src/face_detection//openni_face_detection.cpp src/face_detection//openni_frame_source.cpp BUNDLE)
target_link_libraries(pcl_openni_face_detector pcl_features pcl_recognition pcl_common pcl_io pcl_filters pcl_visualization pcl_segmentation pcl_sample_consensus pcl_surface pcl_keypoints pcl_ml pcl_search pcl_kdtree ${VTK_LIBRARIES})

if(Qt5_FOUND AND VTK_USE_QVTK)
if(Qt5_FOUND AND QVTK_FOUND)
# OpenNI Passthrough application demo
QT5_WRAP_UI(openni_passthrough_ui src/openni_passthrough.ui)
QT5_WRAP_CPP(openni_passthrough_moc include/pcl/apps/openni_passthrough.h OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
PCL_ADD_EXECUTABLE(pcl_openni_passthrough COMPONENT ${SUBSYS_NAME} SOURCES ${openni_passthrough_ui} ${openni_passthrough_moc} src/openni_passthrough.cpp)
target_link_libraries(pcl_openni_passthrough pcl_common pcl_io pcl_filters pcl_visualization ${QVTK_LIBRARY} Qt5::Widgets)
target_link_libraries(pcl_openni_passthrough pcl_common pcl_io pcl_filters pcl_visualization Qt5::Widgets)

# OpenNI Organized Connected Component application demo
QT5_WRAP_UI(organized_segmentation_demo_ui src/organized_segmentation_demo.ui)
QT5_WRAP_CPP(organized_segmentation_demo_moc include/pcl/apps/organized_segmentation_demo.h OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
PCL_ADD_EXECUTABLE(pcl_organized_segmentation_demo COMPONENT ${SUBSYS_NAME} SOURCES ${organized_segmentation_demo_ui} ${organized_segmentation_demo_moc} src/organized_segmentation_demo.cpp BUNDLE)
target_link_libraries(pcl_organized_segmentation_demo pcl_common pcl_io pcl_visualization pcl_segmentation pcl_features pcl_surface ${QVTK_LIBRARY} Qt5::Widgets)
target_link_libraries(pcl_organized_segmentation_demo pcl_common pcl_io pcl_visualization pcl_segmentation pcl_features pcl_surface Qt5::Widgets)
endif()

if(QHULL_FOUND)
Expand Down
4 changes: 2 additions & 2 deletions apps/cloud_composer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ elseif(NOT ${DEFAULT} STREQUAL "AUTO_OFF")
endif()

# QVTK?
if(NOT VTK_USE_QVTK)
if(NOT QVTK_FOUND)
set(DEFAULT AUTO_OFF)
set(REASON "Cloud composer requires QVTK")
elseif(NOT ${DEFAULT} STREQUAL "AUTO_OFF")
Expand Down Expand Up @@ -147,7 +147,7 @@ QT5_ADD_RESOURCES(resource_srcs ${resources})

set(EXE_NAME "pcl_${SUBSUBSYS_NAME}")
PCL_ADD_EXECUTABLE(${EXE_NAME} COMPONENT ${SUBSUBSYS_NAME} SOURCES ${cloud_composer_ui} ${cloud_composer_moc} ${srcs} ${resource_srcs} ${impl_incs})
target_link_libraries("${EXE_NAME}" pcl_cc_tool_interface pcl_common pcl_io pcl_visualization pcl_filters ${QVTK_LIBRARY} Qt5::Widgets)
target_link_libraries("${EXE_NAME}" pcl_cc_tool_interface pcl_common pcl_io pcl_visualization pcl_filters Qt5::Widgets)

# Install include files
PCL_ADD_INCLUDES("${SUBSUBSYS_NAME}" "${SUBSUBSYS_NAME}" ${incs} ${item_incs} ${selector_incs})
Expand Down
4 changes: 2 additions & 2 deletions apps/modeler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ elseif(NOT ${DEFAULT} STREQUAL "AUTO_OFF")
endif()

# QVTK?
if(NOT VTK_USE_QVTK)
if(NOT QVTK_FOUND)
set(DEFAULT AUTO_OFF)
set(REASON "VTK was not built with Qt support.")
elseif(NOT ${DEFAULT} STREQUAL "AUTO_OFF")
Expand Down Expand Up @@ -139,7 +139,7 @@ set_source_files_properties(${srcs} PROPERTIES OBJECT_DEPENDS "${ui_srcs}")
# Generate executable
set(EXE_NAME "pcl_${SUBSUBSYS_NAME}")
PCL_ADD_EXECUTABLE(${EXE_NAME} COMPONENT ${SUBSUBSYS_NAME} SOURCES ${ui_srcs} ${moc_srcs} ${resource_srcs} ${srcs} ${incs} ${impl_incs})
target_link_libraries("${EXE_NAME}" pcl_common pcl_io pcl_kdtree pcl_filters pcl_visualization pcl_segmentation pcl_surface pcl_features pcl_sample_consensus pcl_search ${QVTK_LIBRARY} Qt5::Widgets)
target_link_libraries("${EXE_NAME}" pcl_common pcl_io pcl_kdtree pcl_filters pcl_visualization pcl_segmentation pcl_surface pcl_features pcl_sample_consensus pcl_search Qt5::Widgets)

# Put the ui in the windows project file
if(("${CMAKE_BUILD_TOOL}" MATCHES "msdev") OR("${CMAKE_BUILD_TOOL}" MATCHES "devenv"))
Expand Down
15 changes: 0 additions & 15 deletions cmake/Modules/FindQVTK.cmake

This file was deleted.

2 changes: 0 additions & 2 deletions cuda/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, lib: ${VTK_LIBRARY_DIRS})")
include("${VTK_USE_FILE}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
endif()

Expand Down
2 changes: 0 additions & 2 deletions io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ if(LIBUSB_1_FOUND)
endif()

if(VTK_FOUND AND NOT ANDROID)
set(VTK_USE_FILE "${VTK_USE_FILE}" CACHE INTERNAL "VTK_USE_FILE")
include("${VTK_USE_FILE}")
set(VTK_IO_INCLUDES
"include/pcl/${SUBSYS_NAME}/vtk_lib_io.h"
"include/pcl/${SUBSYS_NAME}/png_io.h"
Expand Down
5 changes: 0 additions & 5 deletions surface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ if(QHULL_FOUND)
endif()

if(VTK_FOUND AND NOT ANDROID)
set(VTK_USE_FILE "${VTK_USE_FILE}" CACHE INTERNAL "VTK_USE_FILE")
include("${VTK_USE_FILE}")

set(VTK_SMOOTHING_INCLUDES
"include/pcl/${SUBSYS_NAME}/vtk_smoothing/vtk.h"
"include/pcl/${SUBSYS_NAME}/vtk_smoothing/vtk_utils.h"
Expand All @@ -48,8 +45,6 @@ if(VTK_FOUND AND NOT ANDROID)
src/vtk_smoothing/vtk_mesh_smoothing_laplacian.cpp
src/vtk_smoothing/vtk_mesh_smoothing_windowed_sinc.cpp
)

set(VTK_SMOOTHING_TARGET_LINK_LIBRARIES vtkCommonCore vtkCommonDataModel vtkCommonExecutionModel vtkFiltersModeling)
endif()

set(BUILD_surface_on_nurbs 0 CACHE BOOL "Fitting NURBS to point-clouds using openNURBS")
Expand Down
2 changes: 0 additions & 2 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
set(VTK_USE_FILE "${VTK_USE_FILE}" CACHE INTERNAL "VTK_USE_FILE")
include("${VTK_USE_FILE}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")

PCL_ADD_EXECUTABLE(pcl_png2pcd COMPONENT ${SUBSYS_NAME} SOURCES png2pcd.cpp)
Expand Down
2 changes: 0 additions & 2 deletions visualization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
set(VTK_USE_FILE "${VTK_USE_FILE}" CACHE INTERNAL "VTK_USE_FILE")
include("${VTK_USE_FILE}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
endif()

Expand Down