本篇 ShengYu 介紹 cmake 的 if 語法、if else 語法以及 if else 語法與範例,後半部會介紹 if 語句搭配 not、and、or 邏輯運算子。
以下內容分為這幾個部份,
- CMake if 語法
- CMake if else 語法
- CMake if elseif 語法
- CMake NOT 邏輯運算子
- CMake AND 邏輯運算子
- CMake OR 邏輯運算子
CMake if 語法
CMake if 語法為
1 | if(condition) |
CMake if else 語法
CMake if else 語法為
1 | if(condition) |
CMake if elseif 語法
CMake if elseif 語法為
1 | if(condition) |
CMake NOT 邏輯運算子
CMake AND 運算子語法為
1 | if(NOT condition) |
CMake AND 邏輯運算子
CMake AND 運算子語法為
1 | if((condition) AND (condition)) |
實際範例,以字串為例,
1 | if((VALUE1 STREQUAL "foo") AND (VALUE2 STREQUAL "bar")) |
CMake OR 邏輯運算子
CMake OR 運算子語法為
1 | if((condition) OR (condition)) |
實際範例,以字串為例,
1 | if((VALUE1 STREQUAL "foo") OR (VALUE2 STREQUAL "bar")) |
AND OR 運算子混用範例為
1 | if((condition) AND (condition OR (condition))) |
其他參考
if — CMake Documentation
https://cmake.org/cmake/help/latest/command/if.html
CMake 入門/流程控制 - 維基教科書,自由的教學讀本
https://zh.wikibooks.org/wiki/CMake_%E5%85%A5%E9%96%80/%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6