|
17 | 17 | # |
18 | 18 | # ============================================================================== |
19 | 19 |
|
20 | | -#============================================================================== |
21 | | - |
22 | 20 | function (_yup_module_parse_config module_header output_module_configs output_module_user_configs) |
23 | 21 | set (module_configs "") |
24 | 22 | set (module_user_configs "") |
@@ -58,6 +56,181 @@ endfunction() |
58 | 56 |
|
59 | 57 | #============================================================================== |
60 | 58 |
|
| 59 | +function (_yup_module_upstream_has_content module_name module_path output_variable) |
| 60 | + _yup_collect_upstream_candidate_paths ("${module_name}" "${module_path}" candidate_paths) |
| 61 | + foreach (candidate_path IN LISTS candidate_paths) |
| 62 | + if (EXISTS "${candidate_path}") |
| 63 | + file (GLOB upstream_items "${candidate_path}/*") |
| 64 | + list (LENGTH upstream_items upstream_items_len) |
| 65 | + if (upstream_items_len GREATER 0) |
| 66 | + set (${output_variable} ON PARENT_SCOPE) |
| 67 | + return() |
| 68 | + endif() |
| 69 | + endif() |
| 70 | + endforeach() |
| 71 | + |
| 72 | + set (${output_variable} OFF PARENT_SCOPE) |
| 73 | +endfunction() |
| 74 | + |
| 75 | +#============================================================================== |
| 76 | + |
| 77 | +function (_yup_module_get_upstream_path module_name module_path output_variable) |
| 78 | + _yup_collect_upstream_candidate_paths ("${module_name}" "${module_path}" candidate_paths) |
| 79 | + foreach (candidate_path IN LISTS candidate_paths) |
| 80 | + if (EXISTS "${candidate_path}") |
| 81 | + set (${output_variable} "${candidate_path}" PARENT_SCOPE) |
| 82 | + return() |
| 83 | + endif() |
| 84 | + endforeach() |
| 85 | + |
| 86 | + set (${output_variable} "" PARENT_SCOPE) |
| 87 | +endfunction() |
| 88 | + |
| 89 | +#============================================================================== |
| 90 | + |
| 91 | +function (_yup_module_fetch_upstream module_name module_path module_upstream module_sha256 module_repository module_branch module_submodules output_target_variable) |
| 92 | + if (NOT YUP_FETCH_UPSTREAM_MODULES) |
| 93 | + return() |
| 94 | + endif() |
| 95 | + |
| 96 | + if (module_upstream AND module_repository) |
| 97 | + _yup_message (FATAL_ERROR "Module ${module_name} defines both upstream and repository sources") |
| 98 | + endif() |
| 99 | + |
| 100 | + if (NOT module_upstream AND NOT module_repository) |
| 101 | + return() |
| 102 | + endif() |
| 103 | + |
| 104 | + _yup_module_upstream_has_content ("${module_name}" "${module_path}" upstream_has_content) |
| 105 | + if (upstream_has_content) |
| 106 | + return() |
| 107 | + endif() |
| 108 | + |
| 109 | + _yup_message (STATUS "Fetching upstream sources for ${module_name}") |
| 110 | + |
| 111 | + if (module_upstream) |
| 112 | + set (download_dir "${CMAKE_BINARY_DIR}/_yup_upstream_downloads") |
| 113 | + file (MAKE_DIRECTORY "${download_dir}") |
| 114 | + get_filename_component (archive_name "${module_upstream}" NAME) |
| 115 | + if ("${archive_name}" STREQUAL "") |
| 116 | + set (archive_name "${module_name}.archive") |
| 117 | + endif() |
| 118 | + set (archive_path "${download_dir}/${archive_name}") |
| 119 | + |
| 120 | + # SHOW_PROGRESS |
| 121 | + if (module_sha256) |
| 122 | + file (DOWNLOAD "${module_upstream}" "${archive_path}" EXPECTED_HASH SHA256=${module_sha256}) |
| 123 | + else() |
| 124 | + file (DOWNLOAD "${module_upstream}" "${archive_path}") |
| 125 | + endif() |
| 126 | + |
| 127 | + set (extract_dir "${CMAKE_BINARY_DIR}/_yup_upstream_extract/${module_name}") |
| 128 | + file (REMOVE_RECURSE "${extract_dir}") |
| 129 | + file (MAKE_DIRECTORY "${extract_dir}") |
| 130 | + file (ARCHIVE_EXTRACT INPUT "${archive_path}" DESTINATION "${extract_dir}") |
| 131 | + |
| 132 | + file (GLOB extracted_entries RELATIVE "${extract_dir}" "${extract_dir}/*") |
| 133 | + list (LENGTH extracted_entries extracted_entries_len) |
| 134 | + set (source_dir "${extract_dir}") |
| 135 | + if (extracted_entries_len EQUAL 1) |
| 136 | + list (GET extracted_entries 0 single_entry) |
| 137 | + if (IS_DIRECTORY "${extract_dir}/${single_entry}") |
| 138 | + set (source_dir "${extract_dir}/${single_entry}") |
| 139 | + endif() |
| 140 | + endif() |
| 141 | + |
| 142 | + set (upstream_target_dir "${CMAKE_BINARY_DIR}/externals/${module_name}/upstream") |
| 143 | + file (REMOVE_RECURSE "${upstream_target_dir}") |
| 144 | + file (MAKE_DIRECTORY "${upstream_target_dir}") |
| 145 | + file (GLOB extracted_items "${source_dir}/*") |
| 146 | + if (extracted_items) |
| 147 | + file (COPY ${extracted_items} DESTINATION "${upstream_target_dir}") |
| 148 | + endif() |
| 149 | + else() |
| 150 | + if (NOT module_branch) |
| 151 | + set (module_branch "HEAD") |
| 152 | + endif() |
| 153 | + |
| 154 | + set (upstream_target_dir "${CMAKE_BINARY_DIR}/externals/${module_name}/upstream") |
| 155 | + if (module_submodules) |
| 156 | + set (module_submodules_recurse ON) |
| 157 | + else() |
| 158 | + set (module_submodules_recurse OFF) |
| 159 | + endif() |
| 160 | + |
| 161 | + file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/externals/${module_name}") |
| 162 | + |
| 163 | + file (REMOVE_RECURSE "${upstream_target_dir}") |
| 164 | + set (module_branch_value "${module_branch}") |
| 165 | + string (STRIP "${module_branch_value}" module_branch_value) |
| 166 | + string (REGEX REPLACE "^\"(.*)\"$" "\\1" module_branch_value "${module_branch_value}") |
| 167 | + string (REGEX REPLACE "^'(.*)'$" "\\1" module_branch_value "${module_branch_value}") |
| 168 | + |
| 169 | + if (module_branch_value AND NOT module_branch_value STREQUAL "HEAD") |
| 170 | + string (REGEX MATCH "^[0-9a-fA-F]+$" module_branch_is_hex "${module_branch_value}") |
| 171 | + string (LENGTH "${module_branch_value}" module_branch_length) |
| 172 | + if (module_branch_is_hex AND module_branch_length GREATER_EQUAL 7 AND module_branch_length LESS_EQUAL 40) |
| 173 | + set (module_branch_is_commit ON) |
| 174 | + else() |
| 175 | + set (module_branch_is_commit "") |
| 176 | + endif() |
| 177 | + else() |
| 178 | + set (module_branch_is_commit "") |
| 179 | + endif() |
| 180 | + |
| 181 | + if (module_branch_is_commit) |
| 182 | + execute_process ( |
| 183 | + COMMAND git clone -q --no-checkout "${module_repository}" "${upstream_target_dir}" |
| 184 | + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/externals/${module_name}" |
| 185 | + RESULT_VARIABLE clone_result) |
| 186 | + if (clone_result EQUAL 0) |
| 187 | + execute_process ( |
| 188 | + COMMAND git -c advice.detachedHead=false -C "${upstream_target_dir}" fetch -q --depth=1 origin "${module_branch_value}" |
| 189 | + RESULT_VARIABLE fetch_result) |
| 190 | + execute_process ( |
| 191 | + COMMAND git -c advice.detachedHead=false -C "${upstream_target_dir}" checkout -q "${module_branch_value}" |
| 192 | + RESULT_VARIABLE checkout_result) |
| 193 | + if (module_submodules_recurse AND fetch_result EQUAL 0 AND checkout_result EQUAL 0) |
| 194 | + execute_process ( |
| 195 | + COMMAND git -c advice.detachedHead=false -C "${upstream_target_dir}" submodule update --init --recursive --depth=1 |
| 196 | + RESULT_VARIABLE submodule_result) |
| 197 | + endif() |
| 198 | + endif() |
| 199 | + else() |
| 200 | + set (clone_args git clone) |
| 201 | + if (module_submodules_recurse) |
| 202 | + list (APPEND clone_args --recurse-submodules --shallow-submodules) |
| 203 | + endif() |
| 204 | + list (APPEND clone_args -q --depth=1) |
| 205 | + if (module_branch_value AND NOT module_branch_value STREQUAL "HEAD") |
| 206 | + list (APPEND clone_args --branch "${module_branch_value}") |
| 207 | + endif() |
| 208 | + list (APPEND clone_args "${module_repository}" "${upstream_target_dir}") |
| 209 | + execute_process ( |
| 210 | + COMMAND ${clone_args} |
| 211 | + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/externals/${module_name}" |
| 212 | + RESULT_VARIABLE clone_result) |
| 213 | + endif() |
| 214 | + |
| 215 | + if (module_branch_is_commit) |
| 216 | + if (NOT clone_result EQUAL 0 OR NOT fetch_result EQUAL 0 OR NOT checkout_result EQUAL 0) |
| 217 | + _yup_message (FATAL_ERROR "Failed to clone ${module_repository} at commit ${module_branch} for ${module_name}") |
| 218 | + endif() |
| 219 | + if (module_submodules_recurse AND NOT submodule_result EQUAL 0) |
| 220 | + _yup_message (FATAL_ERROR "Failed to update submodules for ${module_repository} at commit ${module_branch}") |
| 221 | + endif() |
| 222 | + else() |
| 223 | + if (NOT clone_result EQUAL 0) |
| 224 | + _yup_message (FATAL_ERROR "Failed to clone ${module_repository} for ${module_name}") |
| 225 | + endif() |
| 226 | + endif() |
| 227 | + |
| 228 | + set (${output_target_variable} "" PARENT_SCOPE) |
| 229 | + endif() |
| 230 | +endfunction() |
| 231 | + |
| 232 | +#============================================================================== |
| 233 | + |
61 | 234 | function (_yup_module_collect_sources folder output_variable) |
62 | 235 | set(source_extensions ".c;.cc;.cxx;.cpp;.h;.hh;.hxx;.hpp") |
63 | 236 | if (APPLE) |
@@ -363,14 +536,37 @@ function (yup_add_module module_path modules_definitions module_group) |
363 | 536 | _yup_boolean_property ("${value}" module_arc_enabled) |
364 | 537 | elseif (${key} MATCHES "^needsPython$") |
365 | 538 | _yup_boolean_property ("${value}" module_needs_python) |
| 539 | + elseif (${key} MATCHES "^upstream$") |
| 540 | + set (module_upstream "${value}") |
| 541 | + elseif (${key} MATCHES "^sha256$") |
| 542 | + set (module_sha256 "${value}") |
| 543 | + elseif (${key} MATCHES "^repository$") |
| 544 | + set (module_repository "${value}") |
| 545 | + elseif (${key} MATCHES "^branch$") |
| 546 | + set (module_branch "${value}") |
| 547 | + elseif (${key} MATCHES "^submodules$") |
| 548 | + _yup_boolean_property ("${value}" module_submodules) |
366 | 549 | endif() |
367 | 550 | endforeach() |
368 | 551 |
|
369 | 552 | _yup_set_default (module_cpp_standard "20") |
370 | 553 | _yup_set_default (module_arc_enabled OFF) |
371 | 554 | _yup_set_default (module_needs_python OFF) |
| 555 | + _yup_set_default (module_submodules ON) |
372 | 556 | _yup_resolve_variable_paths ("${module_searchpaths}" module_searchpaths) |
373 | 557 |
|
| 558 | + set (module_upstream_target "") |
| 559 | + if (module_upstream OR module_repository) |
| 560 | + _yup_module_upstream_has_content ("${module_name}" "${module_path}" upstream_has_content) |
| 561 | + if (NOT upstream_has_content) |
| 562 | + if (YUP_FETCH_UPSTREAM_MODULES) |
| 563 | + _yup_module_fetch_upstream ("${module_name}" "${module_path}" "${module_upstream}" "${module_sha256}" "${module_repository}" "${module_branch}" "${module_submodules}" module_upstream_target) |
| 564 | + else() |
| 565 | + _yup_message (WARNING "Upstream sources for ${module_name} are missing and YUP_FETCH_UPSTREAM_MODULES is OFF") |
| 566 | + endif() |
| 567 | + endif() |
| 568 | + endif() |
| 569 | + |
374 | 570 | # ==== Setup Platform-Specific Configurations |
375 | 571 | if (YUP_PLATFORM_IOS) |
376 | 572 | if (module_appleCppStandard) |
@@ -513,11 +709,24 @@ function (yup_add_module module_path modules_definitions module_group) |
513 | 709 | get_filename_component (module_include_path ${module_path} DIRECTORY) |
514 | 710 | list (APPEND module_include_paths "${module_include_path}") |
515 | 711 |
|
| 712 | + if (module_upstream OR module_repository) |
| 713 | + _yup_module_get_upstream_path ("${module_name}" "${module_path}" module_upstream_path) |
| 714 | + if (module_upstream_path) |
| 715 | + list (APPEND module_include_paths "${module_upstream_path}") |
| 716 | + else() |
| 717 | + list (APPEND module_include_paths "${CMAKE_BINARY_DIR}/externals/${module_name}/upstream") |
| 718 | + endif() |
| 719 | + endif() |
| 720 | + |
516 | 721 | foreach (searchpath IN LISTS module_searchpaths) |
517 | 722 | if (EXISTS "${searchpath}") |
518 | 723 | list (APPEND module_include_paths "${searchpath}") |
519 | 724 | elseif (EXISTS "${module_path}/${searchpath}") |
520 | 725 | list (APPEND module_include_paths "${module_path}/${searchpath}") |
| 726 | + elseif (module_upstream_path AND EXISTS "${module_upstream_path}/${searchpath}") |
| 727 | + list (APPEND module_include_paths "${module_upstream_path}/${searchpath}") |
| 728 | + elseif (module_upstream OR module_repository) |
| 729 | + list (APPEND module_include_paths "${CMAKE_BINARY_DIR}/externals/${module_name}/upstream/${searchpath}") |
521 | 730 | endif() |
522 | 731 | endforeach() |
523 | 732 |
|
@@ -558,6 +767,10 @@ function (yup_add_module module_path modules_definitions module_group) |
558 | 767 | "${module_dependencies}" |
559 | 768 | "${module_arc_enabled}") |
560 | 769 |
|
| 770 | + if (module_upstream_target) |
| 771 | + add_dependencies (${module_name} "${module_upstream_target}") |
| 772 | + endif() |
| 773 | + |
561 | 774 | #set (${module_name}_Configs "${module_user_configs}") |
562 | 775 | #set (${module_name}_Configs ${${module_name}_Configs} PARENT_SCOPE) |
563 | 776 |
|
@@ -621,6 +834,9 @@ macro (yup_add_default_modules modules_path) |
621 | 834 | yup_add_module (${modules_path}/thirdparty/oboe_library "${modules_definitions}" ${thirdparty_group}) |
622 | 835 | yup_add_module (${modules_path}/thirdparty/pffft_library "${modules_definitions}" ${thirdparty_group}) |
623 | 836 | yup_add_module (${modules_path}/thirdparty/dr_libs "${modules_definitions}" ${thirdparty_group}) |
| 837 | + yup_add_module (${modules_path}/thirdparty/opus_library "${modules_definitions}" ${thirdparty_group}) |
| 838 | + yup_add_module (${modules_path}/thirdparty/flac_library "${modules_definitions}" ${thirdparty_group}) |
| 839 | + yup_add_module (${modules_path}/thirdparty/hmp3_library "${modules_definitions}" ${thirdparty_group}) |
624 | 840 |
|
625 | 841 | # ==== Yup modules |
626 | 842 | set (modules_group "Modules") |
|
0 commit comments