瀏覽代碼

ajusting cmake to strip executables in release builds

Stasik0 10 年之前
父節點
當前提交
7135b7e5ea
共有 3 個文件被更改,包括 25 次插入0 次删除
  1. 20 0
      CMakeLists.txt
  2. 4 0
      cmake/Toolchain-mingw32.cmake
  3. 1 0
      cmake/Toolchain-rpi.cmake

+ 20 - 0
CMakeLists.txt

@@ -146,11 +146,21 @@ if(CLIENT)
     if(MULTITHREADING)
         target_link_libraries(exampleClient urcu-cds urcu urcu-common pthread)
     endif()
+    if ((CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release"))
+    	add_custom_command(TARGET exampleClient POST_BUILD
+    		COMMAND ${CMAKE_STRIP} $<TARGET_FILE:exampleClient>
+		)
+	endif()
     if(EXTENSION_STATELESS)
         add_executable(statelessClient $<TARGET_OBJECTS:open62541-objects> examples/client_stateless.c)
         if(MULTITHREADING)
             target_link_libraries(statelessClient urcu-cds urcu urcu-common pthread)
         endif()
+        if ((CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release"))
+    	add_custom_command(TARGET statelessClient POST_BUILD
+    		COMMAND ${CMAKE_STRIP} $<TARGET_FILE:statelessClient>
+		)
+		endif()
     endif()
 endif()
 
@@ -167,6 +177,11 @@ if(EXAMPLESERVER)
     if(MULTITHREADING)
         target_link_libraries(exampleServer urcu-cds urcu urcu-common pthread)
     endif()
+    if ((CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release"))
+    	add_custom_command(TARGET exampleServer POST_BUILD
+    		COMMAND ${CMAKE_STRIP} $<TARGET_FILE:exampleServer>
+		)
+	endif()
 endif()
 
 # build rpi example server
@@ -182,6 +197,11 @@ if(EXAMPLESERVER_RPI)
     if(MULTITHREADING)
         target_link_libraries(exampleServerRpi urcu-cds urcu urcu-common pthread)
     endif()
+    if ((CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release"))
+    	add_custom_command(TARGET exampleServerRpi POST_BUILD
+    		COMMAND ${CMAKE_STRIP} $<TARGET_FILE:exampleServerRpi>
+		)
+	endif()
 endif()
 
 ## self-signed certificates

+ 4 - 0
cmake/Toolchain-mingw32.cmake

@@ -8,6 +8,7 @@ set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
 # environment.
 if(EXISTS /usr/i686-w64-mingw32)
 # First look in standard location as used by Debian/Ubuntu/etc.
+set(CMAKE_STRIP i686-w64-mingw32-strip)
 set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
 set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
 set(CMAKE_RC_COMPILER i686-w64-mingw32-windres)
@@ -15,6 +16,7 @@ set(CMAKE_AR:FILEPATH /usr/bin/i686-w64-mingw32-ar)
 set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
 elseif(EXISTS /usr/i586-mingw32msvc)
 # First look in standard location as used by Debian/Ubuntu/etc.
+set(CMAKE_STRIP i586-mingw32msvc-strip)
 set(CMAKE_C_COMPILER i586-mingw32msvc-gcc)
 set(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)
 set(CMAKE_RC_COMPILER i586-mingw32msvc-windres)
@@ -24,6 +26,7 @@ elseif(EXISTS /opt/mingw)
 # It downloads and builds MinGW and most of the dependencies for you.
 # You can use the toolchain file generated by MXE called `mxe-conf.cmake'
 # or you can use this file by adjusting the above and following paths.
+set(CMAKE_STRIP /opt/mingw/usr/bin/i686-pc-mingw32-strip)
 set(CMAKE_C_COMPILER /opt/mingw/usr/bin/i686-pc-mingw32-gcc)
 set(CMAKE_CXX_COMPILER /opt/mingw/usr/bin/i686-pc-mingw32-g++)
 set(CMAKE_RC_COMPILER /opt/mingw/usr/bin/i686-pc-mingw32-windres)
@@ -31,6 +34,7 @@ set(CMAKE_FIND_ROOT_PATH /opt/mingw/usr/i686-pc-mingw32)
 else()
 # Else fill in local path which the user will likely adjust.
 # This is the location assumed by <http://www.libsdl.org/extras/win32/cross/>
+set(CMAKE_STRIP /usr/local/cross-tools/bin/i386-mingw32-strip)
 set(CMAKE_C_COMPILER /usr/local/cross-tools/bin/i386-mingw32-gcc)
 set(CMAKE_CXX_COMPILER /usr/local/cross-tools/bin/i386-mingw32-g++)
 set(CMAKE_RC_COMPILER /usr/local/cross-tools/bin/i386-mingw32-windres)

+ 1 - 0
cmake/Toolchain-rpi.cmake

@@ -9,3 +9,4 @@
 # make
 set(CMAKE_C_COMPILER arm-bcm2708hardfp-linux-gnueabi-gcc)
 set(CMAKE_CXX_COMPILER arm-bcm2708hardfp-linux-gnueabi-g++)
+set(CMAKE_STRIP arm-bcm2708hardfp-linux-gnueabi-strip)