1
+ # Scan for all source files in the current or child directories
1
2
file (GLOB_RECURSE sources "*.cpp" )
3
+ # Scan for all header files in the current or child directories (necessary to install them later)
2
4
file (GLOB_RECURSE headers "*.h" )
3
5
4
6
# This step builds the API in the form of a statically linked library
@@ -7,13 +9,22 @@ add_library(cprover-api-cpp ${sources})
7
9
# Being a library we should include them privately, but for now fair enough
8
10
generic_includes(cprover-api-cpp)
9
11
12
+ # Add all the current and the installed `include` directories as a PUBLIC header location
10
13
target_include_directories (cprover-api-cpp PUBLIC
11
14
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} >"
12
15
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR} >"
13
16
"$<INSTALL_INTERFACE:include>" )
14
17
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.
15
25
get_target_property (LIBRARY_DEPENDENCIES solvers LINK_LIBRARIES )
16
26
27
+ # Get all the dependency targets we know statically.
17
28
list (APPEND
18
29
LIBRARY_DEPENDENCIES
19
30
"goto-programs"
@@ -36,30 +47,41 @@ list(APPEND
36
47
"pointer-analysis"
37
48
"cbmc-lib" )
38
49
50
+ # Remove possible duplicate library targets
39
51
list (REMOVE_DUPLICATES LIBRARY_DEPENDENCIES)
40
52
53
+ # Add all the dependency targets as dependencies of `cprover-api-cpp`
41
54
target_link_libraries (cprover-api-cpp
42
55
PRIVATE
43
56
${LIBRARY_DEPENDENCIES} )
44
57
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.
45
62
set (DEPENDENCY_TARGETS "" )
46
63
foreach (dep ${LIBRARY_DEPENDENCIES} )
47
64
list (APPEND DEPENDENCY_TARGETS "$<TARGET_FILE:${dep} >" )
48
65
endforeach (dep LIBRARY_DEPENDENCIES)
49
-
50
66
string (REPLACE ";" " " DEPENDENCY_TARGETS "${DEPENDENCY_TARGETS} " )
51
67
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
52
71
add_custom_command (TARGET cprover-api-cpp POST_BUILD
53
72
COMMAND "${CMAKE_CURRENT_SOURCE_DIR} /add_dependencies.sh" "${CMAKE_AR} " "$<TARGET_FILE:cprover-api-cpp>" "${DEPENDENCY_TARGETS} "
54
73
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} " )
55
74
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
56
77
set_target_properties (cprover-api-cpp
57
78
PROPERTIES
58
79
OUTPUT_NAME "cprover.${CMAKE_PROJECT_VERSION} " # libcprover.<version>.a
59
80
SOVERSION "${CMAKE_PROJECT_VERSION} "
60
81
PUBLIC_HEADER "${headers} "
61
82
)
62
83
84
+ # Install the target as usual in `lib` the library and in `include/cprover` the public headers.
63
85
install (TARGETS cprover-api-cpp
64
86
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR} "
65
87
COMPONENT lib
0 commit comments