Skip to content

Commit

Permalink
Unify static lib repacking to always use script (#352)
Browse files Browse the repository at this point in the history
Fixes issues with fat archives on macOS.

* Use repack-static-lib.sh for boolector

* Use repack-static-lib.sh for mathsat
  • Loading branch information
CyanoKobalamyne authored Jul 18, 2024
1 parent 363d617 commit ff051c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
29 changes: 21 additions & 8 deletions btor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,31 @@ target_link_libraries(smt-switch-btor m)
if (SMT_SWITCH_LIB_TYPE STREQUAL STATIC)
# we want the static library to include the boolector source
# we need to unpack and repack the libraries
add_custom_target(repack-btor-static-lib
ALL
add_custom_command(
OUTPUT static-smt-switch-btor.stamp
COMMAND
mkdir smt-switch-btor && cd smt-switch-btor && ar -x "../$<TARGET_FILE_NAME:smt-switch-btor>" && cd ../ &&
mkdir boolector && cd boolector && ar -x "${BTOR_HOME}/build/lib/libboolector.a" &&
ar -x "${PROJECT_SOURCE_DIR}/deps/install/lib/libcadical.a" &&
ar -x "${BTOR_HOME}/deps/btor2tools/build/lib/libbtor2parser.a" && cd ../ &&
ar -qc "$<TARGET_FILE_NAME:smt-switch-btor>" ./boolector/*.o ./smt-switch-btor/*.o &&
mkdir smt-switch-btor-working && cd smt-switch-btor-working &&
# create new static library that combines them all
${PROJECT_SOURCE_DIR}/scripts/repack-static-lib.sh "$<TARGET_FILE_NAME:smt-switch-btor>"
"${BTOR_HOME}/build/lib/libboolector.a"
"${PROJECT_SOURCE_DIR}/deps/install/lib/libcadical.a"
"${BTOR_HOME}/deps/btor2tools/build/lib/libbtor2parser.a"
"../$<TARGET_FILE_NAME:smt-switch-btor>" &&
# replace the original one
mv "$<TARGET_FILE_NAME:smt-switch-btor>" "../$<TARGET_FILE_NAME:smt-switch-btor>" &&
# now clean up
rm -rf smt-switch-btor boolector
cd .. && rm -rf smt-switch-btor-working
COMMAND ${CMAKE_COMMAND} -E touch static-smt-switch-btor.stamp
DEPENDS
smt-switch-btor
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)

add_custom_target(repack-btor-static-lib
ALL
DEPENDS
static-smt-switch-btor.stamp
)
endif()

Expand Down
22 changes: 9 additions & 13 deletions msat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,18 @@ target_link_libraries(smt-switch-msat ${GMPXX_LIBRARIES})
if (SMT_SWITCH_LIB_TYPE STREQUAL STATIC)
# we want the static library to include the mathsat source
# we need to unpack and repack the libraries
# newer versions of mathsat (5.6.4+) have the same issue as cvc5 where
# unpacking and repacking with ar seemed to lose info (missing symbols)
# the work around is to just copy libmathsat.a and add to it
add_custom_command(
OUTPUT static-smt-switch-msat.stamp
COMMAND
mkdir ssm && cd ssm &&
ar -x "../$<TARGET_FILE_NAME:smt-switch-msat>" && cd ../
&& rm "$<TARGET_FILE_NAME:smt-switch-msat>" &&
# copy the mathsat static library to libsmt-switch-msat.a
cp "${MSAT_HOME}/lib/libmathsat.a" "$<TARGET_FILE_NAME:smt-switch-msat>" &&
# add the smt-switch-msat object files to the static library
bash -c "ar -rs $<TARGET_FILE_NAME:smt-switch-msat> ./ssm/*.o"
&&
# now clean up the temporary directory
rm -rf ssm
mkdir smt-switch-msat-working && cd smt-switch-msat-working &&
# create new static library that combines them all
${PROJECT_SOURCE_DIR}/scripts/repack-static-lib.sh "$<TARGET_FILE_NAME:smt-switch-msat>"
"${MSAT_HOME}/lib/libmathsat.a"
"../$<TARGET_FILE_NAME:smt-switch-msat>" &&
# replace the original one
mv "$<TARGET_FILE_NAME:smt-switch-msat>" "../$<TARGET_FILE_NAME:smt-switch-msat>" &&
# now clean up the temporary directory
cd .. && rm -rf smt-switch-msat-working
COMMAND ${CMAKE_COMMAND} -E touch static-smt-switch-msat.stamp
DEPENDS
smt-switch-msat
Expand Down

0 comments on commit ff051c8

Please sign in to comment.