久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 CMake 正確添加包含目錄

How to properly add include directories with CMake(如何使用 CMake 正確添加包含目錄)
本文介紹了如何使用 CMake 正確添加包含目錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

大約一年前,我詢問了 CMake 中的標頭依賴項.

About a year ago I asked about header dependencies in CMake.

我最近意識到問題似乎是 CMake 認為這些頭文件是項目的外部.至少,在生成 Code::Blocks 項目時,頭文件不會出現在項目中(源文件會出現).因此,在我看來,CMake 認為這些標頭是項目的外部,并且不會在依賴項中跟蹤它們.

I realized recently that the issue seemed to be that CMake considered those header files to be external to the project. At least, when generating a Code::Blocks project the header files do not appear within the project (the source files do). It therefore seems to me that CMake consider those headers to be external to the project, and does not track them in the depends.

在 CMake 教程中的快速搜索僅指向 include_directories 這似乎沒有做我希望的......

A quick search in the CMake tutorial only pointed to include_directories which does not seem to do what I wish...

向 CMake 表明特定目錄包含要包含的頭文件,并且這些頭文件應由生成的 Makefile 跟蹤的正確方法是什么?

What is the proper way to signal to CMake that a particular directory contains headers to be included, and that those headers should be tracked by the generated Makefile?

推薦答案

必須做兩件事.

首先添加要包含的目錄:

First add the directory to be included:

target_include_directories(test PRIVATE ${YOUR_DIRECTORY})

如果您堅持使用不支持 target_include_directories 的非常舊的 CMake 版本(2.8.10 或更早版本),您也可以改用舊的 include_directories:

In case you are stuck with a very old CMake version (2.8.10 or older) without support for target_include_directories, you can also use the legacy include_directories instead:

include_directories(${YOUR_DIRECTORY})

然后您還必須將頭文件添加到當前目標的源文件列表中,例如:

Then you also must add the header files to the list of your source files for the current target, for instance:

set(SOURCES file.cpp file2.cpp ${YOUR_DIRECTORY}/file1.h ${YOUR_DIRECTORY}/file2.h)
add_executable(test ${SOURCES})

這樣,頭文件將作為依賴項出現在 Makefile 中,例如在生成的 Visual Studio 項目中(如果生成的話).

This way, the header files will appear as dependencies in the Makefile, and also for example in the generated Visual Studio project, if you generate one.

如何將這些頭文件用于多個目標:

How to use those header files for several targets:

set(HEADER_FILES ${YOUR_DIRECTORY}/file1.h ${YOUR_DIRECTORY}/file2.h)

add_library(mylib libsrc.cpp ${HEADER_FILES})
target_include_directories(mylib PRIVATE ${YOUR_DIRECTORY})
add_executable(myexec execfile.cpp ${HEADER_FILES})
target_include_directories(myexec PRIVATE ${YOUR_DIRECTORY})

這篇關于如何使用 CMake 正確添加包含目錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What do compilers do with compile-time branching?(編譯器如何處理編譯時分支?)
Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 嗎?)
Checking for NULL pointer in C/C++(在 C/C++ 中檢查空指針)
Math-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比較運算符的數學式鏈接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之間的區別與“if())
C++, variable declaration in #39;if#39; expression(C++,if 表達式中的變量聲明)
主站蜘蛛池模板: 国产精品一区二区三区久久 | 亚洲成人免费观看 | 国产精品色婷婷久久58 | 福利视频一区二区三区 | 91精品久久久久久久久中文字幕 | 免费观看黄色片视频 | 99福利在线观看 | 久久久久久久一区二区 | 日韩欧美久久精品 | 欧美激情精品久久久久久变态 | 国产精品毛片久久久久久久 | 成人在线免费av | 日韩国产欧美一区 | 亚洲精品 在线播放 | 亚洲第一区久久 | 色噜噜狠狠色综合中国 | 日韩成人在线播放 | 天堂亚洲 | 天天躁日日躁aaaa视频 | 就操在线 | 欧美日韩中文国产一区发布 | 国产乱码一二三区精品 | 国产一区精品在线 | 伊人久久大香线 | 欧美三级免费观看 | 天天躁日日躁狠狠躁白人 | 亚洲成人999 | 成人国产精品免费观看 | 国产高清一区二区 | 国产精品免费看 | 成人免费福利 | 欧美精品久久 | 黄色网址免费在线观看 | 精品国产高清一区二区三区 | 亚洲一区视频 | 91精品国产91 | 亚洲成人综合在线 | 一区二区精品视频 | 亚洲日日 | 最新中文字幕久久 | www.久久久|