-
Notifications
You must be signed in to change notification settings - Fork 273
Creating library archive with all components #7567
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
esteffin
merged 5 commits into
diffblue:develop
from
esteffin:esteffin/creating-public-archive-with-all-components
Mar 1, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b469c26
Added version from config.inc to cmake project
2cee3b1
Aggregating all library dependencies into one
2a48ee5
Renamed api files to avoid object-file clashes
3999157
Removed unecessary dependencies from Rust API
cf4817f
Added comments to API library CMakeLists.txt
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,92 @@ | ||
file(GLOB_RECURSE sources "*.cpp" "*.h") | ||
# Scan for all source files in the current or child directories | ||
file(GLOB_RECURSE sources "*.cpp") | ||
# Scan for all header files in the current or child directories (necessary to install them later) | ||
file(GLOB_RECURSE headers "*.h") | ||
|
||
# This step builds the API in the form of a statically linked library (libcprover-api-cpp.a) | ||
# This step builds the API in the form of a statically linked library | ||
add_library(cprover-api-cpp ${sources}) | ||
|
||
# Being a library we should include them privately, but for now fair enough | ||
generic_includes(cprover-api-cpp) | ||
target_link_libraries(cprover-api-cpp | ||
goto-checker | ||
goto-programs | ||
util | ||
langapi | ||
ansi-c | ||
json-symtab-language | ||
solvers | ||
xml | ||
cpp | ||
cbmc-lib | ||
analyses | ||
statement-list | ||
linking | ||
pointer-analysis | ||
goto-instrument-lib | ||
goto-analyzer-lib | ||
goto-cc-lib) | ||
|
||
# Add all the current and the installed `include` directories as a PUBLIC header location | ||
target_include_directories(cprover-api-cpp PUBLIC | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" | ||
"$<INSTALL_INTERFACE:include>") | ||
|
||
# To create a full static API library we need to archive together the content of all the other | ||
# module libraries we depend on. To do this we will use the `ar` command to unpack the other module | ||
# static libraries and append to the current library `.a` file. | ||
|
||
# Get the dependency targets of the `solver` target (see `../solver/CMakeLists.txt`), so that they | ||
# are merged to the final library too. (such dependencies are not known statically as the selection | ||
# of the SAT backend is left to the building user. | ||
get_target_property(LIBRARY_DEPENDENCIES solvers LINK_LIBRARIES) | ||
|
||
# Get all the dependency targets we know statically. | ||
list(APPEND | ||
LIBRARY_DEPENDENCIES | ||
"goto-programs" | ||
"util" | ||
"langapi" | ||
"ansi-c" | ||
"analyses" | ||
"goto-instrument-lib" | ||
"big-int" | ||
"linking" | ||
"goto-checker" | ||
"solvers" | ||
"assembler" | ||
"xml" | ||
"json" | ||
"json-symtab-language" | ||
"jsil" | ||
"statement-list" | ||
"goto-symex" | ||
"pointer-analysis" | ||
"cbmc-lib") | ||
|
||
# Remove possible duplicate library targets | ||
list(REMOVE_DUPLICATES LIBRARY_DEPENDENCIES) | ||
|
||
# Add all the dependency targets as dependencies of `cprover-api-cpp` | ||
target_link_libraries(cprover-api-cpp | ||
PRIVATE | ||
${LIBRARY_DEPENDENCIES}) | ||
|
||
# To be able to invoke `ar` on the dependencies we need the paths of the libraries `.a` files. | ||
# Ths is done by using the cmake generator `$<TARGET_FILE:dependency>`, that in turn will be | ||
# substituted with the absolute path of the `dependency` output file (a `.a` file in this case). | ||
# Here we prepare a space-separated list of cmake generators that will resolved in absolute paths. | ||
set(DEPENDENCY_TARGETS "") | ||
foreach(dep ${LIBRARY_DEPENDENCIES}) | ||
list(APPEND DEPENDENCY_TARGETS "$<TARGET_FILE:${dep}>") | ||
endforeach(dep LIBRARY_DEPENDENCIES) | ||
string(REPLACE ";" " " DEPENDENCY_TARGETS "${DEPENDENCY_TARGETS}") | ||
|
||
# To aggregate all the dependencies into a final `.a` file we add a custom pass after target | ||
# `cprover-api-cpp` has been built where the `aggregate_dependencies.sh` script is run with the `ar` | ||
# command, the destination library and the dependencies paths | ||
add_custom_command(TARGET cprover-api-cpp POST_BUILD | ||
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/add_dependencies.sh" "${CMAKE_AR}" "$<TARGET_FILE:cprover-api-cpp>" "${DEPENDENCY_TARGETS}" | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") | ||
|
||
# Set the properties of `cprover-api-cpp`. Mainly the output name `libcprover.<version>.a`, its | ||
# version (CBMC version) and the list of public headers to be installed | ||
set_target_properties(cprover-api-cpp | ||
PROPERTIES | ||
OUTPUT_NAME "cprover.${CMAKE_PROJECT_VERSION}" # libcprover.<version>.a | ||
SOVERSION "${CMAKE_PROJECT_VERSION}" | ||
PUBLIC_HEADER "${headers}" | ||
) | ||
|
||
# Install the target as usual in `lib` the library and in `include/cprover` the public headers. | ||
install(TARGETS cprover-api-cpp | ||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
COMPONENT lib | ||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
COMPONENT lib | ||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cprover" | ||
COMPONENT lib | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env sh | ||
|
||
# This script adds to a static library archive file `lib<name>.a` all the object files of a set of | ||
# other libraries it depends on. | ||
# This script takes 3 or more arguments: | ||
# 1. the archive command | ||
# 2. the destination library path | ||
# 3. a list of paths of static libraries to be added to the destination library archive | ||
|
||
set -e | ||
|
||
AR_COMMAND=$1 | ||
shift | ||
DESTINATION=$1 | ||
shift | ||
LIB_LIST=$@ | ||
|
||
# For each library to add: | ||
for lib in ${LIB_LIST}; do | ||
# Unpack the library | ||
${AR_COMMAND} -x ${lib} | ||
done | ||
|
||
# Append all the unpacked files to the destination library | ||
${AR_COMMAND} -rcs ${DESTINATION} *.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/libcprover-cpp/options.cpp → src/libcprover-cpp/api_options.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this bit is correct - do we package in
libminisat
andcadical
in thelibcprover
we're building?(Probably, it might be a dependency of
solvers/
in any case, but can we check before we merge this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Okay, answering my own question here - it seems that we're building without issues, at least on the minisat front https://github.com/diffblue/cbmc/actions/runs/4293367669/jobs/7480953774)
Still, I would be a bit apprehensive to remove this for loop. Can we at least comment it out so that we may re-introduce it if we find we need it for radical?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SAT solvers (dependency of the
solver
target) are added to the final API library.Specifically they are gathered at line 25 of
src/libcprover-cpp/CMakeLists.txt
when doingget_target_property(LIBRARY_DEPENDENCIES solvers LINK_LIBRARIES)
, and added afterwards.For this reason they can be removed from the RUST side.