cmake: Add option --[no]-static-binary. (#7695)
authorMathias Preiner <mathias.preiner@gmail.com>
Wed, 24 Nov 2021 19:29:11 +0000 (11:29 -0800)
committerGitHub <noreply@github.com>
Wed, 24 Nov 2021 19:29:11 +0000 (19:29 +0000)
Allows to disable linking against static system libraries explicitly.

CMakeLists.txt
configure.sh
src/main/CMakeLists.txt

index f7ff3bac38d57cef0f093a4854215680884f1e39..9e70f4c3de16d899f64b66ef9651485bbfbcdd37 100644 (file)
@@ -126,6 +126,10 @@ option(BUILD_BINDINGS_JAVA "Build Java bindings based on new C++ API ")
 # Api documentation
 option(BUILD_DOCS "Build Api documentation")
 
+# Link against static system libraries
+cvc5_option(STATIC_BINARY "Link against static system libraries \
+(enabled by default for static builds)")
+
 #-----------------------------------------------------------------------------#
 # Internal cmake variables
 
@@ -443,6 +447,9 @@ if(BUILD_SHARED_LIBS)
   set(CVC5_STATIC_BUILD OFF)
 else()
   set(CVC5_STATIC_BUILD ON)
+  if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+    cvc5_set_option(STATIC_BINARY ON)
+  endif()
 endif()
 
 #-----------------------------------------------------------------------------#
index 970df2e616851954198db7339503ec548146dfce..18808f3c6d473bfb7351ec66eaa91838fca01d36 100755 (executable)
@@ -31,6 +31,7 @@ General options;
 Features:
 The following flags enable optional features (disable with --no-<option name>).
   --static                 build static libraries and binaries [default=no]
+  --static-binary          link against static system libraries
   --auto-download          automatically download dependencies if necessary
   --debug-symbols          include debug symbols
   --valgrind               Valgrind instrumentation
@@ -123,6 +124,7 @@ python_bindings=default
 java_bindings=default
 editline=default
 build_shared=ON
+static_binary=default
 statistics=default
 tracing=default
 tsan=default
@@ -237,6 +239,9 @@ do
     --static) build_shared=OFF;;
     --no-static) build_shared=ON;;
 
+    --static-binary) static_binary=ON;;
+    --no-static-binary) static_binary=OFF;;
+
     --auto-download) auto_download=ON;;
     --no-auto-download) auto_download=OFF;;
 
@@ -337,6 +342,8 @@ fi
   && cmake_opts="$cmake_opts -DENABLE_MUZZLE=$muzzle"
 [ $build_shared != default ] \
   && cmake_opts="$cmake_opts -DBUILD_SHARED_LIBS=$build_shared"
+[ $static_binary != default ] \
+  && cmake_opts="$cmake_opts -DSTATIC_BINARY=$static_binary"
 [ $statistics != default ] \
   && cmake_opts="$cmake_opts -DENABLE_STATISTICS=$statistics"
 [ $tracing != default ] \
index 51809975c677aa17a9aea2fdb5e008a9a45a15c9..473fc927ae7afcd7fb261eab207fcfd8f0a81a14 100644 (file)
@@ -77,7 +77,7 @@ endif()
 #   https://cmake.org/cmake/help/v3.0/prop_tgt/LINK_SEARCH_START_STATIC.html
 #   https://cmake.org/cmake/help/v3.0/prop_tgt/LINK_SEARCH_END_STATIC.html
 if(NOT BUILD_SHARED_LIBS)
-  if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+  if(STATIC_BINARY)
     set_target_properties(cvc5-bin PROPERTIES LINK_FLAGS -static)
     set_target_properties(cvc5-bin PROPERTIES LINK_SEARCH_START_STATIC ON)
     set_target_properties(cvc5-bin PROPERTIES LINK_SEARCH_END_STATIC ON)