Debian Codegraph @

cmake/utils.cmake

raw
1 # dynamips - utility functions
2
3 # standard checks
4 include ( CheckCCompilerFlag )
5 include ( CheckCSourceCompiles )
6 include ( CheckCSourceRuns )
7 include ( CheckCXXCompilerFlag )
8 include ( CheckCXXSourceCompiles )
9 include ( CheckCXXSourceRuns )
10 include ( CheckFunctionExists )
11 include ( CheckIncludeFile )
12 include ( CheckIncludeFileCXX )
13 include ( CheckIncludeFiles )
14 include ( CheckLibraryExists )
15 include ( CheckPrototypeDefinition )
16 include ( CheckStructHasMember )
17 include ( CheckSymbolExists )
18 include ( CheckTypeSize )
19 include ( CheckVariableExists )
20
21 # print variables
22 function ( print_variables )
23 foreach ( _var ${ARGV} )
24 message ( STATUS "${_var}=${${_var}}" )
25 endforeach ()
26 endfunction ( print_variables )
27
28 # convert the name to a standard variable name
29 macro ( standard_variable_name _var _name )
30 string ( REGEX REPLACE "[^a-zA-Z0-9]" "_" ${_var} "${_name}" )
31 string ( TOUPPER "${${_var}}" ${_var} )
32 endmacro ()
33
34 # check if we can compile with the library for the target architecture
35 macro ( check_arch_library _var _func _header _libvar )
36 set ( _n 0 )
37 set ( ${_var} )
38 foreach ( _lib "${${_libvar}}" ${ARGN} )
39 check_library_exists ( "${_lib}" ${_func} ${_header} ${_var}_${_n} )
40 if ( ${_var}_${_n} )
41 # success
42 set ( ${_var} 1 )
43 if ( NOT "${_lib}" STREQUAL "${${_libvar}}" )
44 set ( ${_libvar} ${_lib} )
45 print_variables ( ${_libvar} )
46 endif ()
47 break ()
48 endif ()
49 math ( EXPR _n "${_n}+1" )
50 endforeach ()
51 endmacro ()
52
53 # could not compile with the library for the target architecture
54 macro ( bad_arch_library _type _lib _vars )
55 message (
56 ${_type}
57 "${_lib} was found but cannot be used with DYNAMIPS_ARCH=${DYNAMIPS_ARCH}. "
58 "Make sure the library for the target architecture is installed. "
59 "If needed, you can set the variables ${_vars} manually. "
60 )
61 endmacro ()
62
63 # rename target DYNAMIPS_RENAME_TARGET to dynamips
64 macro ( maybe_rename_to_dynamips _target )
65 if ( "${_target}" STREQUAL "${DYNAMIPS_RENAME_TARGET}" )
66 set_target_properties ( ${_target} PROPERTIES OUTPUT_NAME "dynamips" )
67 endif()
68 endmacro ( maybe_rename_to_dynamips _target )
69
70 # install executables
71 function ( install_executable _target )
72 install (
73 TARGETS ${_target}
74 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
75 COMPONENT "executables"
76 )
77 endfunction ( install_executable )
78
79 # install docs
80 function ( install_docs )
81 if ( ${ARGC} LESS 1 )
82 # no docs
83 return ()
84 endif ()
85 install (
86 FILES ${ARGV}
87 DESTINATION "${CMAKE_INSTALL_DOCDIR}"
88 COMPONENT "docs"
89 )
90 endfunction ( install_docs )
91
92 # install man pages
93 function ( install_man_pages )
94 if ( ${ARGC} LESS 1 )
95 # no man pages
96 return ()
97 endif ()
98 foreach ( _file ${ARGV} )
99 string ( REGEX REPLACE "^.*\\." "" _page "${_file}" )
100 if ( NOT "${_page}" MATCHES "[0-9]+" )
101 message ( FATAL_ERROR "not a man page: ${_file}" )
102 endif ()
103 install (
104 FILES "${_file}"
105 DESTINATION "${CMAKE_INSTALL_MANDIR}/man${_page}"
106 COMPONENT "docs"
107 )
108 endforeach ()
109 endfunction ( install_man_pages )