forked from CloudCompare/CloudCompare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeInclude.cmake
163 lines (147 loc) · 6.54 KB
/
CMakeInclude.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
# ------------------------------------------------------------------------------
# helpers
# ------------------------------------------------------------------------------
# define CMake designation of shared libraries (DLL or so) whatever the OS is
if( WIN32 )
set( SHARED_LIB_TYPE RUNTIME ) # CMake considers Dlls as RUNTIME on Windows!
else()
set( SHARED_LIB_TYPE LIBRARY )
endif()
# Find mocable files (simply look for Q_OBJECT in all files!)
function( find_mocable_files __out_var_name ) # + input list
set( local_list )
foreach( one_file ${ARGN} )
file( READ ${one_file} stream )
if( stream MATCHES "Q_OBJECT" )
list( APPEND local_list ${one_file} )
endif()
endforeach()
set( ${__out_var_name} ${local_list} PARENT_SCOPE )
endfunction()
# Export Qt Dlls to specified destinations
function( install_Qt_Dlls ) # 2 arguments: ARGV0 = release destination / ARGV1 = debug destination
if( WIN32 )
if( NOT ${ARGC} EQUAL 2 )
message( SEND_ERROR "function install_Qt_Dlls: invalid number of arguments! (need release and debug destinations)" )
else()
set( QT_RELEASE_DLLS QtCore${QT_VERSION_MAJOR} QtGui${QT_VERSION_MAJOR} QtOpenGL${QT_VERSION_MAJOR} )
set( QT_DEBUG_DLLS QtCored${QT_VERSION_MAJOR} QtGuid${QT_VERSION_MAJOR} QtOpenGLd${QT_VERSION_MAJOR} )
#specific case for the MinGW version of Qts
if( MINGW )
list( APPEND QT_RELEASE_DLLS libgcc )
list( APPEND QT_RELEASE_DLLS mingwm )
list( APPEND QT_DEBUG_DLLS libgcc )
list( APPEND QT_DEBUG_DLLS mingwm )
endif()
#release versions
foreach( element ${QT_RELEASE_DLLS} )
file( GLOB dll_files ${QT_BINARY_DIR}/${element}*.dll )
foreach( qtDLL ${dll_files} )
if( NOT CMAKE_CONFIGURATION_TYPES )
install( FILES ${qtDLL} DESTINATION ${ARGV0} )
else()
install( FILES ${qtDLL} CONFIGURATIONS Release DESTINATION ${ARGV0} )
endif()
endforeach()
endforeach()
#debug versions (for mutli-config compiler only)
if( CMAKE_CONFIGURATION_TYPES )
foreach( element ${QT_DEBUG_DLLS} )
file( GLOB dll_files ${QT_BINARY_DIR}/${element}*.dll )
foreach( qtDLL ${dll_files} )
install( FILES ${qtDLL} CONFIGURATIONS Debug DESTINATION ${ARGV1} )
endforeach()
endforeach()
endif()
endif()
endif()
endfunction()
# Export Qt imageformats DLLs to specified destinations
function( install_Qt_ImageFormats )
if( WIN32 ) # 2 arguments: ARGV0 = release destination / ARGV1 = debug destination
if( NOT ${ARGC} EQUAL 2 )
message( SEND_ERROR "function install_Qt_ImageFormats: invalid number of arguments! (need release and debug destinations)" )
else()
foreach( imagePlugin ${QT_IMAGEFORMATS_PLUGINS} )
if( NOT CMAKE_CONFIGURATION_TYPES )
install( FILES ${QT_PLUGINS_DIR}/imageformats/${imagePlugin}4.dll DESTINATION ${ARGV0}/imageformats )
else()
install( FILES ${QT_PLUGINS_DIR}/imageformats/${imagePlugin}4.dll CONFIGURATIONS Release DESTINATION ${ARGV0}/imageformats )
install( FILES ${QT_PLUGINS_DIR}/imageformats/${imagePlugin}d4.dll CONFIGURATIONS Debug DESTINATION ${ARGV1}/imageformats )
endif()
endforeach()
endif()
elseif( APPLE ) # 2 arguments: ARGV0 = bundle's plugin dir (destination) / ARGV1 = list of plugins to pass to fixup_bundle
# install imageformat plugins
foreach( imagePlugin ${QT_IMAGEFORMATS_PLUGINS} )
set( PLUGIN_NAME lib${imagePlugin}${CMAKE_SHARED_LIBRARY_SUFFIX} )
install( FILES ${QT_PLUGINS_DIR}/imageformats/${PLUGIN_NAME} DESTINATION ${ARGV0}/imageformats COMPONENT Runtime )
list( APPEND QT_PLUGINS ${ARGV0}/imageformats/${PLUGIN_NAME} )
endforeach()
set( ${ARGV1} ${QT_PLUGINS} PARENT_SCOPE )
endif()
endfunction()
# Install shared libraries depending on the build configuration and OS
function( install_shared ) # 3 arguments: ARGV0 = target / ARGV1 = release install destination / ARGV2 = debug install destination (if available)
if( NOT CMAKE_CONFIGURATION_TYPES )
install( TARGETS ${ARGV0} ${SHARED_LIB_TYPE} DESTINATION ${ARGV1} )
else()
install( TARGETS ${ARGV0} ${SHARED_LIB_TYPE} CONFIGURATIONS Release DESTINATION ${ARGV1} )
install( TARGETS ${ARGV0} ${SHARED_LIB_TYPE} CONFIGURATIONS Debug DESTINATION ${ARGV2} )
endif()
endfunction()
# Extended 'install' command depending on the build configuration and OS
# 4 arguments:
# - ARGV0 = signature
# - ARGV1 = target (warning: one project or one file at a time)
# - ARGV2 = release install destination (or 0 to skip it)
# - ARGV3 = debug install destination (if configuration exist / optional)
function( install_ext )
if( NOT CMAKE_CONFIGURATION_TYPES )
install( ${ARGV0} ${ARGV1} DESTINATION ${ARGV2} )
else()
if (NOT ${ARGV2} EQUAL 0)
install( ${ARGV0} ${ARGV1} CONFIGURATIONS Release DESTINATION ${ARGV2} )
endif()
if( ARGV3 )
install( ${ARGV0} ${ARGV1} CONFIGURATIONS Debug DESTINATION ${ARGV3} )
endif()
endif()
endfunction()
# Default preprocessors
function( set_default_cc_preproc ) # 1 argument: ARGV0 = target
set( CC_DEFAULT_PREPROCESSORS NOMINMAX _CRT_SECURE_NO_WARNINGS ) #all configurations
set( CC_DEFAULT_PREPROCESSORS_RELEASE NDEBUG ) #release specific
set( CC_DEFAULT_PREPROCESSORS_DEBUG _DEBUG ) #debug specific
set_property( TARGET ${ARGV0} APPEND PROPERTY COMPILE_DEFINITIONS ${CC_DEFAULT_PREPROCESSORS} )
if( NOT CMAKE_CONFIGURATION_TYPES )
set_property( TARGET ${ARGV0} APPEND PROPERTY COMPILE_DEFINITIONS ${CC_DEFAULT_PREPROCESSORS_RELEASE} )
else()
set_property( TARGET ${ARGV0} APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE ${CC_DEFAULT_PREPROCESSORS_RELEASE} )
set_property( TARGET ${ARGV0} APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG ${CC_DEFAULT_PREPROCESSORS_DEBUG} )
endif()
endfunction()
if( APPLE )
function( get_support_libs ) # 1 argument - return var
# get a list of support libs based on configuration
# we need this to install them properly when we are bundling the app
list( APPEND SUPPORT_LIB_NAMES libCC_DLL )
list( APPEND SUPPORT_LIB_NAMES libQCC_DB_DLL )
if( ${OPTION_USE_XIOT} )
list( APPEND SUPPORT_LIB_NAMES libxiot )
list( APPEND SUPPORT_LIB_NAMES libxerces-c )
list( APPEND SUPPORT_LIB_NAMES libopenFI )
endif()
if( ${OPTION_USE_LIBLAS} )
list( APPEND SUPPORT_LIB_NAMES liblas )
list( APPEND SUPPORT_LIB_NAMES liblaszip )
endif()
foreach( supportLib ${SUPPORT_LIB_NAMES} )
set( LIB_NAME ${CMAKE_INSTALL_PREFIX}/lib/${supportLib}${CMAKE_SHARED_LIBRARY_SUFFIX} )
# resolve any symbolic links
get_filename_component( _resolvedFile ${LIB_NAME} REALPATH )
list( APPEND SUPPORT_LIBS ${_resolvedFile} )
endforeach()
set( ${ARGV0} ${SUPPORT_LIBS} PARENT_SCOPE )
endfunction()
endif()