@@ -36,10 +36,10 @@ Custom target:
3636 `find_package(RE2C)`. Options are prepended to additional options passed with
3737 `re2c_target()` arguments.
3838
39- * `RE2C_ENABLE_DOWNLOAD ` - This module can also download and build re2c from its
40- Git repository using the `FetchContent ` module. Set to `TRUE` to enable
41- downloading re2c, when not found on the system or system version is not
42- suitable.
39+ * `RE2C_DISABLE_DOWNLOAD ` - This module can also download and build re2c from
40+ its Git repository using the `ExternalProject ` module. Set to `TRUE` to
41+ disable downloading re2c, when it is not found on the system or system version
42+ is not suitable.
4343
4444* `RE2C_USE_COMPUTED_GOTOS` - Set to `TRUE` before calling `find_package(RE2C)`
4545 to enable the re2c `--computed-gotos` option if the non-standard C
@@ -103,16 +103,16 @@ if(RE2C_EXECUTABLE)
103103 execute_process (
104104 COMMAND ${RE2C_EXECUTABLE} --vernum
105105 OUTPUT_VARIABLE RE2C_VERSION_NUM
106- ERROR_VARIABLE _re2c_version_error
107- RESULT_VARIABLE _re2c_version_result
106+ ERROR_VARIABLE _re2cVersionError
107+ RESULT_VARIABLE _re2cVersionResult
108108 OUTPUT_STRIP_TRAILING_WHITESPACE
109109 )
110110
111- if (NOT _re2c_version_result EQUAL 0)
111+ if (NOT _re2cVersionResult EQUAL 0)
112112 message (
113113 SEND_ERROR
114114 "Command \" ${RE2C_EXECUTABLE} --vernum\" failed with output:\n "
115- "${_re2c_version_error } "
115+ "${_re2cVersionError } "
116116 )
117117 elseif (RE2C_VERSION_NUM)
118118 math (
@@ -127,61 +127,75 @@ if(RE2C_EXECUTABLE)
127127
128128 math (
129129 EXPR RE2C_VERSION_PATCH
130- "${RE2C_VERSION_NUM} - ${RE2C_VERSION_MAJOR} * 10000 - ${RE2C_VERSION_MINOR} * 100"
130+ "${RE2C_VERSION_NUM} \
131+ - ${RE2C_VERSION_MAJOR} * 10000 \
132+ - ${RE2C_VERSION_MINOR} * 100"
131133 )
132134
133- set (RE2C_VERSION "${RE2C_VERSION_MAJOR} .${RE2C_VERSION_MINOR} .${RE2C_VERSION_PATCH} " )
135+ set (
136+ RE2C_VERSION
137+ "${RE2C_VERSION_MAJOR} .${RE2C_VERSION_MINOR} .${RE2C_VERSION_PATCH} "
138+ )
134139
135- find_package_check_version("${RE2C_VERSION} " _re2c_version_valid )
140+ find_package_check_version("${RE2C_VERSION} " _re2cVersionValid )
136141 endif ()
137142endif ()
138143
139- if (RE2C_ENABLE_DOWNLOAD AND (NOT RE2C_EXECUTABLE OR NOT _re2c_version_valid))
140- include (FetchContent)
144+ set (_re2cRequiredVars RE2C_EXECUTABLE RE2C_VERSION)
141145
146+ if (NOT RE2C_DISABLE_DOWNLOAD AND (NOT RE2C_EXECUTABLE OR NOT _re2cVersionValid))
142147 # Set the re2c version to download.
143- set (RE2C_VERSION 3.1)
144-
145- # Configure re2c.
146- set (RE2C_BUILD_RE2GO OFF CACHE INTERNAL "" )
147- set (RE2C_BUILD_RE2RUST OFF CACHE INTERNAL "" )
148-
149- # Disable searching for Python as it is not needed in FetchContent build.
150- set (CMAKE_DISABLE_FIND_PACKAGE_Python3 TRUE )
151- set (Python3_VERSION 3.12)
152-
153- set (FETCHCONTENT_QUIET FALSE )
154-
155- FetchContent_Declare(
156- RE2C
157- URL https://github.com/skvadrik/re2c/archive/refs/tags/${RE2C_VERSION} .tar.gz
148+ set (RE2C_VERSION 4.0.2)
149+
150+ include (ExternalProject)
151+
152+ ExternalProject_Add(
153+ re2c
154+ URL
155+ https://github.com/skvadrik/re2c/archive/refs/tags/${RE2C_VERSION} .tar.gz
156+ CMAKE_ARGS
157+ -DRE2C_BUILD_RE2D=OFF
158+ -DRE2C_BUILD_RE2D=OFF
159+ -DRE2C_BUILD_RE2GO=OFF
160+ -DRE2C_BUILD_RE2HS=OFF
161+ -DRE2C_BUILD_RE2JAVA=OFF
162+ -DRE2C_BUILD_RE2JS=OFF
163+ -DRE2C_BUILD_RE2OCAML=OFF
164+ -DRE2C_BUILD_RE2PY=OFF
165+ -DRE2C_BUILD_RE2RUST=OFF
166+ -DRE2C_BUILD_RE2V=OFF
167+ -DRE2C_BUILD_RE2ZIG=OFF
168+ -DRE2C_BUILD_TESTS=OFF
169+ INSTALL_COMMAND ""
158170 )
159171
160- message (STATUS "Downloading RE2C" )
161- FetchContent_MakeAvailable(RE2C)
162-
163- # Set executable to re2c target name.
164- set (RE2C_EXECUTABLE re2c)
172+ # Set re2c executable.
173+ ExternalProject_Get_property(re2c BINARY_DIR)
174+ add_executable (RE2C::RE2C IMPORTED )
175+ set_target_properties (
176+ RE2C::RE2C
177+ PROPERTIES IMPORTED_LOCATION ${BINARY_DIR} /re2c
178+ )
179+ add_dependencies (RE2C::RE2C re2c)
180+ set_property (CACHE RE2C_EXECUTABLE PROPERTY VALUE RE2C::RE2C)
165181
166- # Unset temporary variables.
167- unset (CMAKE_DISABLE_FIND_PACKAGE_Python3 )
168- unset (Python3_VERSION)
169- unset (FETCHCONTENT_QUIET)
182+ list (PREPEND _re2cRequiredVars _re2cMsg)
183+ set (_re2cMsg "downloading at build" )
170184endif ()
171185
172186mark_as_advanced (RE2C_EXECUTABLE)
173187
174188find_package_handle_standard_args(
175189 RE2C
176- REQUIRED_VARS
177- RE2C_EXECUTABLE
178- RE2C_VERSION
190+ REQUIRED_VARS ${_re2cRequiredVars}
179191 VERSION_VAR RE2C_VERSION
180192 HANDLE_VERSION_RANGE
181193 REASON_FAILURE_MESSAGE "re2c not found. Please install re2c."
182194)
183195
184- unset (_re2c_version_valid)
196+ unset (_re2cMsg)
197+ unset (_re2cRequiredVars)
198+ unset (_re2cVersionValid)
185199
186200if (NOT RE2C_FOUND)
187201 return ()
@@ -287,7 +301,7 @@ function(re2c_target)
287301 ${options}
288302 --output ${output}
289303 ${input}
290- DEPENDS ${input} ${parsed_DEPENDS}
304+ DEPENDS ${input} ${parsed_DEPENDS} $<TARGET_NAME_IF_EXISTS:RE2C::RE2C>
291305 COMMENT "[RE2C][${ARGV0} ] Building lexer with re2c ${RE2C_VERSION} "
292306 VERBATIM
293307 COMMAND_EXPAND_LISTS
0 commit comments