message(STATUS "Windows") //Windows elseif(UNIX) message(STATUS "Unix") //Linux elseif(APPLE) message(STATUS "macOS") //苹果 endif() 比较 条件判断必不可少涉及到比较。我们这里介绍数值比较与字符串比较。 数值比较: LESS <:检查左侧是否小于右侧。 GREATER >:检查左侧是否大于右侧。 EQUAL ==:检...
OFF, NO, FALSE, N, IGNORE, NOTFOUND, the emptystring, or endsinthe suffix -NOTFOUND. Named boolean constants arecase-insensitive. If the argument is not one of these constants, it is treated as a variable.if(<variable>)
if(<condition>):检查条件是否满足。如果满足,则执行随后的命令直到遇到elseif、else或endif。 elseif(<condition>):可选。如果前面的if或elseif的条件不满足,将检查这里的条件。可以有多个elseif块。 else():可选。如果所有的if和elseif条件都不满足,则执行else块中的命令。 endif():结束条件判断块。 在CMak...
# elseif section. COMMAND1(ARGS ...) COMMAND2(ARGS ...) ... else() # else section. COMMAND1(ARGS ...) COMMAND2(ARGS ...) ... endif() 例子: 1 2 3 4 5 6 if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}") message(FATAL_ERROR " FATAL: In-source builds are...
CMake 的做法是:首先看 var 是否是一个已经定义的变量,如果是,则需要将他的值替换到 if 中,否则就直把 var 当成一个字符串/值。 来看一个例子: 此处的 var 是一个已经定义好的变量,因此 if 判断转化为 if("NO") ,它会按照 if(<constant>) 最终...
10.1 if…elseif…else…endif 逻辑判断和比较:if (expression):expression 不为空(0,N,NO,OFF,FALSE,NOTFOUND)时为真if (not exp):与上面相反if (var1 AND var2)if (var1 OR var2)if (COMMAND cmd):如果 cmd 确实是命令并可调用为真if (EXISTS dir) if (EXISTS file):如果目录或文件存在...
(1)if AI检测代码解析 set(ARCH "x86") if(ARCH MATCHES "x86") message("ARCH is x86") else() message("ARCH is arm") endif() 1. 2. 3. 4. 5. 6. (2)while AI检测代码解析 set(a "1") while(${a} LESS "5") message("${a}") ...
(6) if…else[if]…endif 含义:这个不用详细介绍了,用法同编程语言中的控制语句 语法: if/else([<condition>]) 使用样例: if(WIN32) message(STATUS "inWindowsSystem") elseif(UNIX) message(STATUS "in Unix System") endif() (7) include_directories ...
IF(WIN32) #do something related to WIN32 ELSEIF(UNIX) #do something related to UNIX ELSEIF(APPLE) #do something related to APPLE ENDIF (WIN32) 2. WHILE 语法结构如下: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 WHILE(condition) COMMAND1(ARGS ...) COMMAND2(ARGS ...) ... END...
if(USE_LIBRARY) # add_library will create a static library # since BUILD_SHARED_LIBS is OFF add_library(message ${_sources}) add_executable(hello-world hello-world.cpp) target_link_libraries(hello-world message) else() add_executable(hello-world hello-world.cpp ${_sources}) ...