我正在尝试从VTK运行示例并修改它们以获得我想要在屏幕上呈现的内容。 我目前正在尝试添加与VTK渲染并行运行的服务器应用程序。我已经为服务器编写了代码,但我想知道如何将这些头文件和cpp添加到CMakeLists.txt。
确实,这是我到目前为止的CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
PROJECT(RotateActor)
option(INCLUDE_SERVER
"Use the server implementation" ON)
# add the Server library?
if (INCLUDE_SERVER)
include_directories({${CMAKE_CURRENT_SOURCE_DIR}/Server/})
set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Server/tcp_server.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Server/tcp_server.h)
endif (INCLUDE_SERVER)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(RotateActor MACOSX_BUNDLE RotateActor ${SOURCES})
if(VTK_LIBRARIES)
target_link_libraries(RotateActor ${VTK_LIBRARIES})
else()
target_link_libraries(RotateActor vtkHybrid vtkWidgets)
endif()
然后我使用CMake和VS2012生成。打开sln文件并尝试生成时,我收到以下错误,因此我猜测我的标题集成是不正确的。
C:\...\RotateActor.cxx(12): fatal error C1083: Impossible d'ouvrir le fichier include : 'tcp_server.h' : No such file or directory
我认为您不需要RotateActor.cxx文件,但如果您确实让我知道。
提前感谢您的帮助。
答案 0 :(得分:1)
我在你的CMake文件中看到了一些问题。首先,您的*.h
文件不会在add_executable
命令中给出。尝试类似的东西:
cmake_minimum_required(VERSION 2.8)
project(RotateActor)
option(INCLUDE_SERVER "Use the server implementation" ON)
# Manage your libraries before your sources
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
# add the Server library ?
# Here, maybe use the path from the root, and not from the local dir ?
# Don't add the .h in the sources
if(INCLUDE_SERVER)
include_directories({${CMAKE_SOURCE_DIR}/Server})
set(RotateActor_CPP_SOURCES
${RotateActor_CPP_SOURCES}
${CMAKE_SOURCE_DIR}/Server/tcp_server.cpp
)
endif()
if(NOT VTK_LIBRARIES)
set(VTK_LIBRARIES vtkHybrid vtkWidgets)
endif()
add_executable(RotateActor ${RotateActor_CPP_SOURCES})
target_link_libraries(RotateActor ${VTK_LIBRARIES})