1
- from conans import ConanFile , tools , AutoToolsBuildEnvironment , MSBuild
2
- from conans .errors import ConanInvalidConfiguration
3
1
import glob
4
2
import os
5
3
import re
4
+ import shutil
5
+
6
+ from conan import ConanFile , conan_version
7
+ from conan .errors import ConanInvalidConfiguration
8
+ from conan .tools .build import cross_building
9
+ from conan .tools .files import apply_conandata_patches , chdir , copy , export_conandata_patches , get , replace_in_file
10
+ from conan .tools .gnu import Autotools , AutotoolsToolchain , AutotoolsDeps
11
+ from conan .tools .layout import basic_layout
12
+ from conan .tools .microsoft import MSBuild , MSBuildToolchain , is_msvc , check_min_vs
13
+
14
+ required_conan_version = ">=1.53.0"
6
15
7
16
8
17
class PremakeConan (ConanFile ):
9
18
name = "premake"
10
- topics = ("conan" , "premake" , "build" , "build-systems" )
11
- description = "Describe your software project just once, using Premake's simple and easy to read syntax, and build it everywhere"
19
+ description = (
20
+ "Describe your software project just once, "
21
+ "using Premake's simple and easy to read syntax, "
22
+ "and build it everywhere"
23
+ )
24
+ license = "BSD-3-Clause"
12
25
url = "https://github.com/conan-io/conan-center-index"
13
26
homepage = "https://premake.github.io"
14
- license = "BSD-3-Clause"
27
+ topics = ("build" , "build-systems" )
28
+
29
+ package_type = "application"
15
30
settings = "os" , "arch" , "compiler" , "build_type"
16
- exports_sources = "patches/**"
17
31
options = {
18
32
"lto" : [True , False ],
19
33
}
20
34
default_options = {
21
35
"lto" : False ,
22
36
}
23
37
24
- @property
25
- def _source_subfolder (self ):
26
- return "source_subfolder"
27
-
28
- def source (self ):
29
- tools .get (** self .conan_data ["sources" ][self .version ])
30
- extracted_dir = self .name + "-" + self .version
31
- os .rename (extracted_dir , self ._source_subfolder )
38
+ def export_sources (self ):
39
+ export_conandata_patches (self )
32
40
33
41
def config_options (self ):
34
- if self .settings .os != "Windows" or self .settings .compiler == "Visual Studio" :
35
- del self .options .lto
42
+ if self .settings .os != "Windows" or is_msvc (self ):
43
+ self .options .rm_safe ("lto" )
44
+
45
+ def layout (self ):
46
+ basic_layout (self , src_folder = "src" )
47
+
48
+ def package_id (self ):
49
+ del self .info .settings .compiler
50
+
51
+ def requirements (self ):
52
+ if self .settings .os != "Windows" :
53
+ self .requires ("util-linux-libuuid/2.39" )
36
54
37
55
def validate (self ):
38
- if hasattr (self , ' settings_build' ) and tools . cross_building (self , skip_x64_x86 = True ):
56
+ if hasattr (self , " settings_build" ) and cross_building (self , skip_x64_x86 = True ):
39
57
raise ConanInvalidConfiguration ("Cross-building not implemented" )
58
+ if conan_version .major == 1 and self .settings .build_type == "Debug" :
59
+ # This configuration fails without any error messages in C3I.
60
+ # https://c3i.jfrog.io/artifactory/misc/logs/pr/18844/15-linux-clang/premake/5.0.0-alpha15/
61
+ raise ConanInvalidConfiguration ("Debug build not supported with Conan 1.x" )
62
+
63
+ def source (self ):
64
+ get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
40
65
41
66
@property
42
- def _msvc_version (self ):
43
- return {
44
- "12" : "2013" ,
45
- "14" : "2015" ,
46
- "15" : "2017" ,
47
- "16" : "2019" ,
48
- }.get (str (self .settings .compiler .version ), "2017" )
67
+ def _ide_version (self ):
68
+ compiler_version = str (self .settings .compiler .version )
69
+ if str (self .settings .compiler ) == "Visual Studio" :
70
+ return {"17" : "2022" ,
71
+ "16" : "2019" ,
72
+ "15" : "2017" ,
73
+ "14" : "2015" ,
74
+ "12" : "2013" }.get (compiler_version )
75
+ else :
76
+ return {"193" : "2022" ,
77
+ "192" : "2019" ,
78
+ "191" : "2017" ,
79
+ "190" : "2015" ,
80
+ "180" : "2013" }.get (compiler_version )
49
81
50
82
@property
51
- def _msvc_build_dirname (self ):
52
- return " vs{}" . format ( self ._msvc_version )
83
+ def _msvc_build_dir (self ):
84
+ return os . path . join ( self . source_folder , "build" , f" vs{ self ._ide_version } " )
53
85
54
86
def _version_info (self , version ):
55
87
res = []
@@ -63,13 +95,6 @@ def _version_info(self, version):
63
95
res .append (p )
64
96
return tuple (res )
65
97
66
- @property
67
- def _gmake_directory_name_prefix (self ):
68
- if self ._version_info (self .version ) <= self ._version_info ("5.0.0-alpha14" ):
69
- return "gmake"
70
- else :
71
- return "gmake2"
72
-
73
98
@property
74
99
def _gmake_platform (self ):
75
100
return {
@@ -80,8 +105,8 @@ def _gmake_platform(self):
80
105
}[str (self .settings .os )]
81
106
82
107
@property
83
- def _gmake_build_dirname (self ):
84
- return "{}.{}" . format (self ._gmake_directory_name_prefix , self ._gmake_platform )
108
+ def _gmake_build_dir (self ):
109
+ return os . path . join (self .source_folder , "build" , f"gmake2. { self ._gmake_platform } " )
85
110
86
111
@property
87
112
def _gmake_config (self ):
@@ -91,35 +116,62 @@ def _gmake_config(self):
91
116
"x86" : "x86" ,
92
117
"x86_64" : "x64" ,
93
118
}[str (self .settings .arch )]
94
- config = "{ }_{}" . format ( build_type , arch )
119
+ config = f" { build_type } _{ arch } "
95
120
else :
96
121
config = build_type
97
122
return config
98
123
124
+ def generate (self ):
125
+ if is_msvc (self ):
126
+ tc = MSBuildToolchain (self )
127
+ tc .generate ()
128
+ else :
129
+ tc = AutotoolsToolchain (self )
130
+ tc .make_args = ["verbose=1" , f"config={ self ._gmake_config } " ]
131
+ tc .generate ()
132
+ deps = AutotoolsDeps (self )
133
+ deps .generate ()
134
+
99
135
def _patch_sources (self ):
100
- for patch in self .conan_data .get ("patches" , {}).get (self .version , []):
101
- tools .patch (** patch )
102
- if self .options .get_safe ("lto" , None ) == False :
103
- for fn in glob .glob (os .path .join (self ._source_subfolder , "build" , self ._gmake_build_dirname , "*.make" )):
104
- tools .replace_in_file (fn , "-flto" , "" , strict = False )
136
+ apply_conandata_patches (self )
137
+ if self .options .get_safe ("lto" , None ) is False :
138
+ for fn in glob .glob (os .path .join (self ._gmake_build_dir , "*.make" )):
139
+ replace_in_file (self , fn , "-flto" , "" , strict = False )
140
+ if check_min_vs (self , 193 , raise_invalid = False ):
141
+ # Create VS 2022 project directory based on VS 2019 one
142
+ if "alpha" in str (self .version ):
143
+ shutil .move (os .path .join (self .source_folder , "build" , "vs2019" ),
144
+ os .path .join (self .source_folder , "build" , "vs2022" ))
145
+ for vcxproj in glob .glob (os .path .join (self .source_folder , "build" , "vs2022" , "*.vcxproj" )):
146
+ replace_in_file (self , vcxproj , "v142" , "v143" )
105
147
106
148
def build (self ):
107
149
self ._patch_sources ()
108
- if self . settings . compiler == "Visual Studio" :
109
- with tools . chdir (os . path . join ( self . _source_subfolder , "build" , self ._msvc_build_dirname ) ):
150
+ if is_msvc ( self ) :
151
+ with chdir (self , self ._msvc_build_dir ):
110
152
msbuild = MSBuild (self )
111
- msbuild .build ("Premake5.sln" , platforms = { "x86" : "Win32" , "x86_64" : "x64" } )
153
+ msbuild .build (sln = "Premake5.sln" )
112
154
else :
113
- with tools . chdir (os . path . join ( self . _source_subfolder , "build" , self ._gmake_build_dirname ) ):
114
- env_build = AutoToolsBuildEnvironment (self )
115
- env_build .make (target = "Premake5" , args = [ "verbose=1" , "config={}" . format ( self . _gmake_config )] )
155
+ with chdir (self , self ._gmake_build_dir ):
156
+ autotools = Autotools (self )
157
+ autotools .make (target = "Premake5" )
116
158
117
159
def package (self ):
118
- self .copy (pattern = "LICENSE.txt" , dst = "licenses" , src = self ._source_subfolder )
119
- self .copy (pattern = "*premake5.exe" , dst = "bin" , keep_path = False )
120
- self .copy (pattern = "*premake5" , dst = "bin" , keep_path = False )
160
+ copy (self , "LICENSE.txt" ,
161
+ dst = os .path .join (self .package_folder , "licenses" ),
162
+ src = self .source_folder )
163
+ suffix = ".exe" if self .settings .os == "Windows" else ""
164
+ copy (self , f"*/premake5{ suffix } " ,
165
+ dst = os .path .join (self .package_folder , "bin" ),
166
+ src = os .path .join (self .source_folder , "bin" ),
167
+ keep_path = False )
121
168
122
169
def package_info (self ):
170
+ self .cpp_info .frameworkdirs = []
171
+ self .cpp_info .libdirs = []
172
+ self .cpp_info .resdirs = []
173
+ self .cpp_info .includedirs = []
174
+
175
+ # TODO: Legacy, to be removed on Conan 2.0
123
176
bindir = os .path .join (self .package_folder , "bin" )
124
- self .output .info ("Appending PATH environment variable: {}" .format (bindir ))
125
177
self .env_info .PATH .append (bindir )
0 commit comments