将 headers 添加到 Cmake
Adding headers to Cmake
我正在尝试 运行 来自 VTK 的示例并修改它们以获得我想要在屏幕上呈现的内容。
我目前正在尝试添加一个与 VTK 渲染并行的服务器应用程序 运行ning。我已经为服务器编写了代码,但我想知道如何将这些 headers 和 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 文件并尝试生成时出现以下错误,所以我猜我对 headers 的集成不正确。
C:\...\RotateActor.cxx(12): fatal error C1083: Impossible d'ouvrir le fichier include : 'tcp_server.h' : No such file or directory
我认为您不需要 RotateActor.cxx 文件,但如果需要请告诉我。
在此先感谢您的帮助。
我发现您的 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})
我正在尝试 运行 来自 VTK 的示例并修改它们以获得我想要在屏幕上呈现的内容。 我目前正在尝试添加一个与 VTK 渲染并行的服务器应用程序 运行ning。我已经为服务器编写了代码,但我想知道如何将这些 headers 和 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 文件并尝试生成时出现以下错误,所以我猜我对 headers 的集成不正确。
C:\...\RotateActor.cxx(12): fatal error C1083: Impossible d'ouvrir le fichier include : 'tcp_server.h' : No such file or directory
我认为您不需要 RotateActor.cxx 文件,但如果需要请告诉我。
在此先感谢您的帮助。
我发现您的 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})