我希望有一種作法能夠幫助我, 在將來不用思考如何操作及查詢說明文件, 甚至連 GUI 的按鈕都不用知道的情況下, 就能產生我想要的文件.
對 cmake 來說, 我連命令列視窗都不想開, GUI 也不想操作. 那麼答案很簡單, 就是寫一個 script 自動完成我想做的事情.
在 Windows 裡最簡單的 script 檔, 就是 bat 檔.
關鍵知識:
Q: 如何設定 bat 檔變數?
<sol> set target=”c:\bin”
echo target=%target%
Q: 如何在一個字串中取出某個 sub-string ?
<sol>
set target=abc
set driver=%target:~1,2% Rem: 取出第二到第三之間的字串
echo driver=%driver% Rem: 輸出為 bc
下面是我寫的最簡單範例: make.bat
使用方式
Step 1: 只要填入下面三項資訊: target, source, platform 即可.
Step 2: 滑鼠 double clicked “make.bat”
Step 3: 完成
批次檔細節
:: =============== make .bat =================
:: Automatically Generate the VS Project File
:: by Jing.
:: Step 1: Setup variable
set target="c:\bin" REM: 產生的專案檔要放在哪裡
set source="E:\demo\src" REM: 設定你的 Source code 位置
set platform="Visual Studio 8 2005" REM: 我要產生的是 VS 2005 專案檔
echo tartet=%target%
echo dirver=%driver%
echo platform=%platform%
:: Step 2: Get the driver information
set driver=%target:~1,2% REM: driver=c:
:: Step 3: Create the target directory and go to the directory
mkdir %target%
cd %target%
%driver%
:: Step 4: Run cmake to generate the specificed project files
cmake -Wdev -G %platform% %source%
:: =============== end of make .bat =================
Enjoy.
by Jing.
延伸閱讀:
[1] “最簡單的 CMake 使用說明 – how to use cmake ,” http://mqjing.blogspot.com/2009/09/cmake-how-to-use-cmake.html
[2] “如何用 CMake 來編譯最簡單的 OpenCV 範例 – open image ,” http://mqjing.blogspot.com/2009/10/c-cmake-opencv-open-image.html