-
Notifications
You must be signed in to change notification settings - Fork 40
/
Macros.cmake
76 lines (66 loc) · 2.4 KB
/
Macros.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
include(CheckIncludeFile)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckTypeSize)
set(defines "// autogenerated by cmake macro\n\n")
macro(cm_define_project version name tarname string bugreport url package)
set(defines ${defines} "#define PACKAGE_VERSION \"${version}\"\n\n")
set(defines ${defines} "#define PACKAGE_NAME \"${name}\"\n\n")
set(defines ${defines} "#define PACKAGE_TARNAME \"${tarname}\"\n\n")
set(defines ${defines} "#define PACKAGE_STRING \"${string}\"\n\n")
set(defines ${defines} "#define PACKAGE_BUGREPORT \"${bugreport}\"\n\n")
set(defines ${defines} "#define PACKAGE_URL \"${url}\"\n\n")
set(defines ${defines} "#define PACKAGE \"${package}\"\n\n")
endmacro()
macro(cm_define_var varname varvalue)
set(defines ${defines} "#define ${varname} ${varvalue}\n\n")
endmacro()
macro(cm_check_lib libname)
find_library(${libname}_LIBRARY ${libname})
if(${libname}_LIBRARY)
string(TOUPPER ${libname} libname)
set(defines ${defines} "#cmakedefine HAVE_${libname}\n\n")
else()
set(defines ${defines} "/* #undef HAVE_${libname} */\n\n")
endif()
endmacro()
macro(cm_check_include include var)
check_include_file(${include} ${var})
if(${var})
set(defines ${defines} "#cmakedefine ${var}\n\n")
else()
set(defines ${defines} "/* #undef ${var} */\n\n")
endif()
endmacro()
macro(cm_check_function func var)
check_function_exists(${func} ${var})
if(${var})
set(defines ${defines} "#cmakedefine ${var}\n\n")
else()
set(defines ${defines} "/* #undef ${var} */\n\n")
endif()
endmacro()
macro(cm_check_type_size type var)
check_type_size(${type} ${var})
if(${var})
set(defines ${defines} "#cmakedefine ${var} ${${var}}\n\n")
else()
set(defines ${defines} "/* #undef ${var} */\n\n")
endif()
endmacro()
macro(cm_replace_functions sources)
foreach(name ${ARGN})
string(TOUPPER have_${name} SYMBOL_NAME)
cm_check_function(${name} ${SYMBOL_NAME})
message(${defines})
if(NOT ${SYMBOL_NAME})
set(${sources} ${${sources}} ${name}.c)
endif()
endforeach()
endmacro()
set(default_conf_file "config.h.template")
macro(cm_configure_file to_file)
file(WRITE ${default_conf_file} ${defines})
configure_file(${default_conf_file} ${to_file})
file(REMOVE ${default_conf_file}) # uncomment if you want to check the template
endmacro()