Skip to content

Instantly share code, notes, and snippets.

@an-dr
Created October 22, 2019 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save an-dr/b2d50a8882fbb172cb8543b5481dffce to your computer and use it in GitHub Desktop.
Save an-dr/b2d50a8882fbb172cb8543b5481dffce to your computer and use it in GitHub Desktop.
CMake script for using as cross-platform scripting language
# 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