Format:
if(expression) # then section. COMMAND1(ARGS ...) COMMAND2(ARGS ...) ... elseif(expression2) # elseif section. COMMAND1(ARGS ...) COMMAND2(ARGS ...) ... else() # else section. COMMAND1(ARGS ...) COMMAND2(ARGS ...) ... endif()
example:
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}") message(FATAL_ERROR " FATAL: In-source builds are not allowed. You should create a separate directory for build files. ") endif()
STREQUAL is the keyword of CMAKE, used for string comparison, the same returns true
${CMAKE_SOURCE_DIR} is a self-reserved variable of CMAKE (you can use it, the meaning has been determined), the file path
${CMAKE_BINARY_DIR} is the output path