This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
forked from signal11/hidapi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
macros.cmake
168 lines (144 loc) · 5.1 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
########################################################################
#
# BUILD/MACROS.CMAKE
#
# This file provides some useful macros to
# simplify adding of componenents and other
# taskss
# (c) 2009-2012 Marius Zwicker
#
# This file defines a whole bunch of macros
# to add a subdirectory containing another
# CMakeLists.txt as "Subproject". All these
# Macros are not doing that much but giving
# feedback to tell what kind of component was
# added. In all cases NAME is the name of your
# subproject and FOLDER is a relative path to
# the folder containing a CMakeLists.txt
#
# mz_add_library <NAME> <FOLDER>
# macro for adding a new library
#
# mz_add_executable <NAME> <FOLDER>
# macro for adding a new executable
#
# mz_add_control <NAME> <FOLDER>
# macro for adding a new control
#
# mz_add_testtool <NAME> <FOLDER>
# macro for adding a folder containing testtools
#
# mz_add_external <NAME> <FOLDER>
# macro for adding an external library/tool dependancy
#
# mz_target_props <target>
# automatically add a "D" postfix when compiling in debug
# mode to the given target
#
# mz_auto_moc <mocced> ...
# search all passed files in (...) for Q_OBJECT and if found
# run moc on them via qt4_wrap_cpp. Assign the output files
# to <mocced>. Improves the version provided by cmake by searching
# for Q_OBJECT first and thus reducing the needed calls to moc
#
# mz_find_include_library <name> SYS <version> SRC <directory> <include_dir> <target>
# useful when providing a version of a library within the
# own sourcetree but prefer the system's library version over it.
# Will search for the given header in the system includes and when
# not found, it will include the given directory which should contain
# a cmake file defining the given target.
# After calling this macro the following variables will be declared:
# <name>_INCLUDE_DIRS The directory containing the header or
# the passed include_dir if the lib was not
# found on the system
# <name>_LIBRARIES The libs to link against - either lib or target
# <name>_FOUND true if the lib was found on the system
#
########################################################################
# if global.cmake was not included yet, report it
if (NOT HAS_MZ_GLOBAL)
message(FATAL_ERROR "!! include global.cmake before including this file !!")
endif()
########################################################################
## no need to change anything beyond here
########################################################################
macro(mz_add_library NAME FOLDER)
mz_message("adding library ${NAME}")
__mz_add_target(${NAME} ${FOLDER})
endmacro()
macro(mz_add_executable NAME FOLDER)
mz_message("adding executable ${NAME}")
__mz_add_target(${NAME} ${FOLDER})
endmacro()
macro(mz_add_control NAME FOLDER)
mz_message("adding control ${NAME}")
__mz_add_target(${NAME} ${FOLDER})
endmacro()
macro(mz_add_testtool NAME FOLDER)
mz_message("adding testtool ${NAME}")
__mz_add_target(${NAME} ${FOLDER})
endmacro()
macro(mz_add_external NAME FOLDER)
mz_message("adding external dependancy ${NAME}")
__mz_add_target(${NAME} ${FOLDER})
endmacro()
macro(__mz_add_target NAME FOLDER)
add_subdirectory(${FOLDER})
endmacro()
macro(mz_target_props NAME)
set_target_properties(${NAME} PROPERTIES DEBUG_POSTFIX "D")
endmacro()
macro(__mz_extract_files _qt_files)
set(${_qt_files})
FOREACH(_current ${ARGN})
file(STRINGS ${_current} _content LIMIT_COUNT 1 REGEX .*Q_OBJECT.*)
if("${_content}" MATCHES .*Q_OBJECT.*)
LIST(APPEND ${_qt_files} "${_current}")
endif()
ENDFOREACH(_current)
endmacro()
macro(mz_auto_moc mocced)
#mz_debug_message("mz_auto_moc input: ${ARGN}")
set(_mocced "")
# determine the required files
__mz_extract_files(to_moc ${ARGN})
#mz_debug_message("mz_auto_moc mocced: ${to_moc}")
qt4_wrap_cpp(_mocced ${to_moc})
set(${mocced} ${${mocced}} ${_mocced})
endmacro()
include(CheckIncludeFiles)
if( NOT CMAKE_MODULE_PATH )
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Modules" )
endif()
macro(mz_check_include_files FILE VAR)
if( IOS )
mz_debug_message("Using custom check_include_files")
if( NOT DEFINED FOUND_${VAR} )
mz_message("Looking for include files ${FILE}")
find_file( ${VAR}
NAMES ${FILE}
PATHS ${CMAKE_REQUIRED_INCLUDES}
)
if( ${VAR} )
mz_message("Looking for include files ${FILE} - found")
set( FOUND_${VAR} ${${VAR}} CACHE INTERNAL FOUND_${VAR} )
else()
mz_message("Looking for include files ${FILE} - not found")
endif()
else()
set( ${VAR} ${FOUND_${VAR}} )
endif()
else()
mz_debug_message("Using native check_include_files")
CHECK_INCLUDE_FILES( ${FILE} ${VAR} )
endif()
endmacro()
macro(mz_find_include_library _NAME SYS _VERSION SRC _DIRECTORY _INC_DIR _TARGET)
STRING(TOUPPER ${_NAME} _NAME_UPPER)
find_package( ${_NAME} )
if( NOT ${_NAME_UPPER}_FOUND )
set(${_NAME_UPPER}_INCLUDE_DIRS ${_INC_DIR})
set(${_NAME_UPPER}_LIBRARIES ${_TARGET})
mz_add_library(${_NAME} ${_DIRECTORY})
endif()
endmacro()