|
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") |
2 | 5 |
|
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 |
4 | 7 | add_library(cprover-api-cpp ${sources})
|
| 8 | + |
| 9 | +# Being a library we should include them privately, but for now fair enough |
5 | 10 | 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 | + ) |
0 commit comments