Skip to content

Rebuild ansi c when necessary #1503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions src/ansi-c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ generic_flex(ansi_c)

add_executable(converter library/converter.cpp)

file(GLOB ansi_c_library_sources "library/*.c")

add_custom_command(OUTPUT converter_input.txt
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/library/*.c > converter_input.txt
COMMAND cat ${ansi_c_library_sources} > converter_input.txt
DEPENDS ${ansi_c_library_sources}
)

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc
COMMAND converter < converter_input.txt > ${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc
DEPENDS converter_input.txt
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc"
COMMAND converter < "converter_input.txt" > "${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc"
DEPENDS "converter_input.txt" converter
)

add_executable(file_converter file_converter.cpp)

function(make_inc name)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}.inc
COMMAND file_converter < ${CMAKE_CURRENT_SOURCE_DIR}/${name}.h > ${CMAKE_CURRENT_BINARY_DIR}/${name}.inc
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.inc"
COMMAND file_converter < "${CMAKE_CURRENT_SOURCE_DIR}/${name}.h" > "${CMAKE_CURRENT_BINARY_DIR}/${name}.inc"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${name}.h" file_converter
)
endfunction(make_inc)

Expand Down Expand Up @@ -70,13 +74,7 @@ make_inc(gcc_builtin_headers_power)
make_inc(gcc_builtin_headers_tm)
make_inc(gcc_builtin_headers_ubsan)

file(GLOB_RECURSE sources "*.cpp")
file(GLOB_RECURSE headers "*.h")
add_library(ansi-c
${sources}
${headers}
${BISON_parser_OUTPUTS}
${FLEX_scanner_OUTPUTS}
set(extra_dependencies
${CMAKE_CURRENT_BINARY_DIR}/arm_builtin_headers.inc
${CMAKE_CURRENT_BINARY_DIR}/clang_builtin_headers.inc
${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc
Expand All @@ -98,6 +96,27 @@ add_library(ansi-c
${CMAKE_CURRENT_BINARY_DIR}/library-check.stamp
)

file(GLOB_RECURSE sources "*.cpp")
file(GLOB_RECURSE headers "*.h")

list(REMOVE_ITEM sources
"${CMAKE_CURRENT_SOURCE_DIR}/library/converter.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/file_converter.cpp"
)

add_library(ansi-c
${sources}
${headers}
${BISON_parser_OUTPUTS}
${FLEX_scanner_OUTPUTS}
)

set_source_files_properties(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this doing?

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm a bit confused here too - this is removing converter and file_converter sources from the dependencies for ansi-c, which in someways makes sense. But should there be some sort of transitive dependency on the converter/file_converter tools so that if those tools get modified, anything that depends on them also gets rebuilt? (possibly adding the dependencies on the tools in the earlier custom_commands?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this so that the custom commands depend on the executables they run.

I was confused about this, but it turns out CMake only adds a target-level dependency for commands which reference executables built in the project (i.e. the executable is built before the files it generates). CMake doesn't add a file-level dependency for files built by the executable. By adding an explicit DEPENDS to the custom command, we can force CMake to re-generate files that are created by the generator executables whenever the executables are changed.

${sources}
PROPERTIES
OBJECT_DEPENDS "${extra_dependencies}"
)

generic_includes(ansi-c)

target_link_libraries(ansi-c util linking goto-programs assembler)