Changeset View
Changeset View
Standalone View
Standalone View
bin/BuildSystem/CMakeBuildSystem.py
1 | # | 1 | # | ||
---|---|---|---|---|---|
2 | # copyright (c) 2009 Ralf Habacker <ralf.habacker@freenet.de> | 2 | # copyright (c) 2009 Ralf Habacker <ralf.habacker@freenet.de> | ||
3 | # | 3 | # | ||
4 | 4 | | |||
5 | """@package provides cmake build system""" | 5 | """@package provides cmake build system""" | ||
6 | 6 | | |||
7 | import os | 7 | import os | ||
8 | 8 | | |||
9 | from CraftDebug import craftDebug | 9 | from CraftDebug import craftDebug | ||
10 | import utils | 10 | import utils | ||
11 | from BuildSystem.CMakeDependencies import * | 11 | from BuildSystem.CMakeDependencies import * | ||
12 | from BuildSystem.BuildSystemBase import * | 12 | from BuildSystem.BuildSystemBase import * | ||
13 | import compiler | 13 | from compiler import craftCompiler | ||
14 | import utils | 14 | import utils | ||
15 | from CraftOS.osutils import OsUtils | 15 | from CraftOS.osutils import OsUtils | ||
16 | 16 | | |||
17 | 17 | | |||
18 | 18 | | |||
19 | class CMakeBuildSystem(BuildSystemBase): | 19 | class CMakeBuildSystem(BuildSystemBase): | ||
20 | """ cmake build support """ | 20 | """ cmake build support """ | ||
21 | def __init__( self ): | 21 | def __init__( self ): | ||
22 | """constructor. configureOptions are added to the configure command line and makeOptions are added to the make command line""" | 22 | """constructor. configureOptions are added to the configure command line and makeOptions are added to the make command line""" | ||
23 | BuildSystemBase.__init__(self, "cmake") | 23 | BuildSystemBase.__init__(self, "cmake") | ||
24 | self.supportsNinja = True | 24 | self.supportsNinja = True | ||
25 | 25 | | |||
26 | def __makeFileGenerator(self): | 26 | def __makeFileGenerator(self): | ||
27 | """return cmake related make file generator""" | 27 | """return cmake related make file generator""" | ||
28 | if self.makeProgram == "ninja": | 28 | if self.makeProgram == "ninja": | ||
29 | return "Ninja" | 29 | return "Ninja" | ||
30 | if OsUtils.isWin(): | 30 | if OsUtils.isWin(): | ||
31 | if compiler.isMSVC() and not (self.subinfo.options.cmake.useIDE or self.subinfo.options.cmake.openIDE) or compiler.isIntel(): | 31 | if craftCompiler.isMSVC() and not (self.subinfo.options.cmake.useIDE or self.subinfo.options.cmake.openIDE) or craftCompiler.isIntel(): | ||
32 | return "NMake Makefiles" | 32 | return "NMake Makefiles" | ||
33 | else: | 33 | else: | ||
34 | if compiler.isMSVC2017(): | 34 | if craftCompiler.isMSVC2017(): | ||
35 | return "Visual Studio 15 2017" + (" Win64" if compiler.isX64() else "") | 35 | return "Visual Studio 15 2017" + (" Win64" if craftCompiler.isX64() else "") | ||
36 | elif compiler.isMSVC2015(): | 36 | elif craftCompiler.isMSVC2015(): | ||
37 | return "Visual Studio 14 2015" + (" Win64" if compiler.isX64() else "") | 37 | return "Visual Studio 14 2015" + (" Win64" if craftCompiler.isX64() else "") | ||
38 | elif compiler.isMSVC2010(): | 38 | elif craftCompiler.isMSVC2010(): | ||
39 | return "Visual Studio 10" | 39 | return "Visual Studio 10" | ||
40 | if compiler.isMinGW(): | 40 | if craftCompiler.isMinGW(): | ||
41 | return "MinGW Makefiles" | 41 | return "MinGW Makefiles" | ||
42 | elif OsUtils.isUnix(): | 42 | elif OsUtils.isUnix(): | ||
43 | return "Unix Makefiles" | 43 | return "Unix Makefiles" | ||
44 | else: | 44 | else: | ||
45 | craftDebug.log.critical("unknown %s compiler" % self.compiler()) | 45 | craftDebug.log.critical(f"unknown {craftCompiler} compiler") | ||
46 | 46 | | |||
47 | def __onlyBuildDefines( self, buildOnlyTargets ): | 47 | def __onlyBuildDefines( self, buildOnlyTargets ): | ||
48 | """This method returns a list of cmake defines to exclude targets from build""" | 48 | """This method returns a list of cmake defines to exclude targets from build""" | ||
49 | defines = "" | 49 | defines = "" | ||
50 | topLevelCMakeList = os.path.join(self.sourceDir(), "CMakeLists.txt") | 50 | topLevelCMakeList = os.path.join(self.sourceDir(), "CMakeLists.txt") | ||
51 | if os.path.exists(topLevelCMakeList): | 51 | if os.path.exists(topLevelCMakeList): | ||
52 | with open(topLevelCMakeList,'r') as f: | 52 | with open(topLevelCMakeList,'r') as f: | ||
53 | lines = f.read().splitlines() | 53 | lines = f.read().splitlines() | ||
Show All 36 Lines | 85 | def configureOptions( self, defines=""): | |||
90 | options += " -DCMAKE_INSTALL_PREFIX=\"%s\"" % self.mergeDestinationDir().replace( "\\", "/" ) | 90 | options += " -DCMAKE_INSTALL_PREFIX=\"%s\"" % self.mergeDestinationDir().replace( "\\", "/" ) | ||
91 | 91 | | |||
92 | options += " -DCMAKE_PREFIX_PATH=\"%s\"" % \ | 92 | options += " -DCMAKE_PREFIX_PATH=\"%s\"" % \ | ||
93 | self.mergeDestinationDir().replace( "\\", "/" ) | 93 | self.mergeDestinationDir().replace( "\\", "/" ) | ||
94 | 94 | | |||
95 | if( not self.buildType() == None ): | 95 | if( not self.buildType() == None ): | ||
96 | options += " -DCMAKE_BUILD_TYPE=%s" % self.buildType() | 96 | options += " -DCMAKE_BUILD_TYPE=%s" % self.buildType() | ||
97 | 97 | | |||
98 | if compiler.isGCC() and not compiler.isNative(): | 98 | if craftCompiler.isGCC() and not craftCompiler.isNative(): | ||
99 | options += " -DCMAKE_TOOLCHAIN_FILE=%s" % os.path.join( CraftStandardDirs.craftRoot(), "craft", "bin", "toolchains", "Toolchain-cross-mingw32-linux-%s.cmake" % compiler.architecture()) | 99 | options += " -DCMAKE_TOOLCHAIN_FILE=%s" % os.path.join(CraftStandardDirs.craftRoot(), "craft", "bin", "toolchains", "Toolchain-cross-mingw32-linux-%s.cmake" % craftCompiler.architecture) | ||
100 | 100 | | |||
101 | if OsUtils.isWin(): | 101 | if OsUtils.isWin(): | ||
102 | options += " -DKDE_INSTALL_USE_QT_SYS_PATHS=ON" | 102 | options += " -DKDE_INSTALL_USE_QT_SYS_PATHS=ON" | ||
103 | 103 | | |||
104 | if OsUtils.isMac(): | 104 | if OsUtils.isMac(): | ||
105 | options += " -DKDE_INSTALL_BUNDLEDIR=\"%s/Applications/KDE\" -DAPPLE_SUPPRESS_X11_WARNING=ON" % \ | 105 | options += " -DKDE_INSTALL_BUNDLEDIR=\"%s/Applications/KDE\" -DAPPLE_SUPPRESS_X11_WARNING=ON" % \ | ||
106 | self.mergeDestinationDir().replace( "\\", "/" ) | 106 | self.mergeDestinationDir().replace( "\\", "/" ) | ||
107 | 107 | | |||
108 | if not self.buildTests: | 108 | if not self.buildTests: | ||
109 | options += " -DBUILD_TESTING=OFF " | 109 | options += " -DBUILD_TESTING=OFF " | ||
110 | 110 | | |||
111 | if self.subinfo.options.buildTools: | 111 | if self.subinfo.options.buildTools: | ||
112 | options += " " + self.subinfo.options.configure.toolsDefine + " " | 112 | options += " " + self.subinfo.options.configure.toolsDefine + " " | ||
113 | if self.subinfo.options.buildStatic and self.subinfo.options.configure.staticArgs: | 113 | if self.subinfo.options.buildStatic and self.subinfo.options.configure.staticArgs: | ||
114 | options += " " + self.subinfo.options.configure.staticArgs + " " | 114 | options += " " + self.subinfo.options.configure.staticArgs + " " | ||
115 | if self.subinfo.options.configure.onlyBuildTargets : | 115 | if self.subinfo.options.configure.onlyBuildTargets : | ||
116 | options += self.__onlyBuildDefines(self.subinfo.options.configure.onlyBuildTargets ) | 116 | options += self.__onlyBuildDefines(self.subinfo.options.configure.onlyBuildTargets ) | ||
117 | if self.subinfo.options.cmake.useCTest: | 117 | if self.subinfo.options.cmake.useCTest: | ||
118 | options += " -DCMAKE_PROGRAM_PATH=\"%s\" " % \ | 118 | options += " -DCMAKE_PROGRAM_PATH=\"%s\" " % \ | ||
119 | ( os.path.join( self.mergeDestinationDir(), "dev-utils", "svn", "bin" ).replace( "\\", "/" ) ) | 119 | ( os.path.join( self.mergeDestinationDir(), "dev-utils", "svn", "bin" ).replace( "\\", "/" ) ) | ||
120 | if compiler.isIntel(): | 120 | if craftCompiler.isIntel(): | ||
121 | # this is needed because otherwise it'll detect the MSVC environment | 121 | # this is needed because otherwise it'll detect the MSVC environment | ||
122 | options += " -DCMAKE_CXX_COMPILER=\"%s\" " % os.path.join(os.getenv("BIN_ROOT"), os.getenv("ARCH_PATH"), "icl.exe" ).replace( "\\", "/" ) | 122 | options += " -DCMAKE_CXX_COMPILER=\"%s\" " % os.path.join(os.getenv("BIN_ROOT"), os.getenv("ARCH_PATH"), "icl.exe" ).replace( "\\", "/" ) | ||
123 | options += " -DCMAKE_C_COMPILER=\"%s\" " % os.path.join(os.getenv("BIN_ROOT"), os.getenv("ARCH_PATH"), "icl.exe" ).replace( "\\", "/" ) | 123 | options += " -DCMAKE_C_COMPILER=\"%s\" " % os.path.join(os.getenv("BIN_ROOT"), os.getenv("ARCH_PATH"), "icl.exe" ).replace( "\\", "/" ) | ||
124 | options += " -DCMAKE_LINKER=\"%s\" " % os.path.join(os.getenv("BIN_ROOT"), os.getenv("ARCH_PATH"), "xilink.exe" ).replace( "\\", "/" ) | 124 | options += " -DCMAKE_LINKER=\"%s\" " % os.path.join(os.getenv("BIN_ROOT"), os.getenv("ARCH_PATH"), "xilink.exe" ).replace( "\\", "/" ) | ||
125 | options += " \"%s\"" % self.configureSourceDir() | 125 | options += " \"%s\"" % self.configureSourceDir() | ||
126 | return options | 126 | return options | ||
127 | 127 | | |||
128 | def configure( self, defines=""): | 128 | def configure( self, defines=""): | ||
Show All 9 Lines | |||||
138 | return self.system( command, "configure", 0 ) | 138 | return self.system( command, "configure", 0 ) | ||
139 | 139 | | |||
140 | def make( self ): | 140 | def make( self ): | ||
141 | """implements the make step for cmake projects""" | 141 | """implements the make step for cmake projects""" | ||
142 | 142 | | |||
143 | self.enterBuildDir() | 143 | self.enterBuildDir() | ||
144 | 144 | | |||
145 | if self.subinfo.options.cmake.openIDE: | 145 | if self.subinfo.options.cmake.openIDE: | ||
146 | if compiler.isMSVC2010(): | 146 | if craftCompiler.isMSVC2010(): | ||
147 | command = "start vcexpress %s" % self.__slnFileName() | 147 | command = "start vcexpress %s" % self.__slnFileName() | ||
148 | elif self.subinfo.options.cmake.useIDE: | 148 | elif self.subinfo.options.cmake.useIDE: | ||
149 | if compiler.isMSVC2015(): | 149 | if craftCompiler.isMSVC2015(): | ||
150 | command = "msbuild /maxcpucount %s /t:ALL_BUILD /p:Configuration=\"%s\"" % (self.__slnFileName(), self.buildType()) | 150 | command = "msbuild /maxcpucount %s /t:ALL_BUILD /p:Configuration=\"%s\"" % (self.__slnFileName(), self.buildType()) | ||
151 | elif compiler.isMSVC2010(): | 151 | elif craftCompiler.isMSVC2010(): | ||
152 | craftDebug.log.critical("has to be implemented"); | 152 | craftDebug.log.critical("has to be implemented"); | ||
153 | elif self.subinfo.options.cmake.useCTest: | 153 | elif self.subinfo.options.cmake.useCTest: | ||
154 | # first make clean | 154 | # first make clean | ||
155 | self.system( self.makeProgram + " clean", "make clean" ) | 155 | self.system( self.makeProgram + " clean", "make clean" ) | ||
156 | command = "ctest -M " + "Nightly" + " -T Start -T Update -T Configure -T Build -T Submit" | 156 | command = "ctest -M " + "Nightly" + " -T Start -T Update -T Configure -T Build -T Submit" | ||
157 | else: | 157 | else: | ||
158 | command = ' '.join([self.makeProgram, self.makeOptions()]) | 158 | command = ' '.join([self.makeProgram, self.makeOptions()]) | ||
159 | 159 | | |||
160 | 160 | | |||
161 | return self.system( command, "make" ) | 161 | return self.system( command, "make" ) | ||
162 | 162 | | |||
163 | def install( self): | 163 | def install( self): | ||
164 | """install the target""" | 164 | """install the target""" | ||
165 | if not BuildSystemBase.install(self): | 165 | if not BuildSystemBase.install(self): | ||
166 | return False | 166 | return False | ||
167 | 167 | | |||
168 | self.enterBuildDir() | 168 | self.enterBuildDir() | ||
169 | 169 | | |||
170 | fastString = "" | 170 | fastString = "" | ||
171 | if not self.noFast: | 171 | if not self.noFast: | ||
172 | fastString = "/fast" | 172 | fastString = "/fast" | ||
173 | 173 | | |||
174 | env = os.environ | 174 | env = os.environ | ||
175 | if self.subinfo.options.install.useMakeToolForInstall: | 175 | if self.subinfo.options.install.useMakeToolForInstall: | ||
176 | if compiler.isMSVC2015() and (self.subinfo.options.cmake.useIDE or self.subinfo.options.cmake.openIDE): | 176 | if craftCompiler.isMSVC2015() and (self.subinfo.options.cmake.useIDE or self.subinfo.options.cmake.openIDE): | ||
177 | command = "msbuild INSTALL.vcxproj /p:Configuration=\"%s\"" % self.buildType() | 177 | command = "msbuild INSTALL.vcxproj /p:Configuration=\"%s\"" % self.buildType() | ||
178 | else: | 178 | else: | ||
179 | env["DESTDIR"] = self.installDir() | 179 | env["DESTDIR"] = self.installDir() | ||
180 | command = "%s install%s" % ( self.makeProgram, fastString ) | 180 | command = "%s install%s" % ( self.makeProgram, fastString ) | ||
181 | else: | 181 | else: | ||
182 | command = "cmake -DCMAKE_INSTALL_PREFIX=%s -P cmake_install.cmake" % self.installDir() | 182 | command = "cmake -DCMAKE_INSTALL_PREFIX=%s -P cmake_install.cmake" % self.installDir() | ||
183 | 183 | | |||
184 | self.system( command, "install", env=env ) | 184 | self.system( command, "install", env=env ) | ||
Show All 10 Lines | 190 | def unittest( self ): | |||
195 | return self.system("ctest --output-on-failure") | 195 | return self.system("ctest --output-on-failure") | ||
196 | 196 | | |||
197 | def ccacheOptions(self): | 197 | def ccacheOptions(self): | ||
198 | out = " -DCMAKE_CXX_COMPILER=ccache -DCMAKE_CXX_COMPILER_ARG1=g++ " | 198 | out = " -DCMAKE_CXX_COMPILER=ccache -DCMAKE_CXX_COMPILER_ARG1=g++ " | ||
199 | out += " -DCMAKE_C_COMPILER=ccache -DCMAKE_C_COMPILER_ARG1=gcc " | 199 | out += " -DCMAKE_C_COMPILER=ccache -DCMAKE_C_COMPILER_ARG1=gcc " | ||
200 | return out | 200 | return out | ||
201 | 201 | | |||
202 | def clangOptions(self): | 202 | def clangOptions(self): | ||
203 | if compiler.isMSVC(): | 203 | if craftCompiler.isMSVC(): | ||
204 | return " -DCMAKE_CXX_COMPILER=clang-cl" \ | 204 | return " -DCMAKE_CXX_COMPILER=clang-cl" \ | ||
205 | " -DCMAKE_C_COMPILER=clang-cl" | 205 | " -DCMAKE_C_COMPILER=clang-cl" | ||
206 | return out | 206 | return out | ||
207 | else: | 207 | else: | ||
208 | return " -DCMAKE_CXX_COMPILER=clang++" \ | 208 | return " -DCMAKE_CXX_COMPILER=clang++" \ | ||
209 | " -DCMAKE_C_COMPILER=clang" | 209 | " -DCMAKE_C_COMPILER=clang" | ||
210 | 210 | | |||
211 | def _fixCmakeImageDir(self, imagedir, rootdir ): | 211 | def _fixCmakeImageDir(self, imagedir, rootdir ): | ||
Show All 36 Lines |