Skip to content

Commit 5e9b2f4

Browse files
committed
Fail CMake build if make-generated files are found
1 parent c0ce9de commit 5e9b2f4

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/CMakeLists.txt

+17-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,23 @@ endif(DOXYGEN_FOUND)
3030

3131
# Add a bison target named 'parser'.
3232
macro(generic_bison name)
33+
set(bison_header "${name}_y.tab.h")
34+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${bison_header}")
35+
message(FATAL_ERROR "Generated file ${bison_header} found in source tree. If you previously built with `make`, run `make clean` and try again")
36+
endif()
37+
38+
set(bison_source "${name}_y.tab.cpp")
39+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${bison_source}")
40+
message(FATAL_ERROR "Generated file ${bison_source} found in source tree. If you previously built with `make`, run `make clean` and try again")
41+
endif()
42+
3343
bison_target(
3444
parser
3545
"${CMAKE_CURRENT_SOURCE_DIR}/parser.y"
36-
"${CMAKE_CURRENT_BINARY_DIR}/${name}_y.tab.cpp"
46+
"${CMAKE_CURRENT_BINARY_DIR}/${bison_source}"
3747
COMPILE_FLAGS "-pyy${name}"
3848
)
39-
set(renamed_parser_header "${CMAKE_CURRENT_BINARY_DIR}/${name}_y.tab.h")
49+
set(renamed_parser_header "${CMAKE_CURRENT_BINARY_DIR}/${bison_header}")
4050
add_custom_command(OUTPUT "${renamed_parser_header}"
4151
COMMAND "${CMAKE_COMMAND}" -E copy "${BISON_parser_OUTPUT_HEADER}" "${renamed_parser_header}"
4252
MAIN_DEPENDENCY "${BISON_parser_OUTPUT_HEADER}"
@@ -47,6 +57,11 @@ endmacro(generic_bison)
4757

4858
# Add a flex target named 'scanner'
4959
macro(generic_flex name)
60+
set(flex_source "${name}_lex.yy.cpp")
61+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${flex_source}")
62+
message(FATAL_ERROR "Generated file ${flex_source} found in source tree. If you previously built with `make`, run `make clean` and try again")
63+
endif()
64+
5065
flex_target(
5166
scanner
5267
"${CMAKE_CURRENT_SOURCE_DIR}/scanner.l"

0 commit comments

Comments
 (0)