问题描述
我有一个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_directories
或target_include_directories
add_executable (HelloWorld ${source_files})
# Assuming this is meant to be a public directory
target_include_directories(HelloWorld PUBLIC "includes/")