@@ -8,41 +8,65 @@ to build PHP with CMake.
88## 1. Index
99
1010* [ 1. Index] ( #1-index )
11- * [ 2. Introduction] ( #2-introduction )
12- * [ 3. PHP directory structure] ( #3-php-directory-structure )
13- * [ 4. PHP extensions] ( #4-php-extensions )
14- * [ 5. PHP SAPI (Server API) modules] ( #5-php-sapi-server-api-modules )
15- * [ 6. Parser and lexer files] ( #6-parser-and-lexer-files )
16- * [ 7. \* nix build system] ( #7-nix-build-system )
17- * [ 7.1. \* nix build system diagram] ( #71-nix-build-system-diagram )
18- * [ 7.2. Build requirements] ( #72-build-requirements )
19- * [ 7.3. The configure command line options] ( #73-the-configure-command-line-options )
20- * [ 8. Windows build system] ( #8-windows-build-system )
21- * [ 8.1. Windows prerequisites] ( #81-windows-prerequisites )
22- * [ 9. CMake] ( #9-cmake )
23- * [ 9.1. Why using CMake?] ( #91-why-using-cmake )
24- * [ 9.2. Installation] ( #92-installation )
25- * [ 9.3. Directory structure] ( #93-directory-structure )
26- * [ 9.4. CMake build system diagram] ( #94-cmake-build-system-diagram )
27- * [ 9.5. CMake usage] ( #95-cmake-usage )
28- * [ 9.6. CMake minimum version for PHP] ( #96-cmake-minimum-version-for-php )
29- * [ 9.7. CMake code style] ( #97-cmake-code-style )
30- * [ 9.8. Command line options] ( #98-command-line-options )
31- * [ 9.9. CMake generators for building PHP] ( #99-cmake-generators-for-building-php )
32- * [ 9.9.1. Unix Makefiles (default)] ( #991-unix-makefiles-default )
33- * [ 9.9.2. Ninja] ( #992-ninja )
34- * [ 9.10. CMake presets] ( #910-cmake-presets )
35- * [ 9.11. CMake GUI] ( #911-cmake-gui )
36- * [ 9.12. Testing] ( #912-testing )
37- * [ 9.13. Performance] ( #913-performance )
38- * [ 9.14. Installing PHP with CMake] ( #914-installing-php-with-cmake )
39- * [ 10. See more] ( #10-see-more )
40- * [ 10.1. Autotools] ( #101-autotools )
41- * [ 10.2. CMake] ( #102-cmake )
42- * [ 10.3. CMake and PHP] ( #103-cmake-and-php )
43- * [ 10.4. PHP Internals] ( #104-php-internals )
44-
45- ## 2. Introduction
11+ * [ 2. TL;DR - Quick usage] ( #2-tldr---quick-usage )
12+ * [ 3. Introduction] ( #3-introduction )
13+ * [ 4. PHP directory structure] ( #4-php-directory-structure )
14+ * [ 5. PHP extensions] ( #5-php-extensions )
15+ * [ 6. PHP SAPI (Server API) modules] ( #6-php-sapi-server-api-modules )
16+ * [ 7. Parser and lexer files] ( #7-parser-and-lexer-files )
17+ * [ 8. \* nix build system] ( #8-nix-build-system )
18+ * [ 8.1. \* nix build system diagram] ( #81-nix-build-system-diagram )
19+ * [ 8.2. Build requirements] ( #82-build-requirements )
20+ * [ 8.3. The configure command line options] ( #83-the-configure-command-line-options )
21+ * [ 9. Windows build system] ( #9-windows-build-system )
22+ * [ 9.1. Windows prerequisites] ( #91-windows-prerequisites )
23+ * [ 10. CMake] ( #10-cmake )
24+ * [ 10.1. Why using CMake?] ( #101-why-using-cmake )
25+ * [ 10.2. Directory structure] ( #102-directory-structure )
26+ * [ 10.3. CMake build system diagram] ( #103-cmake-build-system-diagram )
27+ * [ 10.4. CMake usage] ( #104-cmake-usage )
28+ * [ 10.5. CMake minimum version for PHP] ( #105-cmake-minimum-version-for-php )
29+ * [ 10.6. Command line options] ( #106-command-line-options )
30+ * [ 10.7. CMake generators for building PHP] ( #107-cmake-generators-for-building-php )
31+ * [ 10.7.1. Unix Makefiles (default)] ( #1071-unix-makefiles-default )
32+ * [ 10.7.2. Ninja] ( #1072-ninja )
33+ * [ 10.8. CMake presets] ( #108-cmake-presets )
34+ * [ 10.9. CMake GUI] ( #109-cmake-gui )
35+ * [ 10.10. Testing] ( #1010-testing )
36+ * [ 10.11. Performance] ( #1011-performance )
37+ * [ 11. See more] ( #11-see-more )
38+ * [ 11.1. CMake] ( #111-cmake )
39+ * [ 11.2. CMake and PHP] ( #112-cmake-and-php )
40+ * [ 11.3. PHP Internals] ( #113-php-internals )
41+
42+ ## 2. TL;DR - Quick usage
43+
44+ Follow these steps to build PHP with CMake using this repository:
45+
46+ ``` sh
47+ # Clone this repository:
48+ git clone https://github.com/petk/php-build-system
49+ cd php-build-system
50+
51+ # Download latest PHP sources and add CMake files to them:
52+ ./bin/php.cmake
53+
54+ # Go into newly created directory, for example:
55+ cd php-8.4-dev
56+
57+ # Generate build system:
58+ cmake .
59+
60+ # Build PHP in parallel:
61+ cmake --build . -- --jobs 12
62+
63+ ./sapi/cli/php -v
64+
65+ # Run tests in parallel:
66+ ./sapi/cli/php run-tests.php -j12
67+ ```
68+
69+ ## 3. Introduction
4670
4771PHP developers typically opt for convenient methods to set up PHP on their
4872machines, such as utilizing prebuilt Linux packages available in their Linux
@@ -79,7 +103,7 @@ PHP build system consist of two parts:
79103* \* nix build system (Linux, macOS, FreeBSD, OpenBSD, etc.)
80104* Windows build system
81105
82- ## 3 . PHP directory structure
106+ ## 4 . PHP directory structure
83107
84108Before we begin, it might be useful to understand directory structure of the PHP
85109source code. PHP is developed at the
@@ -192,7 +216,7 @@ system) are linked together:
192216
193217![ Diagram how PHP libraries are linked together] ( docs/images/links.svg )
194218
195- ## 4 . PHP extensions
219+ ## 5 . PHP extensions
196220
197221PHP has several ways to install PHP extensions:
198222
@@ -238,7 +262,7 @@ PECL tool is a simple shell script wrapper around the PHP code as part of the
238262[ pear-core] ( https://github.com/pear/pear-core/blob/master/scripts/pecl.sh )
239263repository.
240264
241- ## 5 . PHP SAPI (Server API) modules
265+ ## 6 . PHP SAPI (Server API) modules
242266
243267PHP works through the concept of SAPI modules located in the ` sapi ` directory.
244268
@@ -256,7 +280,7 @@ There are other SAPI modules located in the ecosystem:
256280* [ ngx-php] ( https://github.com/rryqszq4/ngx-php )
257281* ...
258282
259- ## 6 . Parser and lexer files
283+ ## 7 . Parser and lexer files
260284
261285Some source files are generated with 3rd party tools. These include so called
262286parser and lexer files which are generated with [ re2c] ( https://re2c.org/ ) and
@@ -355,7 +379,7 @@ the `Makefile.frag` files.
355379 └─ ...
356380```
357381
358- ## 7 . \* nix build system
382+ ## 8 . \* nix build system
359383
360384\* nix build system in PHP uses [ Autoconf] ( https://www.gnu.org/software/autoconf/ )
361385to build a ` configure ` shell script that further creates main ` Makefile ` to
@@ -455,11 +479,11 @@ Build system is a collection of various files across the php-src repository:
455479 └─ ...
456480```
457481
458- ### 7 .1. \* nix build system diagram
482+ ### 8 .1. \* nix build system diagram
459483
460484![ PHP * nix build system using Autotools] ( docs/images/autotools.svg )
461485
462- ### 7 .2. Build requirements
486+ ### 8 .2. Build requirements
463487
464488Before being able to built PHP on Linux and other \* nix systems, there are some
4654893rd party requirements that need to be installed. Note that these names differ
@@ -547,7 +571,7 @@ installed and only libraries without development files are needed to run newly
547571built PHP. In example of ` ext/zip ` extension, the ` libzip ` package is needed and
548572so on.
549573
550- ### 7 .3. The configure command line options
574+ ### 8 .3. The configure command line options
551575
552576With Autoconf, there are two main types of command line options for the
553577` configure ` script (` --enable-FEATURE ` and ` --with-PACKAGE ` ):
@@ -575,7 +599,7 @@ See `./configure --help` for more info.
575599
576600This wraps up the \* nix build system using the Autotools.
577601
578- ## 8 . Windows build system
602+ ## 9 . Windows build system
579603
580604Windows build system is a separate collection of
581605[ JScript] ( https://en.wikipedia.org/wiki/JScript ) files and command line scripts.
@@ -623,7 +647,7 @@ module.
623647 └─ ...
624648```
625649
626- ### 8 .1. Windows prerequisites
650+ ### 9 .1. Windows prerequisites
627651
628652* Windows operating system.
629653* Visual Studio installed (e.g., Visual Studio 2019 or later).
@@ -632,7 +656,7 @@ module.
632656
633657Documentation to build PHP on Windows is available at [ PHP Wiki] ( https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2 ) .
634658
635- ## 9 . CMake
659+ ## 10 . CMake
636660
637661[ CMake] ( https://cmake.org/ ) is another open-source cross-platform build system
638662created by Kitware and contributors. This is what this repository is focusing
@@ -643,7 +667,7 @@ To learn CMake there is a very good
643667[ tutorial] ( https://cmake.org/cmake/help/latest/guide/tutorial/index.html ) which
644668is a prerequisite to follow the files in this repository.
645669
646- ### 9 .1. Why using CMake?
670+ ### 10 .1. Why using CMake?
647671
648672CMake is today more actively developed and more developers might be familiar
649673with it. It also makes C code more attractive to new contributors. Many IDEs
@@ -661,34 +685,7 @@ famililar with it, it can still be a very robust and solid build system option
661685in C/C++ projects on \* nix systems. Many large open-source projects use
662686Autotools. Some even use it together with CMake.
663687
664- ### 9.2. Installation
665-
666- Follow these steps to use CMake build system in PHP using this repository:
667-
668- ``` sh
669- # Clone this repository
670- git clone https://github.com/petk/php-build-system
671- cd php-build-system
672-
673- # Download latest PHP sources and add CMake files to them
674- ./bin/php.cmake
675-
676- # Go into newly created directory, for example
677- cd php-8.4-dev
678-
679- # Generate build system
680- cmake .
681-
682- # Build PHP binaries and libraries
683- cmake --build . -- --jobs $( nproc)
684-
685- ./sapi/cli/php -v
686-
687- # Run tests
688- ./sapi/cli/php run-tests.php -j$( nproc)
689- ```
690-
691- ### 9.3. Directory structure
688+ ### 10.2. Directory structure
692689
693690Directory structure from the CMake perspective looks like this:
694691
@@ -736,18 +733,18 @@ Directory structure from the CMake perspective looks like this:
736733 └─ ...
737734```
738735
739- ### 9.4 . CMake build system diagram
736+ ### 10.3 . CMake build system diagram
740737
741738![ PHP build system using CMake] ( docs/images/cmake.svg )
742739
743- ### 9.5 . CMake usage
740+ ### 10.4 . CMake usage
744741
745742``` sh
746743cmake .
747744cmake --build .
748745```
749746
750- ### 9.6 . CMake minimum version for PHP
747+ ### 10.5 . CMake minimum version for PHP
751748
752749The minimum required version of CMake is defined in the top project file
753750` CMakeLists.txt ` using the ` cmake_minimum_required() ` . Picking the minimum
@@ -778,12 +775,7 @@ properly in the future.
778775CMake versions scheme across the systems is available at
779776[ pkgs.org] ( https://pkgs.org/download/cmake ) .
780777
781- ### 9.7. CMake code style
782-
783- To sync the code style of the CMake files there are a couple of tools available.
784- See [ docs/cmake-code-style.md] ( docs/cmake-code-style.md ) for more info.
785-
786- ### 9.8. Command line options
778+ ### 10.6. Command line options
787779
788780List of configure command line options and their CMake alternatives.
789781
@@ -2303,15 +2295,15 @@ available:
23032295| ` INSTALL_ROOT="..." ` | ` CMAKE_INSTALL_PREFIX="..." ` | Override the installation dir |
23042296| | or ` cmake --install --prefix ` | |
23052297
2306- ### 9.9 . CMake generators for building PHP
2298+ ### 10.7 . CMake generators for building PHP
23072299
23082300When using CMake to build PHP, you have the flexibility to choose from various
23092301build systems through the concept of _ generators_ . CMake generators determine
23102302the type of project files or build scripts that CMake generates from your
23112303` CMakeLists.txt ` file. In this example, we will check the following generators:
23122304Unix Makefiles and Ninja.
23132305
2314- #### 9.9 .1. Unix Makefiles (default)
2306+ #### 10.7 .1. Unix Makefiles (default)
23152307
23162308The Unix Makefiles generator is the most common and widely used generator for
23172309building projects on Unix-like systems, including Linux and macOS. It generates
@@ -2347,7 +2339,7 @@ advantage of multiple CPU cores:
23472339make -j$( nproc) # number of CPU cores you want to utilize.
23482340```
23492341
2350- #### 9.9 .2. Ninja
2342+ #### 10.7 .2. Ninja
23512343
23522344[ Ninja] ( https://ninja-build.org/ ) is another build system supported by CMake and
23532345is known for its fast build times due to its minimalistic design. To use the
@@ -2379,7 +2371,7 @@ number of available CPU cores on your system):
23792371ninja -j$( nproc)
23802372```
23812373
2382- ### 9.10 . CMake presets
2374+ ### 10.8 . CMake presets
23832375
23842376The ` CMakePresets.json ` and ` CMakeUserPresets.json ` files in project root
23852377directory are available since CMake 3.19 for sharing build configurations.
@@ -2404,7 +2396,7 @@ cmake --build --preset default
24042396File ` CMakeUserPresets.json ` is ignored in Git because it is intended for user
24052397specific configuration.
24062398
2407- ### 9.11 . CMake GUI
2399+ ### 10.9 . CMake GUI
24082400
24092401With CMake there comes also a basic graphical user interface to configure and
24102402generate the build system.
@@ -2440,7 +2432,7 @@ Building the sources to binaries can be then done in command line or IDE.
24402432cmake --build --preset default
24412433```
24422434
2443- ### 9.12 . Testing
2435+ ### 10.10 . Testing
24442436
24452437PHP source code tests (` *.phpt ` files) are written in PHP and are executed with
24462438` run-tests.php ` script from the very beginning of the PHP development. When
@@ -2472,7 +2464,7 @@ using the `CMakePresets.json` file and its `testPresets` field.
24722464ctest --preset unix-full
24732465```
24742466
2475- ### 9.13 . Performance
2467+ ### 10.11 . Performance
24762468
24772469When CMake is doing configuration phase, the profiling options can be used to do
24782470build system performance analysis of CMake script.
@@ -2483,37 +2475,26 @@ cmake --profiling-output ./profile.json --profiling-format google-trace ../php-s
24832475
24842476![ CMake profiling] ( docs/images/cmake-profiling.png )
24852477
2486- ### 9.14. Installing PHP with CMake
2487-
2488- See [ PHP installation] ( /docs/php-installation.md ) chapter.
2489-
2490- ## 10. See more
2491-
2492- ### 10.1. Autotools
2493-
2494- Useful resources to learn more about Autoconf and Autotools in general:
2478+ ## 11. See more
24952479
2496- * [ Autoconf documentation] ( https://www.gnu.org/software/autoconf/manual/index.html )
2497- * [ Autotools Mythbuster] ( https://autotools.info/ ) - guide to Autotools
2498- * [ GNU Autoconf Archive] ( https://github.com/autoconf-archive/autoconf-archive ) -
2499- community collection of Autoconf macros.
2480+ Further help is documented at [ docs] ( docs/README.md ) .
25002481
2501- ### 10.2 . CMake
2482+ ### 11.1 . CMake
25022483
25032484Useful resources to learn more about CMake:
25042485
25052486* [ CMake documentation] ( https://cmake.org/documentation/ )
25062487* [ Effective Modern CMake] ( https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1 )
25072488* [ Awesome CMake] ( https://github.com/onqtam/awesome-cmake )
25082489
2509- ### 10.3 . CMake and PHP
2490+ ### 11.2 . CMake and PHP
25102491
25112492Existing CMake and PHP discussions and resources:
25122493
25132494* [ php-cmake] ( https://github.com/gloob/php-cmake ) - CMake implementation in PHP.
25142495* [ CMake discussion on PHP mailing list] ( https://externals.io/message/116655 )
25152496
2516- ### 10.4 . PHP Internals
2497+ ### 11.3 . PHP Internals
25172498
25182499Useful resources to learn more about PHP internals:
25192500
0 commit comments