From 41519e30104fd6fbfbc178f18230a9fa7fd59076 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Thu, 9 Apr 2020 13:40:19 +0200 Subject: [PATCH] Proposal for imported targets --- .../cmake/modules/CGAL_Eigen_support.cmake | 9 ++ .../cmake/modules/CGAL_LASLIB_support.cmake | 7 + .../cmake/modules/CGAL_OpenGR_support.cmake | 6 + .../cmake/modules/CGAL_TBB_support.cmake | 10 ++ .../modules/CGAL_pointmatcher_support.cmake | 7 + .../Point_set_processing_3/CMakeLists.txt | 129 ++++++++---------- 6 files changed, 97 insertions(+), 71 deletions(-) create mode 100644 Installation/cmake/modules/CGAL_Eigen_support.cmake create mode 100644 Installation/cmake/modules/CGAL_LASLIB_support.cmake create mode 100644 Installation/cmake/modules/CGAL_OpenGR_support.cmake create mode 100644 Installation/cmake/modules/CGAL_TBB_support.cmake create mode 100644 Installation/cmake/modules/CGAL_pointmatcher_support.cmake diff --git a/Installation/cmake/modules/CGAL_Eigen_support.cmake b/Installation/cmake/modules/CGAL_Eigen_support.cmake new file mode 100644 index 00000000000..31e5f22abf5 --- /dev/null +++ b/Installation/cmake/modules/CGAL_Eigen_support.cmake @@ -0,0 +1,9 @@ +if(Eigen_FOUND AND NOT TARGET CGAL::Eigen_support) + if(NOT TARGET Threads::Threads) + find_package(Threads REQUIRED) + endif() + add_library(CGAL::Eigen_support INTERFACE IMPORTED) + set_target_properties(CGAL::Eigen_support PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "CGAL_EIGEN3_ENABLED" + INTERFACE_INCLUDE_DIRECTORIES "${EIGEN3_INCLUDE_DIR}") +endif() diff --git a/Installation/cmake/modules/CGAL_LASLIB_support.cmake b/Installation/cmake/modules/CGAL_LASLIB_support.cmake new file mode 100644 index 00000000000..6b1f6cbb58a --- /dev/null +++ b/Installation/cmake/modules/CGAL_LASLIB_support.cmake @@ -0,0 +1,7 @@ +if(LASLIB_FOUND AND NOT TARGET CGAL::LASLIB_support) + add_library(CGAL::LASLIB_support INTERFACE IMPORTED) + set_target_properties(CGAL::LASLIB_support PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "CGAL_LINKED_WITH_LASLIB" + INTERFACE_INCLUDE_DIRECTORIES "${LASLIB_INCLUDE_DIR};${LASZIP_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${LASLIB_LIBRARIES}") +endif() diff --git a/Installation/cmake/modules/CGAL_OpenGR_support.cmake b/Installation/cmake/modules/CGAL_OpenGR_support.cmake new file mode 100644 index 00000000000..227dda5ec57 --- /dev/null +++ b/Installation/cmake/modules/CGAL_OpenGR_support.cmake @@ -0,0 +1,6 @@ +if(OpenGR_FOUND AND NOT TARGET CGAL::OpenGR_support) + add_library(CGAL::OpenGR_support INTERFACE IMPORTED) + set_target_properties(CGAL::OpenGR_support PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "CGAL_LINKED_WITH_OPENGR" + INTERFACE_INCLUDE_DIRECTORIES "${OpenGR_INCLUDE_DIR}") +endif() diff --git a/Installation/cmake/modules/CGAL_TBB_support.cmake b/Installation/cmake/modules/CGAL_TBB_support.cmake new file mode 100644 index 00000000000..e34882e949c --- /dev/null +++ b/Installation/cmake/modules/CGAL_TBB_support.cmake @@ -0,0 +1,10 @@ +if(TBB_FOUND AND NOT TARGET CGAL::TBB_support) + if(NOT TARGET Threads::Threads) + find_package(Threads REQUIRED) + endif() + add_library(CGAL::TBB_support INTERFACE IMPORTED) + set_target_properties(CGAL::TBB_support PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "CGAL_LINKED_WITH_TBB;NOMINMAX" + INTERFACE_INCLUDE_DIRECTORIES "${TBB_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "TBB:tbb;TBB:tbbmalloc;Threads::Threads") +endif() diff --git a/Installation/cmake/modules/CGAL_pointmatcher_support.cmake b/Installation/cmake/modules/CGAL_pointmatcher_support.cmake new file mode 100644 index 00000000000..c023102661f --- /dev/null +++ b/Installation/cmake/modules/CGAL_pointmatcher_support.cmake @@ -0,0 +1,7 @@ +if(libpointmatcher_FOUND AND NOT TARGET CGAL::pointmatcher_support) + add_library(CGAL::pointmatcher_support INTERFACE IMPORTED) + set_target_properties(CGAL::pointmatcher_support PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "CGAL_LINKED_WITH_POINTMATCHER" + INTERFACE_INCLUDE_DIRECTORIES "${libpointmatcher_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${libpointmatcher_LIBRARIES}") +endif() diff --git a/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt b/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt index 36412ac7b68..318f6a91e0c 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt +++ b/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt @@ -31,114 +31,101 @@ if ( CGAL_FOUND ) "Enable concurrency" OFF) + set(CGAL_libs CGAL::CGAL) if( CGAL_ACTIVATE_CONCURRENT_PSP3 OR ENV{CGAL_ACTIVATE_CONCURRENT_PSP3} ) find_package( TBB REQUIRED ) + include(CGAL_TBB_support) + if (TARGET CGAL::TBB_support) + set(CGAL_TBB_target ${CGAL_libs} CGAL::TBB_support) + endif() endif() # Executables that do *not* require EIGEN - create_single_source_cgal_program( "average_spacing_example.cpp" ) - create_single_source_cgal_program( "bilateral_smooth_point_set_example.cpp" ) - create_single_source_cgal_program( "grid_simplification_example.cpp" ) - create_single_source_cgal_program( "grid_simplify_indices.cpp" ) - create_single_source_cgal_program( "property_map.cpp" ) - create_single_source_cgal_program( "random_simplification_example.cpp" ) - create_single_source_cgal_program( "read_write_xyz_point_set_example.cpp" ) - create_single_source_cgal_program( "remove_outliers_example.cpp" ) - create_single_source_cgal_program( "wlop_simplify_and_regularize_point_set_example.cpp" ) - create_single_source_cgal_program( "edge_aware_upsample_point_set_example.cpp" ) - create_single_source_cgal_program( "structuring_example.cpp" ) - - create_single_source_cgal_program( "read_ply_points_with_colors_example.cpp" ) - create_single_source_cgal_program( "write_ply_points_example.cpp" ) + foreach(target + average_spacing_example + bilateral_smooth_point_set_example + grid_simplification_example + grid_simplify_indices + property_map + random_simplification_example + read_write_xyz_point_set_example + remove_outliers_example + wlop_simplify_and_regularize_point_set_example + edge_aware_upsample_point_set_example + structuring_example + read_ply_points_with_colors_example + write_ply_points_example) + add_executable(${target} "${target}.cpp") + target_link_libraries(${target} ${CGAL_libs}) + endforeach() find_package(LASLIB) - if (LASLIB_FOUND) - create_single_source_cgal_program( "read_las_example.cpp" ) - CGAL_target_use_LASLIB(read_las_example) + include(CGAL_LASLIB_support) + if (TARGET CGAL::LASLIB_support) + add_executable( read_las_example "read_las_example.cpp" ) + target_link_libraries(read_las_example ${CGAL_libs} CGAL::LASLIB_support) else() message(STATUS "NOTICE : the LAS reader test requires LASlib and will not be compiled.") endif() # Use Eigen find_package(Eigen3 3.1.0) #(requires 3.1.0 or greater) - if (EIGEN3_FOUND) + include(CGAL_Eigen_support) + if (TARGET CGAL::Eigen_support) + set(CGAL_libs ${CGAL_libs} CGAL::Eigen_support) + # Executables that require Eigen - create_single_source_cgal_program( "jet_smoothing_example.cpp" ) - CGAL_target_use_Eigen(jet_smoothing_example) + foreach(target + jet_smoothing_example + normal_estimation + edges_example - create_single_source_cgal_program( "normal_estimation.cpp" ) - CGAL_target_use_Eigen(normal_estimation) - - create_single_source_cgal_program( "edges_example.cpp" ) + callback_example + scale_estimation_example + scale_estimation_2d_example + hierarchy_simplification_example + normals_example) + add_executable(${target} "${target}.cpp") + target_link_libraries(${target} ${CGAL_libs}) + endforeach() # Executables that require libpointmatcher find_package(libpointmatcher QUIET) - if (libpointmatcher_FOUND) - create_single_source_cgal_program( "registration_with_pointmatcher.cpp" ) - CGAL_target_use_pointmatcher(registration_with_pointmatcher) - CGAL_target_use_Eigen(registration_with_pointmatcher) + include(CGAL_pointmatcher_support) + if (TARGET CGAL::pointmatcher_support) + add_executable(registration_with_pointmatcher "registration_with_pointmatcher.cpp") + target_link_libraries(registration_with_pointmatcher + ${CGAL_libs} CGAL::pointmatcher_support) else() message(STATUS "NOTICE : the registration_with_pointmatcher test requires libpointmatcher and will not be compiled.") endif() # Executables that require OpenGR find_package(OpenGR QUIET) - if (OpenGR_FOUND) - create_single_source_cgal_program( "registration_with_OpenGR.cpp" ) - CGAL_target_use_OpenGR(registration_with_OpenGR) - CGAL_target_use_Eigen(registration_with_OpenGR) + include(CGAL_OpenGR_support) + if (TARGET CGAL::OpenGR_support) + add_executable(registration_with_OpenGR "registration_with_OpenGR.cpp" ) + target_link_libraries(registration_with_OpenGR + ${CGAL_libs} CGAL::OpenGR_support) else() message(STATUS "NOTICE : registration_with_OpenGR requires OpenGR, and will not be compiled.") endif() # Executables that require both libpointmatcher and OpenGR - if (libpointmatcher_FOUND AND OpenGR_FOUND) - create_single_source_cgal_program( "registration_with_opengr_pointmatcher_pipeline.cpp" ) - CGAL_target_use_OpenGR(registration_with_opengr_pointmatcher_pipeline) - CGAL_target_use_pointmatcher(registration_with_opengr_pointmatcher_pipeline) - CGAL_target_use_Eigen(registration_with_opengr_pointmatcher_pipeline) + if (TARGET CGAL::pointmatcher_support AND + TARGET CGAL::OpenGR_support) + add_executable(registration_with_opengr_pointmatcher_pipeline + "registration_with_opengr_pointmatcher_pipeline.cpp" ) + target_link_libraries(registration_with_opengr_pointmatcher_pipeline + ${CGAL_libs} CGAL::pointmatcher_support CGAL::OpenGR_support) else() message(STATUS "NOTICE : registration_with_opengr_pointmatcher_pipeline requires libpointmatcher and OpenGR, and will not be compiled.") endif() - CGAL_target_use_Eigen(edges_example) - - create_single_source_cgal_program( "callback_example.cpp" ) - CGAL_target_use_Eigen(callback_example) - - create_single_source_cgal_program( "scale_estimation_example.cpp" ) - CGAL_target_use_Eigen(scale_estimation_example) - - create_single_source_cgal_program( "scale_estimation_2d_example.cpp" ) - CGAL_target_use_Eigen(scale_estimation_2d_example) - - create_single_source_cgal_program( "hierarchy_simplification_example.cpp" ) - CGAL_target_use_Eigen(hierarchy_simplification_example) - - create_single_source_cgal_program( "normals_example.cpp" ) - CGAL_target_use_Eigen(normals_example) - else() message(STATUS "NOTICE: Some of the executables in this directory need Eigen 3.1 (or greater) and will not be compiled.") endif() - if (TBB_FOUND) - foreach(target - scale_estimation_example - wlop_simplify_and_regularize_point_set_example - bilateral_smooth_point_set_example - edge_aware_upsample_point_set_example - average_spacing_example - normals_example - jet_smoothing_example - normal_estimation - callback_example) - if(TARGET ${target}) - CGAL_target_use_TBB(${target}) - endif() - endforeach() - endif() - else() message(STATUS "NOTICE: This program requires the CGAL library, and will not be compiled.") endif()