diff options
Diffstat (limited to 'build_files/cmake')
20 files changed, 563 insertions, 342 deletions
diff --git a/build_files/cmake/Modules/FindEpoxy.cmake b/build_files/cmake/Modules/FindEpoxy.cmake new file mode 100644 index 00000000000..7cd26e45398 --- /dev/null +++ b/build_files/cmake/Modules/FindEpoxy.cmake @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2022 Blender Foundation. + +# This module defines +# Epoxy_INCLUDE_DIRS, where to find epoxy/gl.h +# Epoxy_LIBRARY, where to find the epoxy library. +# Epoxy_ROOT_DIR, The base directory to search for epoxy. +# This can also be an environment variable. +# Epoxy_FOUND, If false, do not try to use epoxy. + +IF(NOT EPOXY_ROOT_DIR AND NOT $ENV{EPOXY_ROOT_DIR} STREQUAL "") + SET(EPOXY_ROOT_DIR $ENV{EPOXY_ROOT_DIR}) +ENDIF() + +FIND_PATH(Epoxy_INCLUDE_DIR + NAMES + epoxy/gl.h + HINTS + ${EPOXY_ROOT_DIR} + PATH_SUFFIXES + include +) + +FIND_LIBRARY(Epoxy_LIBRARY + NAMES + epoxy + HINTS + ${EPOXY_ROOT_DIR} + PATH_SUFFIXES + lib64 lib +) + +# handle the QUIETLY and REQUIRED arguments and set Epoxy_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Epoxy DEFAULT_MSG + Epoxy_LIBRARY Epoxy_INCLUDE_DIR) + +IF(Epoxy_FOUND) + SET(Epoxy_INCLUDE_DIRS ${Epoxy_INCLUDE_DIR}) + SET(Epoxy_LIBRARIES ${Epoxy_LIBRARY}) +ENDIF() + +MARK_AS_ADVANCED( + Epoxy_INCLUDE_DIR + Epoxy_LIBRARY +) diff --git a/build_files/cmake/Modules/FindGLEW.cmake b/build_files/cmake/Modules/FindGLEW.cmake deleted file mode 100644 index 33b989ec49e..00000000000 --- a/build_files/cmake/Modules/FindGLEW.cmake +++ /dev/null @@ -1,58 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014 Blender Foundation. - -# - Find GLEW library -# Find the native Glew includes and library -# This module defines -# GLEW_INCLUDE_DIRS, where to find glew.h, Set when -# GLEW_INCLUDE_DIR is found. -# GLEW_ROOT_DIR, The base directory to search for Glew. -# This can also be an environment variable. -# GLEW_FOUND, If false, do not try to use Glew. -# -# also defined, -# GLEW_LIBRARY, where to find the Glew library. - -# If GLEW_ROOT_DIR was defined in the environment, use it. -IF(NOT GLEW_ROOT_DIR AND NOT $ENV{GLEW_ROOT_DIR} STREQUAL "") - SET(GLEW_ROOT_DIR $ENV{GLEW_ROOT_DIR}) -ENDIF() - -SET(_glew_SEARCH_DIRS - ${GLEW_ROOT_DIR} -) - -FIND_PATH(GLEW_INCLUDE_DIR - NAMES - GL/glew.h - HINTS - ${_glew_SEARCH_DIRS} - PATH_SUFFIXES - include -) - -FIND_LIBRARY(GLEW_LIBRARY - NAMES - GLEW - HINTS - ${_glew_SEARCH_DIRS} - PATH_SUFFIXES - lib64 lib - ) - -# handle the QUIETLY and REQUIRED arguments and set GLEW_FOUND to TRUE if -# all listed variables are TRUE -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLEW DEFAULT_MSG - GLEW_LIBRARY GLEW_INCLUDE_DIR) - -IF(GLEW_FOUND) - SET(GLEW_INCLUDE_DIRS ${GLEW_INCLUDE_DIR}) -ENDIF() - -MARK_AS_ADVANCED( - GLEW_INCLUDE_DIR - GLEW_LIBRARY -) - -UNSET(_glew_SEARCH_DIRS) diff --git a/build_files/cmake/Modules/FindLibEpoxy.cmake b/build_files/cmake/Modules/FindLibEpoxy.cmake new file mode 100644 index 00000000000..1da52f95f68 --- /dev/null +++ b/build_files/cmake/Modules/FindLibEpoxy.cmake @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2022 Blender Foundation. + +# This module defines +# LibEpoxy_INCLUDE_DIRS, where to find epoxy/gl.h +# LibEpoxy_LIBRARY, where to find the epoxy library. +# LibEpoxy_ROOT_DIR, The base directory to search for libepoxy. +# This can also be an environment variable. +# LibEpoxy_FOUND, If false, do not try to use libepoxy. + +IF(NOT EPOXY_ROOT_DIR AND NOT $ENV{EPOXY_ROOT_DIR} STREQUAL "") + SET(EPOXY_ROOT_DIR $ENV{EPOXY_ROOT_DIR}) +ENDIF() + +FIND_PATH(LibEpoxy_INCLUDE_DIR + NAMES + epoxy/gl.h + HINTS + ${EPOXY_ROOT_DIR} + PATH_SUFFIXES + include +) + +FIND_LIBRARY(LibEpoxy_LIBRARY + NAMES + epoxy + HINTS + ${EPOXY_ROOT_DIR} + PATH_SUFFIXES + lib64 lib +) + +# handle the QUIETLY and REQUIRED arguments and set LibEpoxy_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibEpoxy DEFAULT_MSG + LibEpoxy_LIBRARY LibEpoxy_INCLUDE_DIR) + +IF(LibEpoxy_FOUND) + SET(LibEpoxy_INCLUDE_DIRS ${LibEpoxy_INCLUDE_DIR}) + SET(LibEpoxy_LIBRARIES ${LibEpoxy_LIBRARY}) +ENDIF() + +MARK_AS_ADVANCED( + LibEpoxy_INCLUDE_DIR + LibEpoxy_LIBRARY +) diff --git a/build_files/cmake/Modules/FindOpenGLES.cmake b/build_files/cmake/Modules/FindOpenGLES.cmake deleted file mode 100644 index 5e82984bed6..00000000000 --- a/build_files/cmake/Modules/FindOpenGLES.cmake +++ /dev/null @@ -1,80 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014 Blender Foundation. - -# - Try to find OpenGLES -# Once done this will define -# -# OPENGLES_FOUND - system has OpenGLES and EGL -# OPENGL_EGL_FOUND - system has EGL -# OPENGLES_INCLUDE_DIR - the GLES include directory -# OPENGLES_LIBRARY - the GLES library -# OPENGLES_EGL_INCLUDE_DIR - the EGL include directory -# OPENGLES_EGL_LIBRARY - the EGL library -# OPENGLES_LIBRARIES - all libraries needed for OpenGLES -# OPENGLES_INCLUDES - all includes needed for OpenGLES - -# If OPENGLES_ROOT_DIR was defined in the environment, use it. -IF(NOT OPENGLES_ROOT_DIR AND NOT $ENV{OPENGLES_ROOT_DIR} STREQUAL "") - SET(OPENGLES_ROOT_DIR $ENV{OPENGLES_ROOT_DIR}) -ENDIF() - -SET(_opengles_SEARCH_DIRS - ${OPENGLES_ROOT_DIR} -) - -FIND_PATH(OPENGLES_INCLUDE_DIR - NAMES - GLES2/gl2.h - HINTS - ${_opengles_SEARCH_DIRS} -) - -FIND_LIBRARY(OPENGLES_LIBRARY - NAMES - GLESv2 - PATHS - ${_opengles_SEARCH_DIRS} - PATH_SUFFIXES - lib64 lib -) - -FIND_PATH(OPENGLES_EGL_INCLUDE_DIR - NAMES - EGL/egl.h - HINTS - ${_opengles_SEARCH_DIRS} -) - -FIND_LIBRARY(OPENGLES_EGL_LIBRARY - NAMES - EGL - HINTS - ${_opengles_SEARCH_DIRS} - PATH_SUFFIXES - lib64 lib -) - -IF(OPENGLES_EGL_LIBRARY AND OPENGLES_EGL_INCLUDE_DIR) - SET(OPENGL_EGL_FOUND "YES") -ELSE() - SET(OPENGL_EGL_FOUND "NO") -ENDIF() - -IF(OPENGLES_LIBRARY AND OPENGLES_INCLUDE_DIR AND - OPENGLES_EGL_LIBRARY AND OPENGLES_EGL_INCLUDE_DIR) - SET(OPENGLES_LIBRARIES ${OPENGLES_LIBRARY} ${OPENGLES_LIBRARIES} - ${OPENGLES_EGL_LIBRARY}) - SET(OPENGLES_INCLUDES ${OPENGLES_INCLUDE_DIR} ${OPENGLES_EGL_INCLUDE_DIR}) - SET(OPENGLES_FOUND "YES") -ELSE() - SET(OPENGLES_FOUND "NO") -ENDIF() - -MARK_AS_ADVANCED( - OPENGLES_EGL_INCLUDE_DIR - OPENGLES_EGL_LIBRARY - OPENGLES_LIBRARY - OPENGLES_INCLUDE_DIR -) - -UNSET(_opengles_SEARCH_DIRS) diff --git a/build_files/cmake/Modules/FindPythonLibsUnix.cmake b/build_files/cmake/Modules/FindPythonLibsUnix.cmake index 1e88621303f..0afe1299330 100644 --- a/build_files/cmake/Modules/FindPythonLibsUnix.cmake +++ b/build_files/cmake/Modules/FindPythonLibsUnix.cmake @@ -34,11 +34,17 @@ SET(PYTHON_VERSION 3.10 CACHE STRING "Python Version (major and minor only)") MARK_AS_ADVANCED(PYTHON_VERSION) -# See: http://docs.python.org/extending/embedding.html#linking-requirements -# for why this is needed -SET(PYTHON_LINKFLAGS "-Xlinker -export-dynamic" CACHE STRING "Linker flags for python") -MARK_AS_ADVANCED(PYTHON_LINKFLAGS) - +if(APPLE) + if(WITH_PYTHON_MODULE) + set(PYTHON_LINKFLAGS "-undefined dynamic_lookup") + else() + set(PYTHON_LINKFLAGS) + endif() +else() + # See: http://docs.python.org/extending/embedding.html#linking-requirements + SET(PYTHON_LINKFLAGS "-Xlinker -export-dynamic" CACHE STRING "Linker flags for python") + MARK_AS_ADVANCED(PYTHON_LINKFLAGS) +endif() # if the user passes these defines as args, we don't want to overwrite SET(_IS_INC_DEF OFF) diff --git a/build_files/cmake/Modules/GTest.cmake b/build_files/cmake/Modules/GTest.cmake index a38550958fd..5c7fabdcff7 100644 --- a/build_files/cmake/Modules/GTest.cmake +++ b/build_files/cmake/Modules/GTest.cmake @@ -268,7 +268,8 @@ same as the Google Test name (i.e. ``suite.testcase``); see also cmake_policy(PUSH) cmake_policy(SET CMP0057 NEW) # if IN_LIST -#------------------------------------------------------------------------------ +# ----------------------------------------------------------------------------- + function(gtest_add_tests) if(ARGC LESS 1) diff --git a/build_files/cmake/Modules/GTestTesting.cmake b/build_files/cmake/Modules/GTestTesting.cmake index 92ce403d5f3..5ffd158361e 100644 --- a/build_files/cmake/Modules/GTestTesting.cmake +++ b/build_files/cmake/Modules/GTestTesting.cmake @@ -40,12 +40,10 @@ macro(BLENDER_SRC_GTEST_EX) set(MANIFEST "${CMAKE_BINARY_DIR}/tests.exe.manifest") endif() - add_definitions(-DBLENDER_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) - add_definitions(${GFLAGS_DEFINES}) - add_definitions(${GLOG_DEFINES}) - add_executable(${TARGET_NAME} ${ARG_SRC} ${MANIFEST}) setup_platform_linker_flags(${TARGET_NAME}) + target_compile_definitions(${TARGET_NAME} PRIVATE ${GFLAGS_DEFINES}) + target_compile_definitions(${TARGET_NAME} PRIVATE ${GLOG_DEFINES}) target_include_directories(${TARGET_NAME} PUBLIC "${TEST_INC}") target_include_directories(${TARGET_NAME} SYSTEM PUBLIC "${TEST_INC_SYS}") target_link_libraries(${TARGET_NAME} ${ARG_EXTRA_LIBS} ${PLATFORM_LINKLIBS}) diff --git a/build_files/cmake/buildinfo.cmake b/build_files/cmake/buildinfo.cmake index 53e22ed23ad..b0640acbe96 100644 --- a/build_files/cmake/buildinfo.cmake +++ b/build_files/cmake/buildinfo.cmake @@ -150,10 +150,10 @@ endif() # BUILD_PLATFORM is taken from CMake # but BUILD_DATE and BUILD_TIME are platform dependent if(NOT BUILD_DATE) - STRING(TIMESTAMP BUILD_DATE "%Y-%m-%d" UTC) + string(TIMESTAMP BUILD_DATE "%Y-%m-%d" UTC) endif() if(NOT BUILD_TIME) - STRING(TIMESTAMP BUILD_TIME "%H:%M:%S" UTC) + string(TIMESTAMP BUILD_TIME "%H:%M:%S" UTC) endif() # Write a file with the BUILD_HASH define diff --git a/build_files/cmake/cmake_static_check_cppcheck.py b/build_files/cmake/cmake_static_check_cppcheck.py index 79f9498ce2e..d9271ff8268 100644 --- a/build_files/cmake/cmake_static_check_cppcheck.py +++ b/build_files/cmake/cmake_static_check_cppcheck.py @@ -10,40 +10,77 @@ import tempfile from typing import ( Any, List, + Tuple, ) +USE_VERBOSE = (os.environ.get("VERBOSE", None) is not None) +# Could make configurable. +USE_VERBOSE_PROGRESS = True -USE_QUIET = (os.environ.get("QUIET", None) is not None) +CHECKER_BIN = "cppcheck" CHECKER_IGNORE_PREFIX = [ "extern", ] -CHECKER_BIN = "cppcheck" +CHECKER_EXCLUDE_SOURCE_FILES = set(os.path.join(*f.split("/")) for f in ( + # These files hang (taking longer than 5min with v2.8.2 at time of writing). + # All other files process in under around 10seconds. + "source/blender/editors/space_text/text_format_pov.c", + "source/blender/editors/space_text/text_format_pov_ini.c", +)) CHECKER_ARGS = [ - # not sure why this is needed, but it is. - "-I" + os.path.join(project_source_info.SOURCE_DIR, "extern", "glew", "include"), - "--suppress=*:%s/extern/glew/include/GL/glew.h:241" % project_source_info.SOURCE_DIR, - "--max-configs=1", # speeds up execution - # "--check-config", # when includes are missing - "--enable=all", # if you want sixty hundred pedantic suggestions + # Speed up execution. + # As Blender has many defines, the total number of configurations is large making execution unreasonably slow. + # This could be increased but do so with care. + "--max-configs=1", + + # Enable this when includes are missing. + # "--check-config", + + # Shows many pedantic issues, some are quite useful. + "--enable=all", + + # Also shows useful messages, even if some are false-positives. + "--inconclusive", # Quiet output, otherwise all defines/includes are printed (overly verbose). # Only enable this for troubleshooting (if defines are not set as expected for example). - "--quiet", + *(() if USE_VERBOSE else ("--quiet",)) # NOTE: `--cppcheck-build-dir=<dir>` is added later as a temporary directory. ] -if USE_QUIET: - CHECKER_ARGS.append("--quiet") + +def source_info_filter( + source_info: List[Tuple[str, List[str], List[str]]], +) -> List[Tuple[str, List[str], List[str]]]: + source_dir = project_source_info.SOURCE_DIR + if not source_dir.endswith(os.sep): + source_dir += os.sep + source_info_result = [] + for i, item in enumerate(source_info): + c = item[0] + if c.startswith(source_dir): + c_relative = c[len(source_dir):] + if c_relative in CHECKER_EXCLUDE_SOURCE_FILES: + CHECKER_EXCLUDE_SOURCE_FILES.remove(c_relative) + continue + source_info_result.append(item) + if CHECKER_EXCLUDE_SOURCE_FILES: + sys.stderr.write("Error: exclude file(s) are missing: %r\n" % list(sorted(CHECKER_EXCLUDE_SOURCE_FILES))) + sys.exit(1) + return source_info_result def cppcheck() -> None: source_info = project_source_info.build_info(ignore_prefix_list=CHECKER_IGNORE_PREFIX) source_defines = project_source_info.build_defines_as_args() + # Apply exclusion. + source_info = source_info_filter(source_info) + check_commands = [] for c, inc_dirs, defs in source_info: cmd = ( @@ -60,7 +97,7 @@ def cppcheck() -> None: process_functions = [] def my_process(i: int, c: str, cmd: List[str]) -> subprocess.Popen[Any]: - if not USE_QUIET: + if USE_VERBOSE_PROGRESS: percent = 100.0 * (i / len(check_commands)) percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:" diff --git a/build_files/cmake/config/blender_lite.cmake b/build_files/cmake/config/blender_lite.cmake index c98dfe27285..38997e2139b 100644 --- a/build_files/cmake/config/blender_lite.cmake +++ b/build_files/cmake/config/blender_lite.cmake @@ -7,8 +7,6 @@ # cmake -C../blender/build_files/cmake/config/blender_lite.cmake ../blender # -set(WITH_INSTALL_PORTABLE ON CACHE BOOL "" FORCE) - set(WITH_ALEMBIC OFF CACHE BOOL "" FORCE) set(WITH_AUDASPACE OFF CACHE BOOL "" FORCE) set(WITH_BLENDER_THUMBNAILER OFF CACHE BOOL "" FORCE) @@ -35,6 +33,7 @@ set(WITH_IMAGE_OPENEXR OFF CACHE BOOL "" FORCE) set(WITH_IMAGE_OPENJPEG OFF CACHE BOOL "" FORCE) set(WITH_IMAGE_TIFF OFF CACHE BOOL "" FORCE) set(WITH_IMAGE_WEBP OFF CACHE BOOL "" FORCE) +set(WITH_INPUT_IME OFF CACHE BOOL "" FORCE) set(WITH_INPUT_NDOF OFF CACHE BOOL "" FORCE) set(WITH_INTERNATIONAL OFF CACHE BOOL "" FORCE) set(WITH_IO_STL OFF CACHE BOOL "" FORCE) diff --git a/build_files/cmake/config/blender_release.cmake b/build_files/cmake/config/blender_release.cmake index 3661b1de805..793d1cb0853 100644 --- a/build_files/cmake/config/blender_release.cmake +++ b/build_files/cmake/config/blender_release.cmake @@ -87,7 +87,5 @@ if(NOT APPLE) set(WITH_CYCLES_CUBIN_COMPILER OFF CACHE BOOL "" FORCE) set(WITH_CYCLES_HIP_BINARIES ON CACHE BOOL "" FORCE) set(WITH_CYCLES_DEVICE_ONEAPI ON CACHE BOOL "" FORCE) - - # Disable AoT kernels compilations until buildbot can deliver them in a reasonable time. - set(WITH_CYCLES_ONEAPI_BINARIES OFF CACHE BOOL "" FORCE) + set(WITH_CYCLES_ONEAPI_BINARIES ON CACHE BOOL "" FORCE) endif() diff --git a/build_files/cmake/config/bpy_module.cmake b/build_files/cmake/config/bpy_module.cmake index c4be5c2e61f..7bd5c3fc1a1 100644 --- a/build_files/cmake/config/bpy_module.cmake +++ b/build_files/cmake/config/bpy_module.cmake @@ -8,41 +8,81 @@ set(WITH_PYTHON_MODULE ON CACHE BOOL "" FORCE) -# install into the systems python dir -set(WITH_INSTALL_PORTABLE OFF CACHE BOOL "" FORCE) -# no point int copying python into python +# ----------------------------------------------------------------------------- +# Installation Configuration. +# +# NOTE: `WITH_INSTALL_PORTABLE` always defaults to ON when building as a Python module and +# isn't set here as it makes changing the setting impractical. +# Python-developers could prefer either ON/OFF depending on their usage: +# +# - When using the system's Python, disabling will install into their `site-packages`, +# allowing them to run Python from any directory and `import bpy`. +# - When using Blender's bundled Python in `./../lib/` it will install there +# which isn't especially useful as it requires running Python from this directory too. +# +# So default `WITH_INSTALL_PORTABLE` to ON, and developers who don't use Python from `./../lib/` +# can disable it if they wish to install into their systems Python. + +# There is no point in copying python into Python. set(WITH_PYTHON_INSTALL OFF CACHE BOOL "" FORCE) -# disable audio, its possible some devs may want this but for now disable -# so the python module doesn't hold the audio device and loads quickly. +# Depends on Python install, do this to quiet warning. +set(WITH_DRACO OFF CACHE BOOL "" FORCE) + +if(WIN32) + set(WITH_WINDOWS_BUNDLE_CRT OFF CACHE BOOL "" FORCE) +endif() + + +# ----------------------------------------------------------------------------- +# Library Compatibility. + +# JEMALLOC does not work with `dlopen()` of Python modules: +# https://github.com/jemalloc/jemalloc/issues/1237 +set(WITH_MEM_JEMALLOC OFF CACHE BOOL "" FORCE) + + +# ----------------------------------------------------------------------------- +# Application Support. + +# Not useful to include with the Python module. +# Although a way to extract this from Python could be handle, +# this would be better exposed directly via the Python API. +set(WITH_BLENDER_THUMBNAILER OFF CACHE BOOL "" FORCE) + + +# ----------------------------------------------------------------------------- +# Audio Support. + +# Disable audio, its possible some developers may want this but for now disable +# so the Python module doesn't hold the audio device and loads quickly. set(WITH_AUDASPACE OFF CACHE BOOL "" FORCE) -set(WITH_CODEC_FFMPEG OFF CACHE BOOL "" FORCE) -set(WITH_CODEC_SNDFILE OFF CACHE BOOL "" FORCE) -set(WITH_COREAUDIO OFF CACHE BOOL "" FORCE) set(WITH_JACK OFF CACHE BOOL "" FORCE) set(WITH_OPENAL OFF CACHE BOOL "" FORCE) -set(WITH_PULSEAUDIO OFF CACHE BOOL "" FORCE) set(WITH_SDL OFF CACHE BOOL "" FORCE) -set(WITH_WASAPI OFF CACHE BOOL "" FORCE) +if(UNIX AND NOT APPLE) + set(WITH_PULSEAUDIO OFF CACHE BOOL "" FORCE) +endif() +if(WIN32) + set(WITH_WASAPI OFF CACHE BOOL "" FORCE) +endif() +if(APPLE) + set(WITH_COREAUDIO OFF CACHE BOOL "" FORCE) +endif() + -# other features which are not especially useful as a python module -set(WITH_ALEMBIC OFF CACHE BOOL "" FORCE) -set(WITH_BULLET OFF CACHE BOOL "" FORCE) +# ----------------------------------------------------------------------------- +# Input Device Support. + +# Other features which are not especially useful as a python module. set(WITH_INPUT_NDOF OFF CACHE BOOL "" FORCE) -set(WITH_INTERNATIONAL OFF CACHE BOOL "" FORCE) -set(WITH_NANOVDB OFF CACHE BOOL "" FORCE) -set(WITH_OPENCOLLADA OFF CACHE BOOL "" FORCE) -set(WITH_OPENVDB OFF CACHE BOOL "" FORCE) -set(WITH_X11_XINPUT OFF CACHE BOOL "" FORCE) +if(WIN32 OR APPLE) + set(WITH_INPUT_IME OFF CACHE BOOL "" FORCE) +endif() -# Depends on Python install, do this to quiet warning. -set(WITH_DRACO OFF CACHE BOOL "" FORCE) -# Jemalloc does not work with dlopen() of Python modules: -# https://github.com/jemalloc/jemalloc/issues/1237 -set(WITH_MEM_JEMALLOC OFF CACHE BOOL "" FORCE) +# ----------------------------------------------------------------------------- +# Language Support. -if(WIN32) - set(WITH_WINDOWS_BUNDLE_CRT OFF CACHE BOOL "" FORCE) -endif() +set(WITH_INTERNATIONAL OFF CACHE BOOL "" FORCE) diff --git a/build_files/cmake/have_features.cmake b/build_files/cmake/have_features.cmake new file mode 100644 index 00000000000..dc3b61849ea --- /dev/null +++ b/build_files/cmake/have_features.cmake @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright 2022 Blender Foundation. All rights reserved. + +# This file is used to test the system for headers & symbols. +# Variables should use the `HAVE_` prefix. +# Defines should use the same name as the CMAKE variable. + +include(CheckSymbolExists) + +# Used for: `intern/guardedalloc/intern/mallocn_intern.h`. +# Function `malloc_stats` is only available on GLIBC, +# so check that before defining `HAVE_MALLOC_STATS`. +check_symbol_exists(malloc_stats "malloc.h" HAVE_MALLOC_STATS_H) + +# Used for: `source/creator/creator_signals.c`. +# The function `feenableexcept` is not present non-GLIBC systems, +# hence we need to check if it's available in the `fenv.h` file. +set(HAVE_FEENABLEEXCEPT OFF) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + check_symbol_exists(feenableexcept "fenv.h" HAVE_FEENABLEEXCEPT) +endif() + +# Used for: `source/blender/blenlib/intern/system.c`. +# `execinfo` is not available on non-GLIBC systems (at least not on MUSL-LIBC), +# so check the presence of the header before including it and using the it for back-trace. +set(HAVE_EXECINFO_H OFF) +if(NOT MSVC) + include(CheckIncludeFiles) + check_include_files("execinfo.h" HAVE_EXECINFO_H) + if(HAVE_EXECINFO_H) + add_definitions(-DHAVE_EXECINFO_H) + endif() +endif() diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 5508e8f2104..d41024759fc 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -134,12 +134,11 @@ endfunction() # Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/ # use it instead of include_directories() -function(blender_include_dirs - includes - ) +function(absolute_include_dirs + includes_absolute) set(_ALL_INCS "") - foreach(_INC ${ARGV}) + foreach(_INC ${ARGN}) get_filename_component(_ABS_INC ${_INC} ABSOLUTE) list(APPEND _ALL_INCS ${_ABS_INC}) # for checking for invalid includes, disable for regular use @@ -147,22 +146,24 @@ function(blender_include_dirs # message(FATAL_ERROR "Include not found: ${_ABS_INC}/") # endif() endforeach() - include_directories(${_ALL_INCS}) + + set(${includes_absolute} ${_ALL_INCS} PARENT_SCOPE) endfunction() -function(blender_include_dirs_sys - includes +function(blender_target_include_dirs + name ) - set(_ALL_INCS "") - foreach(_INC ${ARGV}) - get_filename_component(_ABS_INC ${_INC} ABSOLUTE) - list(APPEND _ALL_INCS ${_ABS_INC}) - # if(NOT EXISTS "${_ABS_INC}/") - # message(FATAL_ERROR "Include not found: ${_ABS_INC}/") - # endif() - endforeach() - include_directories(SYSTEM ${_ALL_INCS}) + absolute_include_dirs(_ALL_INCS ${ARGN}) + target_include_directories(${name} PRIVATE ${_ALL_INCS}) +endfunction() + +function(blender_target_include_dirs_sys + name + ) + + absolute_include_dirs(_ALL_INCS ${ARGN}) + target_include_directories(${name} SYSTEM PRIVATE ${_ALL_INCS}) endfunction() # Set include paths for header files included with "*.h" syntax. @@ -268,13 +269,11 @@ function(blender_add_lib__impl # message(STATUS "Configuring library ${name}") - # include_directories(${includes}) - # include_directories(SYSTEM ${includes_sys}) - blender_include_dirs("${includes}") - blender_include_dirs_sys("${includes_sys}") - add_library(${name} ${sources}) + blender_target_include_dirs(${name} ${includes}) + blender_target_include_dirs_sys(${name} ${includes_sys}) + # On Windows certain libraries have two sets of binaries: one for debug builds and one for # release builds. The root of this requirement goes into ABI, I believe, but that's outside # of a scope of this comment. @@ -382,7 +381,7 @@ function(blender_add_test_suite) cmake_parse_arguments(ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # Figure out the release dir, as some tests need files from there. - GET_BLENDER_TEST_INSTALL_DIR(TEST_INSTALL_DIR) + get_blender_test_install_dir(TEST_INSTALL_DIR) if(APPLE) set(_test_release_dir ${TEST_INSTALL_DIR}/Blender.app/Contents/Resources/${BLENDER_VERSION}) else() @@ -425,21 +424,21 @@ function(blender_add_test_lib # This duplicates logic that's also in GTestTesting.cmake, macro BLENDER_SRC_GTEST_EX. # TODO(Sybren): deduplicate after the general approach in D7649 has been approved. - LIST(APPEND includes + list(APPEND includes ${CMAKE_SOURCE_DIR}/tests/gtests ) - LIST(APPEND includes_sys + list(APPEND includes_sys ${GLOG_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/extern/gtest/include ${CMAKE_SOURCE_DIR}/extern/gmock/include ) - add_definitions(-DBLENDER_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) - add_definitions(${GFLAGS_DEFINES}) - add_definitions(${GLOG_DEFINES}) blender_add_lib__impl(${name} "${sources}" "${includes}" "${includes_sys}" "${library_deps}") + target_compile_definitions(${name} PRIVATE ${GFLAGS_DEFINES}) + target_compile_definitions(${name} PRIVATE ${GLOG_DEFINES}) + set_property(GLOBAL APPEND PROPERTY BLENDER_TEST_LIBS ${name}) blender_add_test_suite( @@ -469,16 +468,16 @@ function(blender_add_test_executable ## Otherwise external projects will produce warnings that we cannot fix. remove_strict_flags() - include_directories(${includes}) - include_directories(${includes_sys}) - - BLENDER_SRC_GTEST_EX( + blender_src_gtest_ex( NAME ${name} SRC "${sources}" EXTRA_LIBS "${library_deps}" SKIP_ADD_TEST ) + blender_target_include_dirs(${name}_test ${includes}) + blender_target_include_dirs_sys(${name}_test ${includes_sys}) + blender_add_test_suite( TARGET ${name}_test SUITE_NAME ${name} @@ -513,6 +512,11 @@ function(setup_platform_linker_flags set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " ${PLATFORM_LINKFLAGS}") set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " ${PLATFORM_LINKFLAGS_RELEASE}") set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS_DEBUG " ${PLATFORM_LINKFLAGS_DEBUG}") + + get_target_property(target_type ${target} TYPE) + if (target_type STREQUAL "EXECUTABLE") + set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " ${PLATFORM_LINKFLAGS_EXECUTABLE}") + endif() endfunction() # Platform specific libraries for targets. @@ -760,7 +764,7 @@ function(ADD_CHECK_C_COMPILER_FLAG include(CheckCCompilerFlag) - CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}") + check_c_compiler_flag("${_FLAG}" "${_CACHE_VAR}") if(${_CACHE_VAR}) # message(STATUS "Using CFLAG: ${_FLAG}") set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}" PARENT_SCOPE) @@ -777,7 +781,7 @@ function(ADD_CHECK_CXX_COMPILER_FLAG include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}") + check_cxx_compiler_flag("${_FLAG}" "${_CACHE_VAR}") if(${_CACHE_VAR}) # message(STATUS "Using CXXFLAG: ${_FLAG}") set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}" PARENT_SCOPE) @@ -795,9 +799,11 @@ function(get_blender_version) # - BLENDER_VERSION_PATCH # - BLENDER_VERSION_CYCLE (alpha, beta, rc, release) - # So cmake depends on BKE_blender.h, beware of inf-loops! - CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender_version.h - ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender_version.h.done) + # So CMAKE depends on `BKE_blender.h`, beware of infinite-loops! + configure_file( + ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender_version.h + ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender_version.h.done + ) file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender_version.h _contents REGEX "^#define[ \t]+BLENDER_.*$") @@ -1208,16 +1214,8 @@ endmacro() macro(without_system_libs_begin) set(CMAKE_IGNORE_PATH "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES};${CMAKE_SYSTEM_INCLUDE_PATH};${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES};${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}") - if(APPLE) - # Avoid searching for headers in frameworks (like Mono), and libraries in LIBDIR. - set(CMAKE_FIND_FRAMEWORK NEVER) - endif() endmacro() macro(without_system_libs_end) unset(CMAKE_IGNORE_PATH) - if(APPLE) - # FIRST is the default. - set(CMAKE_FIND_FRAMEWORK FIRST) - endif() endmacro() diff --git a/build_files/cmake/packaging.cmake b/build_files/cmake/packaging.cmake index f6073eba82e..2f2e90dc934 100644 --- a/build_files/cmake/packaging.cmake +++ b/build_files/cmake/packaging.cmake @@ -17,9 +17,9 @@ set(CPACK_PACKAGE_VENDOR ${PROJECT_VENDOR}) set(CPACK_PACKAGE_CONTACT ${PROJECT_CONTACT}) set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING") set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") -SET(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}") -SET(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}") -SET(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}") +set(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}") +set(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}") +set(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}") # Get the build revision, note that this can get out-of-sync, so for packaging run cmake first. diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake index f84be3c5238..27fcaf823e8 100644 --- a/build_files/cmake/platform/platform_apple.cmake +++ b/build_files/cmake/platform/platform_apple.cmake @@ -21,9 +21,25 @@ function(print_found_status endif() endfunction() +# Utility to install precompiled shared libraries. +macro(add_bundled_libraries library) + if(EXISTS ${LIBDIR}) + set(_library_dir ${LIBDIR}/${library}/lib) + file(GLOB _all_library_versions ${_library_dir}/*\.dylib*) + list(APPEND PLATFORM_BUNDLED_LIBRARIES ${_all_library_versions}) + list(APPEND PLATFORM_BUNDLED_LIBRARY_DIRS ${_library_dir}) + unset(_all_library_versions) + unset(_library_dir) + endif() +endmacro() + # ------------------------------------------------------------------------ # Find system provided libraries. +# Avoid searching for headers since this would otherwise override our lib +# directory as well as PYTHON_ROOT_DIR. +set(CMAKE_FIND_FRAMEWORK NEVER) + # Find system ZLIB, not the pre-compiled one supplied with OpenCollada. set(ZLIB_ROOT /usr) find_package(ZLIB REQUIRED) @@ -63,6 +79,11 @@ if(NOT EXISTS "${LIBDIR}/") message(FATAL_ERROR "Mac OSX requires pre-compiled libs at: '${LIBDIR}'") endif() +# Optionally use system Python if PYTHON_ROOT_DIR is specified. +if(WITH_PYTHON AND (WITH_PYTHON_MODULE AND PYTHON_ROOT_DIR)) + find_package(PythonLibsUnix REQUIRED) +endif() + # Prefer lib directory paths file(GLOB LIB_SUBDIRS ${LIBDIR}/*) set(CMAKE_PREFIX_PATH ${LIB_SUBDIRS}) @@ -111,34 +132,8 @@ if(WITH_CODEC_SNDFILE) unset(_sndfile_VORBISENC_LIBRARY) endif() -if(WITH_PYTHON) - # Use precompiled libraries by default. - set(PYTHON_VERSION 3.10) - if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK) - # Normally cached but not since we include them with blender. - set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}") - set(PYTHON_EXECUTABLE "${LIBDIR}/python/bin/python${PYTHON_VERSION}") - set(PYTHON_LIBRARY ${LIBDIR}/python/lib/libpython${PYTHON_VERSION}.a) - set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}") - else() - # Module must be compiled against Python framework. - set(_py_framework "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}") - set(PYTHON_INCLUDE_DIR "${_py_framework}/include/python${PYTHON_VERSION}") - set(PYTHON_EXECUTABLE "${_py_framework}/bin/python${PYTHON_VERSION}") - set(PYTHON_LIBPATH "${_py_framework}/lib/python${PYTHON_VERSION}") - unset(_py_framework) - endif() - - # uncached vars - set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}") - set(PYTHON_LIBRARIES "${PYTHON_LIBRARY}") - - # needed for Audaspace, numpy is installed into python site-packages - set(PYTHON_NUMPY_INCLUDE_DIRS "${PYTHON_LIBPATH}/site-packages/numpy/core/include") - - if(NOT EXISTS "${PYTHON_EXECUTABLE}") - message(FATAL_ERROR "Python executable missing: ${PYTHON_EXECUTABLE}") - endif() +if(WITH_PYTHON AND NOT (WITH_PYTHON_MODULE AND PYTHON_ROOT_DIR)) + find_package(PythonLibsUnix REQUIRED) endif() if(WITH_FFTW3) @@ -201,11 +196,6 @@ if(WITH_JACK) string(APPEND PLATFORM_LINKFLAGS " -F/Library/Frameworks -weak_framework jackmp") endif() -if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK) - # force cmake to link right framework - string(APPEND PLATFORM_LINKFLAGS " /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python") -endif() - if(WITH_OPENCOLLADA) find_package(OpenCOLLADA) find_library(PCRE_LIBRARIES NAMES pcre HINTS ${LIBDIR}/opencollada/lib) @@ -226,6 +216,9 @@ if(WITH_SDL) endif() endif() +set(EPOXY_ROOT_DIR ${LIBDIR}/epoxy) +find_package(Epoxy REQUIRED) + set(PNG_ROOT ${LIBDIR}/png) find_package(PNG REQUIRED) @@ -359,10 +352,6 @@ endif() if(WITH_CYCLES AND WITH_CYCLES_EMBREE) find_package(Embree 3.8.0 REQUIRED) - # Increase stack size for Embree, only works for executables. - if(NOT WITH_PYTHON_MODULE) - string(APPEND PLATFORM_LINKFLAGS " -Wl,-stack_size,0x100000") - endif() # Embree static library linking can mix up SSE and AVX symbols, causing # crashes on macOS systems with older CPUs that don't have AVX. Using @@ -412,6 +401,7 @@ if(WITH_OPENMP) set(OpenMP_LIBRARY_DIR "${LIBDIR}/openmp/lib/") set(OpenMP_LINKER_FLAGS "-L'${OpenMP_LIBRARY_DIR}' -lomp") set(OpenMP_LIBRARY "${OpenMP_LIBRARY_DIR}/libomp.dylib") + add_bundled_libraries(openmp) endif() endif() @@ -446,6 +436,9 @@ if(EXISTS ${LIBDIR}) without_system_libs_end() endif() +# Restore to default. +set(CMAKE_FIND_FRAMEWORK FIRST) + # --------------------------------------------------------------------- # Set compiler and linker flags. @@ -478,6 +471,9 @@ string(APPEND PLATFORM_LINKFLAGS string(APPEND CMAKE_CXX_FLAGS " -stdlib=libc++") string(APPEND PLATFORM_LINKFLAGS " -stdlib=libc++") +# Make stack size more similar to Embree, required for Embree. +string(APPEND PLATFORM_LINKFLAGS_EXECUTABLE " -Wl,-stack_size,0x100000") + # Suppress ranlib "has no symbols" warnings (workaround for T48250) set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>") set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>") @@ -501,17 +497,27 @@ if(WITH_COMPILER_CCACHE) endif() endif() -# For binaries that are built but not installed (also not distributed) (datatoc, -# makesdna, tests, etc.), we add an rpath to the OpenMP library dir through -# CMAKE_BUILD_RPATH. This avoids having to make many copies of the dylib next to each binary. -# -# For the installed Python module and installed Blender executable, CMAKE_INSTALL_RPATH -# is modified to find the dylib in an adjacent folder. Install step puts the libraries there. -set(CMAKE_SKIP_BUILD_RPATH FALSE) -list(APPEND CMAKE_BUILD_RPATH "${OpenMP_LIBRARY_DIR}") +if(WITH_COMPILER_ASAN) + list(APPEND PLATFORM_BUNDLED_LIBRARIES ${COMPILER_ASAN_LIBRARY}) +endif() -set(CMAKE_SKIP_INSTALL_RPATH FALSE) -list(APPEND CMAKE_INSTALL_RPATH "@loader_path/../Resources/${BLENDER_VERSION}/lib") +if(PLATFORM_BUNDLED_LIBRARIES) + # For the installed Python module and installed Blender executable, we set the + # rpath to the location where install step will copy the shared libraries. + set(CMAKE_SKIP_INSTALL_RPATH FALSE) + if(WITH_PYTHON_MODULE) + list(APPEND CMAKE_INSTALL_RPATH "@loader_path/lib") + else() + list(APPEND CMAKE_INSTALL_RPATH "@loader_path/../Resources/lib") + endif() + + # For binaries that are built but not installed (like makesdan or tests), we add + # the original directory of all shared libraries to the rpath. This is needed because + # these can be in different folders, and because the build and install folder may be + # different. + set(CMAKE_SKIP_BUILD_RPATH FALSE) + list(APPEND CMAKE_BUILD_RPATH ${PLATFORM_BUNDLED_LIBRARY_DIRS}) +endif() # Same as `CFBundleIdentifier` in Info.plist. set(CMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "org.blenderfoundation.blender") diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake index 0d7ed9d618c..bfbc6b76b40 100644 --- a/build_files/cmake/platform/platform_unix.cmake +++ b/build_files/cmake/platform/platform_unix.cmake @@ -16,9 +16,16 @@ if(NOT DEFINED LIBDIR) # Choose the best suitable libraries. if(EXISTS ${LIBDIR_NATIVE_ABI}) set(LIBDIR ${LIBDIR_NATIVE_ABI}) + set(WITH_LIBC_MALLOC_HOOK_WORKAROUND True) elseif(EXISTS ${LIBDIR_CENTOS7_ABI}) set(LIBDIR ${LIBDIR_CENTOS7_ABI}) set(WITH_CXX11_ABI OFF) + if(WITH_MEM_JEMALLOC) + # jemalloc provides malloc hooks. + set(WITH_LIBC_MALLOC_HOOK_WORKAROUND False) + else() + set(WITH_LIBC_MALLOC_HOOK_WORKAROUND True) + endif() if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION VERSION_LESS 9.3) @@ -81,6 +88,15 @@ macro(find_package_wrapper) endif() endmacro() +# Utility to install precompiled shared libraries. +macro(add_bundled_libraries library) + if(EXISTS ${LIBDIR}) + file(GLOB _all_library_versions ${LIBDIR}/${library}/lib/*\.so*) + list(APPEND PLATFORM_BUNDLED_LIBRARIES ${_all_library_versions}) + unset(_all_library_versions) + endif() +endmacro() + # ---------------------------------------------------------------------------- # Precompiled Libraries # @@ -95,12 +111,13 @@ find_package_wrapper(JPEG REQUIRED) find_package_wrapper(PNG REQUIRED) find_package_wrapper(ZLIB REQUIRED) find_package_wrapper(Zstd REQUIRED) +find_package_wrapper(Epoxy REQUIRED) function(check_freetype_for_brotli) include(CheckSymbolExists) set(CMAKE_REQUIRED_INCLUDES ${FREETYPE_INCLUDE_DIRS}) - check_symbol_exists(FT_CONFIG_OPTION_USE_BROTLI - "freetype/config/ftconfig.h" HAVE_BROTLI) + check_symbol_exists(FT_CONFIG_OPTION_USE_BROTLI "freetype/config/ftconfig.h" HAVE_BROTLI) + unset(CMAKE_REQUIRED_INCLUDES) if(NOT HAVE_BROTLI) unset(HAVE_BROTLI CACHE) message(FATAL_ERROR "Freetype needs to be compiled with brotli support!") @@ -126,14 +143,38 @@ if(NOT WITH_SYSTEM_FREETYPE) endif() if(WITH_PYTHON) - # No way to set py35, remove for now. - # find_package(PythonLibs) + # This could be used, see: D14954 for details. + # `find_package(PythonLibs)` - # Use our own instead, since without py is such a rare case, - # require this package - # XXX Linking errors with debian static python :/ -# find_package_wrapper(PythonLibsUnix REQUIRED) + # Use our own instead, since without Python is such a rare case, + # require this package. + # XXX: Linking errors with Debian static Python (sigh). + # find_package_wrapper(PythonLibsUnix REQUIRED) find_package(PythonLibsUnix REQUIRED) + + if(WITH_PYTHON_MODULE AND NOT WITH_INSTALL_PORTABLE) + # Installing into `site-packages`, warn when installing into `./../lib/` + # which script authors almost certainly don't want. + if(EXISTS ${LIBDIR}) + cmake_path(IS_PREFIX LIBDIR "${PYTHON_SITE_PACKAGES}" NORMALIZE _is_prefix) + if(_is_prefix) + message(WARNING " +Building Blender with the following configuration: + - WITH_PYTHON_MODULE=ON + - WITH_INSTALL_PORTABLE=OFF + - LIBDIR=\"${LIBDIR}\" + - PYTHON_SITE_PACKAGES=\"${PYTHON_SITE_PACKAGES}\" +In this case you may want to either: + - Use the system Python's site-packages, see: + python -c \"import site; print(site.getsitepackages()[0])\" + - Set WITH_INSTALL_PORTABLE=ON to create a stand-alone \"bpy\" module + which you will need to ensure is in Python's module search path. +Proceeding with PYTHON_SITE_PACKAGES install target, you have been warned!" + ) + endif() + unset(_is_prefix) + endif() + endif() endif() if(WITH_IMAGE_OPENEXR) @@ -643,46 +684,125 @@ endif() if(WITH_GHOST_WAYLAND) find_package(PkgConfig) - pkg_check_modules(wayland-client REQUIRED wayland-client>=1.12) - pkg_check_modules(wayland-egl REQUIRED wayland-egl) - pkg_check_modules(wayland-scanner REQUIRED wayland-scanner) - pkg_check_modules(xkbcommon REQUIRED xkbcommon) - pkg_check_modules(wayland-cursor REQUIRED wayland-cursor) + pkg_check_modules(wayland-client wayland-client>=1.12) + pkg_check_modules(wayland-egl wayland-egl) + pkg_check_modules(wayland-scanner wayland-scanner) + pkg_check_modules(xkbcommon xkbcommon) + pkg_check_modules(wayland-cursor wayland-cursor) + pkg_check_modules(wayland-protocols wayland-protocols>=1.15) + + if(${wayland-protocols_FOUND}) + pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir) + else() + # CentOS 7 packages have too old a version, a newer version exist in the + # precompiled libraries. + find_path(WAYLAND_PROTOCOLS_DIR + NAMES unstable/xdg-decoration/xdg-decoration-unstable-v1.xml + PATH_SUFFIXES share/wayland-protocols + PATHS ${LIBDIR}/wayland-protocols + ) - if(WITH_GHOST_WAYLAND_DBUS) - pkg_check_modules(dbus REQUIRED dbus-1) + if(EXISTS ${WAYLAND_PROTOCOLS_DIR}) + set(wayland-protocols_FOUND ON) + endif() endif() - if(WITH_GHOST_WAYLAND_LIBDECOR) - pkg_check_modules(libdecor REQUIRED libdecor-0>=0.1) + if (NOT ${wayland-client_FOUND}) + message(STATUS "wayland-client not found, disabling WITH_GHOST_WAYLAND") + set(WITH_GHOST_WAYLAND OFF) + endif() + if (NOT ${wayland-egl_FOUND}) + message(STATUS "wayland-egl not found, disabling WITH_GHOST_WAYLAND") + set(WITH_GHOST_WAYLAND OFF) + endif() + if (NOT ${wayland-scanner_FOUND}) + message(STATUS "wayland-scanner not found, disabling WITH_GHOST_WAYLAND") + set(WITH_GHOST_WAYLAND OFF) + endif() + if (NOT ${wayland-cursor_FOUND}) + message(STATUS "wayland-cursor not found, disabling WITH_GHOST_WAYLAND") + set(WITH_GHOST_WAYLAND OFF) + endif() + if (NOT ${wayland-protocols_FOUND}) + message(STATUS "wayland-protocols not found, disabling WITH_GHOST_WAYLAND") + set(WITH_GHOST_WAYLAND OFF) + endif() + if (NOT ${xkbcommon_FOUND}) + message(STATUS "xkbcommon not found, disabling WITH_GHOST_WAYLAND") + set(WITH_GHOST_WAYLAND OFF) endif() - list(APPEND PLATFORM_LINKLIBS - ${xkbcommon_LINK_LIBRARIES} - ) + if(WITH_GHOST_WAYLAND) + if(WITH_GHOST_WAYLAND_DBUS) + pkg_check_modules(dbus REQUIRED dbus-1) + endif() - if(NOT WITH_GHOST_WAYLAND_DYNLOAD) - list(APPEND PLATFORM_LINKLIBS - ${wayland-client_LINK_LIBRARIES} - ${wayland-egl_LINK_LIBRARIES} - ${wayland-cursor_LINK_LIBRARIES} - ) - endif() + if(WITH_GHOST_WAYLAND_LIBDECOR) + pkg_check_modules(libdecor REQUIRED libdecor-0>=0.1) + endif() - if(WITH_GHOST_WAYLAND_DBUS) list(APPEND PLATFORM_LINKLIBS - ${dbus_LINK_LIBRARIES} + ${xkbcommon_LINK_LIBRARIES} ) - add_definitions(-DWITH_GHOST_WAYLAND_DBUS) - endif() - if(WITH_GHOST_WAYLAND_LIBDECOR) if(NOT WITH_GHOST_WAYLAND_DYNLOAD) list(APPEND PLATFORM_LINKLIBS - ${libdecor_LIBRARIES} + ${wayland-client_LINK_LIBRARIES} + ${wayland-egl_LINK_LIBRARIES} + ${wayland-cursor_LINK_LIBRARIES} + ) + endif() + + if(WITH_GHOST_WAYLAND_DBUS) + list(APPEND PLATFORM_LINKLIBS + ${dbus_LINK_LIBRARIES} + ) + add_definitions(-DWITH_GHOST_WAYLAND_DBUS) + endif() + + if(WITH_GHOST_WAYLAND_LIBDECOR) + if(NOT WITH_GHOST_WAYLAND_DYNLOAD) + list(APPEND PLATFORM_LINKLIBS + ${libdecor_LIBRARIES} + ) + endif() + add_definitions(-DWITH_GHOST_WAYLAND_LIBDECOR) + endif() + + pkg_get_variable(WAYLAND_SCANNER wayland-scanner wayland_scanner) + + # When using dynamic loading, headers generated + # from older versions of `wayland-scanner` aren't compatible. + if(WITH_GHOST_WAYLAND_DYNLOAD) + execute_process( + COMMAND ${WAYLAND_SCANNER} --version + # The version is written to the `stderr`. + ERROR_VARIABLE _wayland_scanner_out + ERROR_STRIP_TRAILING_WHITESPACE ) + if(NOT "${_wayland_scanner_out}" STREQUAL "") + string( + REGEX REPLACE + "^wayland-scanner[ \t]+([0-9]+)\.([0-9]+).*" + "\\1.\\2" + _wayland_scanner_ver + "${_wayland_scanner_out}" + ) + if("${_wayland_scanner_ver}" VERSION_LESS "1.20") + message( + FATAL_ERROR + "Found ${WAYLAND_SCANNER} version \"${_wayland_scanner_ver}\", " + "the minimum version is 1.20!" + ) + endif() + unset(_wayland_scanner_ver) + else() + message(WARNING "Unable to access the version from ${WAYLAND_SCANNER}, continuing.") + endif() + unset(_wayland_scanner_out) endif() - add_definitions(-DWITH_GHOST_WAYLAND_LIBDECOR) + # End wayland-scanner version check. + endif() endif() @@ -956,6 +1076,7 @@ function(CONFIGURE_ATOMIC_LIB_IF_NEEDED) set(CMAKE_REQUIRED_LIBRARIES atomic) check_cxx_source_compiles("${_source}" ATOMIC_OPS_WITH_LIBATOMIC) + unset(CMAKE_REQUIRED_LIBRARIES) if(ATOMIC_OPS_WITH_LIBATOMIC) set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -latomic" PARENT_SCOPE) @@ -968,4 +1089,17 @@ function(CONFIGURE_ATOMIC_LIB_IF_NEEDED) endif() endfunction() -CONFIGURE_ATOMIC_LIB_IF_NEEDED() +configure_atomic_lib_if_needed() + +if(PLATFORM_BUNDLED_LIBRARIES) + # For the installed Python module and installed Blender executable, we set the + # rpath to the relative path where the install step will copy the shared libraries. + set(CMAKE_SKIP_INSTALL_RPATH FALSE) + list(APPEND CMAKE_INSTALL_RPATH $ORIGIN/lib) + + # For executables that are built but not installed (mainly tests) we set an absolute + # rpath to the lib folder. This is needed because these can be in different folders, + # and because the build and install folder may be different. + set(CMAKE_SKIP_BUILD_RPATH FALSE) + list(APPEND CMAKE_BUILD_RPATH $ORIGIN/lib ${CMAKE_INSTALL_PREFIX_WITH_CONFIG}/lib) +endif() diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake index e81582f0460..eeec4760b80 100644 --- a/build_files/cmake/platform/platform_win32.cmake +++ b/build_files/cmake/platform/platform_win32.cmake @@ -26,7 +26,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang") set(OPENMP_FOUND ON) set(OpenMP_C_FLAGS "/clang:-fopenmp") set(OpenMP_CXX_FLAGS "/clang:-fopenmp") - GET_FILENAME_COMPONENT(LLVMROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\LLVM\\LLVM;]" ABSOLUTE CACHE) + get_filename_component(LLVMROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\LLVM\\LLVM;]" ABSOLUTE CACHE) set(CLANG_OPENMP_DLL "${LLVMROOT}/bin/libomp.dll") set(CLANG_OPENMP_LIB "${LLVMROOT}/lib/libomp.lib") if(NOT EXISTS "${CLANG_OPENMP_DLL}") @@ -323,6 +323,13 @@ if(NOT JPEG_FOUND) set(JPEG_LIBRARIES ${LIBDIR}/jpeg/lib/libjpeg.lib) endif() +set(EPOXY_ROOT_DIR ${LIBDIR}/epoxy) +windows_find_package(Epoxy REQUIRED) +if(NOT EPOXY_FOUND) + set(Epoxy_INCLUDE_DIRS ${LIBDIR}/epoxy/include) + set(Epoxy_LIBRARIES ${LIBDIR}/epoxy/lib/epoxy.lib) +endif() + set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include) set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC3.lib) @@ -497,12 +504,16 @@ if(WITH_JACK) endif() if(WITH_PYTHON) - set(PYTHON_VERSION 3.10) # CACHE STRING) + # Cache version for make_bpy_wheel.py to detect. + unset(PYTHON_VERSION CACHE) + set(PYTHON_VERSION "3.10" CACHE STRING "Python version") string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION}) set(PYTHON_LIBRARY ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/libs/python${_PYTHON_VERSION_NO_DOTS}.lib) set(PYTHON_LIBRARY_DEBUG ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/libs/python${_PYTHON_VERSION_NO_DOTS}_d.lib) + set(PYTHON_EXECUTABLE ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/bin/python$<$<CONFIG:Debug>:_d>.exe) + set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/include) set(PYTHON_NUMPY_INCLUDE_DIRS ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/lib/site-packages/numpy/core/include) set(NUMPY_FOUND ON) @@ -756,7 +767,7 @@ if(WITH_TBB) endif() # used in many places so include globally, like OpenGL -blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}") +include_directories(SYSTEM "${PTHREADS_INCLUDE_DIRS}") set(WINTAB_INC ${LIBDIR}/wintab/include) @@ -863,8 +874,8 @@ endif() if(WINDOWS_PYTHON_DEBUG) # Include the system scripts in the blender_python_system_scripts project. - FILE(GLOB_RECURSE inFiles "${CMAKE_SOURCE_DIR}/release/scripts/*.*" ) - ADD_CUSTOM_TARGET(blender_python_system_scripts SOURCES ${inFiles}) + file(GLOB_RECURSE inFiles "${CMAKE_SOURCE_DIR}/release/scripts/*.*" ) + add_custom_target(blender_python_system_scripts SOURCES ${inFiles}) foreach(_source IN ITEMS ${inFiles}) get_filename_component(_source_path "${_source}" PATH) string(REPLACE "${CMAKE_SOURCE_DIR}/release/scripts/" "" _source_path "${_source_path}") @@ -884,8 +895,8 @@ if(WINDOWS_PYTHON_DEBUG) endif() file(TO_CMAKE_PATH ${USER_SCRIPTS_ROOT} USER_SCRIPTS_ROOT) - FILE(GLOB_RECURSE inFiles "${USER_SCRIPTS_ROOT}/*.*" ) - ADD_CUSTOM_TARGET(blender_python_user_scripts SOURCES ${inFiles}) + file(GLOB_RECURSE inFiles "${USER_SCRIPTS_ROOT}/*.*" ) + add_custom_target(blender_python_user_scripts SOURCES ${inFiles}) foreach(_source IN ITEMS ${inFiles}) get_filename_component(_source_path "${_source}" PATH) string(REPLACE "${USER_SCRIPTS_ROOT}" "" _source_path "${_source_path}") diff --git a/build_files/cmake/platform/platform_win32_bundle_crt.cmake b/build_files/cmake/platform/platform_win32_bundle_crt.cmake index f5dd0c8c7bc..f197498d97b 100644 --- a/build_files/cmake/platform/platform_win32_bundle_crt.cmake +++ b/build_files/cmake/platform/platform_win32_bundle_crt.cmake @@ -3,20 +3,22 @@ # First generate the manifest for tests since it will not need the dependency on the CRT. configure_file(${CMAKE_SOURCE_DIR}/release/windows/manifest/blender.exe.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/tests.exe.manifest @ONLY) -if(WITH_WINDOWS_BUNDLE_CRT) - set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE) - set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE) - set(CMAKE_INSTALL_OPENMP_LIBRARIES ${WITH_OPENMP}) - - # This sometimes can change when updates are installed and the compiler version - # changes, so test if it exists and if not, give InstallRequiredSystemLibraries - # another chance to figure out the path. - if(MSVC_REDIST_DIR AND NOT EXISTS "${MSVC_REDIST_DIR}") - unset(MSVC_REDIST_DIR CACHE) - endif() +# Always detect system libraries, since they are also used by oneAPI. +# But don't always install them, only for WITH_WINDOWS_BUNDLE_CRT=ON. +set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE) +set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE) +set(CMAKE_INSTALL_OPENMP_LIBRARIES ${WITH_OPENMP}) + +# This sometimes can change when updates are installed and the compiler version +# changes, so test if it exists and if not, give InstallRequiredSystemLibraries +# another chance to figure out the path. +if(MSVC_REDIST_DIR AND NOT EXISTS "${MSVC_REDIST_DIR}") + unset(MSVC_REDIST_DIR CACHE) +endif() - include(InstallRequiredSystemLibraries) +include(InstallRequiredSystemLibraries) +if(WITH_WINDOWS_BUNDLE_CRT) # ucrtbase(d).dll cannot be in the manifest, due to the way windows 10 handles # redirects for this dll, for details see T88813. foreach(lib ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}) diff --git a/build_files/cmake/project_source_info.py b/build_files/cmake/project_source_info.py index a544f5733f0..f29d068044c 100644 --- a/build_files/cmake/project_source_info.py +++ b/build_files/cmake/project_source_info.py @@ -30,6 +30,8 @@ from typing import ( cast, ) +import shlex + SOURCE_DIR = join(dirname(__file__), "..", "..") SOURCE_DIR = normpath(SOURCE_DIR) @@ -160,7 +162,7 @@ def build_info( for c in compilers: args = args.replace(c, fake_compiler) - args = args.split() + args = shlex.split(args) # end # remove compiler |