Skip to content

Commit c35bbc6

Browse files
committed
Add note about CheckIncludeFiles
1 parent 80ad8e8 commit c35bbc6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

docs/cmake/cmake-code-style.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ecosystem.
4444

4545
CMake is quite lenient regarding code style, but applying consistency for
4646
writing CMake files can enhance both code quality and comprehension of the build
47-
system, especially when multiple developers are involved. Following some naming
47+
system, especially when multiple developers are involved. Following some coding
4848
conventions can maintain a clear and organized CMake project structure while
4949
avoiding conflicts with external libraries and CMake scope.
5050

@@ -195,8 +195,18 @@ these variables become distinct.
195195

196196
### 2.3. Check modules
197197

198-
Use `check_compiler_flag()`, `check_source_compiles()`, `check_source_runs()`
199-
instead of language-specific `check_<LANG>_...()`.
198+
* Use `check_compiler_flag()`, `check_source_compiles()`, `check_source_runs()`
199+
instead of language-specific `check_<LANG>_...()`.
200+
201+
* For checking header files, use `CheckIncludeFiles` module instead of
202+
`CheckIncludeFile` or `CheckIncludeFileCXX`. It simplifies and unifies
203+
checking single or multiple headers into a common usage across the code.
204+
205+
```cmake
206+
include(CheckIncludeFiles)
207+
check_include_files(sys/types.h HAVE_SYS_TYPES_H)
208+
check_include_files("sys/socket.h;net/if.h" HAVE_NET_IF_H)
209+
```
200210

201211
## 3. Variables
202212

0 commit comments

Comments
 (0)