CMake: add WITH_LINKER_LLD option for unix platforms
[blender-staging.git] / GNUmakefile
1 # -*- mode: gnumakefile; tab-width: 4; indent-tabs-mode: t; -*-
2 # vim: tabstop=4
3 #
4 # ##### BEGIN GPL LICENSE BLOCK #####
5 #
6 #  This program is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU General Public License
8 #  as published by the Free Software Foundation; either version 2
9 #  of the License, or (at your option) any later version.
10 #
11 #  This program is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with this program; if not, write to the Free Software Foundation,
18 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #
20 # ##### END GPL LICENSE BLOCK #####
21
22 # This Makefile does an out-of-source CMake build in ../build_`OS`_`CPU`
23 # eg:
24 #   ../build_linux_i386
25 # This is for users who like to configure & build blender with a single command.
26
27 define HELP_TEXT
28
29 Convenience Targets
30    Provided for building Blender, (multiple at once can be used).
31
32    * debug:         Build a debug binary.
33    * full:          Enable all supported dependencies & options.
34    * lite:          Disable non essential features for a smaller binary and faster build.
35    * headless:      Build without an interface (renderfarm or server automation).
36    * cycles:        Build Cycles standalone only, without Blender.
37    * bpy:           Build as a python module which can be loaded from python directly.
38    * deps:          Build library dependencies (intended only for platform maintainers).
39
40    * developer:     Enable faster builds, error checking and tests, recommended for developers.
41    * config:        Run cmake configuration tool to set build options.
42    * ninja:         Use ninja build tool for faster builds.
43
44    Note: passing the argument 'BUILD_DIR=path' when calling make will override the default build dir.
45    Note: passing the argument 'BUILD_CMAKE_ARGS=args' lets you add cmake arguments.
46
47
48 Project Files
49    Generate project files for development environments.
50
51    * project_qtcreator:     QtCreator Project Files.
52    * project_netbeans:      NetBeans Project Files.
53    * project_eclipse:       Eclipse CDT4 Project Files.
54
55 Package Targets
56
57    * package_debian:    Build a debian package.
58    * package_pacman:    Build an arch linux pacman package.
59    * package_archive:   Build an archive package.
60
61 Testing Targets
62    Not associated with building Blender.
63
64    * test:
65      Run automated tests with ctest.
66    * test_cmake:
67      Runs our own cmake file checker
68      which detects errors in the cmake file list definitions
69    * test_pep8:
70      Checks all python script are pep8
71      which are tagged to use the stricter formatting
72    * test_deprecated:
73      Checks for deprecation tags in our code which may need to be removed
74
75 Static Source Code Checking
76    Not associated with building Blender.
77
78    * check_cppcheck:        Run blender source through cppcheck (C & C++).
79    * check_clang_array:     Run blender source through clang array checking script (C & C++).
80    * check_splint:          Run blenders source through splint (C only).
81    * check_sparse:          Run blenders source through sparse (C only).
82    * check_smatch:          Run blenders source through smatch (C only).
83    * check_spelling_c:      Check for spelling errors (C/C++ only).
84    * check_spelling_c_qtc:  Same as check_spelling_c but outputs QtCreator tasks format.
85    * check_spelling_osl:    Check for spelling errors (OSL only).
86    * check_spelling_py:     Check for spelling errors (Python only).
87    * check_descriptions:    Check for duplicate/invalid descriptions.
88
89 Utilities
90    Not associated with building Blender.
91
92    * icons:
93      Updates PNG icons from SVG files.
94
95      Optionally pass in variables: 'BLENDER_BIN', 'INKSCAPE_BIN'
96      otherwise default paths are used.
97
98      Example
99         make icons INKSCAPE_BIN=/path/to/inkscape
100
101    * icons_geom:
102      Updates Geometry icons from BLEND file.
103
104      Optionally pass in variable: 'BLENDER_BIN'
105      otherwise default paths are used.
106
107      Example
108         make icons_geom BLENDER_BIN=/path/to/blender
109
110    * source_archive:
111      Create a compressed archive of the source code.
112
113    * update:
114      updates git and all submodules
115
116    * format
117      Format source code using clang (uses PATHS if passed in). For example::
118
119         make format PATHS="source/blender/blenlib source/blender/blenkernel"
120
121 Environment Variables
122
123    * BUILD_CMAKE_ARGS:      Arguments passed to CMake.
124    * BUILD_DIR:             Override default build path.
125    * PYTHON:                Use this for the Python command (used for checking tools).
126    * NPROCS:                Number of processes to use building (auto-detect when omitted).
127
128 Documentation Targets
129    Not associated with building Blender.
130
131    * doc_py:        Generate sphinx python api docs.
132    * doc_doxy:      Generate doxygen C/C++ docs.
133    * doc_dna:       Generate blender file format reference.
134    * doc_man:       Generate manpage.
135
136 Information
137
138    * help:              This help message.
139    * help_features:     Show a list of optional features when building.
140
141 endef
142 # HELP_TEXT (end)
143
144
145 # System Vars
146 OS:=$(shell uname -s)
147 OS_NCASE:=$(shell uname -s | tr '[A-Z]' '[a-z]')
148 CPU:=$(shell uname -m)
149
150
151 # Source and Build DIR's
152 BLENDER_DIR:=$(shell pwd -P)
153 BUILD_TYPE:=Release
154
155 # CMake arguments, assigned to local variable to make it mutable.
156 CMAKE_CONFIG_ARGS := $(BUILD_CMAKE_ARGS)
157
158 ifndef BUILD_DIR
159         BUILD_DIR:=$(shell dirname "$(BLENDER_DIR)")/build_$(OS_NCASE)
160 endif
161
162 # Dependencies DIR's
163 DEPS_SOURCE_DIR:=$(BLENDER_DIR)/build_files/build_environment
164
165 ifndef DEPS_BUILD_DIR
166         DEPS_BUILD_DIR:=$(BUILD_DIR)/deps
167 endif
168
169 ifndef DEPS_INSTALL_DIR
170         DEPS_INSTALL_DIR:=$(shell dirname "$(BLENDER_DIR)")/lib/$(OS_NCASE)
171
172         ifneq ($(OS_NCASE),darwin)
173                 # Add processor type to directory name
174                 DEPS_INSTALL_DIR:=$(DEPS_INSTALL_DIR)_$(CPU)
175         endif
176 endif
177
178 # Allow to use alternative binary (pypy3, etc)
179 ifndef PYTHON
180         PYTHON:=python3
181 endif
182
183 # For macOS python3 is not installed by default, so fallback to python binary
184 # in libraries, or python 2 for running make update to get it.
185 ifeq ($(OS_NCASE),darwin)
186         ifeq (, $(shell command -v $(PYTHON)))
187                 PYTHON:=../lib/darwin/python/bin/python3.7m
188                 ifeq (, $(shell command -v $(PYTHON)))
189                         PYTHON:=python
190                 endif
191         endif
192 endif
193
194 # -----------------------------------------------------------------------------
195 # additional targets for the build configuration
196
197 # support 'make debug'
198 ifneq "$(findstring debug, $(MAKECMDGOALS))" ""
199         BUILD_DIR:=$(BUILD_DIR)_debug
200         BUILD_TYPE:=Debug
201 endif
202 ifneq "$(findstring full, $(MAKECMDGOALS))" ""
203         BUILD_DIR:=$(BUILD_DIR)_full
204         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/blender_full.cmake" $(CMAKE_CONFIG_ARGS)
205 endif
206 ifneq "$(findstring lite, $(MAKECMDGOALS))" ""
207         BUILD_DIR:=$(BUILD_DIR)_lite
208         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/blender_lite.cmake" $(CMAKE_CONFIG_ARGS)
209 endif
210 ifneq "$(findstring cycles, $(MAKECMDGOALS))" ""
211         BUILD_DIR:=$(BUILD_DIR)_cycles
212         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/cycles_standalone.cmake" $(CMAKE_CONFIG_ARGS)
213 endif
214 ifneq "$(findstring headless, $(MAKECMDGOALS))" ""
215         BUILD_DIR:=$(BUILD_DIR)_headless
216         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/blender_headless.cmake" $(CMAKE_CONFIG_ARGS)
217 endif
218 ifneq "$(findstring bpy, $(MAKECMDGOALS))" ""
219         BUILD_DIR:=$(BUILD_DIR)_bpy
220         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/bpy_module.cmake" $(CMAKE_CONFIG_ARGS)
221 endif
222
223 ifneq "$(findstring developer, $(MAKECMDGOALS))" ""
224         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/blender_developer.cmake" $(CMAKE_CONFIG_ARGS)
225 endif
226
227 # -----------------------------------------------------------------------------
228 # build tool
229
230 ifneq "$(findstring ninja, $(MAKECMDGOALS))" ""
231         CMAKE_CONFIG_ARGS:=$(CMAKE_CONFIG_ARGS) -G Ninja
232         BUILD_COMMAND:=ninja
233         DEPS_BUILD_COMMAND:=ninja
234 else
235         ifneq ("$(wildcard $(BUILD_DIR)/build.ninja)","")
236                 BUILD_COMMAND:=ninja
237         else
238                 BUILD_COMMAND:=make -s
239         endif
240
241         ifneq ("$(wildcard $(DEPS_BUILD_DIR)/build.ninja)","")
242                 DEPS_BUILD_COMMAND:=ninja
243         else
244                 DEPS_BUILD_COMMAND:=make -s
245         endif
246 endif
247
248 # -----------------------------------------------------------------------------
249 # Blender binary path
250
251 # Allow passing in own BLENDER_BIN so developers who don't
252 # use the default build path can still use utility helpers.
253 ifeq ($(OS), Darwin)
254         BLENDER_BIN?="$(BUILD_DIR)/bin/Blender.app/Contents/MacOS/Blender"
255 else
256         BLENDER_BIN?="$(BUILD_DIR)/bin/blender"
257 endif
258
259
260 # -----------------------------------------------------------------------------
261 # Get the number of cores for threaded build
262 ifndef NPROCS
263         NPROCS:=1
264         ifeq ($(OS), Linux)
265                 NPROCS:=$(shell nproc)
266         endif
267         ifeq ($(OS), NetBSD)
268                 NPROCS:=$(shell getconf NPROCESSORS_ONLN)
269         endif
270         ifneq (,$(filter $(OS),Darwin FreeBSD))
271                 NPROCS:=$(shell sysctl -n hw.ncpu)
272         endif
273 endif
274
275
276 # -----------------------------------------------------------------------------
277 # Macro for configuring cmake
278
279 CMAKE_CONFIG = cmake $(CMAKE_CONFIG_ARGS) \
280                      -H"$(BLENDER_DIR)" \
281                      -B"$(BUILD_DIR)" \
282                      -DCMAKE_BUILD_TYPE_INIT:STRING=$(BUILD_TYPE)
283
284
285 # -----------------------------------------------------------------------------
286 # Tool for 'make config'
287
288 # X11 spesific
289 ifdef DISPLAY
290         CMAKE_CONFIG_TOOL = cmake-gui
291 else
292         CMAKE_CONFIG_TOOL = ccmake
293 endif
294
295
296 # -----------------------------------------------------------------------------
297 # Build Blender
298 all: .FORCE
299         @echo
300         @echo Configuring Blender in \"$(BUILD_DIR)\" ...
301
302 #       # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
303 #       #       $(CMAKE_CONFIG); \
304 #       # fi
305
306 #       # do this always incase of failed initial build, could be smarter here...
307         @$(CMAKE_CONFIG)
308
309         @echo
310         @echo Building Blender ...
311         $(BUILD_COMMAND) -C "$(BUILD_DIR)" -j $(NPROCS) install
312         @echo
313         @echo edit build configuration with: "$(BUILD_DIR)/CMakeCache.txt" run make again to rebuild.
314         @echo Blender successfully built, run from: $(BLENDER_BIN)
315         @echo
316
317 debug: all
318 full: all
319 lite: all
320 cycles: all
321 headless: all
322 bpy: all
323 developer: all
324 ninja: all
325
326 # -----------------------------------------------------------------------------
327 # Build dependencies
328 DEPS_TARGET = install
329 ifneq "$(findstring clean, $(MAKECMDGOALS))" ""
330         DEPS_TARGET = clean
331 endif
332
333 deps: .FORCE
334         @echo
335         @echo Configuring dependencies in \"$(DEPS_BUILD_DIR)\"
336
337         @cmake -H"$(DEPS_SOURCE_DIR)" \
338                -B"$(DEPS_BUILD_DIR)" \
339                    -DHARVEST_TARGET=$(DEPS_INSTALL_DIR)
340
341         @echo
342         @echo Building dependencies ...
343         $(DEPS_BUILD_COMMAND) -C "$(DEPS_BUILD_DIR)" -j $(NPROCS) $(DEPS_TARGET)
344         @echo
345         @echo Dependencies successfully built and installed to $(DEPS_INSTALL_DIR).
346         @echo
347
348 # -----------------------------------------------------------------------------
349 # Configuration (save some cd'ing around)
350 config: .FORCE
351         $(CMAKE_CONFIG_TOOL) "$(BUILD_DIR)"
352
353
354 # -----------------------------------------------------------------------------
355 # Help for build targets
356 export HELP_TEXT
357 help: .FORCE
358         @echo "$$HELP_TEXT"
359
360 # -----------------------------------------------------------------------------
361 # Packages
362 #
363 package_debian: .FORCE
364         cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
365
366 package_pacman: .FORCE
367         cd build_files/package_spec/pacman ; MAKEFLAGS="-j$(NPROCS)" makepkg
368
369 package_archive: .FORCE
370         make -C "$(BUILD_DIR)" -s package_archive
371         @echo archive in "$(BUILD_DIR)/release"
372
373
374 # -----------------------------------------------------------------------------
375 # Tests
376 #
377 test: .FORCE
378         $(PYTHON) ./build_files/utils/make_test.py "$(BUILD_DIR)"
379
380 # run pep8 check check on scripts we distribute.
381 test_pep8: .FORCE
382         $(PYTHON) tests/python/pep8.py > test_pep8.log 2>&1
383         @echo "written: test_pep8.log"
384
385 # run some checks on our cmakefiles.
386 test_cmake: .FORCE
387         $(PYTHON) build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
388         @echo "written: test_cmake_consistency.log"
389
390 # run deprecation tests, see if we have anything to remove.
391 test_deprecated: .FORCE
392         $(PYTHON) tests/check_deprecated.py
393
394
395 # -----------------------------------------------------------------------------
396 # Project Files
397 #
398
399 project_qtcreator: .FORCE
400         $(PYTHON) build_files/cmake/cmake_qtcreator_project.py --build-dir "$(BUILD_DIR)"
401
402 project_netbeans: .FORCE
403         $(PYTHON) build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
404
405 project_eclipse: .FORCE
406         cmake -G"Eclipse CDT4 - Unix Makefiles" -H"$(BLENDER_DIR)" -B"$(BUILD_DIR)"
407
408
409 # -----------------------------------------------------------------------------
410 # Static Checking
411 #
412
413 check_cppcheck: .FORCE
414         $(CMAKE_CONFIG)
415         cd "$(BUILD_DIR)" ; \
416         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
417             "$(BLENDER_DIR)/check_cppcheck.txt"
418         @echo "written: check_cppcheck.txt"
419
420 check_clang_array: .FORCE
421         $(CMAKE_CONFIG)
422         cd "$(BUILD_DIR)" ; \
423         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
424
425 check_splint: .FORCE
426         $(CMAKE_CONFIG)
427         cd "$(BUILD_DIR)" ; \
428         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
429
430 check_sparse: .FORCE
431         $(CMAKE_CONFIG)
432         cd "$(BUILD_DIR)" ; \
433         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
434
435 check_smatch: .FORCE
436         $(CMAKE_CONFIG)
437         cd "$(BUILD_DIR)" ; \
438         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
439
440 check_spelling_py: .FORCE
441         cd "$(BUILD_DIR)" ; \
442         PYTHONIOENCODING=utf_8 $(PYTHON) \
443             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
444             "$(BLENDER_DIR)/release/scripts"
445
446 check_spelling_c: .FORCE
447         cd "$(BUILD_DIR)" ; \
448         PYTHONIOENCODING=utf_8 $(PYTHON) \
449             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
450             "$(BLENDER_DIR)/source" \
451             "$(BLENDER_DIR)/intern/cycles" \
452             "$(BLENDER_DIR)/intern/guardedalloc" \
453             "$(BLENDER_DIR)/intern/ghost" \
454
455 check_spelling_c_qtc: .FORCE
456         cd "$(BUILD_DIR)" ; USE_QTC_TASK=1 \
457         PYTHONIOENCODING=utf_8 $(PYTHON) \
458             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
459             "$(BLENDER_DIR)/source" \
460             "$(BLENDER_DIR)/intern/cycles" \
461             "$(BLENDER_DIR)/intern/guardedalloc" \
462             "$(BLENDER_DIR)/intern/ghost" \
463             > \
464             "$(BLENDER_DIR)/check_spelling_c.tasks"
465
466 check_spelling_osl: .FORCE
467         cd "$(BUILD_DIR)" ;\
468         PYTHONIOENCODING=utf_8 $(PYTHON) \
469             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
470             "$(BLENDER_DIR)/intern/cycles/kernel/shaders"
471
472 check_descriptions: .FORCE
473         $(BLENDER_BIN) --background -noaudio --factory-startup --python \
474             "$(BLENDER_DIR)/source/tools/check_source/check_descriptions.py"
475
476 # -----------------------------------------------------------------------------
477 # Utilities
478 #
479
480 source_archive: .FORCE
481         ./build_files/utils/make_source_archive.sh
482
483 INKSCAPE_BIN?="inkscape"
484 icons: .FORCE
485         BLENDER_BIN=$(BLENDER_BIN) INKSCAPE_BIN=$(INKSCAPE_BIN) \
486                 "$(BLENDER_DIR)/release/datafiles/blender_icons_update.py"
487         BLENDER_BIN=$(BLENDER_BIN) INKSCAPE_BIN=$(INKSCAPE_BIN) \
488                 "$(BLENDER_DIR)/release/datafiles/prvicons_update.py"
489
490 icons_geom: .FORCE
491         BLENDER_BIN=$(BLENDER_BIN) \
492             "$(BLENDER_DIR)/release/datafiles/blender_icons_geom_update.py"
493
494 update: .FORCE
495         $(PYTHON) ./build_files/utils/make_update.py
496
497 format: .FORCE
498         PATH="../lib/${OS_NCASE}_${CPU}/llvm/bin/:../lib/${OS_NCASE}_centos7_${CPU}/llvm/bin/:../lib/${OS_NCASE}/llvm/bin/:$(PATH)" \
499                 $(PYTHON) source/tools/utils_maintenance/clang_format_paths.py $(PATHS)
500
501
502 # -----------------------------------------------------------------------------
503 # Documentation
504 #
505
506 # Simple version of ./doc/python_api/sphinx_doc_gen.sh with no PDF generation.
507 doc_py: .FORCE
508         ASAN_OPTIONS=halt_on_error=0 \
509         $(BLENDER_BIN) --background -noaudio --factory-startup \
510                 --python doc/python_api/sphinx_doc_gen.py
511         cd doc/python_api ; sphinx-build -b html sphinx-in sphinx-out
512         @echo "docs written into: '$(BLENDER_DIR)/doc/python_api/sphinx-out/index.html'"
513
514 doc_doxy: .FORCE
515         cd doc/doxygen; doxygen Doxyfile
516         @echo "docs written into: '$(BLENDER_DIR)/doc/doxygen/html/index.html'"
517
518 doc_dna: .FORCE
519         $(BLENDER_BIN) --background -noaudio --factory-startup \
520                 --python doc/blender_file_format/BlendFileDnaExporter_25.py
521         @echo "docs written into: '$(BLENDER_DIR)/doc/blender_file_format/dna.html'"
522
523 doc_man: .FORCE
524         $(PYTHON) doc/manpage/blender.1.py $(BLENDER_BIN) blender.1
525
526 help_features: .FORCE
527         @$(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_print_build_options.py" $(BLENDER_DIR)"/CMakeLists.txt"
528
529 clean: .FORCE
530         $(BUILD_COMMAND) -C "$(BUILD_DIR)" clean
531
532 .PHONY: all
533
534 .FORCE: