Created
May 16, 2018 16:59
-
-
Save shorttermmem/10ca60eb909c9387488221b981634bca to your computer and use it in GitHub Desktop.
Sample cmake script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################## | |
# run this script | |
cmake -DWIN32 -P CMakeList.txt | |
################################################## | |
# control flow | |
if(WIN32) | |
message("You are running on Windows.") | |
endif | |
if(${WIN32}) | |
message("You are running on Windows.") | |
endif | |
################################################## | |
# math operations | |
math(EXPR MY_SUM "1 + 1") # Evaluate 1 + 1; store result in MY_SUM | |
message("The sum is ${MY_SUM}.") | |
math(EXPR DOUBLE_SUM "${MY_SUM} * 2") # Multiply by 2; store result in DOUBLE_SUM | |
message("Double that is ${DOUBLE_SUM}.") | |
################################################## | |
# function example | |
function(fibonacci MAX) | |
set(A "1") | |
set(B "1") | |
while(A LESS "${MAX}") | |
message("${A}") # Print A | |
math(EXPR T "${A} + ${B}") # Add the numeric values of A and B; store result in T | |
set(A "${B}") # Assign the value of B to A | |
set(B "${T}") # Assign the value of T to B | |
endwhile() | |
endfunction() | |
fibonacci(RESULT "100") | |
message("${RESULT}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment