Skip to content

Commit b0dc2ea

Browse files
author
Enrico Steffinlongo
authored
Merge pull request #7567 from esteffin/esteffin/creating-public-archive-with-all-components
Creating library archive with all components
2 parents 557f4bf + cf4817f commit b0dc2ea

File tree

8 files changed

+129
-49
lines changed

8 files changed

+129
-49
lines changed

regression/libcprover-cpp/call_bmc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <util/exception_utils.h>
55

66
#include <libcprover-cpp/api.h>
7-
#include <libcprover-cpp/options.h>
7+
#include <libcprover-cpp/api_options.h>
88

99
#include "goto_model.h"
1010

src/CMakeLists.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
project(CBMC)
1+
file(STRINGS
2+
"${CMAKE_CURRENT_SOURCE_DIR}/config.inc"
3+
cbmc_version_string
4+
REGEX "CBMC_VERSION.*")
5+
6+
string(REGEX REPLACE "CBMC_VERSION = (.*)" "\\1" CBMC_VERSION "${cbmc_version_string}")
7+
unset(cbmc_version_string)
8+
9+
project(CBMC VERSION ${CBMC_VERSION})
210

311
find_package(BISON REQUIRED)
412
find_package(FLEX REQUIRED)
@@ -102,7 +110,6 @@ add_subdirectory(jsil)
102110
add_subdirectory(json)
103111
add_subdirectory(json-symtab-language)
104112
add_subdirectory(langapi)
105-
add_subdirectory(libcprover-cpp)
106113
add_subdirectory(linking)
107114
add_subdirectory(pointer-analysis)
108115
add_subdirectory(solvers)
@@ -119,6 +126,7 @@ add_subdirectory(goto-diff)
119126
add_subdirectory(goto-harness)
120127
add_subdirectory(goto-synthesizer)
121128
add_subdirectory(symtab2gb)
129+
add_subdirectory(libcprover-cpp)
122130

123131
if(UNIX OR WITH_MEMORY_ANALYZER)
124132
add_subdirectory(memory-analyzer)

src/libcprover-cpp/CMakeLists.txt

+89-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,92 @@
1-
file(GLOB_RECURSE sources "*.cpp" "*.h")
1+
# Scan for all source files in the current or child directories
2+
file(GLOB_RECURSE sources "*.cpp")
3+
# Scan for all header files in the current or child directories (necessary to install them later)
4+
file(GLOB_RECURSE headers "*.h")
25

3-
# This step builds the API in the form of a statically linked library (libcprover-api-cpp.a)
6+
# This step builds the API in the form of a statically linked library
47
add_library(cprover-api-cpp ${sources})
8+
9+
# Being a library we should include them privately, but for now fair enough
510
generic_includes(cprover-api-cpp)
6-
target_link_libraries(cprover-api-cpp
7-
goto-checker
8-
goto-programs
9-
util
10-
langapi
11-
ansi-c
12-
json-symtab-language
13-
solvers
14-
xml
15-
cpp
16-
cbmc-lib
17-
analyses
18-
statement-list
19-
linking
20-
pointer-analysis
21-
goto-instrument-lib
22-
goto-analyzer-lib
23-
goto-cc-lib)
11+
12+
# Add all the current and the installed `include` directories as a PUBLIC header location
13+
target_include_directories(cprover-api-cpp PUBLIC
14+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
15+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
16+
"$<INSTALL_INTERFACE:include>")
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.
25+
get_target_property(LIBRARY_DEPENDENCIES solvers LINK_LIBRARIES)
26+
27+
# Get all the dependency targets we know statically.
28+
list(APPEND
29+
LIBRARY_DEPENDENCIES
30+
"goto-programs"
31+
"util"
32+
"langapi"
33+
"ansi-c"
34+
"analyses"
35+
"goto-instrument-lib"
36+
"big-int"
37+
"linking"
38+
"goto-checker"
39+
"solvers"
40+
"assembler"
41+
"xml"
42+
"json"
43+
"json-symtab-language"
44+
"jsil"
45+
"statement-list"
46+
"goto-symex"
47+
"pointer-analysis"
48+
"cbmc-lib")
49+
50+
# Remove possible duplicate library targets
51+
list(REMOVE_DUPLICATES LIBRARY_DEPENDENCIES)
52+
53+
# Add all the dependency targets as dependencies of `cprover-api-cpp`
54+
target_link_libraries(cprover-api-cpp
55+
PRIVATE
56+
${LIBRARY_DEPENDENCIES})
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.
62+
set(DEPENDENCY_TARGETS "")
63+
foreach(dep ${LIBRARY_DEPENDENCIES})
64+
list(APPEND DEPENDENCY_TARGETS "$<TARGET_FILE:${dep}>")
65+
endforeach(dep LIBRARY_DEPENDENCIES)
66+
string(REPLACE ";" " " DEPENDENCY_TARGETS "${DEPENDENCY_TARGETS}")
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
71+
add_custom_command(TARGET cprover-api-cpp POST_BUILD
72+
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/add_dependencies.sh" "${CMAKE_AR}" "$<TARGET_FILE:cprover-api-cpp>" "${DEPENDENCY_TARGETS}"
73+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
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
77+
set_target_properties(cprover-api-cpp
78+
PROPERTIES
79+
OUTPUT_NAME "cprover.${CMAKE_PROJECT_VERSION}" # libcprover.<version>.a
80+
SOVERSION "${CMAKE_PROJECT_VERSION}"
81+
PUBLIC_HEADER "${headers}"
82+
)
83+
84+
# Install the target as usual in `lib` the library and in `include/cprover` the public headers.
85+
install(TARGETS cprover-api-cpp
86+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
87+
COMPONENT lib
88+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
89+
COMPONENT lib
90+
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cprover"
91+
COMPONENT lib
92+
)
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env sh
2+
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+
10+
set -e
11+
12+
AR_COMMAND=$1
13+
shift
14+
DESTINATION=$1
15+
shift
16+
LIB_LIST=$@
17+
18+
# For each library to add:
19+
for lib in ${LIB_LIST}; do
20+
# Unpack the library
21+
${AR_COMMAND} -x ${lib}
22+
done
23+
24+
# Append all the unpacked files to the destination library
25+
${AR_COMMAND} -rcs ${DESTINATION} *.o

src/libcprover-cpp/api.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct api_session_implementationt;
1717
// a pragma like below to silence the warning (at least as long
1818
// as the design principle is to be followed.)
1919

20-
#include "options.h" // IWYU pragma: keep
20+
#include "api_options.h" // IWYU pragma: keep
2121

2222
/// Opaque message type. Properties of messages to be fetched through further
2323
/// api calls.

src/libcprover-cpp/options.cpp renamed to src/libcprover-cpp/api_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Author: Fotis Koutoulakis for Diffblue Ltd.
22

3-
#include "options.h"
3+
#include "api_options.h"
44

55
#include <util/cmdline.h>
66
#include <util/make_unique.h>
File renamed without changes.

src/libcprover-rust/build.rs

+2-24
Original file line numberDiff line numberDiff line change
@@ -111,28 +111,6 @@ fn main() {
111111
"cargo:rustc-link-search=native={}",
112112
libraries_path.display()
113113
);
114-
println!("cargo:rustc-link-lib=static=goto-programs");
115-
println!("cargo:rustc-link-lib=static=util");
116-
println!("cargo:rustc-link-lib=static=langapi");
117-
println!("cargo:rustc-link-lib=static=ansi-c");
118-
println!("cargo:rustc-link-lib=static=analyses");
119-
println!("cargo:rustc-link-lib=static=goto-instrument-lib");
120-
println!("cargo:rustc-link-lib=static=big-int");
121-
println!("cargo:rustc-link-lib=static=linking");
122-
println!("cargo:rustc-link-lib=static=goto-checker");
123-
println!("cargo:rustc-link-lib=static=solvers");
124-
println!("cargo:rustc-link-lib=static=assembler");
125-
println!("cargo:rustc-link-lib=static=xml");
126-
println!("cargo:rustc-link-lib=static=json");
127-
println!("cargo:rustc-link-lib=static=json-symtab-language");
128-
println!("cargo:rustc-link-lib=static=cpp");
129-
println!("cargo:rustc-link-lib=static=jsil");
130-
println!("cargo:rustc-link-lib=static=statement-list");
131-
println!("cargo:rustc-link-lib=static=goto-symex");
132-
println!("cargo:rustc-link-lib=static=pointer-analysis");
133-
for solver_lib in solver_libs {
134-
println!("cargo:rustc-link-lib=static={}", solver_lib);
135-
}
136-
println!("cargo:rustc-link-lib=static=cbmc-lib");
137-
println!("cargo:rustc-link-lib=static=cprover-api-cpp");
114+
115+
println!("cargo:rustc-link-lib=static=cprover.5.77.0");
138116
}

0 commit comments

Comments
 (0)