0

我把某个header.h文件放进去project/include/subfolder1

other.cpp并在另一个子文件夹中输入以下内容2

#include "../subfolder1/header.h"

但我希望通过 CMake 删除../subfolder1/in#include使它像这样:

#include "header.h"

但我是 CMake 的新手,我需要一些提示,任何帮助都很大。

以下是我的 cmakelist.txt project

macro(addAllSubDirectory rootDir)
    FILE(GLOB children RELATIVE ${CMAKE_SOURCE_DIR}/${rootDir} ${CMAKE_SOURCE_DIR}/${rootDir}/*)
    foreach(child ${children})
        if(IS_DIRECTORY ./${rootDir}/${child})
            add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${rootDir}/${child})
            addAllSubDirectory(${rootDir}/${child})
        else()
            message("include ./${rootDir}/${child} Success.")
        endif()
    endforeach()
endmacro()

#===============================
# Init Project
#===============================
project(testProject)
cmake_minimum_required(VERSION 3.19)
set(CMAKE_CXX_STANDARD 14)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})

#===============================
# include
#===============================
addAllSubDirectory(appsMgr)
addAllSubDirectory(ctrlBase)
4

0 回答 0