summaryrefslogtreecommitdiffstats
path: root/project/cmake/scripts/common/handle-depends.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'project/cmake/scripts/common/handle-depends.cmake')
-rw-r--r--project/cmake/scripts/common/handle-depends.cmake209
1 files changed, 0 insertions, 209 deletions
diff --git a/project/cmake/scripts/common/handle-depends.cmake b/project/cmake/scripts/common/handle-depends.cmake
deleted file mode 100644
index 4d78928..0000000
--- a/project/cmake/scripts/common/handle-depends.cmake
+++ /dev/null
@@ -1,209 +0,0 @@
1include(${APP_ROOT}/project/cmake/scripts/common/check_target_platform.cmake)
2
3# handle addon depends
4function(add_addon_depends addon searchpath)
5 # input: string addon string searchpath
6
7 set(OUTPUT_DIR ${DEPENDS_PATH})
8 file(GLOB_RECURSE cmake_input_files ${searchpath}/${CORE_SYSTEM_NAME}/*.txt)
9 file(GLOB_RECURSE cmake_input_files2 ${searchpath}/common/*.txt)
10 list(APPEND cmake_input_files ${cmake_input_files2})
11
12 foreach(file ${cmake_input_files})
13 if(NOT (file MATCHES CMakeLists.txt OR
14 file MATCHES install.txt OR
15 file MATCHES noinstall.txt OR
16 file MATCHES flags.txt OR
17 file MATCHES deps.txt OR
18 file MATCHES platforms.txt))
19 message(STATUS "Processing ${file}")
20 file(STRINGS ${file} def)
21 separate_arguments(def)
22 list(LENGTH def deflength)
23 get_filename_component(dir ${file} PATH)
24
25 # get the id of the dependency
26 if(NOT "${def}" STREQUAL "")
27 # read the id from the file
28 list(GET def 0 id)
29 else()
30 # read the id from the filename
31 get_filename_component(id ${file} NAME_WE)
32 endif()
33
34 # check if the dependency has a platforms.txt
35 set(platform_found FALSE)
36 check_target_platform(${dir} ${CORE_SYSTEM_NAME} platform_found)
37
38 if(${platform_found} AND NOT TARGET ${id})
39 # determine the download URL of the dependency
40 set(url "")
41 if(deflength GREATER 1)
42 list(GET def 1 url)
43 message(STATUS "${id} url: ${url}")
44 endif()
45
46 # check if there are any library specific flags that need to be passed on
47 if(EXISTS ${dir}/flags.txt)
48 file(STRINGS ${dir}/flags.txt extraflags)
49 separate_arguments(extraflags)
50 message(STATUS "${id} extraflags: ${extraflags}")
51 endif()
52
53 set(BUILD_ARGS -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
54 -DOUTPUT_DIR=${OUTPUT_DIR}
55 -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
56 -DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_USER_MAKE_RULES_OVERRIDE}
57 -DCMAKE_USER_MAKE_RULES_OVERRIDE_CXX=${CMAKE_USER_MAKE_RULES_OVERRIDE_CXX}
58 -DCMAKE_INSTALL_PREFIX=${OUTPUT_DIR}
59 -DCORE_SYSTEM_NAME=${CORE_SYSTEM_NAME}
60 -DENABLE_STATIC=1
61 -DBUILD_SHARED_LIBS=0)
62 # if there are no make rules override files available take care of manually passing on ARCH_DEFINES
63 if(NOT CMAKE_USER_MAKE_RULES_OVERRIDE AND NOT CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
64 # make sure we create strings, not lists
65 set(TMP_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH_DEFINES}")
66 set(TMP_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_DEFINES}")
67 list(APPEND BUILD_ARGS -DCMAKE_C_FLAGS=${TMP_C_FLAGS}
68 -DCMAKE_CXX_FLAGS=${TMP_CXX_FLAGS})
69 endif()
70
71 if(CMAKE_TOOLCHAIN_FILE)
72 list(APPEND BUILD_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
73 MESSAGE("toolchain specified")
74 MESSAGE(${BUILD_ARGS})
75 endif()
76
77 # if there's a CMakeLists.txt use it to prepare the build
78 set(PATCH_FILE ${BUILD_DIR}/${id}/tmp/patch.cmake)
79 if(EXISTS ${dir}/CMakeLists.txt)
80 file(APPEND ${PATCH_FILE}
81 "file(COPY ${dir}/CMakeLists.txt
82 DESTINATION ${BUILD_DIR}/${id}/src/${id})\n")
83 endif()
84
85 # check if we have patches to apply
86 file(GLOB patches ${dir}/*.patch)
87 list(SORT patches)
88 foreach(patch ${patches})
89 if(NOT PATCH_PROGRAM OR "${PATCH_PROGRAM}" STREQUAL "")
90 if(NOT PATCH_EXECUTABLE)
91 # find the path to the patch executable
92 find_program(PATCH_EXECUTABLE NAMES patch)
93
94 if(NOT PATCH_EXECUTABLE)
95 message(FATAL_ERROR "Missing patch command (we looked in ${CMAKE_PREFIX_PATH})")
96 endif()
97 endif()
98
99 # on windows "patch.exe" can only handle CR-LF line-endings so we
100 # need to force it to also handle LF-only line endings
101 set(PATCH_PROGRAM ${PATCH_EXECUTABLE})
102 if(WIN32)
103 set(PATCH_PROGRAM "\"${PATCH_PROGRAM}\" --binary")
104 endif()
105 endif()
106
107 file(APPEND ${PATCH_FILE}
108 "execute_process(COMMAND ${PATCH_PROGRAM} -p1 -i \"${patch}\")\n")
109 endforeach()
110
111
112 # if there's an install.txt use it to properly install the built files
113 set(INSTALL_COMMAND "")
114 if(EXISTS ${dir}/install.txt)
115 set(INSTALL_COMMAND INSTALL_COMMAND ${CMAKE_COMMAND}
116 -DINPUTDIR=${BUILD_DIR}/${id}/src/${id}-build/
117 -DINPUTFILE=${dir}/install.txt
118 -DDESTDIR=${OUTPUT_DIR}
119 -DENABLE_STATIC=1
120 "${extraflags}"
121 -P ${PROJECT_SOURCE_DIR}/install.cmake)
122 elseif(EXISTS ${dir}/noinstall.txt)
123 set(INSTALL_COMMAND INSTALL_COMMAND "")
124 endif()
125
126 # check if there's a deps.txt containing dependencies on other libraries
127 if(EXISTS ${dir}/deps.txt)
128 file(STRINGS ${dir}/deps.txt deps)
129 message(STATUS "${id} depends: ${deps}")
130 else()
131 set(deps)
132 endif()
133
134 if(CROSS_AUTOCONF AND AUTOCONF_FILES)
135 foreach(afile ${AUTOCONF_FILES})
136 file(APPEND ${PATCH_FILE}
137 "message(STATUS \"AUTOCONF: copying ${afile} to ${BUILD_DIR}/${id}/src/${id}\")\n
138 file(COPY ${afile} DESTINATION ${BUILD_DIR}/${id}/src/${id})\n")
139 endforeach()
140 endif()
141
142 # if the patch file exists we need to set the PATCH_COMMAND
143 set(PATCH_COMMAND "")
144 if (EXISTS ${PATCH_FILE})
145 set(PATCH_COMMAND ${CMAKE_COMMAND} -P ${PATCH_FILE})
146 endif()
147
148 # prepare the setup of the call to externalproject_add()
149 set(EXTERNALPROJECT_SETUP PREFIX ${BUILD_DIR}/${id}
150 CMAKE_ARGS ${extraflags} ${BUILD_ARGS}
151 PATCH_COMMAND ${PATCH_COMMAND}
152 "${INSTALL_COMMAND}")
153
154 # if there's an url defined we need to pass that to externalproject_add()
155 if(DEFINED url AND NOT "${url}" STREQUAL "")
156 # check if there's a third parameter in the file
157 if(deflength GREATER 2)
158 # the third parameter is considered as a revision of a git repository
159 list(GET def 2 revision)
160
161 externalproject_add(${id}
162 GIT_REPOSITORY ${url}
163 GIT_TAG ${revision}
164 "${EXTERNALPROJECT_SETUP}")
165 else()
166 set(CONFIGURE_COMMAND "")
167 if(NOT WIN32)
168 # manually specify the configure command to be able to pass in the custom PKG_CONFIG_PATH
169 set(CONFIGURE_COMMAND PKG_CONFIG_PATH=${OUTPUT_DIR}/lib/pkgconfig
170 ${CMAKE_COMMAND} -DCMAKE_LIBRARY_PATH=${OUTPUT_DIR}/lib ${extraflags} ${BUILD_ARGS}
171 ${BUILD_DIR}/${id}/src/${id}
172 -DPACKAGE_CONFIG_PATH=${OUTPUT_DIR}/lib/pkgconfig
173 -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
174 -DOUTPUT_DIR=${OUTPUT_DIR}
175 -DCMAKE_PREFIX_PATH=${OUTPUT_DIR}
176 -DCMAKE_INSTALL_PREFIX=${OUTPUT_DIR}
177 -DCMAKE_EXE_LINKER_FLAGS=-L${OUTPUT_DIR}/lib
178 -DCMAKE_INCLUDE_PATH=${OUTPUT_DIR}/include)
179 endif()
180
181 externalproject_add(${id}
182 URL ${url}
183 DOWNLOAD_DIR ${BUILD_DIR}/download
184 CONFIGURE_COMMAND ${CONFIGURE_COMMAND}
185 "${EXTERNALPROJECT_SETUP}")
186 endif()
187 else()
188 externalproject_add(${id}
189 SOURCE_DIR ${dir}
190 "${EXTERNALPROJECT_SETUP}")
191 endif()
192
193 if(deps)
194 add_dependencies(${id} ${deps})
195 endif()
196 endif()
197
198 # if the dependency is available for the target platform add it to the list of the addon's dependencies
199 # (even if the target already exists as it still has to be built before the addon)
200 if(${platform_found})
201 list(APPEND ${addon}_DEPS ${id})
202 endif()
203 endif()
204 endforeach()
205
206 # make the ${addon}_DEPS variable available to the calling script
207 set(${addon}_DEPS "${${addon}_DEPS}" PARENT_SCOPE)
208endfunction()
209