具有使用要求的Cmake项目

时间:2014-08-03 23:52:41

标签: linux cmake

我目前正在尝试使用以下结构设置C ++项目:

GUI
| CMakeLists.txt
| deps/
| | src/
| | install/
| src/
| | GLWindows/
| | | GLWindow.h
| | RocketShell/
| | | CMakeLists.txt
| | | RocketShell.h
| | | RocketShell.cpp
| | | ShellInterfaces/

我的想法是将RocketShell构建为库,然后将其链接到顶级CMakelists文件中添加的可执行文件。请注意,我还使用deps目录来存储,编译和安装项目的依赖项。我的一些依赖项例如是:boost,glfw,libRocket。

我正在尝试通过RocketShelltarget_include_directoriestarget_link_libraries使用相应的target_compile_options模式,让PUBLIC目标导出其使用要求。

问题是没有导出要求。顶级CMakeLists文件能够创建和使用RocketShell目标,但无法看到导出的变量。

我正在尝试在"现代"中进行项目配置。办法。我刚开始学习cmake,所以如果你能指出我正确的方向,我将不胜感激。感谢。

顶部CMakeLists.txt

cmake_minimum_required (VERSION 3.0) 
project(GUI)

set(DEPS_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/deps/install CACHE PATH "Installation directory's prefix for the dependencies")

add_subdirectory(${PROJECT_SOURCE_DIR}/src/RocketShell)

link_directories(${DEPS_INSTALL_PREFIX}/lib)

add_executable(GUI src/main.cpp src/GLWindows/GLFWWindow.h src/GLWindows/GLFWWindow.cpp)
target_link_libraries(GUI RocketShell)

RocketShell CMakeLists.txt文件

cmake_minimum_required(VERSION 3.0)

project (RocketShell VERSION 0.1 LANGUAGES C CXX)

# find GLFW
include(${DEPS_INSTALL_PREFIX}/lib/cmake/glfw/glfwConfig.cmake)
link_directories(${DEPS_INSTALL_PREFIX}/lib)

file(GLOB ${PROJECT_NAME}_SRCS ${PROJECT_SOURCE_DIR}/ShellInterfaces/*.cpp)
list(APPEND ${PROJECT_NAME}_SRCS ${PROJECT_SOURCE_DIR}/RocketShell.cpp)

add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SRCS})

target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/RocketShell> $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/RocketShell>)
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/RocketShell/ShellInterfaces)
target_include_directories(${PROJECT_NAME} PRIVATE ${DEPS_INSTALL_PREFIX}/include)


target_link_libraries(${PROJECT_NAME} PUBLIC glfw ${OPENGL_glu_LIBRARY} ${GLFW_LIBRARIES} ${GLEW_LIBRARIES}
   boost_thread boost_system boost_log boost_log_setup boost_filesystem GLEW GL
    RocketControls RocketCore RocketDebugger)

target_compile_options(${PROJECT_NAME} PRIVATE -DBOOST_LOG_DYN_LINK -std=c++0x)

解决方案

问题在于我没有导出-DBOOST_LOG_DYN_LINK定义,因此GUI目标无法链接到boost_log。传递使用要求传播就像一个魅力。 要解决此问题,请在RocketShell子目录CMakeLists文件的以下行中将PRIVATE替换为PUBLIC

target_compile_options(${PROJECT_NAME} PRIVATE -DBOOST_LOG_DYN_LINK -std=c++0x)

0 个答案:

没有答案