所以我想要包含一个位于不同文件夹中的全局头文件。 CMakeList.txt的代码如下。在我的.cpp中,当我包含来自本地包含文件夹的内容时,它可以正常工作,但不适用于不同文件夹中的内容。
cmake_minimum_required(VERSION 2.8)
#Project name
project(Server-Client)
#Add all cpp files as source files
file(GLOB_RECURSE SOURCES "src/*.cpp")
#Build executable 'Server' with all files in SOURCES
add_executable(Server ${SOURCES})
#Include all files in include directory
include_directories("include")
target_include_directories(Server PUBLIC "../../GlobalFiles/include")
find_package(Threads REQUIRED)
#Build executable 'localization' with all files in SOURCES
target_link_libraries(Server ${CMAKE_THREAD_LIBS_INIT})
答案 0 :(得分:3)
不要使用相对路径,而是使用CMAKE_CURRENT_SOURCE_DIR变量,如下所示:
target_include_directories(Server PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../GlobalFiles/include")
除此之外,使用宏来查找您正在寻找的全局标题可能是个好主意。