@@ -5,10 +5,6 @@ Generate parser-related files with Bison. This module includes common `bison`
55configuration with minimum required version and common settings across the
66PHP build.
77
8- When `bison` cannot be found on the system or the found version is not suitable,
9- this module can also download and build it from its Git repository sources
10- release archive as part of the project build.
11-
128## Configuration variables
139
1410These variables can be set before including this module
@@ -18,18 +14,16 @@ These variables can be set before including this module
1814 BISON package with `find_package(BISON <version-constraint> ...)` in this
1915 module.
2016
17+ * `PHP_BISON_DOWNLOAD_VERSION` - When Bison cannot be found on the system or the
18+ found version is not suitable, this module can also download and build it from
19+ its release archive sources as part of the project build. Set which Bison
20+ version should be downloaded.
21+
2122* `PHP_BISON_OPTIONS` - A semicolon-separated list of default Bison options.
2223 This module sets some sensible defaults. When `php_bison(APPEND)` is used, the
2324 options specified in the `php_bison(OPTIONS <options>...)` are appended to
2425 these default global options.
2526
26- * `PHP_BISON_DISABLE_DOWNLOAD` - Set to `TRUE` to disable downloading and
27- building bison package from source, when it is not found on the system or
28- found version is not suitable.
29-
30- * `PHP_BISON_DOWNLOAD_VERSION` - Override the default `bison` version to be
31- downloaded when not found on the system.
32-
3327* `PHP_BISON_WORKING_DIRECTORY` - Set the default global working directory
3428 (`WORKING_DIRECTORY <dir>` option) for all `php_bison()` invocations in the
3529 scope of the current directory.
@@ -266,14 +260,13 @@ php_bison(foo parser.y parser.c OPTIONS $<$<CONFIG:Debug>:--debug> --yacc)
266260
267261include_guard (GLOBAL )
268262
269- include (FetchContent)
270263include (FeatureSummary)
271264
272265################################################################################
273266# Configuration.
274267################################################################################
275268
276- macro (_php_bison_config )
269+ macro (php_bison_config )
277270 # Minimum required bison version.
278271 if (NOT PHP_BISON_VERSION)
279272 set (PHP_BISON_VERSION 3.0.0)
@@ -365,7 +358,7 @@ function(php_bison name input output)
365358 set (outputs ${output} )
366359 set (extraOutputs "" )
367360
368- _php_bison_config ()
361+ php_bison_config ()
369362 _php_bison_process_header_file()
370363 _php_bison_set_package_properties()
371364
@@ -375,12 +368,15 @@ function(php_bison name input output)
375368 set (quiet "QUIET" )
376369 endif ()
377370
378- find_package (BISON ${PHP_BISON_VERSION} GLOBAL ${quiet} )
371+ if (NOT TARGET Bison::Bison)
372+ find_package (BISON ${PHP_BISON_VERSION} GLOBAL ${quiet} )
373+ endif ()
379374
380375 if (
381376 NOT BISON_FOUND
382- AND NOT PHP_BISON_DISABLE_DOWNLOAD
377+ AND PHP_BISON_DOWNLOAD_VERSION
383378 AND packageType STREQUAL "REQUIRED"
379+ AND NOT CMAKE_SCRIPT_MODE_FILE
384380 )
385381 _php_bison_download()
386382 endif ()
@@ -436,7 +432,6 @@ function(php_bison name input output)
436432 ${input}
437433 ${parsed_DEPENDS}
438434 $<TARGET_NAME_IF_EXISTS:Bison::Bison>
439- $<TARGET_NAME_IF_EXISTS:bison>
440435 COMMENT "${message} "
441436 VERBATIM
442437 COMMAND_EXPAND_LISTS
@@ -698,53 +693,49 @@ function(_php_bison_get_commands result)
698693 return (PROPAGATE ${result} )
699694endfunction ()
700695
701- ################################################################################
702- # Download and build bison if not found.
703- ################################################################################
704-
696+ # Download and build Bison if not found.
705697function (_php_bison_download)
706698 set (BISON_VERSION ${PHP_BISON_DOWNLOAD_VERSION} )
699+ set (BISON_FOUND TRUE )
707700
708- message (STATUS "Downloading bison ${BISON_VERSION} " )
709- FetchContent_Populate(
710- BISON
711- URL https://ftp.gnu.org/gnu/bison/bison-${BISON_VERSION} .tar.gz
712- SOURCE_DIR ${CMAKE_BINARY_DIR} /_deps/bison
713- )
701+ if (TARGET Bison::Bison)
702+ return (PROPAGATE BISON_FOUND BISON_VERSION)
703+ endif ()
714704
715- message (STATUS "Configuring Bison ${BISON_VERSION} " )
716- execute_process (
717- COMMAND ./configure
718- OUTPUT_VARIABLE result
719- ECHO_OUTPUT_VARIABLE
720- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /_deps/bison
721- )
705+ message (STATUS "Bison ${BISON_VERSION} will be downloaded at build phase" )
706+
707+ include (ExternalProject)
722708
723- message (STATUS "Building Bison ${BISON_VERSION} " )
724- include (ProcessorCount)
725- processorcount(processors )
726- execute_process (
727- COMMAND ${CMAKE_MAKE_PROGRAM} -j${processors}
728- OUTPUT_VARIABLE result
729- ECHO_OUTPUT_VARIABLE
730- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /_deps/bison
709+ ExternalProject_Add(
710+ bison
711+ URL https://ftp.gnu.org/gnu/bison/bison-${BISON_VERSION} .tar.gz
712+ DOWNLOAD_EXTRACT_TIMESTAMP TRUE
713+ CONFIGURE_COMMAND
714+ <SOURCE_DIR>/configure
715+ --prefix =<INSTALL_DIR>
716+ --enable-silent-rules
717+ --disable-yacc
718+ --disable-dependency-tracking
719+ LOG_INSTALL TRUE
731720 )
732721
733- set (BISON_FOUND TRUE )
722+ # Set bison executable.
723+ ExternalProject_Get_Property(bison INSTALL_DIR)
724+ set_property (CACHE BISON_EXECUTABLE PROPERTY VALUE ${INSTALL_DIR} /bin/bison)
734725
735- set_property (
736- CACHE BISON_EXECUTABLE
737- PROPERTY VALUE ${CMAKE_BINARY_DIR} /_deps/bison/src/bison
726+ add_executable (Bison::Bison IMPORTED GLOBAL )
727+ set_target_properties (
728+ Bison::Bison
729+ PROPERTIES IMPORTED_LOCATION ${BISON_EXECUTABLE}
738730 )
731+ add_dependencies (Bison::Bison bison)
739732
740733 # Move dependency to PACKAGES_FOUND.
741- block()
742- get_property (packagesNotFound GLOBAL PROPERTY PACKAGES_NOT_FOUND )
743- list (REMOVE_ITEM packagesNotFound BISON)
744- set_property (GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound)
745- get_property (packagesFound GLOBAL PROPERTY PACKAGES_FOUND )
746- set_property (GLOBAL APPEND PROPERTY PACKAGES_FOUND BISON)
747- endblock()
734+ get_property (packagesNotFound GLOBAL PROPERTY PACKAGES_NOT_FOUND )
735+ list (REMOVE_ITEM packagesNotFound BISON)
736+ set_property (GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound)
737+ get_property (packagesFound GLOBAL PROPERTY PACKAGES_FOUND )
738+ set_property (GLOBAL APPEND PROPERTY PACKAGES_FOUND BISON)
748739
749740 return (PROPAGATE BISON_FOUND BISON_VERSION)
750741endfunction ()
0 commit comments