@@ -117,10 +117,15 @@ These variables can be set before using this module to configure behavior:
117
117
* `PHP_BISON_VERSION` - The version constraint, when looking for BISON package
118
118
with `find_package (BISON <version-constraint> ... )` in this module.
119
119
120
- * `PHP_BISON_VERSION_DOWNLOAD` - When Bison cannot be found on the system or the
121
- found version is not suitable, this module can also download and build it from
122
- its release archive sources as part of the project build . Set which version
123
- should be downloaded.
120
+ * `PHP_BISON_GNU_VERSION_DOWNLOAD` - When Bison cannot be found on the system or
121
+ the found version is not suitable, this module can also download and build it
122
+ from its release archive sources as part of the project build . Set which
123
+ version should be downloaded.
124
+
125
+ * `PHP_BISON_WIN_VERSION_DOWNLOAD` - When Bison cannot be found on the Windows
126
+ host system or the found version is not suitable, this module can also
127
+ download [`win_bison.exe`] (https://github.com/lexxmark/winflexbison ). This
128
+ variable specifies which `winflexbison` version should be downloaded.
124
129
125
130
* `PHP_BISON_WORKING_DIRECTORY` - Set the default global working directory
126
131
for all `php_bison ()` invocations in the directory scope where the
@@ -206,8 +211,14 @@ macro(_php_bison_config)
206
211
endif ()
207
212
208
213
# If Bison is not found on the system, set which version to download.
209
- if (NOT PHP_BISON_VERSION_DOWNLOAD )
210
- set (PHP_BISON_VERSION_DOWNLOAD 3.8.2 )
214
+ if (NOT PHP_BISON_GNU_VERSION_DOWNLOAD )
215
+ set (PHP_BISON_GNU_VERSION_DOWNLOAD 3.8.2 )
216
+ endif ()
217
+
218
+ # If Bison is not found on the Windows host system, set which winflexbison
219
+ # version to download.
220
+ if (NOT PHP_BISON_WIN_VERSION_DOWNLOAD )
221
+ set (PHP_BISON_WIN_VERSION_DOWNLOAD 2.5.25 )
211
222
endif ()
212
223
endmacro ()
213
224
@@ -311,11 +322,10 @@ function(php_bison name input output)
311
322
312
323
if (
313
324
NOT BISON_FOUND
314
- AND PHP_BISON_VERSION_DOWNLOAD
325
+ AND PHP_BISON_GNU_VERSION_DOWNLOAD
326
+ AND PHP_BISON_WIN_VERSION_DOWNLOAD
315
327
AND packageType STREQUAL "REQUIRED"
316
328
AND role STREQUAL "PROJECT"
317
- # TODO: Support for other platforms.
318
- AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux"
319
329
)
320
330
_php_bison_download ()
321
331
endif ()
@@ -616,14 +626,58 @@ endfunction()
616
626
617
627
# Download and build Bison if not found.
618
628
function (_php_bison_download )
619
- set (BISON_VERSION ${PHP_BISON_VERSION_DOWNLOAD } )
629
+ set (BISON_VERSION ${PHP_BISON_GNU_VERSION_DOWNLOAD } )
620
630
set (BISON_FOUND TRUE )
621
631
622
632
if (TARGET Bison::Bison )
623
633
return (PROPAGATE BISON_FOUND BISON_VERSION )
624
634
endif ()
625
635
626
- message (STATUS "Bison ${BISON_VERSION} will be downloaded at build phase" )
636
+ if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" )
637
+ _php_bison_download_windows ()
638
+ elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" )
639
+ _php_bison_download_gnu ()
640
+ else ()
641
+ # TODO: Add support for more platforms.
642
+ message (
643
+ WARNING
644
+ "Bison couldn't be downloaded. The current platform ${CMAKE_SYSTEM_NAME} "
645
+ "is not yet supported by PHP/Bison module. Please install Bison manually."
646
+ )
647
+ return ()
648
+ endif ()
649
+
650
+ add_executable (Bison::Bison IMPORTED GLOBAL )
651
+ set_target_properties (
652
+ Bison::Bison
653
+ PROPERTIES IMPORTED_LOCATION ${BISON_EXECUTABLE}
654
+ )
655
+
656
+ # Target created by ExternalProject:
657
+ if (TARGET bison )
658
+ add_dependencies (Bison::Bison bison )
659
+ endif ()
660
+
661
+ # Move dependency to PACKAGES_FOUND.
662
+ get_property (packagesNotFound GLOBAL PROPERTY PACKAGES_NOT_FOUND )
663
+ list (REMOVE_ITEM packagesNotFound BISON )
664
+ set_property (GLOBAL PROPERTY PACKAGES_NOT_FOUND ${packagesNotFound} )
665
+ get_property (packagesFound GLOBAL PROPERTY PACKAGES_FOUND )
666
+ set_property (GLOBAL APPEND PROPERTY PACKAGES_FOUND BISON )
667
+
668
+ set (
669
+ _PHP_BISON_DOWNLOAD
670
+ TRUE
671
+ CACHE INTERNAL
672
+ "Internal marker whether the Bison will be downloaded."
673
+ )
674
+
675
+ return (PROPAGATE BISON_FOUND BISON_VERSION )
676
+ endfunction ()
677
+
678
+ # Downloads GNU Bison.
679
+ function (_php_bison_download_gnu )
680
+ message (STATUS "GNU Bison ${BISON_VERSION} will be downloaded at build phase" )
627
681
628
682
include (ExternalProject )
629
683
@@ -641,28 +695,36 @@ function(_php_bison_download)
641
695
)
642
696
643
697
ExternalProject_Get_Property (bison INSTALL_DIR )
698
+
644
699
set_property (CACHE BISON_EXECUTABLE PROPERTY VALUE ${INSTALL_DIR} /bin/bison )
700
+ endfunction ()
645
701
646
- add_executable (Bison::Bison IMPORTED GLOBAL )
647
- set_target_properties (
648
- Bison::Bison
649
- PROPERTIES IMPORTED_LOCATION ${BISON_EXECUTABLE}
702
+ # Downloads https://github.com/lexxmark/winflexbison.
703
+ function (_php_bison_download_windows )
704
+ message (
705
+ STATUS
706
+ "Downloading win_bison ${BISON_VERSION} (${PHP_BISON_WIN_VERSION_DOWNLOAD} )"
650
707
)
651
- add_dependencies (Bison::Bison bison )
652
708
653
- # Move dependency to PACKAGES_FOUND.
654
- get_property (packagesNotFound GLOBAL PROPERTY PACKAGES_NOT_FOUND )
655
- list (REMOVE_ITEM packagesNotFound BISON )
656
- set_property (GLOBAL PROPERTY PACKAGES_NOT_FOUND ${packagesNotFound} )
657
- get_property (packagesFound GLOBAL PROPERTY PACKAGES_FOUND )
658
- set_property (GLOBAL APPEND PROPERTY PACKAGES_FOUND BISON )
709
+ get_directory_property (dir EP_BASE )
710
+ if (NOT dir )
711
+ set (dir "${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles" )
712
+ endif ()
659
713
660
- set (
661
- _PHP_BISON_DOWNLOAD
662
- TRUE
663
- CACHE INTERNAL
664
- "Internal marker whether the Bison will be downloaded."
714
+ set (file "${dir} /win_flex_bison.zip" )
715
+
716
+ file (
717
+ DOWNLOAD
718
+ "https://github.com/lexxmark/winflexbison/releases/download/v${PHP_BISON_WIN_VERSION_DOWNLOAD} /win_flex_bison-${PHP_BISON_WIN_VERSION_DOWNLOAD} .zip"
719
+ ${file}
720
+ SHOW_PROGRESS
665
721
)
666
722
667
- return (PROPAGATE BISON_FOUND BISON_VERSION )
723
+ file (ARCHIVE_EXTRACT INPUT "${file} " DESTINATION "${dir} /win_flex_bison" )
724
+
725
+ set_property (
726
+ CACHE
727
+ BISON_EXECUTABLE
728
+ PROPERTY VALUE "${dir} /win_flex_bison/win_bison.exe"
729
+ )
668
730
endfunction ()
0 commit comments