summaryrefslogtreecommitdiffstats
path: root/project/cmake/scripts/common/Macros.cmake
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2017-06-04 16:57:49 +0200
committermanuel <manuel@mausz.at>2017-06-04 16:57:49 +0200
commitf44ecaa4f27e7538ddcad66d40e543bffa2d2d86 (patch)
treed8de60fc7e17edeb6f0921726c038ee54b281445 /project/cmake/scripts/common/Macros.cmake
parentae08c8b7221bc965ac40d70e53fc8fcddb050c46 (diff)
downloadkodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.tar.gz
kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.tar.bz2
kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.zip
sync with upstream
Diffstat (limited to 'project/cmake/scripts/common/Macros.cmake')
-rw-r--r--project/cmake/scripts/common/Macros.cmake622
1 files changed, 0 insertions, 622 deletions
diff --git a/project/cmake/scripts/common/Macros.cmake b/project/cmake/scripts/common/Macros.cmake
deleted file mode 100644
index cce3245..0000000
--- a/project/cmake/scripts/common/Macros.cmake
+++ /dev/null
@@ -1,622 +0,0 @@
1# This script holds the main functions used to construct the build system
2
3# include system specific macros
4include(${CORE_SOURCE_DIR}/project/cmake/scripts/${CORE_SYSTEM_NAME}/Macros.cmake)
5
6# IDEs: Group source files in target in folders (file system hierarchy)
7# Source: http://blog.audio-tk.com/2015/09/01/sorting-source-files-and-projects-in-folders-with-cmake-and-visual-studioxcode/
8# Arguments:
9# target The target that shall be grouped by folders.
10# Optional Arguments:
11# RELATIVE allows to specify a different reference folder.
12function(source_group_by_folder target)
13 if(NOT TARGET ${target})
14 message(FATAL_ERROR "There is no target named '${target}'")
15 endif()
16
17 set(SOURCE_GROUP_DELIMITER "/")
18
19 cmake_parse_arguments(arg "" "RELATIVE" "" ${ARGN})
20 if(arg_RELATIVE)
21 set(relative_dir ${arg_RELATIVE})
22 else()
23 set(relative_dir ${CMAKE_CURRENT_SOURCE_DIR})
24 endif()
25
26 get_property(files TARGET ${target} PROPERTY SOURCES)
27 if(files)
28 list(SORT files)
29
30 if(CMAKE_GENERATOR STREQUAL Xcode)
31 set_target_properties(${target} PROPERTIES SOURCES "${files}")
32 endif()
33 endif()
34 foreach(file ${files})
35 if(NOT IS_ABSOLUTE ${file})
36 set(file ${CMAKE_CURRENT_SOURCE_DIR}/${file})
37 endif()
38 file(RELATIVE_PATH relative_file ${relative_dir} ${file})
39 get_filename_component(dir "${relative_file}" DIRECTORY)
40 if(NOT dir STREQUAL "${last_dir}")
41 if(files)
42 source_group("${last_dir}" FILES ${files})
43 endif()
44 set(files "")
45 endif()
46 set(files ${files} ${file})
47 set(last_dir "${dir}")
48 endforeach(file)
49 if(files)
50 source_group("${last_dir}" FILES ${files})
51 endif()
52endfunction()
53
54# Add sources to main application
55# Arguments:
56# name name of the library to add
57# Implicit arguments:
58# ENABLE_STATIC_LIBS Build static libraries per directory
59# SOURCES the sources of the library
60# HEADERS the headers of the library (only for IDE support)
61# OTHERS other library related files (only for IDE support)
62# On return:
63# Library will be built, optionally added to ${core_DEPENDS}
64# Sets CORE_LIBRARY for calls for setting target specific options
65function(core_add_library name)
66 if(ENABLE_STATIC_LIBS)
67 add_library(${name} STATIC ${SOURCES} ${HEADERS} ${OTHERS})
68 set_target_properties(${name} PROPERTIES PREFIX "")
69 set(core_DEPENDS ${name} ${core_DEPENDS} CACHE STRING "" FORCE)
70 add_dependencies(${name} libcpluff ffmpeg dvdnav crossguid)
71 set(CORE_LIBRARY ${name} PARENT_SCOPE)
72
73 # Add precompiled headers to Kodi main libraries
74 if(CORE_SYSTEM_NAME STREQUAL windows)
75 add_precompiled_header(${name} pch.h ${CORE_SOURCE_DIR}/xbmc/platform/win32/pch.cpp PCH_TARGET kodi)
76 set_language_cxx(${name})
77 target_link_libraries(${name} PUBLIC effects11)
78 endif()
79 else()
80 foreach(src IN LISTS SOURCES HEADERS OTHERS)
81 get_filename_component(src_path "${src}" ABSOLUTE)
82 list(APPEND FILES ${src_path})
83 endforeach()
84 target_sources(lib${APP_NAME_LC} PRIVATE ${FILES})
85 set(CORE_LIBRARY lib${APP_NAME_LC} PARENT_SCOPE)
86 endif()
87endfunction()
88
89# Add a test library, and add sources to list for gtest integration macros
90function(core_add_test_library name)
91 if(ENABLE_STATIC_LIBS)
92 add_library(${name} STATIC ${SOURCES} ${SUPPORTED_SOURCES} ${HEADERS} ${OTHERS})
93 set_target_properties(${name} PROPERTIES PREFIX ""
94 EXCLUDE_FROM_ALL 1
95 FOLDER "Build Utilities/tests")
96 add_dependencies(${name} libcpluff ffmpeg dvdnav crossguid)
97 set(test_archives ${test_archives} ${name} CACHE STRING "" FORCE)
98 endif()
99 foreach(src IN LISTS SOURCES)
100 get_filename_component(src_path "${src}" ABSOLUTE)
101 set(test_sources "${src_path}" ${test_sources} CACHE STRING "" FORCE)
102 endforeach()
103endfunction()
104
105# Add an addon callback library
106# Arguments:
107# name name of the library to add
108# Implicit arguments:
109# SOURCES the sources of the library
110# HEADERS the headers of the library (only for IDE support)
111# OTHERS other library related files (only for IDE support)
112# On return:
113# Library target is defined and added to LIBRARY_FILES
114function(core_add_addon_library name)
115 get_filename_component(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} NAME)
116 list(APPEND SOURCES lib${name}.cpp)
117 core_add_shared_library(${name} OUTPUT_DIRECTORY addons/${DIRECTORY})
118 set_target_properties(${name} PROPERTIES FOLDER addons)
119 target_include_directories(${name} PRIVATE
120 ${CMAKE_CURRENT_SOURCE_DIR}
121 ${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi
122 ${CORE_SOURCE_DIR}/xbmc)
123endfunction()
124
125# Add an dl-loaded shared library
126# Arguments:
127# name name of the library to add
128# Optional arguments:
129# WRAPPED wrap this library on POSIX platforms to add VFS support for
130# libraries that would otherwise not support it.
131# OUTPUT_DIRECTORY where to create the library in the build dir
132# (default: system)
133# Implicit arguments:
134# SOURCES the sources of the library
135# HEADERS the headers of the library (only for IDE support)
136# OTHERS other library related files (only for IDE support)
137# On return:
138# Library target is defined and added to LIBRARY_FILES
139function(core_add_shared_library name)
140 cmake_parse_arguments(arg "WRAPPED" "OUTPUT_DIRECTORY" "" ${ARGN})
141 if(arg_OUTPUT_DIRECTORY)
142 set(OUTPUT_DIRECTORY ${arg_OUTPUT_DIRECTORY})
143 else()
144 if(NOT CORE_SYSTEM_NAME STREQUAL windows)
145 set(OUTPUT_DIRECTORY system)
146 endif()
147 endif()
148 if(CORE_SYSTEM_NAME STREQUAL windows)
149 set(OUTPUT_NAME lib${name})
150 else()
151 set(OUTPUT_NAME lib${name}-${ARCH})
152 endif()
153
154 if(NOT arg_WRAPPED OR CORE_SYSTEM_NAME STREQUAL windows)
155 add_library(${name} SHARED ${SOURCES} ${HEADERS} ${OTHERS})
156 set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${OUTPUT_DIRECTORY}
157 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${OUTPUT_DIRECTORY}
158 OUTPUT_NAME ${OUTPUT_NAME} PREFIX "")
159 foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
160 string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
161 set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OUTPUT_DIRECTORY}
162 RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OUTPUT_DIRECTORY})
163 endforeach()
164
165 set(LIBRARY_FILES ${LIBRARY_FILES} ${CMAKE_BINARY_DIR}/${OUTPUT_DIRECTORY}/${OUTPUT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX} CACHE STRING "" FORCE)
166 add_dependencies(${APP_NAME_LC}-libraries ${name})
167 else()
168 add_library(${name} STATIC ${SOURCES} ${HEADERS} ${OTHERS})
169 set_target_properties(${name} PROPERTIES POSITION_INDEPENDENT_CODE 1)
170 core_link_library(${name} ${OUTPUT_DIRECTORY}/lib${name})
171 endif()
172endfunction()
173
174# Sets the compile language for all C source files in a target to CXX.
175# Needs to be called from the CMakeLists.txt that defines the target.
176# Arguments:
177# target target
178function(set_language_cxx target)
179 get_property(sources TARGET ${target} PROPERTY SOURCES)
180 foreach(file IN LISTS sources)
181 if(file MATCHES "\.c$")
182 set_source_files_properties(${file} PROPERTIES LANGUAGE CXX)
183 endif()
184 endforeach()
185endfunction()
186
187# Add a data file to installation list with a mirror in build tree
188# Mirroring files in the buildtree allows to execute the app from there.
189# Arguments:
190# file full path to file to mirror
191# Optional Arguments:
192# NO_INSTALL: exclude file from installation target (only mirror)
193# DIRECTORY: directory where the file should be mirrored to
194# (default: preserve tree structure relative to CORE_SOURCE_DIR)
195# On return:
196# Files is mirrored to the build tree and added to ${install_data}
197# (if NO_INSTALL is not given).
198function(copy_file_to_buildtree file)
199 cmake_parse_arguments(arg "NO_INSTALL" "DIRECTORY" "" ${ARGN})
200 if(arg_DIRECTORY)
201 set(outdir ${arg_DIRECTORY})
202 get_filename_component(outfile ${file} NAME)
203 set(outfile ${outdir}/${outfile})
204 else()
205 string(REPLACE "${CORE_SOURCE_DIR}/" "" outfile ${file})
206 get_filename_component(outdir ${outfile} DIRECTORY)
207 endif()
208
209 if(NOT TARGET export-files)
210 file(REMOVE ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake)
211 add_custom_target(export-files ALL COMMENT "Copying files into build tree"
212 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake)
213 set_target_properties(export-files PROPERTIES FOLDER "Build Utilities")
214 file(APPEND ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake "# Export files to build tree\n")
215 endif()
216
217 # Exclude autotools build artefacts and other blacklisted files in source tree.
218 if(file MATCHES "(Makefile|\.in|\.xbt|\.so|\.dylib|\.gitignore)$")
219 if(VERBOSE)
220 message(STATUS "copy_file_to_buildtree - ignoring file: ${file}")
221 endif()
222 return()
223 endif()
224
225 if(NOT file STREQUAL ${CMAKE_BINARY_DIR}/${outfile})
226 if(VERBOSE)
227 message(STATUS "copy_file_to_buildtree - copying file: ${file} -> ${CMAKE_BINARY_DIR}/${outfile}")
228 endif()
229 file(APPEND ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake
230 "file(COPY \"${file}\" DESTINATION \"${CMAKE_BINARY_DIR}/${outdir}\")\n")
231 endif()
232
233 if(NOT arg_NO_INSTALL)
234 list(APPEND install_data ${outfile})
235 set(install_data ${install_data} PARENT_SCOPE)
236 endif()
237endfunction()
238
239# Add data files to installation list with a mirror in build tree.
240# reads list of files to install from a given list of text files.
241# Arguments:
242# pattern globbing pattern for text files to read
243# Optional Arguments:
244# NO_INSTALL: exclude files from installation target
245# Implicit arguments:
246# CORE_SOURCE_DIR - root of source tree
247# On return:
248# Files are mirrored to the build tree and added to ${install_data}
249# (if NO_INSTALL is not given).
250function(copy_files_from_filelist_to_buildtree pattern)
251 # copies files listed in text files to the buildtree
252 # Input: [glob pattern: filepattern]
253 cmake_parse_arguments(arg "NO_INSTALL" "" "" ${ARGN})
254 list(APPEND pattern ${ARGN})
255 list(SORT pattern)
256 if(VERBOSE)
257 message(STATUS "copy_files_from_filelist_to_buildtree - got pattern: ${pattern}")
258 endif()
259 foreach(pat ${pattern})
260 file(GLOB filenames ${pat})
261 foreach(filename ${filenames})
262 string(STRIP ${filename} filename)
263 core_file_read_filtered(fstrings ${filename})
264 foreach(dir ${fstrings})
265 string(REPLACE " " ";" dir ${dir})
266 list(GET dir 0 src)
267 list(LENGTH dir len)
268 if(len EQUAL 1)
269 set(dest)
270 else()
271 list(GET dir -1 dest)
272 endif()
273
274 # If the full path to an existing file is specified then add that single file.
275 # Don't recursively add all files with the given name.
276 if(EXISTS ${CORE_SOURCE_DIR}/${src} AND NOT IS_DIRECTORY ${CORE_SOURCE_DIR}/${src})
277 set(files ${src})
278 else()
279 file(GLOB_RECURSE files RELATIVE ${CORE_SOURCE_DIR} ${CORE_SOURCE_DIR}/${src})
280 endif()
281
282 foreach(file ${files})
283 if(arg_NO_INSTALL)
284 copy_file_to_buildtree(${CORE_SOURCE_DIR}/${file} DIRECTORY ${dest} NO_INSTALL)
285 else()
286 copy_file_to_buildtree(${CORE_SOURCE_DIR}/${file} DIRECTORY ${dest})
287 endif()
288 endforeach()
289 endforeach()
290 endforeach()
291 endforeach()
292 set(install_data ${install_data} PARENT_SCOPE)
293endfunction()
294
295# helper macro to set modified variables in parent scope
296macro(export_dep)
297 set(SYSTEM_INCLUDES ${SYSTEM_INCLUDES} PARENT_SCOPE)
298 set(DEPLIBS ${DEPLIBS} PARENT_SCOPE)
299 set(DEP_DEFINES ${DEP_DEFINES} PARENT_SCOPE)
300 set(${depup}_FOUND ${${depup}_FOUND} PARENT_SCOPE)
301 mark_as_advanced(${depup}_LIBRARIES)
302endmacro()
303
304# add a required dependency of main application
305# Arguments:
306# dep name of find rule for dependency, used uppercased for variable prefix
307# On return:
308# dependency added to ${SYSTEM_INCLUDES}, ${DEPLIBS} and ${DEP_DEFINES}
309function(core_require_dep dep)
310 find_package(${dep} REQUIRED)
311 string(TOUPPER ${dep} depup)
312 list(APPEND SYSTEM_INCLUDES ${${depup}_INCLUDE_DIRS})
313 list(APPEND DEPLIBS ${${depup}_LIBRARIES})
314 list(APPEND DEP_DEFINES ${${depup}_DEFINITIONS})
315 export_dep()
316endfunction()
317
318# add a required dyloaded dependency of main application
319# Arguments:
320# dep name of find rule for dependency, used uppercased for variable prefix
321# On return:
322# dependency added to ${SYSTEM_INCLUDES}, ${dep}_SONAME is set up
323function(core_require_dyload_dep dep)
324 find_package(${dep} REQUIRED)
325 string(TOUPPER ${dep} depup)
326 list(APPEND SYSTEM_INCLUDES ${${depup}_INCLUDE_DIRS})
327 list(APPEND DEP_DEFINES ${${depup}_DEFINITIONS})
328 find_soname(${depup} REQUIRED)
329 export_dep()
330 set(${depup}_SONAME ${${depup}_SONAME} PARENT_SCOPE)
331endfunction()
332
333# helper macro for optional deps
334macro(setup_enable_switch)
335 string(TOUPPER ${dep} depup)
336 if(ARGV1)
337 set(enable_switch ${ARGV1})
338 else()
339 set(enable_switch ENABLE_${depup})
340 endif()
341 # normal options are boolean, so we override set our ENABLE_FOO var to allow "auto" handling
342 set(${enable_switch} "AUTO" CACHE STRING "Enable ${depup} support?")
343endmacro()
344
345# add an optional dependency of main application
346# Arguments:
347# dep name of find rule for dependency, used uppercased for variable prefix
348# On return:
349# dependency optionally added to ${SYSTEM_INCLUDES}, ${DEPLIBS} and ${DEP_DEFINES}
350function(core_optional_dep dep)
351 setup_enable_switch()
352 if(${enable_switch} STREQUAL AUTO)
353 find_package(${dep})
354 elseif(${${enable_switch}})
355 find_package(${dep} REQUIRED)
356 endif()
357
358 if(${depup}_FOUND)
359 list(APPEND SYSTEM_INCLUDES ${${depup}_INCLUDE_DIRS})
360 list(APPEND DEPLIBS ${${depup}_LIBRARIES})
361 list(APPEND DEP_DEFINES ${${depup}_DEFINITIONS})
362 set(final_message ${final_message} "${depup} enabled: Yes" PARENT_SCOPE)
363 export_dep()
364 else()
365 set(final_message ${final_message} "${depup} enabled: No" PARENT_SCOPE)
366 endif()
367endfunction()
368
369# add an optional dyloaded dependency of main application
370# Arguments:
371# dep name of find rule for dependency, used uppercased for variable prefix
372# On return:
373# dependency optionally added to ${SYSTEM_INCLUDES}, ${DEP_DEFINES}, ${dep}_SONAME is set up
374function(core_optional_dyload_dep dep)
375 setup_enable_switch()
376 if(${enable_switch})
377 find_package(${dep})
378 if(${depup}_FOUND)
379 list(APPEND SYSTEM_INCLUDES ${${depup}_INCLUDE_DIRS})
380 find_soname(${depup} REQUIRED)
381 list(APPEND DEP_DEFINES ${${depup}_DEFINITIONS})
382 set(final_message ${final_message} "${depup} enabled: Yes" PARENT_SCOPE)
383 export_dep()
384 set(${depup}_SONAME ${${depup}_SONAME} PARENT_SCOPE)
385 endif()
386 endif()
387endfunction()
388
389function(core_file_read_filtered result filepattern)
390 # Reads STRINGS from text files
391 # with comments filtered out
392 # Result: [list: result]
393 # Input: [glob pattern: filepattern]
394 file(GLOB filenames ${filepattern})
395 list(SORT filenames)
396 foreach(filename ${filenames})
397 if(VERBOSE)
398 message(STATUS "core_file_read_filtered - filename: ${filename}")
399 endif()
400 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${filename})
401 file(STRINGS ${filename} fstrings REGEX "^[^#//]")
402 foreach(fstring ${fstrings})
403 string(REGEX REPLACE "^(.*)#(.*)" "\\1" fstring ${fstring})
404 string(REGEX REPLACE "[ \n\r\t]//.*" "" fstring ${fstring})
405 string(STRIP ${fstring} fstring)
406 list(APPEND filename_strings ${fstring})
407 endforeach()
408 endforeach()
409 set(${result} ${filename_strings} PARENT_SCOPE)
410endfunction()
411
412function(core_add_subdirs_from_filelist files)
413 # Adds subdirectories from a sorted list of files
414 # Input: [list: filenames] [bool: sort]
415 foreach(arg ${ARGN})
416 list(APPEND files ${arg})
417 endforeach()
418 list(SORT files)
419 if(VERBOSE)
420 message(STATUS "core_add_subdirs_from_filelist - got pattern: ${files}")
421 endif()
422 foreach(filename ${files})
423 string(STRIP ${filename} filename)
424 core_file_read_filtered(fstrings ${filename})
425 foreach(subdir ${fstrings})
426 string(REPLACE " " ";" subdir ${subdir})
427 list(GET subdir 0 subdir_src)
428 list(GET subdir -1 subdir_dest)
429 if(VERBOSE)
430 message(STATUS " core_add_subdirs_from_filelist - adding subdir: ${CORE_SOURCE_DIR}/${subdir_src} -> ${CORE_BUILD_DIR}/${subdir_dest}")
431 endif()
432 add_subdirectory(${CORE_SOURCE_DIR}/${subdir_src} ${CORE_BUILD_DIR}/${subdir_dest})
433 endforeach()
434 endforeach()
435endfunction()
436
437macro(core_add_optional_subdirs_from_filelist pattern)
438 # Adds subdirectories from text files
439 # if the option(s) in the 3rd field are enabled
440 # Input: [glob pattern: filepattern]
441 foreach(arg ${ARGN})
442 list(APPEND pattern ${arg})
443 endforeach()
444 foreach(elem ${pattern})
445 string(STRIP ${elem} elem)
446 list(APPEND filepattern ${elem})
447 endforeach()
448
449 file(GLOB filenames ${filepattern})
450 list(SORT filenames)
451 if(VERBOSE)
452 message(STATUS "core_add_optional_subdirs_from_filelist - got pattern: ${filenames}")
453 endif()
454
455 foreach(filename ${filenames})
456 if(VERBOSE)
457 message(STATUS "core_add_optional_subdirs_from_filelist - reading file: ${filename}")
458 endif()
459 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${filename})
460 file(STRINGS ${filename} fstrings REGEX "^[^#//]")
461 foreach(line ${fstrings})
462 string(REPLACE " " ";" line "${line}")
463 list(GET line 0 subdir_src)
464 list(GET line 1 subdir_dest)
465 list(GET line 3 opts)
466 foreach(opt ${opts})
467 if(ENABLE_${opt})
468 if(VERBOSE)
469 message(STATUS " core_add_optional_subdirs_from_filelist - adding subdir: ${CORE_SOURCE_DIR}/${subdir_src} -> ${CORE_BUILD_DIR}/${subdir_dest}")
470 endif()
471 add_subdirectory(${CORE_SOURCE_DIR}/${subdir_src} ${CORE_BUILD_DIR}/${subdir_dest})
472 else()
473 if(VERBOSE)
474 message(STATUS " core_add_optional_subdirs_from_filelist: OPTION ${opt} not enabled for ${subdir_src}, skipping subdir")
475 endif()
476 endif()
477 endforeach()
478 endforeach()
479 endforeach()
480endmacro()
481
482# Generates an RFC2822 timestamp
483#
484# The following variable is set:
485# RFC2822_TIMESTAMP
486function(rfc2822stamp)
487 execute_process(COMMAND date -R
488 OUTPUT_VARIABLE RESULT)
489 set(RFC2822_TIMESTAMP ${RESULT} PARENT_SCOPE)
490endfunction()
491
492# Generates an user stamp from git config info
493#
494# The following variable is set:
495# PACKAGE_MAINTAINER - user stamp in the form of "username <username@example.com>"
496# if no git tree is found, value is set to "nobody <nobody@example.com>"
497function(userstamp)
498 find_package(Git)
499 if(GIT_FOUND AND EXISTS ${CORE_SOURCE_DIR}/.git)
500 execute_process(COMMAND ${GIT_EXECUTABLE} config user.name
501 OUTPUT_VARIABLE username
502 WORKING_DIRECTORY ${CORE_SOURCE_DIR}
503 OUTPUT_STRIP_TRAILING_WHITESPACE)
504 execute_process(COMMAND ${GIT_EXECUTABLE} config user.email
505 OUTPUT_VARIABLE useremail
506 WORKING_DIRECTORY ${CORE_SOURCE_DIR}
507 OUTPUT_STRIP_TRAILING_WHITESPACE)
508 set(PACKAGE_MAINTAINER "${username} <${useremail}>" PARENT_SCOPE)
509 else()
510 set(PACKAGE_MAINTAINER "nobody <nobody@example.com>" PARENT_SCOPE)
511 endif()
512endfunction()
513
514# Parses git info and sets variables used to identify the build
515# Arguments:
516# stamp variable name to return
517# Optional Arguments:
518# FULL: generate git HEAD commit in the form of 'YYYYMMDD-hash'
519# if git tree is dirty, value is set in the form of 'YYYYMMDD-hash-dirty'
520# if no git tree is found, value is set in the form of 'YYYYMMDD-nogitfound'
521# if FULL is not given, stamp is generated following the same process as above
522# but without 'YYYYMMDD'
523# On return:
524# Variable is set with generated stamp to PARENT_SCOPE
525function(core_find_git_rev stamp)
526 # allow manual setting GIT_VERSION
527 if(GIT_VERSION)
528 set(${stamp} ${GIT_VERSION} PARENT_SCOPE)
529 else()
530 find_package(Git)
531 if(GIT_FOUND AND EXISTS ${CORE_SOURCE_DIR}/.git)
532 execute_process(COMMAND ${GIT_EXECUTABLE} diff-files --ignore-submodules --quiet --
533 RESULT_VARIABLE status_code
534 WORKING_DIRECTORY ${CORE_SOURCE_DIR})
535 if(NOT status_code)
536 execute_process(COMMAND ${GIT_EXECUTABLE} diff-index --ignore-submodules --quiet HEAD --
537 RESULT_VARIABLE status_code
538 WORKING_DIRECTORY ${CORE_SOURCE_DIR})
539 endif()
540 if(status_code)
541 execute_process(COMMAND ${GIT_EXECUTABLE} log -n 1 --pretty=format:"%h-dirty" HEAD
542 OUTPUT_VARIABLE HASH
543 WORKING_DIRECTORY ${CORE_SOURCE_DIR})
544 string(SUBSTRING ${HASH} 1 13 HASH)
545 else()
546 execute_process(COMMAND ${GIT_EXECUTABLE} log -n 1 --pretty=format:"%h" HEAD
547 OUTPUT_VARIABLE HASH
548 WORKING_DIRECTORY ${CORE_SOURCE_DIR})
549 string(SUBSTRING ${HASH} 1 7 HASH)
550 endif()
551 execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:"%cd" --date=short HEAD
552 OUTPUT_VARIABLE DATE
553 WORKING_DIRECTORY ${CORE_SOURCE_DIR})
554 string(SUBSTRING ${DATE} 1 10 DATE)
555 string(REPLACE "-" "" DATE ${DATE})
556 else()
557 string(TIMESTAMP DATE "%Y%m%d" UTC)
558 set(HASH "nogitfound")
559 endif()
560 cmake_parse_arguments(arg "FULL" "" "" ${ARGN})
561 if(arg_FULL)
562 set(${stamp} ${DATE}-${HASH} PARENT_SCOPE)
563 else()
564 set(${stamp} ${HASH} PARENT_SCOPE)
565 endif()
566 endif()
567endfunction()
568
569# Parses version.txt and libKODI_guilib.h and sets variables
570# used to construct dirs structure, file naming, API version, etc.
571#
572# The following variables are set from version.txt:
573# APP_NAME - app name
574# APP_NAME_LC - lowercased app name
575# APP_NAME_UC - uppercased app name
576# COMPANY_NAME - company name
577# APP_VERSION_MAJOR - the app version major
578# APP_VERSION_MINOR - the app version minor
579# APP_VERSION_TAG - the app version tag
580# APP_VERSION_TAG_LC - lowercased app version tag
581# APP_VERSION - the app version (${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}-${APP_VERSION_TAG})
582# APP_ADDON_API - the addon API version in the form of 16.9.702
583# FILE_VERSION - file version in the form of 16,9,702,0 - Windows only
584#
585# The following variables are set from libKODI_guilib.h:
586# guilib_version - current ADDONGUI API version
587# guilib_version_min - minimal ADDONGUI API version
588macro(core_find_versions)
589 include(CMakeParseArguments)
590 core_file_read_filtered(version_list ${CORE_SOURCE_DIR}/version.txt)
591 string(REPLACE " " ";" version_list "${version_list}")
592 cmake_parse_arguments(APP "" "APP_NAME;COMPANY_NAME;WEBSITE;VERSION_MAJOR;VERSION_MINOR;VERSION_TAG;VERSION_CODE;ADDON_API" "" ${version_list})
593
594 set(APP_NAME ${APP_APP_NAME}) # inconsistency but APP_APP_NAME looks weird
595 string(TOLOWER ${APP_APP_NAME} APP_NAME_LC)
596 string(TOUPPER ${APP_APP_NAME} APP_NAME_UC)
597 set(COMPANY_NAME ${APP_COMPANY_NAME})
598 set(APP_VERSION ${APP_VERSION_MAJOR}.${APP_VERSION_MINOR})
599 if(APP_VERSION_TAG)
600 set(APP_VERSION ${APP_VERSION}-${APP_VERSION_TAG})
601 string(TOLOWER ${APP_VERSION_TAG} APP_VERSION_TAG_LC)
602 endif()
603 string(REPLACE "." "," FILE_VERSION ${APP_ADDON_API}.0)
604 file(STRINGS ${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_guilib.h guilib_version REGEX "^.*GUILIB_API_VERSION (.*)$")
605 string(REGEX REPLACE ".*\"(.*)\"" "\\1" guilib_version ${guilib_version})
606 file(STRINGS ${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_guilib.h guilib_version_min REGEX "^.*GUILIB_MIN_API_VERSION (.*)$")
607 string(REGEX REPLACE ".*\"(.*)\"" "\\1" guilib_version_min ${guilib_version_min})
608 # unset variables not used anywhere else
609 unset(version_list)
610 unset(APP_APP_NAME)
611
612 # bail if we can't parse version.txt
613 if(NOT DEFINED APP_VERSION_MAJOR OR NOT DEFINED APP_VERSION_MINOR)
614 message(FATAL_ERROR "Could not determine app version! Make sure that ${CORE_SOURCE_DIR}/version.txt exists")
615 endif()
616
617 # bail if we can't parse libKODI_guilib.h
618 if(NOT DEFINED guilib_version OR NOT DEFINED guilib_version_min)
619 message(FATAL_ERROR "Could not determine add-on API version! Make sure that ${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_guilib.h exists")
620 endif()
621endmacro()
622