يتطلب كل مشروع CMake استدعاء cmake_minimum_required
لتعيين الحد الأدنى المطلوب من إصدار CMake. ومع ذلك، لا يقدم CMake أي إرشادات حول ماهية هذا الإصدار، والعديد من المشاريع تأخذ فقط إصدار CMake الحالي أو أي شيء يقترحه IDE كإعداد افتراضي. هذه مشكلة، لأن بعض الأنظمة الأساسية لا توفر دائمًا أحدث إصدار من CMake، وهناك حاجة إلى الكثير من التجربة والخطأ قبل استخدام المشاريع.
cmake_min_version
هو برنامج نصي لتحديد الحد الأدنى من إصدار العمل من CMake لمشروع معين. إنه لا يقوم بأي سحر، ولكنه يقوم فقط بإجراء بحث ثنائي باستخدام مجموعة من ثنائيات CMake ويقوم بشكل أساسي بتنفيذ "التجربة والخطأ" بطريقة فعالة.
افترض أن ~/projects/example
يحتوي على مشروع بملف CMakeLists.txt
. ثم يحدد الاستدعاء التالي الحد الأدنى لإصدار العمل من CMake:
❯ venv/bin/python cmake_min_version.py ~ /projects/example
Found 94 CMake binaries from directory tools
[ 0%] CMake 3.9.2 ✔ works
[ 12%] CMake 3.2.2 ✘ error
CMakeLists.txt:7 (cmake_minimum_required)
[ 33%] CMake 3.8.0 ✔ works
[ 50%] CMake 3.7.1 ✘ error
CMakeLists.txt:16 (target_compile_features)
[ 80%] CMake 3.7.2 ✘ error
CMakeLists.txt:16 (target_compile_features)
[100%] Minimal working version: CMake 3.8.0
cmake_minimum_required(VERSION 3.8.0)
ونتيجة لذلك، يمكن تعديل ~/projects/example/CMakeLists.txt
ليتطلب CMake 3.8.0.
المزيد من الخيارات:
usage: cmake_min_version.py [-h] [--tools_directory DIR] [--full_search] [--error_details]
params [params ...]
Find the minimal required CMake version for a project.
positional arguments:
params parameters to pass to CMake
options:
-h, --help show this help message and exit
--tools_directory DIR
path to the CMake binaries (default: " tools " )
--full_search Searches using a top down approach instead of a binary search (default: False)
--error_details Print the full stderr output in case of an error (default: False)
يتطلب الكود تثبيت بعض الحزم:
python3 -mvenv venv
venv/bin/pip3 install -r requirements.txt
يعتني البرنامج النصي cmake_downloader.py
بتنزيل ثنائيات CMake:
usage: cmake_downloader.py [-h] [--os {macos,linux,windows}] [--latest_release]
[--latest_patch] [--first_minor]
[--release_candidates] [--min_version MIN_VERSION]
[--max_version MAX_VERSION] [--tools_directory DIR]
Download CMake binaries.
options:
-h, --help show this help message and exit
--os {macos,linux,windows}
OS to download CMake for (default: linux)
--latest_release only download the latest release (default: False)
--latest_patch only download the latest patch version for each release (default: False)
--first_minor only download the first minor version for each release (default: False)
--release_candidates also consider release candidates (default: False)
--min_version MIN_VERSION
only download versions greater or equal than MIN_VERSION
--max_version MAX_VERSION
only download versions less or equal than MAX_VERSION
--tools_directory DIR
path to the CMake binaries (default: " tools " )
تشغيل المثال:
❯ venv/bin/python3 cmake_downloader.py --latest_patch
Retrieving URLs...
100% | ███████████████████████████████████████████ | 32/32 [00: 18< 00:00, 1.71it/s]
Downloading CMake 2.8.12.2...
100% | ██████████████████████████████████████ | 40.5M/40.5M [00: 12< 00:00, 3.34MB/s]
Downloading CMake 3.0.2...
100% | ██████████████████████████████████████ | 38.7M/38.7M [00: 10< 00:00, 3.90MB/s]
Downloading CMake 3.1.3...
100% | ██████████████████████████████████████ | 28.6M/28.6M [00: 07< 00:00, 3.99MB/s]
Downloading CMake 3.2.3...
100% | ██████████████████████████████████████ | 26.4M/26.4M [00: 07< 00:00, 3.52MB/s]
Downloading CMake 3.3.2...
100% | ██████████████████████████████████████ | 21.3M/21.3M [00: 06< 00:00, 3.68MB/s]
Downloading CMake 3.4.3...
100% | ██████████████████████████████████████ | 21.6M/21.6M [00: 07< 00:00, 3.07MB/s]
Downloading CMake 3.5.2...
100% | ██████████████████████████████████████ | 21.8M/21.8M [00: 06< 00:00, 3.33MB/s]
Downloading CMake 3.6.3...
100% | ██████████████████████████████████████ | 24.9M/24.9M [00: 08< 00:00, 2.92MB/s]
Downloading CMake 3.7.2...
100% | ██████████████████████████████████████ | 25.1M/25.1M [00: 09< 00:00, 2.85MB/s]
Downloading CMake 3.8.2...
100% | ██████████████████████████████████████ | 25.2M/25.2M [00: 06< 00:00, 3.95MB/s]
Downloading CMake 3.9.6...
100% | ██████████████████████████████████████ | 25.5M/25.5M [00: 07< 00:00, 3.41MB/s]
Downloading CMake 3.10.3...
100% | ██████████████████████████████████████ | 25.9M/25.9M [00: 06< 00:00, 3.93MB/s]
Downloading CMake 3.11.4...
100% | ██████████████████████████████████████ | 26.1M/26.1M [00: 06< 00:00, 3.96MB/s]
Downloading CMake 3.12.4...
100% | ██████████████████████████████████████ | 27.7M/27.7M [00: 08< 00:00, 3.44MB/s]
Downloading CMake 3.13.5...
100% | ██████████████████████████████████████ | 30.6M/30.6M [00: 08< 00:00, 3.82MB/s]
Downloading CMake 3.14.7...
100% | ██████████████████████████████████████ | 32.0M/32.0M [00: 08< 00:00, 4.04MB/s]
Downloading CMake 3.15.7...
100% | ██████████████████████████████████████ | 33.2M/33.2M [00: 10< 00:00, 3.44MB/s]
Downloading CMake 3.16.5...
100% | ██████████████████████████████████████ | 34.2M/34.2M [00: 08< 00:00, 4.11MB/s]
Downloading CMake 3.17.0...
100% | ██████████████████████████████████████ | 35.3M/35.3M [00: 10< 00:00, 3.67MB/s]
يقوم البرنامج النصي بتنزيل وتفريغ إصدارات مختلفة من CMake في مجلد tools
.
الكود مرخص بموجب ترخيص MIT:
حقوق النشر © 2020-2024 نيلز لوهمان
يُمنح الإذن مجانًا لأي شخص يحصل على نسخة من هذا البرنامج وملفات الوثائق المرتبطة به ("البرنامج") للتعامل في البرنامج دون قيود، بما في ذلك، على سبيل المثال لا الحصر، حقوق الاستخدام والنسخ والتعديل والدمج. ونشر و/أو توزيع وترخيص من الباطن و/أو بيع نسخ من البرنامج، والسماح للأشخاص الذين تم توفير البرنامج لهم بالقيام بذلك، وفقًا للشروط التالية:
يجب تضمين إشعار حقوق الطبع والنشر أعلاه وإشعار الإذن هذا في جميع النسخ أو الأجزاء الكبيرة من البرنامج.
يتم توفير البرنامج "كما هو"، دون أي ضمان من أي نوع، صريحًا أو ضمنيًا، بما في ذلك، على سبيل المثال لا الحصر، ضمانات القابلية للتسويق والملاءمة لغرض معين وعدم الانتهاك. لا يتحمل المؤلفون أو أصحاب حقوق الطبع والنشر بأي حال من الأحوال المسؤولية عن أي مطالبة أو أضرار أو مسؤولية أخرى، سواء في إجراء العقد أو الضرر أو غير ذلك، الناشئة عن أو خارج أو فيما يتعلق بالبرنامج أو الاستخدام أو المعاملات الأخرى في برمجة.