Created
October 22, 2019 12:42
-
-
Save an-dr/b2d50a8882fbb172cb8543b5481dffce to your computer and use it in GitHub Desktop.
CMake script for using as cross-platform scripting language
This file contains 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
# to execute: "cmake -P ./script.cmake" | |
# ***************************************************************************** | |
if(CMAKE_SCRIPT_MODE_FILE AND NOT CMAKE_PARENT_LIST_FILE) # if it is dirrectly launched in a script mode | |
execute_process( | |
# vvv | |
COMMAND "python" "--version" | |
# ^^^ | |
RESULT_VARIABLE RES # result of the cmd | |
OUTPUT_VARIABLE OUT # output var | |
ERROR_VARIABLE ERR) # error var | |
if(${RES} STREQUAL "0") # if no errors | |
message("The python version is : ${OUT}") | |
else() | |
message(FATAL_ERROR "Not executed! \n${ERR}") | |
endif() | |
else() | |
message(FATAL_ERROR "Should be run directly with `-P`-key, not included. E.g. cmake -P ./script.cmake") | |
endif() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment