前言
cmake
這個編譯工具提供了執行指令的功能,只要在cmake
之後加上-E
及欲執行的命令即可。注意cmake
支援的命令與linux不完全相通,在使用之前建議先前往cmake - Run a Command-Line Tool查詢用法。
幾個常用指令的demo如下。
常用指令
make_directory
cmake -E make_directory tmp1 tmp2
touch
cmake -E touch parent.txt tmp1/tmp1_file.txt tmp2/tmp1_file.txt tmp2/tmp2_file.txt
經過以上這兩個指令後,目錄結構變成:
.
├── parent.txt
├── tmp1
│ └── tmp1_file.txt
└── tmp2
├── tmp1_file.txt
└── tmp2_file.txt
2 directories, 4 files
chdir
cmake -E chdir tmp1 ls
結果:
tmp1_file.txt
copy
原來的目錄結構為:
├── parent.txt
├── tmp1
│ └── tmp1_file.txt
└── tmp2
├── tmp1_file.txt
└── tmp2_file.txt
2 directories, 4 files
使用copy
指令做複製:
cmake -E copy parent.txt tmp1/
之後目錄結構變為:
├── parent.txt
├── tmp1
│ ├── parent.txt
│ └── tmp1_file.txt
└── tmp2
├── tmp1_file.txt
└── tmp2_file.txt
2 directories, 5 files
copy_directory
Copy content of <dir>... directories to <destination> directory. If <destination> directory does not exist it will be created. copy_directory does follow symlinks.
將<dir>
目錄裡的內容複製到<destination>
目錄裡。如果<destination>
目錄不存在會自動創建。
原來的目錄結構:
├── parent.txt
├── tmp1
│ ├── parent.txt
│ └── tmp1_file.txt
└── tmp2
├── tmp1_file.txt
└── tmp2_file.txt
2 directories, 5 files
使用copy_directory
指令做複製:
cmake -E copy_directory tmp2/ tmp1/
之後目錄結構變為:
.
├── parent.txt
├── tmp1
│ ├── parent.txt
│ ├── tmp1_file.txt
│ └── tmp2_file.txt
└── tmp2
├── tmp1_file.txt
└── tmp2_file.txt
2 directories, 6 files
remove
原來的目錄結構:
.
├── parent.txt
├── tmp1
│ ├── parent.txt
│ ├── tmp1_file.txt
│ └── tmp2_file.txt
└── tmp2
├── tmp1_file.txt
└── tmp2_file.txt
2 directories, 6 files
使用remove
指令移除檔案:
cmake -E remove tmp2/tmp1_file.txt tmp1/tmp2_file.txt tmp1/parent.txt
之後目錄結構變為:
.
├── parent.txt
├── tmp1
│ └── tmp1_file.txt
└── tmp2
└── tmp2_file.txt
2 directories, 3 files
remove_directory
原來的目錄結構:
.
├── parent.txt
├── tmp1
│ └── tmp1_file.txt
└── tmp2
└── tmp2_file.txt
2 directories, 3 files
使用remove_directory
指令移除目錄:
cmake -E remove_directory tmp2
之後目錄結構變為:
.
├── parent.txt
└── tmp1
└── tmp1_file.txt
1 directory, 2 files