cmake: Add support for building static binaries/libraries.
authorMathias Preiner <mathias.preiner@gmail.com>
Wed, 29 Aug 2018 17:26:10 +0000 (10:26 -0700)
committerMathias Preiner <mathias.preiner@gmail.com>
Sat, 22 Sep 2018 23:30:59 +0000 (16:30 -0700)
CMakeLists.txt

index 69f56f0bf0c69149bc23278a8d037a6d5cc04364..aa91a631fd0e9d6cfed2560f9ed67cae9d2c28d4 100644 (file)
@@ -201,18 +201,6 @@ set(CVC4_BUILD_PROFILE_COMPETITION 0)
 # Whether CVC4 is built with the (optional) GPLed library dependences.
 set(CVC4_GPL_DEPS 0)
 
-#-----------------------------------------------------------------------------#
-
-find_package(PythonInterp REQUIRED)
-
-set(ANTLR_HOME ${ANTLR_DIR})
-find_package(ANTLR REQUIRED)
-
-set(GMP_HOME ${GMP_DIR})
-find_package(GMP REQUIRED)
-cvc4_link_library(${GMP_LIBRARIES})
-include_directories(${GMP_INCLUDE_DIR})
-
 #-----------------------------------------------------------------------------#
 # Compiler flags
 
@@ -258,6 +246,27 @@ cvc4_set_option(ENABLE_PORTFOLIO OFF)
 cvc4_set_option(ENABLE_SHARED ON)
 cvc4_set_option(ENABLE_VALGRIND OFF)
 
+#-----------------------------------------------------------------------------#
+
+# This needs to be set before any find_package(...) command since we want to
+# search for static libraries with suffix .a.
+if(NOT ENABLE_SHARED)
+  set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+  set(CMAKE_EXE_LINKER_FLAGS "-static")
+  set(BUILD_SHARED_LIBS OFF)
+endif()
+
+find_package(PythonInterp REQUIRED)
+
+set(ANTLR_HOME ${ANTLR_DIR})
+find_package(ANTLR REQUIRED)
+
+set(GMP_HOME ${GMP_DIR})
+find_package(GMP REQUIRED)
+cvc4_link_library(${GMP_LIBRARIES})
+include_directories(${GMP_INCLUDE_DIR})
+
+
 #-----------------------------------------------------------------------------#
 # Enable the ctest testing framework