From ff051c824d8d4ae29977c552561e278b38e0e42f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ron=20Ricardo=20Perez-Lopez?= Date: Thu, 18 Jul 2024 19:06:40 -0400 Subject: [PATCH] Unify static lib repacking to always use script (#352) Fixes issues with fat archives on macOS. * Use repack-static-lib.sh for boolector * Use repack-static-lib.sh for mathsat --- btor/CMakeLists.txt | 29 +++++++++++++++++++++-------- msat/CMakeLists.txt | 22 +++++++++------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/btor/CMakeLists.txt b/btor/CMakeLists.txt index 2a7efbf2c..7bddaf5cb 100644 --- a/btor/CMakeLists.txt +++ b/btor/CMakeLists.txt @@ -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 "../$" && 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 "$" ./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 "$" + "${BTOR_HOME}/build/lib/libboolector.a" + "${PROJECT_SOURCE_DIR}/deps/install/lib/libcadical.a" + "${BTOR_HOME}/deps/btor2tools/build/lib/libbtor2parser.a" + "../$" && + # replace the original one + mv "$" "../$" && # 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() diff --git a/msat/CMakeLists.txt b/msat/CMakeLists.txt index 1bda8ca55..f35115dec 100644 --- a/msat/CMakeLists.txt +++ b/msat/CMakeLists.txt @@ -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 "../$" && cd ../ - && rm "$" && - # copy the mathsat static library to libsmt-switch-msat.a - cp "${MSAT_HOME}/lib/libmathsat.a" "$" && - # add the smt-switch-msat object files to the static library - bash -c "ar -rs $ ./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 "$" + "${MSAT_HOME}/lib/libmathsat.a" + "../$" && + # replace the original one + mv "$" "../$" && + # 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