blob: cc2db2fb386a8feb51aad13109491008a77917e7 (
plain)
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
|
option(WITH_TESTS "Build Tests" ON)
option(WITH_UNIT_TESTS "Build Unit Tests" OFF)
option(INSTALL_PUBLIC_HEADERS "Whether to install public headers" ON)
option(QBS_ENABLE_RPATH "Whether to enable RPATH" ON)
option(QBS_USE_BUNDLED_QT_SCRIPT "Whether to use bundled QtScript module" OFF)
set(QBS_APP_INSTALL_DIR "bin" CACHE STRING "Relative install location for Qbs binaries.")
# default paths
set(QBS_LIBDIR_NAME "lib")
if(WIN32)
set(_DEFAULT_LIB_INSTALL_DIR ${QBS_APP_INSTALL_DIR})
set(_DEFAULT_LIBEXEC_INSTALL_DIR ${QBS_APP_INSTALL_DIR})
else()
set(_DEFAULT_LIB_INSTALL_DIR ${QBS_LIBDIR_NAME})
set(_DEFAULT_LIBEXEC_INSTALL_DIR "libexec/qbs")
endif()
# path options
set(QBS_OUTPUT_PREFIX "" CACHE STRING "Qbs build output location relative to CMAKE_BINARY_DIR.")
set(QBS_LIB_INSTALL_DIR "${_DEFAULT_LIB_INSTALL_DIR}" CACHE STRING "Relative install location for Qbs libraries.")
set(QBS_DLL_INSTALL_DIR "${QBS_LIB_INSTALL_DIR}" CACHE STRING "Relative install location for Qbs DLLs.")
set(QBS_LIBEXEC_INSTALL_DIR "${_DEFAULT_LIBEXEC_INSTALL_DIR}" CACHE STRING "Relative install location for Qbs libexec.")
set(QBS_PLUGINS_INSTALL_BASE "${QBS_LIBDIR_NAME}" CACHE STRING "Relative install location for Qbs plugins.")
set(QBS_RESOURCES_INSTALL_BASE "." CACHE STRING "Relative install location for Qbs resources.")
set(QBS_HEADERS_INSTALL_DIR "include/qbs" CACHE STRING "Relative install location for Qbs headers.")
set(QBS_DOC_INSTALL_DIR "${QBS_RESOURCES_INSTALL_BASE}/share/doc/qbs" CACHE STRING "Relative install location for Qbs documentation.")
set(QBS_DOC_HTML_DIR_NAME "html" CACHE STRING "The name of the dir with HTML files, appended to QBS_DOC_INSTALL_DIR.")
set(QBS_PLUGINS_INSTALL_DIR "${QBS_PLUGINS_INSTALL_BASE}/qbs/plugins")
set(QBS_RESOURCES_INSTALL_DIR "${QBS_RESOURCES_INSTALL_BASE}/share")
# rpaths
file(RELATIVE_PATH QBS_RELATIVE_LIBEXEC_RPATH "/${QBS_LIBEXEC_INSTALL_DIR}" "/${QBS_LIB_INSTALL_DIR}")
file(RELATIVE_PATH QBS_RELATIVE_APP_RPATH "/${QBS_APP_INSTALL_DIR}" "/${QBS_LIB_INSTALL_DIR}")
file(RELATIVE_PATH QBS_RELATIVE_PLUGINS_RPATH "/${QBS_PLUGINS_INSTALL_DIR}" "/${QBS_LIB_INSTALL_DIR}")
if(WIN32 OR NOT QBS_ENABLE_RPATH)
set(QBS_MACOSX_RPATH OFF)
set(QBS_LIB_RPATH "")
set(QBS_LIBEXEC_RPATH "")
set(QBS_APP_RPATH "")
set(QBS_PLUGINS_RPATH "")
elseif(APPLE)
set(QBS_MACOSX_RPATH ON)
set(QBS_LIB_RPATH "@loader_path")
set(QBS_LIBEXEC_RPATH "@loader_path/${QBS_RELATIVE_LIBEXEC_RPATH}")
set(QBS_APP_RPATH "@loader_path/${QBS_RELATIVE_APP_RPATH}")
set(QBS_PLUGINS_RPATH "@loader_path/${QBS_RELATIVE_PLUGINS_RPATH}")
else()
set(QBS_MACOSX_RPATH OFF)
set(QBS_LIB_RPATH "\$ORIGIN")
set(QBS_LIBEXEC_RPATH "\$ORIGIN/${QBS_RELATIVE_LIBEXEC_RPATH}")
set(QBS_APP_RPATH "\$ORIGIN/${QBS_RELATIVE_APP_RPATH}")
set(QBS_PLUGINS_RPATH "\$ORIGIN/${QBS_RELATIVE_PLUGINS_RPATH}")
endif()
function(get_update_path_command var)
if(WIN32)
get_target_property(_QTCORE_LIBRARY Qt${QT_VERSION_MAJOR}::Core IMPORTED_LOCATION_RELEASE)
if(NOT _QTCORE_LIBRARY)
get_target_property(_QTCORE_LIBRARY Qt${QT_VERSION_MAJOR}::Core IMPORTED_LOCATION_DEBUG)
endif()
get_filename_component(_QT_LIBRARY_PATH "${_QTCORE_LIBRARY}" DIRECTORY)
get_target_property(_QBS_LIBRARY_PATH qbscore LIBRARY_OUTPUT_DIRECTORY)
file(TO_NATIVE_PATH "${_QT_LIBRARY_PATH}\;${_QBS_LIBRARY_PATH}\;$ENV{PATH}" _NEW_PATH)
set(${var} "PATH=${_NEW_PATH}" PARENT_SCOPE)
else()
set(${var} "")
endif()
endfunction()
if(WITH_UNIT_TESTS)
set(QBS_UNIT_TESTS_DEFINES "QBS_ENABLE_UNIT_TESTS")
else()
set(QBS_UNIT_TESTS_DEFINES "")
endif()
file(RELATIVE_PATH QBS_RELATIVE_LIBEXEC_PATH "/${QBS_APP_INSTALL_DIR}" "/${QBS_LIBEXEC_INSTALL_DIR}")
file(RELATIVE_PATH QBS_RELATIVE_SEARCH_PATH "/${QBS_APP_INSTALL_DIR}" "/${QBS_RESOURCES_INSTALL_BASE}")
file(RELATIVE_PATH QBS_RELATIVE_PLUGINS_PATH "/${QBS_APP_INSTALL_DIR}" "/${QBS_PLUGINS_INSTALL_BASE}")
set(DEFAULT_DEFINES "")
if(WIN32)
list(APPEND DEFAULT_DEFINES UNICODE _UNICODE _SCL_SECURE_NO_WARNINGS)
endif()
# CMake 3.10 doesn't have list(TRANSFORM)
function(list_transform_prepend var prefix)
set(temp "")
foreach(f ${${var}})
list(APPEND temp "${prefix}${f}")
endforeach()
set(${var} "${temp}" PARENT_SCOPE)
endfunction()
function(add_qbs_app target_name)
cmake_parse_arguments(_arg
""
"DESTINATION"
"DEFINES;PUBLIC_DEFINES;DEPENDS;PUBLIC_DEPENDS;INCLUDES;PUBLIC_INCLUDES;SOURCES;"
${ARGN}
)
if (${_arg_UNPARSED_ARGUMENTS})
message(FATAL_ERROR "add_qbs_app had unparsed arguments")
endif()
set(_DESTINATION "${QBS_APP_INSTALL_DIR}")
if(_arg_DESTINATION)
set(_DESTINATION "${_arg_DESTINATION}")
endif()
add_executable(${target_name} ${_arg_SOURCES})
target_compile_definitions(
${target_name} PRIVATE ${_arg_DEFINES} ${DEFAULT_DEFINES} PUBLIC ${_arg_PUBLIC_DEFINES})
target_include_directories(
${target_name} PRIVATE ${_arg_INCLUDES} PUBLIC ${_arg_PUBLIC_INCLUDES})
target_link_libraries(${target_name} PRIVATE ${_arg_DEPENDS} PUBLIC ${_arg_PUBLIC_DEPENDS})
set_target_properties(${target_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${_DESTINATION}
BUILD_RPATH "${QBS_APP_RPATH}"
INSTALL_RPATH "${QBS_APP_RPATH}"
MACOSX_RPATH ${QBS_MACOSX_RPATH}
)
install(TARGETS ${target_name} RUNTIME DESTINATION ${_DESTINATION})
endfunction()
function(add_qbs_library target_name)
cmake_parse_arguments(_arg
"STATIC"
""
"DEFINES;PUBLIC_DEFINES;DEPENDS;PUBLIC_DEPENDS;INCLUDES;PUBLIC_INCLUDES;SOURCES;"
${ARGN}
)
if (${_arg_UNPARSED_ARGUMENTS})
message(FATAL_ERROR "add_qbs_library had unparsed arguments")
endif()
set(library_type SHARED)
if (_arg_STATIC)
set(library_type STATIC)
endif()
string(REGEX REPLACE "\\.[0-9]+$" "" _SOVERSION ${QBS_VERSION})
add_library(${target_name} ${library_type} ${_arg_SOURCES})
target_compile_definitions(
${target_name}
PRIVATE ${_arg_DEFINES} ${DEFAULT_DEFINES}
PUBLIC ${_arg_PUBLIC_DEFINES})
target_include_directories(
${target_name}
PRIVATE ${_arg_INCLUDES}
PUBLIC ${_arg_PUBLIC_INCLUDES}
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>)
target_link_libraries(${target_name} PRIVATE ${_arg_DEPENDS} PUBLIC ${_arg_PUBLIC_DEPENDS})
set_target_properties(${target_name} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_LIB_INSTALL_DIR}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_LIB_INSTALL_DIR}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_DLL_INSTALL_DIR}
BUILD_RPATH "${QBS_LIB_RPATH}"
INSTALL_RPATH "${QBS_LIB_RPATH}"
MACOSX_RPATH ${QBS_MACOSX_RPATH}
SOVERSION ${_SOVERSION}
VERSION ${QBS_VERSION}
)
if (NOT _arg_STATIC)
install(TARGETS ${target_name}
LIBRARY DESTINATION ${QBS_LIB_INSTALL_DIR}
RUNTIME DESTINATION ${QBS_DLL_INSTALL_DIR}
)
endif()
endfunction()
function(add_qbs_plugin target_name)
cmake_parse_arguments(_arg
""
""
"DEFINES;PUBLIC_DEFINES;DEPENDS;PUBLIC_DEPENDS;INCLUDES;PUBLIC_INCLUDES;SOURCES;"
${ARGN}
)
if (${_arg_UNPARSED_ARGUMENTS})
message(FATAL_ERROR "add_qbs_plugin had unparsed arguments")
endif()
add_library(${target_name} SHARED ${_arg_SOURCES})
target_compile_definitions(
${target_name} PRIVATE ${_arg_DEFINES} ${DEFAULT_DEFINES} PUBLIC ${_arg_PUBLIC_DEFINES})
target_include_directories(
${target_name} PRIVATE ${_arg_INCLUDES} PUBLIC ${_arg_PUBLIC_INCLUDES})
target_link_libraries(${target_name} PRIVATE ${_arg_DEPENDS} PUBLIC ${_arg_PUBLIC_DEPENDS})
set_target_properties(${target_name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_PLUGINS_INSTALL_DIR}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_PLUGINS_INSTALL_DIR}
BUILD_RPATH "${QBS_PLUGINS_RPATH}"
INSTALL_RPATH "${QBS_PLUGINS_RPATH}"
MACOSX_RPATH ${QBS_MACOSX_RPATH}
)
install(TARGETS ${target_name}
LIBRARY DESTINATION ${QBS_PLUGINS_INSTALL_DIR}
RUNTIME DESTINATION ${QBS_PLUGINS_INSTALL_DIR}
)
endfunction()
function(add_qbs_test test_name)
cmake_parse_arguments(_arg
""
""
"DEFINES;PUBLIC_DEFINES;DEPENDS;PUBLIC_DEPENDS;INCLUDES;PUBLIC_INCLUDES;SOURCES;"
${ARGN}
)
if (${_arg_UNPARSED_ARGUMENTS})
message(FATAL_ERROR "add_qbs_test had unparsed arguments")
endif()
set(target_name "tst_${test_name}")
string(TOUPPER ${test_name} suite_name) # cmake is beatiful, here we have <input, output>
string(REPLACE - _ suite_name ${suite_name}) # and here we have <output, input>
add_executable(${target_name} ${_arg_SOURCES})
target_compile_definitions(${target_name} PRIVATE
"QBS_TEST_SUITE_NAME=\"${suite_name}\""
"SRCDIR=\"${CMAKE_CURRENT_SOURCE_DIR}\""
)
target_compile_definitions(
${target_name} PRIVATE ${_arg_DEFINES} ${DEFAULT_DEFINES} PUBLIC ${_arg_PUBLIC_DEFINES})
target_include_directories(
${target_name}
PRIVATE ${_arg_INCLUDES} "${CMAKE_CURRENT_SOURCE_DIR}/../../../src"
PUBLIC ${_arg_PUBLIC_INCLUDES}
)
target_link_libraries(
${target_name}
PRIVATE ${_arg_DEPENDS} qbscore qbsconsolelogger Qt${QT_VERSION_MAJOR}::Test
PUBLIC ${_arg_PUBLIC_DEPENDS}
)
set_target_properties(${target_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${QBS_OUTPUT_PREFIX}${QBS_APP_INSTALL_DIR}
BUILD_RPATH "${QBS_APP_RPATH}"
INSTALL_RPATH "${QBS_APP_RPATH}"
MACOSX_RPATH ${QBS_MACOSX_RPATH}
)
install(TARGETS ${target_name} RUNTIME DESTINATION ${QBS_APP_INSTALL_DIR})
add_test(NAME ${target_name} COMMAND ${target_name})
endfunction()
|