1
1
#[=============================================================================[
2
2
# PHP/Bison
3
3
4
- Finds the Bison command-line parser generator and provides a command to generate
5
- parser files with Bison:
4
+ This module finds the Bison command-line parser generator and provides a command
5
+ to generate parser files with Bison:
6
6
7
7
```cmake
8
8
include(PHP/Bison)
@@ -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 . This variable
123
+ specifies which GNU Bison 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
@@ -205,9 +210,16 @@ macro(_php_bison_config)
205
210
set (PHP_BISON_VERSION 3.0.0 )
206
211
endif ()
207
212
208
- # 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 )
213
+ # If Bison is not found on the system, set which version to download for
214
+ # POSIX platforms that might support GNU Bison.
215
+ if (NOT PHP_BISON_GNU_VERSION_DOWNLOAD )
216
+ set (PHP_BISON_GNU_VERSION_DOWNLOAD 3.8.2 )
217
+ endif ()
218
+
219
+ # If Bison is not found on the Windows host system, set which winflexbison
220
+ # version to download.
221
+ if (NOT PHP_BISON_WIN_VERSION_DOWNLOAD )
222
+ set (PHP_BISON_WIN_VERSION_DOWNLOAD 2.5.25 )
211
223
endif ()
212
224
endmacro ()
213
225
@@ -311,11 +323,10 @@ function(php_bison name input output)
311
323
312
324
if (
313
325
NOT BISON_FOUND
314
- AND PHP_BISON_VERSION_DOWNLOAD
326
+ AND PHP_BISON_GNU_VERSION_DOWNLOAD
327
+ AND PHP_BISON_WIN_VERSION_DOWNLOAD
315
328
AND packageType STREQUAL "REQUIRED"
316
329
AND role STREQUAL "PROJECT"
317
- # TODO: Support for other platforms.
318
- AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux"
319
330
)
320
331
_php_bison_download ()
321
332
endif ()
@@ -616,14 +627,58 @@ endfunction()
616
627
617
628
# Download and build Bison if not found.
618
629
function (_php_bison_download )
619
- set (BISON_VERSION ${PHP_BISON_VERSION_DOWNLOAD } )
630
+ set (BISON_VERSION ${PHP_BISON_GNU_VERSION_DOWNLOAD } )
620
631
set (BISON_FOUND TRUE )
621
632
622
633
if (TARGET Bison::Bison )
623
634
return (PROPAGATE BISON_FOUND BISON_VERSION )
624
635
endif ()
625
636
626
- message (STATUS "Bison ${BISON_VERSION} will be downloaded at build phase" )
637
+ if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" )
638
+ _php_bison_download_windows ()
639
+ elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" )
640
+ _php_bison_download_gnu ()
641
+ else ()
642
+ # TODO: Add support for more platforms.
643
+ message (
644
+ WARNING
645
+ "Bison couldn't be downloaded. The current platform ${CMAKE_SYSTEM_NAME} "
646
+ "is not yet supported by PHP/Bison module. Please install Bison manually."
647
+ )
648
+ return ()
649
+ endif ()
650
+
651
+ add_executable (Bison::Bison IMPORTED GLOBAL )
652
+ set_target_properties (
653
+ Bison::Bison
654
+ PROPERTIES IMPORTED_LOCATION ${BISON_EXECUTABLE}
655
+ )
656
+
657
+ # Target created by ExternalProject:
658
+ if (TARGET bison )
659
+ add_dependencies (Bison::Bison bison )
660
+ endif ()
661
+
662
+ # Move dependency to PACKAGES_FOUND.
663
+ get_property (packagesNotFound GLOBAL PROPERTY PACKAGES_NOT_FOUND )
664
+ list (REMOVE_ITEM packagesNotFound BISON )
665
+ set_property (GLOBAL PROPERTY PACKAGES_NOT_FOUND ${packagesNotFound} )
666
+ get_property (packagesFound GLOBAL PROPERTY PACKAGES_FOUND )
667
+ set_property (GLOBAL APPEND PROPERTY PACKAGES_FOUND BISON )
668
+
669
+ set (
670
+ _PHP_BISON_DOWNLOAD
671
+ TRUE
672
+ CACHE INTERNAL
673
+ "Internal marker whether the Bison will be downloaded."
674
+ )
675
+
676
+ return (PROPAGATE BISON_FOUND BISON_VERSION )
677
+ endfunction ()
678
+
679
+ # Downloads GNU Bison.
680
+ function (_php_bison_download_gnu )
681
+ message (STATUS "GNU Bison ${BISON_VERSION} will be downloaded at build phase" )
627
682
628
683
include (ExternalProject )
629
684
@@ -641,28 +696,36 @@ function(_php_bison_download)
641
696
)
642
697
643
698
ExternalProject_Get_Property (bison INSTALL_DIR )
699
+
644
700
set_property (CACHE BISON_EXECUTABLE PROPERTY VALUE ${INSTALL_DIR} /bin/bison )
701
+ endfunction ()
645
702
646
- add_executable (Bison::Bison IMPORTED GLOBAL )
647
- set_target_properties (
648
- Bison::Bison
649
- PROPERTIES IMPORTED_LOCATION ${BISON_EXECUTABLE}
703
+ # Downloads https://github.com/lexxmark/winflexbison.
704
+ function (_php_bison_download_windows )
705
+ message (
706
+ STATUS
707
+ "Downloading win_bison ${BISON_VERSION} (${PHP_BISON_WIN_VERSION_DOWNLOAD} )"
650
708
)
651
- add_dependencies (Bison::Bison bison )
652
709
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 )
710
+ get_directory_property (dir EP_BASE )
711
+ if (NOT dir )
712
+ set (dir "${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles" )
713
+ endif ()
659
714
660
- set (
661
- _PHP_BISON_DOWNLOAD
662
- TRUE
663
- CACHE INTERNAL
664
- "Internal marker whether the Bison will be downloaded."
715
+ set (file "${dir} /win_flex_bison.zip" )
716
+
717
+ file (
718
+ DOWNLOAD
719
+ "https://github.com/lexxmark/winflexbison/releases/download/v${PHP_BISON_WIN_VERSION_DOWNLOAD} /win_flex_bison-${PHP_BISON_WIN_VERSION_DOWNLOAD} .zip"
720
+ ${file}
721
+ SHOW_PROGRESS
665
722
)
666
723
667
- return (PROPAGATE BISON_FOUND BISON_VERSION )
724
+ file (ARCHIVE_EXTRACT INPUT "${file} " DESTINATION "${dir} /win_flex_bison" )
725
+
726
+ set_property (
727
+ CACHE
728
+ BISON_EXECUTABLE
729
+ PROPERTY VALUE "${dir} /win_flex_bison/win_bison.exe"
730
+ )
668
731
endfunction ()
0 commit comments