mirror of
https://github.com/blender/blender
synced 2026-11-22 03:45:13 +03:00
113 lines
4.6 KiB
CMake
113 lines
4.6 KiB
CMake
# SPDX-FileCopyrightText: 2026 Blender Authors
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
# Host-architecture code generation tools for cross-compilation.
|
|
#
|
|
# Blender provides build-time code-gen tools (makesdna, makesrna, datatoc, shader_tool)
|
|
# that must run on the host machine performing the build, not on the cross-compile target.
|
|
#
|
|
# When CMAKE_CROSSCOMPILING is TRUE, this module spawns a second Blender configure/build
|
|
# under <build_dir>/host_tools using the host's default compiler (no toolchain file),
|
|
# and exposes the resulting binaries via BLENDER_*_EXE variables. BLENDER_*_DEPENDENCY
|
|
# variables are also exposed to allow for consumer targets to depend on the host_tools
|
|
# target, as the tool targets do not exist in the cross-compile case.
|
|
|
|
if(CMAKE_CROSSCOMPILING)
|
|
include(ExternalProject)
|
|
|
|
set(HOST_TOOLS_BUILD_DIR ${CMAKE_BINARY_DIR}/host_tools)
|
|
set(HOST_TOOLS_BIN_DIR ${HOST_TOOLS_BUILD_DIR}/bin)
|
|
|
|
# These tools are built for and executed on the host, so they carry the host executable
|
|
# suffix rather than the target one CMAKE_EXECUTABLE_SUFFIX would give.
|
|
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
|
set(HOST_TOOLS_EXE_SUFFIX ".exe")
|
|
else()
|
|
set(HOST_TOOLS_EXE_SUFFIX "")
|
|
endif()
|
|
|
|
# Forward every WITH_* variables so the host_tools build options match the target build.
|
|
get_cmake_property(_target_build_all_vars VARIABLES)
|
|
set(_host_tools_forwarded_args "")
|
|
foreach(_v IN LISTS _target_build_all_vars)
|
|
if(_v MATCHES "^WITH_")
|
|
list(APPEND _host_tools_forwarded_args "-D${_v}=${${_v}}")
|
|
endif()
|
|
endforeach()
|
|
unset(_target_build_all_vars)
|
|
|
|
set(_host_tools_targets
|
|
--target makesdna
|
|
--target makesrna
|
|
--target datatoc
|
|
--target shader_tool
|
|
)
|
|
set(_host_tools_byproducts
|
|
${HOST_TOOLS_BIN_DIR}/makesdna${HOST_TOOLS_EXE_SUFFIX}
|
|
${HOST_TOOLS_BIN_DIR}/makesrna${HOST_TOOLS_EXE_SUFFIX}
|
|
${HOST_TOOLS_BIN_DIR}/datatoc${HOST_TOOLS_EXE_SUFFIX}
|
|
${HOST_TOOLS_BIN_DIR}/shader_tool${HOST_TOOLS_EXE_SUFFIX}
|
|
)
|
|
|
|
# Unlike other targets, msgfmt depends on WITH_INTERNATIONAL
|
|
if(WITH_INTERNATIONAL)
|
|
list(APPEND _host_tools_targets
|
|
--target msgfmt
|
|
)
|
|
list(APPEND _host_tools_byproducts
|
|
${HOST_TOOLS_BIN_DIR}/msgfmt${HOST_TOOLS_EXE_SUFFIX}
|
|
)
|
|
endif()
|
|
|
|
ExternalProject_Add(host_tools
|
|
SOURCE_DIR ${CMAKE_SOURCE_DIR}
|
|
BINARY_DIR ${HOST_TOOLS_BUILD_DIR}
|
|
CMAKE_GENERATOR "${CMAKE_GENERATOR}"
|
|
CMAKE_ARGS
|
|
-DCMAKE_BUILD_TYPE=Release
|
|
${_host_tools_forwarded_args}
|
|
|
|
# Ensure the target is always checked for incremental compilation / tool rebuild on file changes.
|
|
BUILD_ALWAYS TRUE
|
|
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> ${_host_tools_targets}
|
|
BUILD_BYPRODUCTS ${_host_tools_byproducts}
|
|
INSTALL_COMMAND ""
|
|
|
|
# Nicer build output on ninja: hide verbose configure, show build steps
|
|
USES_TERMINAL_CONFIGURE FALSE
|
|
USES_TERMINAL_BUILD TRUE
|
|
)
|
|
|
|
unset(_host_tools_forwarded_args)
|
|
unset(_host_tools_targets)
|
|
unset(_host_tools_byproducts)
|
|
|
|
set(MAKESDNA_EXECUTABLE ${HOST_TOOLS_BIN_DIR}/makesdna${HOST_TOOLS_EXE_SUFFIX})
|
|
set(MAKESRNA_EXECUTABLE ${HOST_TOOLS_BIN_DIR}/makesrna${HOST_TOOLS_EXE_SUFFIX})
|
|
set(DATATOC_EXECUTABLE ${HOST_TOOLS_BIN_DIR}/datatoc${HOST_TOOLS_EXE_SUFFIX})
|
|
set(SHADER_TOOL_EXECUTABLE ${HOST_TOOLS_BIN_DIR}/shader_tool${HOST_TOOLS_EXE_SUFFIX})
|
|
set(MSGFMT_EXECUTABLE ${HOST_TOOLS_BIN_DIR}/msgfmt${HOST_TOOLS_EXE_SUFFIX})
|
|
|
|
# For code generation tools, depend on both:
|
|
# - `host_tools`, which provides *ordering* only, ensuring host tools are rebuilt before custom command tool generation targets.
|
|
# - The actual tool executable, ensuring the tool is re-executed (and re-generates its files) if it was rebuilt.
|
|
# Only depending on `host_tools` ensure tools are rebuilt first but doesn't cause them to be re-executed on changes.
|
|
set(MAKESDNA_DEPENDENCY host_tools ${MAKESDNA_EXECUTABLE})
|
|
set(MAKESRNA_DEPENDENCY host_tools ${MAKESRNA_EXECUTABLE})
|
|
set(DATATOC_DEPENDENCY host_tools ${DATATOC_EXECUTABLE})
|
|
set(SHADER_TOOL_DEPENDENCY host_tools ${SHADER_TOOL_EXECUTABLE})
|
|
set(MSGFMT_DEPENDENCY host_tools ${MSGFMT_EXECUTABLE})
|
|
else()
|
|
set(MAKESDNA_EXECUTABLE "$<TARGET_FILE:makesdna>")
|
|
set(MAKESRNA_EXECUTABLE "$<TARGET_FILE:makesrna>")
|
|
set(DATATOC_EXECUTABLE "$<TARGET_FILE:datatoc>")
|
|
set(SHADER_TOOL_EXECUTABLE "$<TARGET_FILE:shader_tool>")
|
|
set(MSGFMT_EXECUTABLE "$<TARGET_FILE:msgfmt>")
|
|
|
|
set(MAKESDNA_DEPENDENCY makesdna)
|
|
set(MAKESRNA_DEPENDENCY makesrna)
|
|
set(DATATOC_DEPENDENCY datatoc)
|
|
set(SHADER_TOOL_DEPENDENCY shader_tool)
|
|
set(MSGFMT_DEPENDENCY msgfmt)
|
|
endif()
|