Skip to content

Commit cf4817f

Browse files
author
Enrico Steffinlongo
committed
Added comments to API library CMakeLists.txt
1 parent 3999157 commit cf4817f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/libcprover-cpp/CMakeLists.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
# Scan for all source files in the current or child directories
12
file(GLOB_RECURSE sources "*.cpp")
3+
# Scan for all header files in the current or child directories (necessary to install them later)
24
file(GLOB_RECURSE headers "*.h")
35

46
# This step builds the API in the form of a statically linked library
@@ -7,13 +9,22 @@ add_library(cprover-api-cpp ${sources})
79
# Being a library we should include them privately, but for now fair enough
810
generic_includes(cprover-api-cpp)
911

12+
# Add all the current and the installed `include` directories as a PUBLIC header location
1013
target_include_directories(cprover-api-cpp PUBLIC
1114
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
1215
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
1316
"$<INSTALL_INTERFACE:include>")
1417

18+
# To create a full static API library we need to archive together the content of all the other
19+
# module libraries we depend on. To do this we will use the `ar` command to unpack the other module
20+
# static libraries and append to the current library `.a` file.
21+
22+
# Get the dependency targets of the `solver` target (see `../solver/CMakeLists.txt`), so that they
23+
# are merged to the final library too. (such dependencies are not known statically as the selection
24+
# of the SAT backend is left to the building user.
1525
get_target_property(LIBRARY_DEPENDENCIES solvers LINK_LIBRARIES)
1626

27+
# Get all the dependency targets we know statically.
1728
list(APPEND
1829
LIBRARY_DEPENDENCIES
1930
"goto-programs"
@@ -36,30 +47,41 @@ list(APPEND
3647
"pointer-analysis"
3748
"cbmc-lib")
3849

50+
# Remove possible duplicate library targets
3951
list(REMOVE_DUPLICATES LIBRARY_DEPENDENCIES)
4052

53+
# Add all the dependency targets as dependencies of `cprover-api-cpp`
4154
target_link_libraries(cprover-api-cpp
4255
PRIVATE
4356
${LIBRARY_DEPENDENCIES})
4457

58+
# To be able to invoke `ar` on the dependencies we need the paths of the libraries `.a` files.
59+
# Ths is done by using the cmake generator `$<TARGET_FILE:dependency>`, that in turn will be
60+
# substituted with the absolute path of the `dependency` output file (a `.a` file in this case).
61+
# Here we prepare a space-separated list of cmake generators that will resolved in absolute paths.
4562
set(DEPENDENCY_TARGETS "")
4663
foreach(dep ${LIBRARY_DEPENDENCIES})
4764
list(APPEND DEPENDENCY_TARGETS "$<TARGET_FILE:${dep}>")
4865
endforeach(dep LIBRARY_DEPENDENCIES)
49-
5066
string(REPLACE ";" " " DEPENDENCY_TARGETS "${DEPENDENCY_TARGETS}")
5167

68+
# To aggregate all the dependencies into a final `.a` file we add a custom pass after target
69+
# `cprover-api-cpp` has been built where the `aggregate_dependencies.sh` script is run with the `ar`
70+
# command, the destination library and the dependencies paths
5271
add_custom_command(TARGET cprover-api-cpp POST_BUILD
5372
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/add_dependencies.sh" "${CMAKE_AR}" "$<TARGET_FILE:cprover-api-cpp>" "${DEPENDENCY_TARGETS}"
5473
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
5574

75+
# Set the properties of `cprover-api-cpp`. Mainly the output name `libcprover.<version>.a`, its
76+
# version (CBMC version) and the list of public headers to be installed
5677
set_target_properties(cprover-api-cpp
5778
PROPERTIES
5879
OUTPUT_NAME "cprover.${CMAKE_PROJECT_VERSION}" # libcprover.<version>.a
5980
SOVERSION "${CMAKE_PROJECT_VERSION}"
6081
PUBLIC_HEADER "${headers}"
6182
)
6283

84+
# Install the target as usual in `lib` the library and in `include/cprover` the public headers.
6385
install(TARGETS cprover-api-cpp
6486
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
6587
COMPONENT lib

src/libcprover-cpp/add_dependencies.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/usr/bin/env sh
22

3+
# This script adds to a static library archive file `lib<name>.a` all the object files of a set of
4+
# other libraries it depends on.
5+
# This script takes 3 or more arguments:
6+
# 1. the archive command
7+
# 2. the destination library path
8+
# 3. a list of paths of static libraries to be added to the destination library archive
9+
310
set -e
411

512
AR_COMMAND=$1
@@ -8,8 +15,11 @@ DESTINATION=$1
815
shift
916
LIB_LIST=$@
1017

18+
# For each library to add:
1119
for lib in ${LIB_LIST}; do
20+
# Unpack the library
1221
${AR_COMMAND} -x ${lib}
1322
done
1423

24+
# Append all the unpacked files to the destination library
1525
${AR_COMMAND} -rcs ${DESTINATION} *.o

0 commit comments

Comments
 (0)