Skip to content

Commit

Permalink
Add CMakeLists.txt to build extension
Browse files Browse the repository at this point in the history
  • Loading branch information
howetuft committed Jan 5, 2025
1 parent 0744a99 commit 3d37f25
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/bundles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ jobs:
python-version: '3.11'
cache: 'pip'

- name: Fetch build dependencies
run: |
pip install --upgrade pip
pip install tomlkit
- uses: moguri/setup-blender@v1
with:
blender-version: '4.2.4'
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ release/*

# For ignored files in bin/ subdirectory, see the .gitignore file in bin/
wheels/

# CMake various files
build/
CMakeCache.txt
CMakeFiles/
Makefile
cmake_install.cmake
46 changes: 46 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.25)
project(BlendLuxCore LANGUAGES NONE)

file(MAKE_DIRECTORY build)

function(validate_blender_version result blender)
execute_process(
COMMAND ${blender} --version
OUTPUT_VARIABLE blender_output
)
if (blender_output MATCHES "Blender ([0-9]+\.[0-9]+\.[0-9]+).*")
set(version ${CMAKE_MATCH_1})
message(STATUS "Blender version: ${version}")
if (${version} VERSION_LESS "4.2.0")
message(FATAL_ERROR "Bad Blender version - expected 4.2.0 or higher")
set(${result} FALSE PARENT_SCOPE)
else()
message(STATUS "Blender version OK")
set(${result} TRUE PARENT_SCOPE)
endif()
else()
message(FATAL_ERROR "Blender version: Not found")
set(${result} FALSE PARENT_SCOPE)
endif()
endfunction()


# Get BlendLuxCore version
execute_process(
COMMAND python
${CMAKE_CURRENT_SOURCE_DIR}/cmake/blendluxcore_version.py
${CMAKE_CURRENT_SOURCE_DIR}/blender_manifest.toml
OUTPUT_VARIABLE BLC_VERSION
)

find_program(BLENDER blender NAMES blender.exe VALIDATOR validate_blender_version NO_CACHE)

# Add BlendLuxCore target
add_custom_target(
extension ALL
COMMAND ${BLENDER}
--command extension build
--source-dir ${CMAKE_CURRENT_SOURCE_DIR}
--output-filepath ${CMAKE_CURRENT_BINARY_DIR}/build/BlendLuxCore-${BLC_VERSION}.zip
VERBATIM
)
15 changes: 15 additions & 0 deletions cmake/blendluxcore_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Retrieve BlendLuxCore version from blender_manifest.toml"""
import tomllib
import os
from pathlib import Path
import argparse


parser = argparse.ArgumentParser()
parser.add_argument("filepath", type=Path)
args = parser.parse_args()

with open(args.filepath, 'rb') as fp:
manifest = tomllib.load(fp)
version = manifest['version']
print(version, end='')

0 comments on commit 3d37f25

Please sign in to comment.