Skip to content

Commit f508c8e

Browse files
committed
Build: Re-enable LEX_FILES_{H,CPP}, streamline
- The problem with these vars (in older CMake) wasn't that they don't work as intended, it's that the values were being built wrong. The previous code constructed each variable as a list of filenames, each item separated by an item containing a single space. CMake understands how to explode a list of filenames into arguments to a command, or even expand a list _of arguments_ when calling a command, but older versions weren't smart enough to handle empty arguments without breaking. Construct the list in a way CMake understands, with no blank items, and it works everywhere, even ancient CMake 3.0/3.1/3.2. - Use a couple of temporary variables to streamline and DRY out the add_custom_command that processes lexer files.
1 parent 8887ee5 commit f508c8e

File tree

1 file changed

+51
-70
lines changed

1 file changed

+51
-70
lines changed

src/CMakeLists.txt

Lines changed: 51 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -94,53 +94,65 @@ add_custom_command(
9494
)
9595
set_source_files_properties(${GENERATED_SRC}/resources.cpp PROPERTIES GENERATED 1)
9696

97-
set(LEX_FILES scanner
97+
set(LEX_FILES
9898
code
99-
pyscanner
100-
pycode
101-
fortranscanner
102-
fortrancode
103-
vhdlcode
104-
pre
105-
declinfo
106-
defargs
107-
doctokenizer
10899
commentcnv
109100
commentscan
101+
configimpl
110102
constexp
111-
xmlcode
112-
sqlcode
103+
declinfo
104+
defargs
105+
doctokenizer
106+
fortrancode
107+
fortranscanner
113108
lexcode
114109
lexscanner
115-
configimpl)
110+
pre
111+
pycode
112+
pyscanner
113+
scanner
114+
sqlcode
115+
vhdlcode
116+
xmlcode
117+
)
116118

117119
if (NOT depfile_supported)
118120
# In case the DEPFILE possibility is not supported the complete list of lex include files for the dependency has to be used
119121
set(LEX_INC_FILES)
120122
endif()
121123

122-
# unfortunately ${LEX_FILES_H} and ${LEX_FILES_CPP} don't work in older versions of CMake (like 3.6.2) for add_library
124+
set(LEX_FILES_H)
125+
set(LEX_FILES_CPP)
126+
set(_depfile_args)
127+
123128
foreach(lex_file ${LEX_FILES})
124-
set(LEX_FILES_H ${LEX_FILES_H} " " ${GENERATED_SRC}/${lex_file}.l.h CACHE INTERNAL "Stores generated files")
125-
set(LEX_FILES_CPP ${LEX_FILES_CPP} " " ${GENERATED_SRC}/${lex_file}.cpp CACHE INTERNAL "Stores generated files")
129+
# configimpl is handled specially (it's in the static lib)
130+
if (NOT lex_file STREQUAL "configimpl")
131+
list(APPEND LEX_FILES_H ${GENERATED_SRC}/${lex_file}.l.h)
132+
list(APPEND LEX_FILES_CPP ${GENERATED_SRC}/${lex_file}.cpp)
133+
endif()
134+
135+
set(_generated_files
136+
${GENERATED_SRC}/${lex_file}.l
137+
${GENERATED_SRC}/${lex_file}.corr
138+
${GENERATED_SRC}/${lex_file}.d)
126139

127140
if (depfile_supported)
128-
add_custom_command(
129-
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/pre_lex.py ${CMAKE_CURRENT_LIST_DIR}/${lex_file}.l ${GENERATED_SRC}/${lex_file}.l ${GENERATED_SRC}/${lex_file}.corr ${GENERATED_SRC}/${lex_file}.d ${CMAKE_CURRENT_LIST_DIR}
130-
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/pre_lex.py ${CMAKE_CURRENT_LIST_DIR}/${lex_file}.l
131-
DEPFILE ${GENERATED_SRC}/${lex_file}.d
132-
OUTPUT ${GENERATED_SRC}/${lex_file}.l ${GENERATED_SRC}/${lex_file}.corr ${GENERATED_SRC}/${lex_file}.d
133-
)
134-
else()
135-
add_custom_command(
136-
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/pre_lex.py ${CMAKE_CURRENT_LIST_DIR}/${lex_file}.l ${GENERATED_SRC}/${lex_file}.l ${GENERATED_SRC}/${lex_file}.corr ${GENERATED_SRC}/${lex_file}.d ${CMAKE_CURRENT_LIST_DIR}
137-
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/pre_lex.py ${CMAKE_CURRENT_LIST_DIR}/${lex_file}.l ${LEX_INC_FILES}
138-
OUTPUT ${GENERATED_SRC}/${lex_file}.l ${GENERATED_SRC}/${lex_file}.corr ${GENERATED_SRC}/${lex_file}.d
139-
)
141+
set(_depfile_args DEPFILE ${GENERATED_SRC}/${lex_file}.d)
140142
endif()
141-
set_source_files_properties(${GENERATED_SRC}/${lex_file}.l PROPERTIES GENERATED 1)
142-
set_source_files_properties(${GENERATED_SRC}/${lex_file}.corr PROPERTIES GENERATED 1)
143-
set_source_files_properties(${GENERATED_SRC}/${lex_file}.d PROPERTIES GENERATED 1)
143+
add_custom_command(
144+
OUTPUT ${_generated_files}
145+
COMMAND ${PYTHON_EXECUTABLE}
146+
${CMAKE_CURRENT_LIST_DIR}/pre_lex.py
147+
${CMAKE_CURRENT_LIST_DIR}/${lex_file}.l
148+
${_generated_files}
149+
${CMAKE_CURRENT_LIST_DIR}
150+
DEPENDS
151+
${CMAKE_CURRENT_LIST_DIR}/pre_lex.py
152+
${CMAKE_CURRENT_LIST_DIR}/${lex_file}.l
153+
${_depfile_args}
154+
)
155+
set_source_files_properties(${_generated_files} PROPERTIES GENERATED 1)
144156

145157
add_custom_command(
146158
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/scan_states.py ${GENERATED_SRC}/${lex_file}.l > ${GENERATED_SRC}/${lex_file}.l.h
@@ -168,6 +180,12 @@ foreach(lex_file ${LEX_FILES})
168180
OUTPUT ${GENERATED_SRC}/${lex_file}.cpp
169181
)
170182
endforeach()
183+
unset(_depfile_args)
184+
unset(_generated_files)
185+
186+
# Cache generated sources lists
187+
set(LEX_FILES_H ${LEX_FILES_H} CACHE INTERNAL "Stores generated files")
188+
set(LEX_FILES_CPP ${LEX_FILES_CPP} CACHE INTERNAL "Stores generated files")
171189

172190

173191
BISON_TARGET(constexp
@@ -200,44 +218,8 @@ add_sanitizers(doxycfg)
200218

201219
add_library(doxymain STATIC
202220
# generated for/by flex/bison
203-
#${LEX_FILES_H} #unfortunately doesn't work in older versions of CMake (like 3.6.2)
204-
#${LEX_FILES_CPP} #unfortunately doesn't work in older versions of CMake (like 3.6.2)
205-
${GENERATED_SRC}/code.l.h
206-
${GENERATED_SRC}/commentcnv.l.h
207-
${GENERATED_SRC}/commentscan.l.h
208-
${GENERATED_SRC}/constexp.cpp
209-
${GENERATED_SRC}/constexp.l.h
210-
${GENERATED_SRC}/declinfo.l.h
211-
${GENERATED_SRC}/defargs.l.h
212-
${GENERATED_SRC}/doctokenizer.l.h
213-
${GENERATED_SRC}/fortrancode.l.h
214-
${GENERATED_SRC}/fortranscanner.l.h
215-
${GENERATED_SRC}/lexcode.l.h
216-
${GENERATED_SRC}/lexscanner.l.h
217-
${GENERATED_SRC}/pre.l.h
218-
${GENERATED_SRC}/pycode.l.h
219-
${GENERATED_SRC}/pyscanner.l.h
220-
${GENERATED_SRC}/scanner.l.h
221-
${GENERATED_SRC}/sqlcode.l.h
222-
${GENERATED_SRC}/vhdlcode.l.h
223-
${GENERATED_SRC}/xmlcode.l.h
224-
${GENERATED_SRC}/code.cpp
225-
${GENERATED_SRC}/commentcnv.cpp
226-
${GENERATED_SRC}/commentscan.cpp
227-
${GENERATED_SRC}/declinfo.cpp
228-
${GENERATED_SRC}/defargs.cpp
229-
${GENERATED_SRC}/doctokenizer.cpp
230-
${GENERATED_SRC}/fortrancode.cpp
231-
${GENERATED_SRC}/fortranscanner.cpp
232-
${GENERATED_SRC}/lexcode.cpp
233-
${GENERATED_SRC}/lexscanner.cpp
234-
${GENERATED_SRC}/pre.cpp
235-
${GENERATED_SRC}/pycode.cpp
236-
${GENERATED_SRC}/pyscanner.cpp
237-
${GENERATED_SRC}/scanner.cpp
238-
${GENERATED_SRC}/sqlcode.cpp
239-
${GENERATED_SRC}/vhdlcode.cpp
240-
${GENERATED_SRC}/xmlcode.cpp
221+
${LEX_FILES_H}
222+
${LEX_FILES_CPP}
241223
#
242224
${GENERATED_SRC}/ce_parse.cpp
243225
# custom generated files
@@ -422,4 +404,3 @@ set_project_coverage(doxymain)
422404
set_project_coverage(doxygen)
423405

424406
install(TARGETS doxygen DESTINATION bin)
425-

0 commit comments

Comments
 (0)