如何为包含 CGAL 和 VTK 库的项目创建 CMakeLists.txt

How to create a CMakeLists.txt for a project containing CGAL and VTK libraries

我编写了一个用于评估科学数据(3D 表面网格)的小程序。我使用 vtk 库提供的函数进行所有几何计算。 vtkBooleanOperationPolyDataFilter 不够健壮,会随机崩溃。所以我决定用 cgal 库的函数执行布尔运算(用一些样本数据测试 -> 没有稳定性问题)。

现在我想将这两个项目合并在一起。

vtk 项目CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
PROJECT(calcporosity)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

add_executable(calcporosity MACOSX_BUNDLE calcporosity)

if(VTK_LIBRARIES)
  target_link_libraries(calcporosity ${VTK_LIBRARIES})

else()
  target_link_libraries(calcporosity vtkHybrid vtkWidgets)
endif()

cgal 项目CMakeLists.txt:

project( cgal_test )

cmake_minimum_required(VERSION 2.6.2) if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) cmake_policy(VERSION 2.8.4) else() cmake_policy(VERSION 2.6) endif() endif()

find_package(CGAL QUIET COMPONENTS Core )

if ( CGAL_FOUND )

include( ${CGAL_USE_FILE} )

include( CGAL_CreateSingleSourceCGALProgram )

include_directories (BEFORE "../../include")

include_directories (BEFORE "include")

create_single_source_cgal_program( "cgaltest.cpp" ) else()

message(STATUS "This program requires the CGAL library, and will not be compiled.")
endif()

我试图将其合并到文件中,但失败了。有人可以提示我如何为使用这两个库的项目创建适当的 CMakeLists.txt。

在此先致谢并致以最诚挚的问候!

P.s.: 我正在开发 Windows 平台

基本上需要做的是,您需要将包含目录和 link 库从您的两个依赖项提供到您的可执行文件。

cmake_minimum_required(VERSION 2.8.4)

project( cgal_vtk_test )

# Find CGAL
find_package(CGAL REQUIRED COMPONENTS Core) # If the dependency is required, use REQUIRED option - if it's not found CMake will issue an error
include( ${CGAL_USE_FILE} )

# Find VTK
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})


# Setup your executable
include_directories (BEFORE "../../include")
include_directories (BEFORE "include")

include( CGAL_CreateSingleSourceCGALProgram )
create_single_source_cgal_program( "cgal_vtk_test.cpp" ) # This will create an executable target with name 'cgal_vtk_test'

# Add VTK link libraries to your executable target
target_link_libraries(cgal_vtk_test ${VTK_LIBRARIES})