| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# @HEADER |
| 4 |
# ***************************************************************************** |
| 5 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 6 |
# |
| 7 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 8 |
# SPDX-License-Identifier: BSD-3-Clause |
| 9 |
# ***************************************************************************** |
| 10 |
# @HEADER |
| 11 |
|
| 12 |
|
| 13 |
# |
| 14 |
# Defaults |
| 15 |
# |
| 16 |
|
| 17 |
cmakeBaseName = "cmake" |
| 18 |
cmakeDefaultVersion = "3.23.4" |
| 19 |
|
| 20 |
|
| 21 |
# |
| 22 |
# Script code |
| 23 |
# |
| 24 |
|
| 25 |
|
| 26 |
from InstallProgramDriver import * |
| 27 |
from GeneralScriptSupport import * |
| 28 |
|
| 29 |
import os.path |
| 30 |
|
| 31 |
devtools_install_dir = os.path.dirname(os.path.abspath(__file__)) |
| 32 |
|
| 33 |
class CMakeInstall: |
| 34 |
|
| 35 |
def __init__(self): |
| 36 |
self.dummy = None |
| 37 |
|
| 38 |
# |
| 39 |
# Called before even knowing the product version |
| 40 |
# |
| 41 |
|
| 42 |
def getScriptName(self): |
| 43 |
return "install-cmake.py" |
| 44 |
|
| 45 |
def getProductBaseName(self): |
| 46 |
return cmakeBaseName |
| 47 |
|
| 48 |
def getProductDefaultVersion(self): |
| 49 |
return cmakeDefaultVersion |
| 50 |
|
| 51 |
def getProductSupportedVersions(self): |
| 52 |
return [] # Support all versions! |
| 53 |
|
| 54 |
# |
| 55 |
# Called after knowing the product version but before parsing the |
| 56 |
# command-line. |
| 57 |
# |
| 58 |
|
| 59 |
def getProductName(self, version): |
| 60 |
return cmakeBaseName+"-"+version |
| 61 |
|
| 62 |
def getBaseDirName(self, version): |
| 63 |
return cmakeBaseName+"-"+version |
| 64 |
|
| 65 |
def getExtraHelpStr(self, version): |
| 66 |
return """ |
| 67 |
This script builds """+self.getProductName(version)+""" from source compiled with the |
| 68 |
configured C/C++ compilers in your path. To select a C and C++ compiler which is not |
| 69 |
the default in your path, run with: |
| 70 |
|
| 71 |
env CC=<path-to-c-compiler> CXX=<path-to-cxx-compiler> install-cmake.py [other options] |
| 72 |
|
| 73 |
This downloads tarballs from GitHub by default for the given cmake version. |
| 74 |
|
| 75 |
This build script sets the environment vars CXXFLAGS=-O3 AND CFLAGS=-O3 |
| 76 |
when doing the configure. Therefore, this builds and installs an optimized |
| 77 |
version of CMake by default. |
| 78 |
|
| 79 |
NOTE: To install CMake from the tip of a branch such as 'master', one must |
| 80 |
override the 'download' command and eliminate the 'untar' command. One must |
| 81 |
stick with the directory structure that is assumed by the underlying code |
| 82 |
which creates temp directories based in the CMake version. For example, to |
| 83 |
cone and install the tip of the CMake 'master' branch one can run: |
| 84 |
|
| 85 |
install-cmake.py \\ |
| 86 |
--install-dir=<install-prefix./cmake-master-YYYYMMDD \\ |
| 87 |
--cmake-version=master \\ |
| 88 |
--download-cmnd="git clone [email protected]:kitware/cmake.git cmake-master" \\ |
| 89 |
--parallel=15 --download --configure --build --install |
| 90 |
|
| 91 |
What this does is to combine the 'download' and 'untar' commands together to |
| 92 |
produce the source dir 'cmake-master' in one shot. Note that the 'master' in |
| 93 |
'cmake-master' in the git clone command must match the 'master' passed in the |
| 94 |
argument '--cmake-version=master'. |
| 95 |
""" |
| 96 |
|
| 97 |
def injectExtraCmndLineOptions(self, clp, version): |
| 98 |
setStdGithubDownloadCmndOption(self, "kitware", "cmake", clp, version) |
| 99 |
clp.add_option( |
| 100 |
"--extra-configure-options", dest="extraConfigureOptions", type="string", \ |
| 101 |
default="", \ |
| 102 |
help="Extra options to add to the 'configure' command for "\ |
| 103 |
+self.getProductName(version)+"." \ |
| 104 |
+" Note: This does not override the hard-coded configure options." ) |
| 105 |
addOptionParserChoiceOption( |
| 106 |
"--use-native-cmake-config", "cmakeNativeConfig", |
| 107 |
["on", "off", "auto"], 1, |
| 108 |
"Use an already installed version of CMake for configuring " \ |
| 109 |
+self.getProductName(version)+".", clp) |
| 110 |
addOptionParserChoiceOption( |
| 111 |
"--use-openssl", "useOpenSSL", |
| 112 |
["on", "off"], 1, |
| 113 |
"Build in support for OpenSSL to submit to CDash via HTTPS for " \ |
| 114 |
+self.getProductName(version)+".", clp) |
| 115 |
|
| 116 |
def echoExtraCmndLineOptions(self, inOptions): |
| 117 |
cmndLine = "" |
| 118 |
cmndLine += " --download-cmnd='"+inOptions.downloadCmnd+"' \\\n" |
| 119 |
cmndLine += " --extra-configure-options='"+inOptions.extraConfigureOptions+"' \\\n" |
| 120 |
cmndLine += " --use-native-cmake-config='"+inOptions.cmakeNativeConfig+"' \\\n" |
| 121 |
cmndLine += " --use-openssl='"+inOptions.useOpenSSL+"' \\\n" |
| 122 |
return cmndLine |
| 123 |
|
| 124 |
# |
| 125 |
# Called after parsing the command-line |
| 126 |
# |
| 127 |
|
| 128 |
def setup(self, inOptions): |
| 129 |
self.inOptions = inOptions |
| 130 |
self.baseDir = os.getcwd() |
| 131 |
self.cmakeBaseDir = self.baseDir+"/"+self.getBaseDirName(self.inOptions.version) |
| 132 |
cmakeVersionFull = self.inOptions.version |
| 133 |
self.cmakeTarball = "cmake-"+cmakeVersionFull+".tar.gz" |
| 134 |
self.cmakeSrcDir = "cmake-"+cmakeVersionFull |
| 135 |
self.cmakeBuildBaseDir = self.cmakeBaseDir+"/cmake-build" |
| 136 |
self.scriptBaseDir = getScriptBaseDir() |
| 137 |
|
| 138 |
# |
| 139 |
# Called after setup() |
| 140 |
# |
| 141 |
|
| 142 |
def doDownload(self): |
| 143 |
removeDirIfExists(self.cmakeBaseDir, True) |
| 144 |
createDir(self.cmakeBaseDir, cdIntoDir=True, verbose=True) |
| 145 |
echoRunSysCmnd(self.inOptions.downloadCmnd) |
| 146 |
|
| 147 |
def doUntar(self): |
| 148 |
# Find the full name of the source tarball |
| 149 |
echoChDir(self.cmakeBaseDir) |
| 150 |
createDir(self.cmakeSrcDir, verbose=True) |
| 151 |
echoRunSysCmnd("tar -xzf "+self.cmakeTarball \ |
| 152 |
+" -C "+self.cmakeSrcDir+" --strip-components 1") |
| 153 |
|
| 154 |
def doConfigure(self): |
| 155 |
createDir(self.cmakeBuildBaseDir, True, True) |
| 156 |
|
| 157 |
# Look for an already installed CMake |
| 158 |
if self.inOptions.cmakeNativeConfig is not "off": |
| 159 |
cmakeCmd = self.which("cmake") |
| 160 |
else: |
| 161 |
# Configuring NOT with CMake was explicitly requested |
| 162 |
cmakeCmd = None |
| 163 |
|
| 164 |
if self.inOptions.useOpenSSL == "on": |
| 165 |
openSSLCachVarStr=" -DCMAKE_USE_OPENSSL=ON" |
| 166 |
else: |
| 167 |
openSSLCachVarStr=" -DCMAKE_USE_OPENSSL=OFF" |
| 168 |
|
| 169 |
if cmakeCmd is not None: |
| 170 |
# CMake is installed, configure CMake with CMake |
| 171 |
echoRunSysCmnd( |
| 172 |
cmakeCmd+" ../"+self.cmakeSrcDir+\ |
| 173 |
" "+self.inOptions.extraConfigureOptions+\ |
| 174 |
" -DCMAKE_BUILD_TYPE=Release"+\ |
| 175 |
openSSLCachVarStr+\ |
| 176 |
" -DCMAKE_INSTALL_PREFIX="+self.inOptions.installDir |
| 177 |
) |
| 178 |
|
| 179 |
elif self.inOptions.cmakeNativeConfig is "on": |
| 180 |
# Configuring CMake with CMake was explicitly requested but |
| 181 |
# the CMake executable was not found in PATH |
| 182 |
raise Exception("Could not find 'cmake' in PATH and --use-native-cmake-config=on!") |
| 183 |
else: |
| 184 |
# CMake is not already installed on system, so use configure |
| 185 |
echoRunSysCmnd( |
| 186 |
"../"+self.cmakeSrcDir+"/bootstrap "+\ |
| 187 |
" "+self.inOptions.extraConfigureOptions+\ |
| 188 |
getParallelOpt(self.inOptions, "--parallel=")+\ |
| 189 |
" --prefix="+self.inOptions.installDir+\ |
| 190 |
" -- "+openSSLCachVarStr, |
| 191 |
extraEnv={"CXXFLAGS":"-O3", "CFLAGS":"-O3"}, |
| 192 |
) |
| 193 |
|
| 194 |
def doBuild(self): |
| 195 |
echoChDir(self.cmakeBuildBaseDir) |
| 196 |
echoRunSysCmnd("make "+getParallelOpt(self.inOptions, "-j")+self.inOptions.makeOptions) |
| 197 |
|
| 198 |
def doInstall(self): |
| 199 |
echoChDir(self.cmakeBuildBaseDir) |
| 200 |
echoRunSysCmnd("make "+self.inOptions.makeOptions+" install") |
| 201 |
|
| 202 |
def getFinalInstructions(self): |
| 203 |
return """ |
| 204 |
To use the installed version of cmake-"""+self.inOptions.version+""" add the path: |
| 205 |
|
| 206 |
"""+self.inOptions.installDir+"""/bin |
| 207 |
|
| 208 |
to your path and that should be it! |
| 209 |
""" |
| 210 |
@staticmethod |
| 211 |
def which(program): |
| 212 |
def is_exe(fpath): |
| 213 |
return os.path.isfile(fpath) and os.access(fpath, os.X_OK) |
| 214 |
|
| 215 |
fpath, fname = os.path.split(program) |
| 216 |
if fpath: |
| 217 |
if is_exe(program): |
| 218 |
return program |
| 219 |
else: |
| 220 |
for path in os.environ["PATH"].split(os.pathsep): |
| 221 |
path = path.strip('"') |
| 222 |
exe_file = os.path.join(path, program) |
| 223 |
if is_exe(exe_file): |
| 224 |
return exe_file |
| 225 |
|
| 226 |
return None |
| 227 |
|
| 228 |
# |
| 229 |
# Executable statements |
| 230 |
# |
| 231 |
|
| 232 |
cmakeInstaller = InstallProgramDriver(CMakeInstall()) |
| 233 |
cmakeInstaller.runDriver() |