[x265] [PATCH 1 of 2] cmake: add support for statically linking with C runtime with MinGW

Steve Borho steve at borho.org
Tue Mar 31 09:05:31 CEST 2015


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1427781315 18000
#      Tue Mar 31 00:55:15 2015 -0500
# Branch stable
# Node ID 7635fec148da3d9e275756fdf987cf954867ad4b
# Parent  0c4c8b1115548a10f87419b9273ec69b3942a5dc
cmake: add support for statically linking with C runtime with MinGW

avoids having to package libgcc_s_dw2-1.dll

diff -r 0c4c8b111554 -r 7635fec148da source/CMakeLists.txt
--- a/source/CMakeLists.txt	Mon Mar 30 17:29:31 2015 +0530
+++ b/source/CMakeLists.txt	Tue Mar 31 00:55:15 2015 -0500
@@ -26,6 +26,7 @@
 option(FPROFILE_GENERATE "Compile executable to generate usage data" OFF)
 option(FPROFILE_USE "Compile executable using generated usage data" OFF)
 option(NATIVE_BUILD "Target the build CPU" OFF)
+option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 
 # X265_BUILD must be incremented each time the public API is changed
@@ -108,13 +109,12 @@
     set(MSVC 1)
 endif()
 if(MSVC)
-    option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
-    if (STATIC_LINK_CRT)
+    if(STATIC_LINK_CRT)
         set(CompilerFlags CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE)
         foreach(CompilerFlag ${CompilerFlags})
             string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
         endforeach()
-    endif (STATIC_LINK_CRT)
+    endif(STATIC_LINK_CRT)
     add_definitions(/W4)  # Full warnings
     add_definitions(/Ob2) # always inline
     add_definitions(/MP)  # multithreaded build
@@ -162,6 +162,10 @@
         add_definitions(-fprofile-use)
         list(APPEND LINKER_OPTIONS "-fprofile-use")
     endif(FPROFILE_USE)
+    if(STATIC_LINK_CRT)
+        add_definitions(-static)
+        list(APPEND LINKER_OPTIONS "-static")
+    endif(STATIC_LINK_CRT)
     check_cxx_compiler_flag(-Wno-narrowing CC_HAS_NO_NARROWING) 
     check_cxx_compiler_flag(-Wno-array-bounds CC_HAS_NO_ARRAY_BOUNDS) 
     if (CC_HAS_NO_ARRAY_BOUNDS)
@@ -458,7 +462,9 @@
     endif()
     set_target_properties(cli PROPERTIES OUTPUT_NAME x265)
     if(LINKER_OPTIONS)
-        set_target_properties(cli PROPERTIES LINK_FLAGS ${LINKER_OPTIONS})
+        # set_target_properties can't do list expansion
+        string(REPLACE ";" " " LINKER_OPTIONS "${LINKER_OPTIONS}")
+        set_target_properties(cli PROPERTIES LINK_FLAGS "${LINKER_OPTIONS}")
     endif()
 
     install(TARGETS cli DESTINATION ${BIN_INSTALL_DIR})


More information about the x265-devel mailing list