我正在尝试为我正在做的一个项目设置cmake,但是我有一个问题,我目前还不能解决。我的项目具有以下文件夹结构:
MotorEngine (root dir)
| CMakeLists.txt
| ThirdParty
|-| SDL2
|-|-| include (contains all header files for SDL2)
|-|-| lib
|-|-|-| x64
|-|-|-|-| SDL2.lib (the library file I need to link with)
| Source
|-| CMakeLists.txt
|-| main.cpp根CMakeLists.txt文件:
cmake_minimum_required(VERSION 2.6)
project(MotorEngine)
# Set an output directory for our binaries
set(BIN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Binaries)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Binaries)
set(THIRDPARTY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty)
# Include SDL2
include_directories(${THIRDPARTY_PATH}/SDL2/include)
# Add the engine + third party subdirectory
add_subdirectory(Source)来源的CMakeLists.txt:
project(MotorEngine)
add_executable(MotorEngine main.cpp)
target_link_libraries(MotorEngine ${THIRDPARTY_PATH}/SDL2/lib/x64/SDL2.lib)现在,我想实现以下目标,在我想要编写的main.cpp中
#include "SDL2/include/SDL2.h"但目前我不得不写
#include "SDL2.h"因为稍后会有同名的文件,所以我需要在它们的文件夹中区分它们。因此,最简单的方法是添加"ThirdParty“文件夹作为根目录,这样我就可以使用与此相关的#include,但要做的是
include_directories(${THIRDPARTY_PATH})不起作用。有什么想法吗?谢谢!
发布于 2018-01-29 02:14:23
在k.v.的帮助下,我能够解决这个问题。我需要在源目录的CMakeLists.txt中添加以下内容:
target_include_directories(MotorEngine PUBLIC ${THIRDPARTY_PATH})https://stackoverflow.com/questions/48488943
复制相似问题