summaryrefslogtreecommitdiffstats
path: root/project/cmake/scripts/common/CheckTargetPlatform.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'project/cmake/scripts/common/CheckTargetPlatform.cmake')
-rw-r--r--project/cmake/scripts/common/CheckTargetPlatform.cmake63
1 files changed, 63 insertions, 0 deletions
diff --git a/project/cmake/scripts/common/CheckTargetPlatform.cmake b/project/cmake/scripts/common/CheckTargetPlatform.cmake
new file mode 100644
index 0000000..5b5d9a1
--- /dev/null
+++ b/project/cmake/scripts/common/CheckTargetPlatform.cmake
@@ -0,0 +1,63 @@
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 string(REPLACE " " ";" platforms ${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(testfile_lib ${install_dir}/lib/kodi/.cmake-inst-test)
47 set(testfile_share ${install_dir}/share/kodi/.cmake-inst-test)
48 get_filename_component(testdir_lib ${testfile_lib} DIRECTORY)
49 get_filename_component(testdir_share ${testfile_share} DIRECTORY)
50
51 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${testdir_lib})
52 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${testdir_share})
53 execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${testfile_lib})
54 execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${testfile_share})
55
56 if(EXISTS ${testfile_lib} AND EXISTS ${testfile_share})
57 set(${have_perms} True PARENT_SCOPE)
58 else()
59 message(STATUS "check_install_permissions ${install_dir}: failed to create files")
60 set(${have_perms} False PARENT_SCOPE)
61 endif()
62 file(REMOVE ${testfile_lib} ${testfile_share})
63endfunction()