@@ -13,7 +13,9 @@ syntax, e.g. 'find_package(RE2C 0.15.3)'.
1313
1414## Cache variables
1515
16- * `RE2C_EXECUTABLE` - Path to the re2c program.
16+ * `RE2C_EXECUTABLE` - Path to the re2c program. When RE2C is downloaded and
17+ built from source as part of the built (using below ExternalProject), this
18+ path will not exist until the built phase.
1719
1820Custom target:
1921
@@ -98,8 +100,15 @@ find_program(
98100 NAMES re2c
99101 DOC "The re2c executable path"
100102)
103+ mark_as_advanced (RE2C_EXECUTABLE)
104+
105+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.29)
106+ set (_re2cCondition IS_EXECUTABLE ${RE2C_EXECUTABLE} )
107+ else ()
108+ set (_re2cCondition EXISTS ${RE2C_EXECUTABLE} )
109+ endif ()
101110
102- if (RE2C_EXECUTABLE )
111+ if (${_re2cCondition} )
103112 execute_process (
104113 COMMAND ${RE2C_EXECUTABLE} --vernum
105114 OUTPUT_VARIABLE RE2C_VERSION_NUM
@@ -177,14 +186,13 @@ if(NOT RE2C_DISABLE_DOWNLOAD AND (NOT RE2C_EXECUTABLE OR NOT _re2cVersionValid))
177186 PROPERTIES IMPORTED_LOCATION ${BINARY_DIR} /re2c
178187 )
179188 add_dependencies (RE2C::RE2C re2c)
180- set_property (CACHE RE2C_EXECUTABLE PROPERTY VALUE RE2C::RE2C)
189+ set_property (CACHE RE2C_EXECUTABLE PROPERTY VALUE ${BINARY_DIR} /re2c)
190+ unset (BINARY_DIR)
181191
182192 list (PREPEND _re2cRequiredVars _re2cMsg)
183193 set (_re2cMsg "downloading at build" )
184194endif ()
185195
186- mark_as_advanced (RE2C_EXECUTABLE)
187-
188196find_package_handle_standard_args(
189197 RE2C
190198 REQUIRED_VARS ${_re2cRequiredVars}
@@ -193,6 +201,7 @@ find_package_handle_standard_args(
193201 REASON_FAILURE_MESSAGE "re2c not found. Please install re2c."
194202)
195203
204+ unset (_re2cCondition)
196205unset (_re2cMsg)
197206unset (_re2cRequiredVars)
198207unset (_re2cVersionValid)
@@ -297,11 +306,11 @@ function(re2c_target)
297306
298307 add_custom_command (
299308 OUTPUT ${outputs}
300- COMMAND ${RE2C_EXECUTABLE}
309+ COMMAND $<IF:$<TARGET_EXISTS:RE2C::RE2C>,RE2C::RE2C, $ {RE2C_EXECUTABLE}>
301310 ${options}
302311 --output ${output}
303312 ${input}
304- DEPENDS ${input} ${parsed_DEPENDS} $<TARGET_NAME_IF_EXISTS:RE2C::RE2C>
313+ DEPENDS ${input} ${parsed_DEPENDS}
305314 COMMENT "[RE2C][${ARGV0} ] Building lexer with re2c ${RE2C_VERSION} "
306315 VERBATIM
307316 COMMAND_EXPAND_LISTS
0 commit comments