]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Add support for fully static linkage
authorMatthias Maier <tamiko@kyomu.43-1.org>
Thu, 11 Jul 2013 22:17:25 +0000 (22:17 +0000)
committerMatthias Maier <tamiko@kyomu.43-1.org>
Thu, 11 Jul 2013 22:17:25 +0000 (22:17 +0000)
git-svn-id: https://svn.dealii.org/trunk@29978 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/cmake/checks/check_01_compiler_features.cmake
deal.II/cmake/config/Config.cmake.in
deal.II/cmake/macros/macro_deal_ii_setup_target.cmake
deal.II/cmake/macros/macro_enable_if_supported.cmake
deal.II/cmake/setup_cached_variables.cmake
deal.II/cmake/setup_compiler_flags_gnu.cmake
deal.II/doc/development/Config.sample
deal.II/doc/development/cmake.html

index 17063b529ea266812ef5001fc212b02452bb3ef8..736514b1d623bfc22ec0614bae79171afa339cd8 100644 (file)
@@ -148,7 +148,7 @@ CHECK_CXX_SOURCE_COMPILES(
   "
   HAVE_GLIBC_STACKTRACE)
 
-IF(HAVE_GLIBC_STACKTRACE)
+IF(HAVE_GLIBC_STACKTRACE AND NOT DEAL_II_STATIC_EXECUTABLE)
   ENABLE_IF_SUPPORTED(CMAKE_SHARED_LINKER_FLAGS "-rdynamic")
 ENDIF()
 
index c28eb394956ef89b11ee58218eb6cc96ebffc8a2..0d33e257abc27ca67f319f527b1b643a6845028e 100644 (file)
@@ -126,6 +126,13 @@ SET(DEAL_II_USER_DEFINITIONS_DEBUG "@DEAL_II_USER_DEFINITIONS_DEBUG@")
 SET(DEAL_II_USER_DEFINITIONS_RELEASE "@DEAL_II_USER_DEFINITIONS_RELEASE@")
 
 
+#
+# Build a static executable:
+#
+
+SET(DEAL_II_STATIC_EXECUTABLE "@DEAL_II_STATIC_EXECUTABLE@")
+
+
 #
 # Information about include directories and libraries
 #
index ef17eb7e7fca95fa7d32773a8007b53c9ef556ba..3eaee853661f303a303f3cfa3debb01ce00b785b 100644 (file)
@@ -116,4 +116,14 @@ MACRO(DEAL_II_SETUP_TARGET _target)
   #
   TARGET_LINK_LIBRARIES(${_target} ${DEAL_II_TARGET})
 
+  #
+  # If DEAL_II_STATIC_EXECUTABLE is set, switch to final link type to
+  # static:
+  #
+  IF(DEAL_II_STATIC_EXECUTABLE)
+    SET_PROPERTY(TARGET ${_target} PROPERTY
+      LINK_SEARCH_END_STATIC TRUE
+      )
+  ENDIF()
+
 ENDMACRO()
index 9c98c9155ea74fca9b8c45d135074d6aa0b3e253..8c9f0e0af8b025e95c209901a166dc7ef1deb5aa 100644 (file)
@@ -26,6 +26,7 @@ MACRO(ENABLE_IF_SUPPORTED _variable _flag)
     STRING(REGEX REPLACE "^-" "" _flag_name "${_flag_stripped}")
     STRING(REPLACE "," "" _flag_name "${_flag_name}")
     STRING(REPLACE "--" "__" _flag_name "${_flag_name}")
+    STRING(REPLACE "++" "__" _flag_name "${_flag_name}")
     CHECK_CXX_COMPILER_FLAG(
       "${_flag_stripped}"
       DEAL_II_HAVE_FLAG_${_flag_name}
index 4213865644c132abe6d0a3b8f40449071f2035de..4e12f4241486f80342d5b97ba3076235ad4e6a9f 100644 (file)
 #
 # Options regarding compilation and linking:
 #
+#     CMAKE_BUILD_TYPE
 #     DEAL_II_ALLOW_PLATFORM_INTROSPECTION
 #     DEAL_II_SETUP_DEFAULT_COMPILER_FLAGS
-#     CMAKE_BUILD_TYPE
+#     DEAL_II_STATIC_EXECUTABLE
 #     BUILD_SHARED_LIBS
 #     CMAKE_INSTALL_RPATH_USE_LINK_PATH
-#     CMAKE_C_FLAGS
+#     CMAKE_C_FLAGS                     *)
 #     CMAKE_CXX_FLAGS                   *)
 #     CMAKE_SHARED_LINKER_FLAGS         *)
 #     DEAL_II_CXX_FLAGS_DEBUG
@@ -45,8 +46,8 @@
 #     DEAL_II_WITH_64BIT_INDICES
 #
 # *)  May also be set via environment variable (CFLAGS, CXXFLAGS, LDFLAGS)
-#     (nonempty cached variable has precedence will not be overwritten by
-#     environment)
+#     (a nonempty cached variable has precedence and will not be
+#     overwritten by environment)
 #
 
 
@@ -115,18 +116,6 @@ ENDIF()
 #                                                                         #
 ###########################################################################
 
-OPTION(DEAL_II_ALLOW_PLATFORM_INTROSPECTION
-  "Allow platform introspection for CPU command set, SSE and AVX"
-  ON
-  )
-MARK_AS_ADVANCED(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
-
-OPTION(DEAL_II_SETUP_DEFAULT_COMPILER_FLAGS
-  "Configure sensible default CFLAGS and CXXFLAGS depending on platform, compiler and build target."
-  ON
-  )
-MARK_AS_ADVANCED(DEAL_II_SETUP_DEFAULT_COMPILER_FLAGS)
-
 #
 # Setup CMAKE_BUILD_TYPE:
 #
@@ -148,11 +137,37 @@ IF( NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND
     )
 ENDIF()
 
-SET(BUILD_SHARED_LIBS "ON" CACHE BOOL
-  "Build a shared library"
+
+OPTION(DEAL_II_ALLOW_PLATFORM_INTROSPECTION
+  "Allow platform introspection for CPU command set, SSE and AVX"
+  ON
+  )
+MARK_AS_ADVANCED(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
+
+OPTION(DEAL_II_SETUP_DEFAULT_COMPILER_FLAGS
+  "Configure sensible default CFLAGS and CXXFLAGS depending on platform, compiler and build target."
+  ON
   )
+MARK_AS_ADVANCED(DEAL_II_SETUP_DEFAULT_COMPILER_FLAGS)
+
+OPTION(DEAL_II_STATIC_EXECUTABLE
+  "Provide a link interface that is suitable for static linkage of executables. Enabling this option forces BUILD_SHARED_LIBS=OFF"
+  OFF
+  )
+MARK_AS_ADVANCED(DEAL_II_STATIC_EXECUTABLE)
+
+IF(DEAL_II_STATIC_EXECUTABLE)
+  SET(BUILD_SHARED_LIBS "OFF" CACHE BOOL
+    "Build a shared library" FORCE
+    )
+ELSE()
+  SET(BUILD_SHARED_LIBS "ON" CACHE BOOL
+    "Build a shared library"
+    )
+ENDIF()
 MARK_AS_ADVANCED(BUILD_SHARED_LIBS)
 
+
 #
 # Set CMAKE_INSTALL_RPATH_USE_LINK_PATH to default to ON and promote to
 # cache so that the user can see the value.
@@ -162,6 +177,7 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH "ON" CACHE BOOL
   )
 MARK_AS_ADVANCED(CMAKE_INSTALL_RPATH_USE_LINK_PATH)
 
+
 #
 # Define the variable that defines whether we should use 32- or 64-bit
 # global DoF indices.
index fdc33164cdd17ad2b52977f23e5a3fbbe42934ef..1f6135460ee521e73997ca962f972d96e3dcfd3c 100644 (file)
@@ -95,6 +95,18 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
 ENDIF()
 
 
+IF(DEAL_II_STATIC_EXECUTABLE)
+  #
+  # To produce a static executable, we have to statically link libstdc++
+  # and gcc's support libraries and glibc:
+  #
+  # (Well... the name "CMAKE_SHARED_LINKER_FLAGS" is a bit misleading :-])
+  #
+  ENABLE_IF_SUPPORTED(CMAKE_SHARED_LINKER_FLAGS "-static")
+  ENABLE_IF_SUPPORTED(CMAKE_SHARED_LINKER_FLAGS "-pthread")
+ENDIF()
+
+
 #############################
 #                           #
 #    For Release target:    #
index 393634f3378ad7de6b3d2fc4fefbafeec036b5ca..db9285adfee089b57cc3f27e2b30d62413ed65af 100644 (file)
 #   "The user supplied cache variable will be appended _at the end_ of the auto generated DEAL_II_SHARED_LINKER_FLAGS_RELEASE variable"
 #   )
 #
+# OPTION(DEAL_II_STATIC_EXECUTABLE "ON" CACHE BOOL
+#   "Provide a link interface that is suitable for static linkage of executables. Enabling this option forces BUILD_SHARED_LIBS=OFF"
+#   )
+#
+#
 # SET(BUILD_SHARED_LIBS "ON" CACHE BOOL
 #   "Build a shared library"
 #   )
index 0b1c072f981231ffa23262889f430ddd89d803b6..b169825b1d29e5f91f802a6cad880dc20ed859fd 100644 (file)
           <code>BUILD_SHARED_LIBS</code>: If set (default),
           <acronym>deal.II</acronym> will be linked as a shared library
 
+       <li>
+          <code>DEAL_II_STATIC_EXECUTABLE</code> (defaults to off):
+          If set to true, <acronym>deal.II</acronym> will be configured in
+          a way to provide a link interface that is suitable for static
+          linkage of executables. Enabling this option forces
+          <code>BUILD_SHARED_LIBS=OFF</code>
+
        <li>
          <code>CMAKE_INSTALL_RPATH_USE_LINK_PATH</code>: If set
          (default), the <acronym>deal.II</acronym> library will be

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.