Browse Source

added static build option

Grant Limberg 5 years ago
parent
commit
5166aa6913
2 changed files with 12 additions and 1 deletions
  1. 6 0
      CMakeLists.txt
  2. 6 1
      Jenkinsfile

+ 6 - 0
CMakeLists.txt

@@ -105,6 +105,7 @@ else(WIN32)
 			$<$<CONFIG:RELWITHDEBINFO>:-g>
 		)
 		option(BUILD_32BIT "Force building as 32-bit binary" OFF)
+		option(BUILD_STATIC "Build statically linked executable" OFF)
 		if(BUILD_32BIT)
 			set(CMAKE_SYSTEM_PROCESSOR "x86" CACHE STRING "system processor")
 			set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags")
@@ -114,6 +115,11 @@ else(WIN32)
 				-m32
 			)
 		endif(BUILD_32BIT)
+		if(BUILD_STATIC)
+			add_link_options(
+				-static
+			)
+		endif(BUILD_STATIC)
 	endif(APPLE)
 endif(WIN32)
 

+ 6 - 1
Jenkinsfile

@@ -55,7 +55,12 @@ def buildStaticBinaries() {
                 def runtime = docker.image("ztbuild/${distro}-${platform}:latest")
                 runtime.inside {
                     dir("build") {
-                        sh 'make -j8 ZT_STATIC=1 all'
+                        def cmakeFlags = 'CMAKE_ARGS="-DBUILD_STATIC=1"'
+                        if (arch == "i386") {
+                            cmakeFlags = 'CMAKE_ARGS="-DBUILD_32BIT=1 -DBUILD_STATIC=1"'
+                         }
+                   
+                        sh "${cmakeFlags} make -j8 ZT_STATIC=1 all"
                         dir("build") {
                             sh "mv zerotier zerotier-static-${platform}"
                             stash includes: 'zerotier-static-*', name: "static-${platform}"