Skip to content

Commit 09d30a1

Browse files
committed
Download re2c and Bison with FetchContent
This uses FetchContent and ExternalProject modules together. FetchContent integrates better with find_package() calls, and ExternalProject takes care of isolation.
1 parent 8154ec4 commit 09d30a1

File tree

2 files changed

+72
-41
lines changed

2 files changed

+72
-41
lines changed

cmake/cmake/modules/PHP/Bison.cmake

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ function(_php_bison_download)
655655
)
656656

657657
# Target created by ExternalProject:
658-
if(TARGET bison)
659-
add_dependencies(Bison::Bison bison)
658+
if(TARGET BISON-install)
659+
add_dependencies(Bison::Bison BISON-install)
660660
endif()
661661

662662
# Move dependency to PACKAGES_FOUND.
@@ -676,22 +676,38 @@ function(_php_bison_download)
676676
_PHP_BISON_DOWNLOAD
677677
TRUE
678678
CACHE INTERNAL
679-
"Internal marker whether the Bison will be downloaded."
679+
"Internal marker whether Bison is downloaded."
680680
)
681681

682682
return(PROPAGATE BISON_FOUND BISON_VERSION)
683683
endfunction()
684684

685685
# Downloads GNU Bison.
686686
function(_php_bison_download_gnu)
687-
message(STATUS "GNU Bison ${BISON_VERSION} will be downloaded at build phase")
687+
message(
688+
STATUS
689+
"Downloading GNU Bison ${BISON_VERSION} from https://ftp.gnu.org/gnu/bison"
690+
)
688691

689692
include(ExternalProject)
693+
include(FetchContent)
690694

691-
ExternalProject_Add(
692-
bison
695+
FetchContent_Declare(
696+
BISON
693697
URL https://ftp.gnu.org/gnu/bison/bison-${BISON_VERSION}.tar.gz
698+
SOURCE_SUBDIR non-existing
694699
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
700+
OVERRIDE_FIND_PACKAGE
701+
)
702+
703+
FetchContent_MakeAvailable(BISON)
704+
705+
ExternalProject_Add(
706+
BISON
707+
STEP_TARGETS build install
708+
SOURCE_DIR ${bison_SOURCE_DIR}
709+
BINARY_DIR ${bison_BINARY_DIR}
710+
INSTALL_DIR ${FETCHCONTENT_BASE_DIR}/bison-install
695711
CONFIGURE_COMMAND
696712
<SOURCE_DIR>/configure
697713
--disable-dependency-tracking
@@ -701,16 +717,18 @@ function(_php_bison_download_gnu)
701717
LOG_INSTALL TRUE
702718
)
703719

704-
ExternalProject_Get_Property(bison INSTALL_DIR)
720+
ExternalProject_Get_Property(BISON INSTALL_DIR)
705721

706722
set_property(CACHE BISON_EXECUTABLE PROPERTY VALUE ${INSTALL_DIR}/bin/bison)
707723
endfunction()
708724

709-
# Downloads https://github.com/lexxmark/winflexbison.
725+
# Downloads winflexbison.
710726
function(_php_bison_download_windows)
711727
message(
712728
STATUS
713-
"Downloading win_bison ${BISON_VERSION} (${PHP_BISON_WIN_VERSION_DOWNLOAD})"
729+
"Downloading win_bison ${BISON_VERSION} from "
730+
"https://github.com/lexxmark/winflexbison "
731+
"(${PHP_BISON_WIN_VERSION_DOWNLOAD})"
714732
)
715733

716734
get_directory_property(dir EP_BASE)

cmake/cmake/modules/PHP/Re2c.cmake

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -618,60 +618,73 @@ function(_php_re2c_download)
618618
)
619619
endif()
620620

621-
message(STATUS "Re2c ${RE2C_VERSION} will be downloaded at build phase")
621+
message(
622+
STATUS
623+
"Downloading re2c ${RE2C_VERSION} from https://github.com/skvadrik/re2c"
624+
)
622625

623626
include(ExternalProject)
627+
include(FetchContent)
628+
629+
FetchContent_Declare(
630+
RE2C
631+
URL https://github.com/skvadrik/re2c/archive/refs/tags/${RE2C_VERSION}.tar.gz
632+
SOURCE_SUBDIR non-existing
633+
OVERRIDE_FIND_PACKAGE
634+
)
635+
636+
FetchContent_MakeAvailable(RE2C)
624637

625638
# Configure re2c build.
639+
set(options -DRE2C_BUILD_RE2GO=OFF -DRE2C_BUILD_RE2RUST=OFF)
640+
626641
if(RE2C_VERSION VERSION_GREATER_EQUAL 4)
627-
set(
628-
re2cOptions
629-
-DRE2C_BUILD_RE2D=OFF
630-
-DRE2C_BUILD_RE2HS=OFF
631-
-DRE2C_BUILD_RE2JAVA=OFF
632-
-DRE2C_BUILD_RE2JS=OFF
633-
-DRE2C_BUILD_RE2OCAML=OFF
634-
-DRE2C_BUILD_RE2PY=OFF
635-
-DRE2C_BUILD_RE2V=OFF
636-
-DRE2C_BUILD_RE2ZIG=OFF
637-
-DRE2C_BUILD_TESTS=OFF
642+
list(
643+
APPEND
644+
options
645+
-DRE2C_BUILD_RE2D=OFF
646+
-DRE2C_BUILD_RE2HS=OFF
647+
-DRE2C_BUILD_RE2JAVA=OFF
648+
-DRE2C_BUILD_RE2JS=OFF
649+
-DRE2C_BUILD_RE2OCAML=OFF
650+
-DRE2C_BUILD_RE2PY=OFF
651+
-DRE2C_BUILD_RE2V=OFF
652+
-DRE2C_BUILD_RE2ZIG=OFF
653+
-DRE2C_BUILD_TESTS=OFF
638654
)
639655
else()
640-
set(
641-
re2cOptions
642-
-DCMAKE_DISABLE_FIND_PACKAGE_Python3=TRUE
643-
-DPython3_VERSION=3.7
656+
list(
657+
APPEND
658+
options
659+
-DCMAKE_DISABLE_FIND_PACKAGE_Python3=TRUE
660+
-DPython3_VERSION=3.7
644661
)
645662
endif()
646663

647664
if(RE2C_VERSION VERSION_GREATER_EQUAL 4.2)
648-
list(APPEND re2cOptions -DRE2C_BUILD_RE2SWIFT=OFF)
665+
list(APPEND options -DRE2C_BUILD_RE2SWIFT=OFF)
649666
endif()
650667

651668
ExternalProject_Add(
652-
re2c
653-
URL
654-
https://github.com/skvadrik/re2c/archive/refs/tags/${RE2C_VERSION}.tar.gz
655-
CMAKE_ARGS
656-
-DRE2C_BUILD_RE2GO=OFF
657-
-DRE2C_BUILD_RE2RUST=OFF
658-
${re2cOptions}
669+
RE2C
670+
STEP_TARGETS build
671+
SOURCE_DIR ${re2c_SOURCE_DIR}
672+
BINARY_DIR ${re2c_BINARY_DIR}
673+
CMAKE_ARGS ${options}
659674
INSTALL_COMMAND ""
660675
)
661676

662-
ExternalProject_Get_Property(re2c BINARY_DIR)
663-
set(re2c ${BINARY_DIR}/re2c)
664-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
665-
string(APPEND re2c ".exe")
666-
endif()
667-
set_property(CACHE RE2C_EXECUTABLE PROPERTY VALUE ${re2c})
677+
set_property(
678+
CACHE RE2C_EXECUTABLE
679+
PROPERTY VALUE ${re2c_BINARY_DIR}/re2c${CMAKE_EXECUTABLE_SUFFIX}
680+
)
668681

669682
add_executable(RE2C::RE2C IMPORTED GLOBAL)
670683
set_target_properties(
671684
RE2C::RE2C
672685
PROPERTIES IMPORTED_LOCATION ${RE2C_EXECUTABLE}
673686
)
674-
add_dependencies(RE2C::RE2C re2c)
687+
add_dependencies(RE2C::RE2C RE2C-build)
675688

676689
# Move dependency to PACKAGES_FOUND.
677690
block()
@@ -690,7 +703,7 @@ function(_php_re2c_download)
690703
_PHP_RE2C_DOWNLOAD
691704
TRUE
692705
CACHE INTERNAL
693-
"Internal marker whether the re2c will be downloaded."
706+
"Internal marker whether the re2c is downloaded."
694707
)
695708

696709
return(PROPAGATE RE2C_FOUND RE2C_VERSION)

0 commit comments

Comments
 (0)