| 1 |
cmake_policy(SET CMP0075 NEW) |
| 2 |
|
| 3 |
enable_language(C) |
| 4 |
enable_language(CXX) |
| 5 |
|
| 6 |
function(test_check_result isSucceed functionName) |
| 7 |
if(isSucceed AND NOT IS_NEED_SUCCESS) |
| 8 |
message(SEND_ERROR "${functionName}: check succeeded instead of failure") |
| 9 |
elseif((NOT isSucceed) AND IS_NEED_SUCCESS) |
| 10 |
message(SEND_ERROR "${functionName}: check failed instead of success") |
| 11 |
endif() |
| 12 |
endfunction() |
| 13 |
|
| 14 |
# Common variables |
| 15 |
set(validCSourceCode "int main() {return 0;}") |
| 16 |
|
| 17 |
### |
| 18 |
# Checking checkers |
| 19 |
### |
| 20 |
|
| 21 |
# It uses common internal function `CMAKE_CHECK_SOURCE_COMPILES()` |
| 22 |
# include(CheckCCompilerFlag) |
| 23 |
|
| 24 |
# Also checks common internal function `CMAKE_CHECK_SOURCE_COMPILES()` |
| 25 |
include(CheckCSourceCompiles) |
| 26 |
check_c_source_compiles("${validCSourceCode}" CHECK_C_SOURCE_COMPILES_SUCCEED) |
| 27 |
test_check_result("${CHECK_C_SOURCE_COMPILES_SUCCEED}" check_c_source_compiles) |
| 28 |
|
| 29 |
# Also checks common internal function `CMAKE_CHECK_SOURCE_RUNS()` |
| 30 |
include(CheckCSourceRuns) |
| 31 |
check_c_source_runs("${validCSourceCode}" CHECK_C_SOURCE_RUNS_SUCCEED) |
| 32 |
test_check_result("${CHECK_C_SOURCE_RUNS_SUCCEED}" check_c_source_runs) |
| 33 |
|
| 34 |
# Shares code with similar C checkers |
| 35 |
# include(CheckCXXCompilerFlag) |
| 36 |
# include(CheckCXXSourceCompiles) |
| 37 |
# include(CheckCXXSourceRuns) |
| 38 |
# include(CheckCXXSymbolExists) |
| 39 |
|
| 40 |
# Shares code with similar C checkers |
| 41 |
# include(CheckCompilerFlag) |
| 42 |
# include(CheckSourceCompiles) |
| 43 |
# include(CheckSourceRuns) |
| 44 |
|
| 45 |
# Shares code with similar C checkers |
| 46 |
# include(CheckFortranCompilerFlag) |
| 47 |
# include(CheckFortranFunctionExists) # No way to test it |
| 48 |
# include(CheckFortranSourceCompiles) |
| 49 |
# include(CheckFortranSourceRuns) |
| 50 |
|
| 51 |
include(CheckFunctionExists) |
| 52 |
check_function_exists (memcpy CHECK_FUNCTION_EXISTS_SUCCEED) |
| 53 |
test_check_result("${CHECK_FUNCTION_EXISTS_SUCCEED}" check_function_exists) |
| 54 |
|
| 55 |
include(CheckIncludeFile) |
| 56 |
check_include_file("stddef.h" CHECK_INCLUDE_FILE_SUCCEED) |
| 57 |
test_check_result("${CHECK_INCLUDE_FILE_SUCCEED}" check_include_file) |
| 58 |
|
| 59 |
include(CheckIncludeFileCXX) |
| 60 |
check_include_file_cxx("stddef.h" CHECK_INCLUDE_FILE_CXX_SUCCEED) |
| 61 |
test_check_result("${CHECK_INCLUDE_FILE_CXX_SUCCEED}" check_include_file_cxx) |
| 62 |
|
| 63 |
include(CheckIncludeFiles) |
| 64 |
check_include_files("stddef.h;stdlib.h" CHECK_INCLUDE_FILES_SUCCEED) |
| 65 |
test_check_result("${CHECK_INCLUDE_FILES_SUCCEED}" check_include_files) |
| 66 |
|
| 67 |
include(CheckLibraryExists) |
| 68 |
block(PROPAGATE HAVE_LIBM) |
| 69 |
unset(CMAKE_REQUIRED_LIBRARIES) |
| 70 |
unset(CMAKE_REQUIRED_LINK_DIRECTORIES) |
| 71 |
check_library_exists(m ceil "" HAVE_LIBM) |
| 72 |
endblock() |
| 73 |
|
| 74 |
if(HAVE_LIBM) |
| 75 |
check_library_exists(m ceil "" CHECK_LIBRARY_EXISTS_SUCCEED) |
| 76 |
test_check_result("${CHECK_LIBRARY_EXISTS_SUCCEED}" check_library_exists) |
| 77 |
endif() |
| 78 |
|
| 79 |
# Shares code with similar C checkers |
| 80 |
# include(CheckOBJCCompilerFlag) |
| 81 |
# include(CheckOBJCSourceCompiles) |
| 82 |
# include(CheckOBJCSourceRuns) |
| 83 |
|
| 84 |
# Shares code with similar C checkers |
| 85 |
# include(CheckOBJCXXCompilerFlag) |
| 86 |
# include(CheckOBJCXXSourceCompiles) |
| 87 |
# include(CheckOBJCXXSourceRuns) |
| 88 |
|
| 89 |
include(CheckPrototypeDefinition) |
| 90 |
block(PROPAGATE CHECK_PROTOTYPE_DEFINITION_WORKS) |
| 91 |
unset(CMAKE_REQUIRED_LIBRARIES) |
| 92 |
unset(CMAKE_REQUIRED_LINK_DIRECTORIES) |
| 93 |
check_prototype_definition(memmove |
| 94 |
"void *memmove(void *dest, const void *src, size_t n)" |
| 95 |
"NULL" |
| 96 |
"string.h" |
| 97 |
CHECK_PROTOTYPE_DEFINITION_SUCCEED) |
| 98 |
endblock() |
| 99 |
|
| 100 |
if (CHECK_PROTOTYPE_DEFINITION_WORKS) |
| 101 |
check_prototype_definition(memmove |
| 102 |
"void *memmove(void *dest, const void *src, size_t n)" |
| 103 |
"NULL" |
| 104 |
"string.h" |
| 105 |
CHECK_PROTOTYPE_DEFINITION_SUCCEED) |
| 106 |
test_check_result("${CHECK_PROTOTYPE_DEFINITION_SUCCEED}" check_prototype_definition) |
| 107 |
endif() |
| 108 |
|
| 109 |
# It uses common internal function `CMAKE_CHECK_SOURCE_COMPILES()` |
| 110 |
# include(CheckStructHasMember) |
| 111 |
|
| 112 |
include(CheckSymbolExists) |
| 113 |
check_symbol_exists(errno "errno.h" CHECK_SYMBOL_EXISTS_SUCCEED) |
| 114 |
test_check_result("${CHECK_SYMBOL_EXISTS_SUCCEED}" check_symbol_exists) |
| 115 |
|
| 116 |
include(CheckTypeSize) |
| 117 |
check_type_size(int SIZEOF_INT) |
| 118 |
test_check_result("${HAVE_SIZEOF_INT}" check_type_size) |
| 119 |
|
| 120 |
include(CheckVariableExists) |
| 121 |
check_variable_exists(myTestVar CHECK_VARIABLE_EXISTS_SUCCEED) |
| 122 |
test_check_result("${CHECK_VARIABLE_EXISTS_SUCCEED}" check_variable_exists) |