|
| 1 | +# To build extension: |
| 2 | +# Get out of the tree, for instance in .. |
| 3 | +# cmake -B blc-build -S BlendLuxCore && cmake --build blc-build |
| 4 | + |
| 5 | +cmake_minimum_required(VERSION 3.25) |
| 6 | + |
| 7 | +set(CMAKE_DISABLE_SOURCE_CHANGES ON) |
| 8 | +set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) |
| 9 | +if(NOT CMAKE_BUILD_TYPE) |
| 10 | + set(CMAKE_BUILD_TYPE "Release") |
| 11 | +endif() |
| 12 | + |
| 13 | +project(BlendLuxCore LANGUAGES NONE) |
| 14 | +if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") |
| 15 | + message(SEND_ERROR "In-source builds are not allowed.") |
| 16 | +endif() |
| 17 | + |
| 18 | +function(validate_blender_version result blender) |
| 19 | + execute_process( |
| 20 | + COMMAND ${blender} --version |
| 21 | + OUTPUT_VARIABLE blender_output |
| 22 | + ) |
| 23 | + if (blender_output MATCHES "Blender ([0-9]+\.[0-9]+\.[0-9]+).*") |
| 24 | + set(version ${CMAKE_MATCH_1}) |
| 25 | + message(STATUS "Found Blender - version ${version}") |
| 26 | + if (${version} VERSION_LESS "4.2.0") |
| 27 | + message(FATAL_ERROR "ERROR: Blender version is not suitable - expected 4.2.0 or higher") |
| 28 | + set(${result} FALSE PARENT_SCOPE) |
| 29 | + else() |
| 30 | + message(STATUS "Blender version OK") |
| 31 | + set(${result} TRUE PARENT_SCOPE) |
| 32 | + endif() |
| 33 | + else() |
| 34 | + message(FATAL_ERROR "Blender version: Not found") |
| 35 | + set(${result} FALSE PARENT_SCOPE) |
| 36 | + endif() |
| 37 | +endfunction() |
| 38 | + |
| 39 | + |
| 40 | +# Get BlendLuxCore version |
| 41 | +find_package(Python 3.11 REQUIRED COMPONENTS Interpreter) |
| 42 | +if (CMAKE_BUILD_TYPE STREQUAL "Latest") |
| 43 | + set(BLC_VERSION "Latest") |
| 44 | +else() |
| 45 | + execute_process( |
| 46 | + COMMAND python |
| 47 | + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/blendluxcore_version.py |
| 48 | + ${CMAKE_CURRENT_SOURCE_DIR}/blender_manifest.toml |
| 49 | + OUTPUT_VARIABLE BLC_VERSION |
| 50 | + ) |
| 51 | +endif() |
| 52 | + |
| 53 | +find_program(BLENDER blender NAMES blender.exe VALIDATOR validate_blender_version NO_CACHE REQUIRED) |
| 54 | + |
| 55 | +# Add BlendLuxCore target |
| 56 | +add_custom_target( |
| 57 | + extension ALL ${BLENDER} |
| 58 | + --command extension build |
| 59 | + --source-dir ${CMAKE_CURRENT_SOURCE_DIR} |
| 60 | + --output-filepath ${CMAKE_CURRENT_BINARY_DIR}/BlendLuxCore-${BLC_VERSION}.zip |
| 61 | + VERBATIM |
| 62 | +) |
0 commit comments