我如何将目录中的头文件包含到cmake中

问题描述

我有一个cmake文件,该文件生成了我的helloworld.workspace。我如何获取我的cmake包含目录和外部库示例中的头文件-glfw3就像我通常直接使用gcc时的用法一样。注意:我在使用ubuntu。任何帮助表示赞赏。

CMakeLists.txt

cmake_minimum_required (VERSION 3.5)

project (HelloWorld)

set (CMAKE_CXX_fLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++14")
set (source_dir "${PROJECT_SOURCE_DIR}/src/")

add_executable (HelloWorld ${source_files})

build.sh(运行cmake)

#!/bin/sh

cmake . -G "CodeLite - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug

我的文件夹看起来像这样

-HelloWorldProject
   -CMakeLists.txt
   -build.sh
   -src
      -main.cpp
   -includes
      -(heres where i will put my .h and .cpp includes)

解决方法

您需要告诉CMake将includes/添加到程序的包含路径。通常,这是通过include_directoriestarget_include_directories

完成的
add_executable (HelloWorld ${source_files})

# Assuming this is meant to be a public directory
target_include_directories(HelloWorld PUBLIC "includes/")

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...