Skip to content

Commit cfb8658

Browse files
committed
Download m4 dependency for GNU Bison
Building GNU Bison from scratch is for now only Autotools-based and it needs also m4 program to be fully functional. Also, dotsrc.org mirrors used, as gnu.org site seems to be relatively slow.
1 parent 8286a57 commit cfb8658

File tree

1 file changed

+55
-22
lines changed

1 file changed

+55
-22
lines changed

cmake/cmake/modules/PHP/Bison.cmake

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -645,16 +645,8 @@ function(_php_bison_download)
645645

646646
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
647647
_php_bison_download_windows()
648-
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "^(Haiku|Linux)$")
649-
_php_bison_download_gnu()
650648
else()
651-
# TODO: Add support for more platforms.
652-
message(
653-
WARNING
654-
"Bison couldn't be downloaded. The current platform ${CMAKE_SYSTEM_NAME} "
655-
"is not yet supported by PHP/Bison module. Please install Bison manually."
656-
)
657-
return()
649+
_php_bison_download_gnu()
658650
endif()
659651

660652
add_executable(Bison::Bison IMPORTED GLOBAL)
@@ -693,24 +685,30 @@ endfunction()
693685

694686
# Downloads GNU Bison.
695687
function(_php_bison_download_gnu)
696-
message(
697-
STATUS
698-
"Downloading GNU Bison ${BISON_VERSION} from https://ftp.gnu.org/gnu/bison"
699-
)
688+
set(url https://mirrors.dotsrc.org/gnu/bison/bison-${BISON_VERSION}.tar.gz)
689+
690+
message(STATUS "Downloading ${url}")
700691

701692
FetchContent_Declare(
702693
BISON
703-
URL https://ftp.gnu.org/gnu/bison/bison-${BISON_VERSION}.tar.gz
694+
URL ${url}
704695
SOURCE_SUBDIR non-existing
705696
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
706697
OVERRIDE_FIND_PACKAGE
707698
)
708699

709700
FetchContent_MakeAvailable(BISON)
710701

702+
# GNU Bison depends on m4 program.
703+
find_program(PHP_BISON_M4_EXECUTABLE m4)
704+
mark_as_advanced(PHP_BISON_M4_EXECUTABLE)
705+
if(NOT PHP_BISON_M4_EXECUTABLE)
706+
_php_bison_download_m4()
707+
endif()
708+
711709
ExternalProject_Add(
712710
BISON
713-
STEP_TARGETS build install
711+
STEP_TARGETS configure build install
714712
SOURCE_DIR ${bison_SOURCE_DIR}
715713
BINARY_DIR ${bison_BINARY_DIR}
716714
INSTALL_DIR ${FETCHCONTENT_BASE_DIR}/bison-install
@@ -720,26 +718,28 @@ function(_php_bison_download_gnu)
720718
--disable-yacc
721719
--enable-silent-rules
722720
--prefix=<INSTALL_DIR>
721+
M4=${PHP_BISON_M4_EXECUTABLE}
723722
LOG_INSTALL TRUE
724723
)
725724

726725
ExternalProject_Get_Property(BISON INSTALL_DIR)
727726

728727
set_property(CACHE BISON_EXECUTABLE PROPERTY VALUE ${INSTALL_DIR}/bin/bison)
728+
729+
if(TARGET M4-install)
730+
add_dependencies(BISON-configure M4-install)
731+
endif()
729732
endfunction()
730733

731734
# Downloads winflexbison.
732735
function(_php_bison_download_windows)
733-
message(
734-
STATUS
735-
"Downloading win_bison ${BISON_VERSION} from "
736-
"https://github.com/lexxmark/winflexbison "
737-
"(${PHP_BISON_WIN_VERSION_DOWNLOAD})"
738-
)
736+
set(url https://github.com/lexxmark/winflexbison/releases/download/v${PHP_BISON_WIN_VERSION_DOWNLOAD}/win_flex_bison-${PHP_BISON_WIN_VERSION_DOWNLOAD}.zip)
737+
738+
message(STATUS "Downloading ${url}")
739739

740740
FetchContent_Declare(
741741
BISON
742-
URL https://github.com/lexxmark/winflexbison/releases/download/v${PHP_BISON_WIN_VERSION_DOWNLOAD}/win_flex_bison-${PHP_BISON_WIN_VERSION_DOWNLOAD}.zip
742+
URL ${url}
743743
SOURCE_SUBDIR non-existing
744744
OVERRIDE_FIND_PACKAGE
745745
)
@@ -752,3 +752,36 @@ function(_php_bison_download_windows)
752752
PROPERTY VALUE "${bison_SOURCE_DIR}/win_bison.exe"
753753
)
754754
endfunction()
755+
756+
function(_php_bison_download_m4)
757+
set(url https://mirrors.dotsrc.org/gnu/m4/m4-1.4.20.tar.gz)
758+
759+
message(STATUS "Downloading ${url}")
760+
761+
FetchContent_Declare(
762+
M4
763+
URL ${url}
764+
SOURCE_SUBDIR non-existing
765+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
766+
)
767+
768+
FetchContent_MakeAvailable(M4)
769+
770+
ExternalProject_Add(
771+
M4
772+
STEP_TARGETS build install
773+
SOURCE_DIR ${m4_SOURCE_DIR}
774+
BINARY_DIR ${m4_BINARY_DIR}
775+
INSTALL_DIR ${FETCHCONTENT_BASE_DIR}/m4-install
776+
CONFIGURE_COMMAND
777+
<SOURCE_DIR>/configure
778+
--disable-dependency-tracking
779+
--enable-silent-rules
780+
--prefix=<INSTALL_DIR>
781+
LOG_INSTALL TRUE
782+
)
783+
784+
ExternalProject_Get_Property(M4 INSTALL_DIR)
785+
786+
set_property(CACHE PHP_BISON_M4_EXECUTABLE PROPERTY VALUE ${INSTALL_DIR}/bin/m4)
787+
endfunction()

0 commit comments

Comments
 (0)