summaryrefslogtreecommitdiffstats
path: root/project/cmake/scripts/common/check_target_platform.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'project/cmake/scripts/common/check_target_platform.cmake')
-rw-r--r--project/cmake/scripts/common/check_target_platform.cmake61
1 files changed, 61 insertions, 0 deletions
diff --git a/project/cmake/scripts/common/check_target_platform.cmake b/project/cmake/scripts/common/check_target_platform.cmake
new file mode 100644
index 0000000..fc8b403
--- /dev/null
+++ b/project/cmake/scripts/common/check_target_platform.cmake
@@ -0,0 +1,61 @@
1# handle target platforms
2function(check_target_platform dir target_platform build)
3 # param[in] dir path/directory of the addon/dependency
4 # param[in] target_platform target platform of the build
5 # param[out] build Result whether the addon/dependency should be built for the specified target platform
6
7 set(${build} FALSE)
8 # check if the given directory exists and contains a platforms.txt
9 if(EXISTS ${dir} AND EXISTS ${dir}/platforms.txt)
10 # get all the specified platforms
11 file(STRINGS ${dir}/platforms.txt platforms)
12 separate_arguments(platforms)
13
14 # check if the addon/dependency should be built for the current platform
15 foreach(platform ${platforms})
16 if(${platform} STREQUAL "all" OR ${platform} STREQUAL ${target_platform})
17 set(${build} TRUE)
18 else()
19 # check if the platform is defined as "!<platform>"
20 string(SUBSTRING ${platform} 0 1 platform_first)
21 if(${platform_first} STREQUAL "!")
22 # extract the platform
23 string(LENGTH ${platform} platform_length)
24 MATH(EXPR platform_length "${platform_length} - 1")
25 string(SUBSTRING ${platform} 1 ${platform_length} platform)
26
27 # check if the current platform does not match the extracted platform
28 if (NOT ${platform} STREQUAL ${target_platform})
29 set(${build} TRUE)
30 endif()
31 endif()
32 endif()
33 endforeach()
34 else()
35 set(${build} TRUE)
36 endif()
37
38 # make the ${build} variable available to the calling script
39 set(${build} "${${build}}" PARENT_SCOPE)
40endfunction()
41
42function(check_install_permissions install_dir have_perms)
43 # param[in] install_dir directory to check for write permissions
44 # param[out] have_perms wether we have permissions to install to install_dir
45
46 set(${have_perms} TRUE)
47 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}/lib/kodi
48 COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}/share/kodi
49 COMMAND ${CMAKE_COMMAND} -E touch ${install_dir}/lib/kodi/.cmake-inst-test ${install_dir}/share/kodi/.cmake-inst-test
50 RESULT_VARIABLE permtest)
51
52 if(${permtest} GREATER 0)
53 message(STATUS "check_install_permissions: ${permtest}")
54 set(${have_perms} FALSE)
55 endif()
56 set(${have_perms} "${${have_perms}}" PARENT_SCOPE)
57
58 if(EXISTS ${install_dir}/lib/kodi/.cmake-inst-test OR EXISTS ${install_dir}/share/kodi/.cmake-inst-test)
59 file(REMOVE ${install_dir}/lib/kodi/.cmake-inst-test ${install_dir}/share/kodi/.cmake-inst-test)
60 endif()
61endfunction()