@@ -36,10 +36,10 @@ Custom target:
36
36
`find_package(RE2C)`. Options are prepended to additional options passed with
37
37
`re2c_target()` arguments.
38
38
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.
43
43
44
44
* `RE2C_USE_COMPUTED_GOTOS` - Set to `TRUE` before calling `find_package(RE2C)`
45
45
to enable the re2c `--computed-gotos` option if the non-standard C
@@ -103,16 +103,16 @@ if(RE2C_EXECUTABLE)
103
103
execute_process (
104
104
COMMAND ${RE2C_EXECUTABLE} --vernum
105
105
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
108
108
OUTPUT_STRIP_TRAILING_WHITESPACE
109
109
)
110
110
111
- if (NOT _re2c_version_result EQUAL 0)
111
+ if (NOT _re2cVersionResult EQUAL 0)
112
112
message (
113
113
SEND_ERROR
114
114
"Command \" ${RE2C_EXECUTABLE} --vernum\" failed with output:\n "
115
- "${_re2c_version_error } "
115
+ "${_re2cVersionError } "
116
116
)
117
117
elseif (RE2C_VERSION_NUM)
118
118
math (
@@ -127,61 +127,75 @@ if(RE2C_EXECUTABLE)
127
127
128
128
math (
129
129
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"
131
133
)
132
134
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
+ )
134
139
135
- find_package_check_version("${RE2C_VERSION} " _re2c_version_valid )
140
+ find_package_check_version("${RE2C_VERSION} " _re2cVersionValid )
136
141
endif ()
137
142
endif ()
138
143
139
- if (RE2C_ENABLE_DOWNLOAD AND (NOT RE2C_EXECUTABLE OR NOT _re2c_version_valid))
140
- include (FetchContent)
144
+ set (_re2cRequiredVars RE2C_EXECUTABLE RE2C_VERSION)
141
145
146
+ if (NOT RE2C_DISABLE_DOWNLOAD AND (NOT RE2C_EXECUTABLE OR NOT _re2cVersionValid))
142
147
# 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 ""
158
170
)
159
171
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)
165
181
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" )
170
184
endif ()
171
185
172
186
mark_as_advanced (RE2C_EXECUTABLE)
173
187
174
188
find_package_handle_standard_args(
175
189
RE2C
176
- REQUIRED_VARS
177
- RE2C_EXECUTABLE
178
- RE2C_VERSION
190
+ REQUIRED_VARS ${_re2cRequiredVars}
179
191
VERSION_VAR RE2C_VERSION
180
192
HANDLE_VERSION_RANGE
181
193
REASON_FAILURE_MESSAGE "re2c not found. Please install re2c."
182
194
)
183
195
184
- unset (_re2c_version_valid)
196
+ unset (_re2cMsg)
197
+ unset (_re2cRequiredVars)
198
+ unset (_re2cVersionValid)
185
199
186
200
if (NOT RE2C_FOUND)
187
201
return ()
@@ -287,7 +301,7 @@ function(re2c_target)
287
301
${options}
288
302
--output ${output}
289
303
${input}
290
- DEPENDS ${input} ${parsed_DEPENDS}
304
+ DEPENDS ${input} ${parsed_DEPENDS} $<TARGET_NAME_IF_EXISTS:RE2C::RE2C>
291
305
COMMENT "[RE2C][${ARGV0} ] Building lexer with re2c ${RE2C_VERSION} "
292
306
VERBATIM
293
307
COMMAND_EXPAND_LISTS
0 commit comments