summaryrefslogtreecommitdiffstats
path: root/cmake/scripts/common/CheckTargetPlatform.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/scripts/common/CheckTargetPlatform.cmake')
-rw-r--r--cmake/scripts/common/CheckTargetPlatform.cmake67
1 files changed, 67 insertions, 0 deletions
diff --git a/cmake/scripts/common/CheckTargetPlatform.cmake b/cmake/scripts/common/CheckTargetPlatform.cmake
new file mode 100644
index 0000000..82ee668
--- /dev/null
+++ b/cmake/scripts/common/CheckTargetPlatform.cmake
@@ -0,0 +1,67 @@
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
13 list( LENGTH platforms listlen )
14 if(${listlen} EQUAL 1)
15 string(REPLACE " " ";" platforms ${platforms})
16 endif()
17
18 # check if the addon/dependency should be built for the current platform
19 foreach(platform ${platforms})
20 if(${platform} STREQUAL "all" OR ${platform} STREQUAL ${target_platform})
21 set(${build} TRUE)
22 else()
23 # check if the platform is defined as "!<platform>"
24 string(SUBSTRING ${platform} 0 1 platform_first)
25 if(${platform_first} STREQUAL "!")
26 # extract the platform
27 string(LENGTH ${platform} platform_length)
28 math(EXPR platform_length "${platform_length} - 1")
29 string(SUBSTRING ${platform} 1 ${platform_length} platform)
30
31 # check if the current platform does not match the extracted platform
32 if(NOT ${platform} STREQUAL ${target_platform})
33 set(${build} TRUE)
34 endif()
35 endif()
36 endif()
37 endforeach()
38 else()
39 set(${build} TRUE)
40 endif()
41
42 # make the ${build} variable available to the calling script
43 set(${build} "${${build}}" PARENT_SCOPE)
44endfunction()
45
46function(check_install_permissions install_dir have_perms)
47 # param[in] install_dir directory to check for write permissions
48 # param[out] have_perms wether we have permissions to install to install_dir
49
50 set(testfile_lib ${install_dir}/lib/kodi/.cmake-inst-test)
51 set(testfile_share ${install_dir}/share/kodi/.cmake-inst-test)
52 get_filename_component(testdir_lib ${testfile_lib} DIRECTORY)
53 get_filename_component(testdir_share ${testfile_share} DIRECTORY)
54
55 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${testdir_lib})
56 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${testdir_share})
57 execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${testfile_lib})
58 execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${testfile_share})
59
60 if(EXISTS ${testfile_lib} AND EXISTS ${testfile_share})
61 set(${have_perms} True PARENT_SCOPE)
62 else()
63 message(STATUS "check_install_permissions ${install_dir}: failed to create files")
64 set(${have_perms} False PARENT_SCOPE)
65 endif()
66 file(REMOVE ${testfile_lib} ${testfile_share})
67endfunction()