This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
forked from fx5/usbdmx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
macros.cmake
300 lines (261 loc) · 11.8 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
########################################################################
#
# BUILD/MACROS.CMAKE
#
# This file provides some useful macros to
# simplify adding of componenents and other
# tasks
# Copyright (c) 2009-2013 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 library in the system using find_package 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
# <name>_IGNORE_SYSTEM_LIBRARY Will be an option available
# for custom configuration. Enable to ignore the
# detected system install library and force use
# of the version in <directory>
#
# mz_find_checkout_library <name> SYS <version> SVN <repository> <target_dir> <include_dir> <target>
# useful when needing a version of a library but not sure wether
# it is available on the target system.
# Will search for the given library in the system using find_package and when
# not found, it will do a checkout of the given repository 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
# <name>_IGNORE_SYSTEM_LIBRARY Will be an option available
# for custom configuration. Enable to ignore the
# detected system install library and force use
# of the version in <directory>
#
########################################################################
# 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)
get_filename_component(_ABS_FOLDER ${FOLDER} ABSOLUTE)
file(RELATIVE_PATH _REL_FOLDER ${CMAKE_SOURCE_DIR} ${_ABS_FOLDER})
add_subdirectory(${FOLDER} ${CMAKE_BINARY_DIR}/${_REL_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 in: ${to_moc}")
# the definition of -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED is to bypass a parsing bug within moc
if( Qt5Core_VERSION_STRING )
qt5_wrap_cpp(_mocced ${to_moc} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
else()
qt4_wrap_cpp(_mocced ${to_moc} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
endif()
set(${mocced} ${${mocced}} ${_mocced})
endmacro()
include(CheckIncludeFiles)
include(FindPackageHandleStandardArgs)
if( NOT CMAKE_MODULE_PATH )
cmake_policy(SET CMP0017 OLD)
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_UPPER2)
STRING(REPLACE "-" "_" _NAME_UPPER "${_NAME_UPPER2}") # special care for libraries with - in their names
get_filename_component(_DIRECTORY_ABS ${_DIRECTORY} ABSOLUTE)
# we only search for the library in case
# - the given target was not defined before (think hierarchies)
if( NOT TARGET ${_TARGET} )
find_package( ${_NAME} ${_VERSION} QUIET )
endif()
# take care of find_package not converting to upper-case
if( ${_NAME}_FOUND OR ${_NAME_UPPER2}_FOUND )
set( ${_NAME_UPPER}_FOUND TRUE )
endif()
# give some choice to the user
if( ${_NAME_UPPER}_FOUND )
option(${_NAME_UPPER}_IGNORE_SYSTEM_LIBRARY "Force use of the in-source library version of ${_NAME}" OFF)
else()
option(${_NAME_UPPER}_IGNORE_SYSTEM_LIBRARY "Force use of the in-source library version of ${_NAME}" ON)
endif()
# we only add the library as our own target in case
# - no system library was found
# - the given target was not defined before (think hierarchies)
# - the use explicitly wants to build the library himself
if( ( NOT ${_NAME_UPPER}_FOUND OR ${_NAME_UPPER}_IGNORE_SYSTEM_LIBRARY ) AND NOT TARGET ${_TARGET} )
get_filename_component(_INC_DIR_ABS ${_INC_DIR} ABSOLUTE)
set(${_NAME_UPPER}_INCLUDE_DIRS ${_INC_DIR_ABS})
set(${_NAME_UPPER}_LIBRARIES ${_TARGET} ${ARGN})
set(${_NAME_UPPER}_FOUND TRUE)
mz_message("No system library for '${_NAME}', building own version")
if( NOT ${_TARGET} STREQUAL "" )
mz_add_library(${_NAME} ${_DIRECTORY})
else()
mz_debug_message("${_NAME} is a header only library, no new target")
endif()
else()
mz_message("Using system installed version of '${_NAME}'")
endif()
endmacro()
macro(mz_find_checkout_library _NAME SYS _VERSION SVN _REPOSITORY _DEST_DIR _INC_DIR _TARGET)
STRING(TOUPPER ${_NAME} _NAME_UPPER2)
STRING(REPLACE "-" "_" _NAME_UPPER "${_NAME_UPPER2}") # special care for libraries with - in their names
get_filename_component(_DEST_DIR_ABS ${_DEST_DIR} ABSOLUTE)
# we only search for the library in case
# - the given target was not defined before (think hierarchies)
if( NOT TARGET ${_TARGET} )
find_package( ${_NAME} ${_VERSION} QUIET )
endif()
# take care of find_package not converting to upper-case
if( ${_NAME}_FOUND OR ${_NAME_UPPER2}_FOUND )
set( ${_NAME_UPPER}_FOUND TRUE )
endif()
# give some choice to the user
if( ${_NAME_UPPER}_FOUND )
option(${_NAME_UPPER}_IGNORE_SYSTEM_LIBRARY "Force use of the in-source library version of ${_NAME}" OFF)
else()
option(${_NAME_UPPER}_IGNORE_SYSTEM_LIBRARY "Force use of the in-source library version of ${_NAME}" ON)
endif()
# we only add the library as our own target in case
# - no system library was found
# - the given target was not defined before (think hierarchies)
# - the use explicitly wants to build the library himself
if( ( NOT ${_NAME_UPPER}_FOUND OR ${_NAME_UPPER}_IGNORE_SYSTEM_LIBRARY ) AND NOT TARGET ${_TARGET} )
mz_message("No system library for '${_NAME}', retrieving own version")
find_package( Subversion QUIET )
if( SUBVERSION_FOUND )
if(NOT EXISTS ${_DEST_DIR_ABS})
execute_process(
COMMAND ${Subversion_SVN_EXECUTABLE} checkout ${_REPOSITORY} ${_DEST_DIR_ABS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _SVN_OUT
)
mz_debug_message( ${_SVN_OUT} )
endif()
else()
mz_message( "WARNING: No Subversion found, please do a manual checkout of ${_REPOSITORY} to ${_DEST_DIR_ABS} and re-run project generation" )
endif()
if(NOT EXISTS ${_DEST_DIR_ABS})
mz_error_message( "Failed to include ${_DEST_DIR_ABS} as library source, please make sure a valid checkout exists there" )
endif()
set(${_NAME_UPPER}_INCLUDE_DIRS "")
foreach(_DIR ${_INC_DIR})
get_filename_component(_DIR_ABS ${_DIR} ABSOLUTE)
list(APPEND ${_NAME_UPPER}_INCLUDE_DIRS "${_DIR_ABS}")
mz_debug_message("Adding ${_DIR_ABS} to ${${_NAME_UPPER}_INCLUDE_DIRS}")
endforeach(_DIR)
set(${_NAME_UPPER}_LIBRARIES ${_TARGET} ${ARGN})
set(${_NAME_UPPER}_FOUND TRUE)
if( NOT ${_TARGET} STREQUAL "" )
mz_add_library(${_NAME} ${_DEST_DIR})
else()
mz_debug_message("${_NAME} is a header only library, no new target")
endif()
else()
mz_message("Using system installed version of '${_NAME}'")
endif()
endmacro()