... | ... | @@ -49,12 +49,14 @@ CMakeLists.txt. CMake comes with several modules for checking the |
|
|
system, they all follow the same style, as an example here
|
|
|
CHECK_INCLUDE_FILES:
|
|
|
|
|
|
INCLUDE (CheckIncludeFiles)
|
|
|
# usage: CHECK_INCLUDE_FILES (<header> <RESULT_VARIABLE> )
|
|
|
```cmake
|
|
|
INCLUDE (CheckIncludeFiles)
|
|
|
# usage: CHECK_INCLUDE_FILES (<header> <RESULT_VARIABLE> )
|
|
|
|
|
|
CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
|
|
|
CHECK_INCLUDE_FILES ("sys/param.h;sys/mount.h" HAVE_SYS_MOUNT_H)
|
|
|
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
|
|
CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
|
|
|
CHECK_INCLUDE_FILES ("sys/param.h;sys/mount.h" HAVE_SYS_MOUNT_H)
|
|
|
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
|
|
```
|
|
|
|
|
|
The CMake module CheckIncludeFiles offers the command
|
|
|
CHECK_INCLUDE_FILES(). The first argument to this command is the
|
... | ... | @@ -118,48 +120,32 @@ configure header in the subdirectory `foo/` and `config-bar.h` in the |
|
|
The other commands coming with cmake to do system checks follow this
|
|
|
style, so we can handle them much shorter now.
|
|
|
|
|
|
-----
|
|
|
|
|
|
- Module: INCLUDE (CheckIncludeFiles)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Usage: CHECK_INCLUDE_FILES(headers variable)
|
|
|
## System Introspection Functions
|
|
|
|
|
|
<!-- end list -->
|
|
|
-----
|
|
|
|
|
|
- Example: CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)
|
|
|
- Module: `INCLUDE(CheckIncludeFiles)`
|
|
|
- Usage: `CHECK_INCLUDE_FILES(headers variable)`
|
|
|
- Example: `CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)`
|
|
|
|
|
|
As just discussed at length, this can be used to check for the existence
|
|
|
of a header.
|
|
|
|
|
|
-----
|
|
|
|
|
|
- Module: INCLUDE (CheckFunctionExists)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Usage: CHECK_FUNCTION_EXISTS(function variable)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Example: CHECK_FUNCTION_EXISTS(madvise HAVE_MADVISE)
|
|
|
- Module: `INCLUDE(CheckFunctionExists)`
|
|
|
- Usage: `CHECK_FUNCTION_EXISTS(function variable)`
|
|
|
- Example: `CHECK_FUNCTION_EXISTS(madvise HAVE_MADVISE)`
|
|
|
|
|
|
Checks whether the given function exists. This is done by linking a
|
|
|
small program, which may not result in undefined references.
|
|
|
|
|
|
-----
|
|
|
|
|
|
- Module: INCLUDE (CheckSymbolExists)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Usage: CHECK_SYMBOL_EXISTS(symbol headers variable)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Example: CHECK_SYMBOL_EXISTS((LC_MESSAGES "locale.h"
|
|
|
HAVE_LC_MESSAGES)
|
|
|
- Module: `INCLUDE (CheckSymbolExists)`
|
|
|
- Usage: `CHECK_SYMBOL_EXISTS(symbol headers variable)`
|
|
|
- Example: `CHECK_SYMBOL_EXISTS((LC_MESSAGES "locale.h"
|
|
|
HAVE_LC_MESSAGES)`
|
|
|
|
|
|
Checks whether the given symbol exists if the specified headers are
|
|
|
included. "Symbol" is defined as something that is either a preprocessor
|
... | ... | @@ -168,16 +154,10 @@ values of a C enumeration. |
|
|
|
|
|
-----
|
|
|
|
|
|
- Module: INCLUDE (CheckLibraryExists)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Usage: CHECK_LIBRARY_EXISTS(library function location variable)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Example: CHECK_LIBRARY_EXISTS(volmgt volmgt_running ""
|
|
|
HAVE_VOLMGT)
|
|
|
- Module: `INCLUDE (CheckLibraryExists)`
|
|
|
- Usage: `CHECK_LIBRARY_EXISTS(library function location variable)`
|
|
|
- Example: `CHECK_LIBRARY_EXISTS(volmgt volmgt_running ""
|
|
|
HAVE_VOLMGT)`
|
|
|
|
|
|
Checks whether the given library exists and contains the given function.
|
|
|
This is done by linking a small program which uses the function and
|
... | ... | @@ -186,19 +166,20 @@ directory (-Ldir) can be given if required. |
|
|
|
|
|
-----
|
|
|
|
|
|
- Module: INCLUDE (CheckTypeSize)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Usage: SET(CMAKE_EXTRA_INCLUDE_FILES header)
|
|
|
CHECK_TYPE_SIZE(type variable)
|
|
|
SET(CMAKE_EXTRA_INCLUDE_FILES)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Example: SET(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
|
|
|
CHECK_TYPE_SIZE("struct ucred" STRUCT_UCRED)
|
|
|
SET(CMAKE_EXTRA_INCLUDE_FILES)
|
|
|
- Module: `INCLUDE(CheckTypeSize)`
|
|
|
- Usage:
|
|
|
```cmake
|
|
|
SET(CMAKE_EXTRA_INCLUDE_FILES header)
|
|
|
CHECK_TYPE_SIZE(type variable)
|
|
|
SET(CMAKE_EXTRA_INCLUDE_FILES)
|
|
|
```
|
|
|
|
|
|
- Example:
|
|
|
```cmake
|
|
|
SET(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
|
|
|
CHECK_TYPE_SIZE("struct ucred" STRUCT_UCRED)
|
|
|
SET(CMAKE_EXTRA_INCLUDE_FILES)
|
|
|
```
|
|
|
|
|
|
Checks whether the specified type exists and returns the size of the
|
|
|
type. In the variable the size of the type will be returned,
|
... | ... | @@ -208,21 +189,14 @@ CMAKE_EXTRA_INCLUDE_FILES to the required headers for this type, and |
|
|
you should reset it after calling CHECK_TYPE_SIZE. If you are not
|
|
|
really interested in the size of the type, but only whether it exists or
|
|
|
not, you can also use STRUCT_UCRED directly, if the type doesn't exist,
|
|
|
it will be empty and so also evaluate to FALSE (as will
|
|
|
HAVE_STRUCT_UCRED).
|
|
|
it will be empty and so also evaluate to FALSE.
|
|
|
|
|
|
-----
|
|
|
|
|
|
- Module: INCLUDE (CheckPrototypeExists)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Usage: CHECK_PROTOTYPE_EXISTS(function headers variable)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Example: CHECK_PROTOTYPE_EXISTS(mkstemps "stdlib.h;unistd.h"
|
|
|
HAVE_MKSTEMPS_PROTO)
|
|
|
- Module: `INCLUDE(CheckPrototypeExists)`
|
|
|
- Usage: `CHECK_PROTOTYPE_EXISTS(function headers variable)`
|
|
|
- Example: `CHECK_PROTOTYPE_EXISTS(mkstemps "stdlib.h;unistd.h"
|
|
|
HAVE_MKSTEMPS_PROTO)`
|
|
|
|
|
|
Checks whether the *headers* provide the declaration for the given
|
|
|
*function*, i.e. it does not check whether using *function* will lead to
|
... | ... | @@ -230,19 +204,11 @@ undefined references. |
|
|
|
|
|
-----
|
|
|
|
|
|
- Module: INCLUDE (CheckCXXSourceCompiles)
|
|
|
INCLUDE (CheckCSourceCompiles)
|
|
|
|
|
|
<!-- end list -->
|
|
|
|
|
|
- Usage: CHECK_CXX_SOURCE_COMPILES(source variable)
|
|
|
CHECK_C_SOURCE_COMPILES(source variable)
|
|
|
- Module: `INCLUDE(CheckCXXSourceCompiles)`, `INCLUDE(CheckCSourceCompiles)`
|
|
|
- Usage: `CHECK_CXX_SOURCE_COMPILES(source variable)`, `CHECK_C_SOURCE_COMPILES(source variable)`
|
|
|
|
|
|
Checks whether the code given in *source* will compile and link. You can
|
|
|
set CMAKE_REQUIRED_LIBRARIES, CMAKE_REQUIRED_FLAGS and
|
|
|
CMAKE_REQUIRED_INCLUDES accordingly if additional libraries or
|
|
|
set `CMAKE_REQUIRED_LIBRARIES`, `CMAKE_REQUIRED_FLAGS` and
|
|
|
`CMAKE_REQUIRED_INCLUDES` accordingly if additional libraries or
|
|
|
compiler flags are required.
|
|
|
|
|
|
|
|
|
----
|
|
|
This page was initially populated by conversion from its [original location](https://public.kitware.com/Wiki/CMake:How_To_Write_Platform_Checks) in another wiki. |