-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
86 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,17 @@ | ||
class Premake(object): | ||
class Premake: | ||
def __init__(self, conanfile): | ||
self._conanfile = conanfile | ||
|
||
# automatically chooses premake action based on used compiler | ||
def configure(self): | ||
if "Visual Studio" in self._conanfile.settings.compiler: | ||
_visuals = {'8': '2005', | ||
'9': '2008', | ||
'10': '2010', | ||
'11': '2012', | ||
'12': '2013', | ||
'14': '2015', | ||
'15': '2017', | ||
'16': '2019'} | ||
premake_command = "premake5 vs%s" % _visuals.get(str(self._conanfile.settings.compiler.version)) | ||
self._conanfile.run(premake_command) | ||
elif "msvc" in self._conanfile.settings.compiler: | ||
_visuals = {'14.0': '2005', | ||
'15.0': '2008', | ||
'16.0': '2010', | ||
'17.0': '2012', | ||
'18.0': '2013', | ||
'19.0': '2015', | ||
# add non-trailing 0 variation manually | ||
'19.1': '2017', | ||
'19.2': '2019'} | ||
# generate VS2017 versions | ||
for i in range(0,7): | ||
ver = '19.1' + str(i) | ||
_visuals[ver] = '2017' | ||
# generate VS2019 versions | ||
for i in range(0,10): | ||
ver = '19.2' + str(i) | ||
_visuals[ver] = '2019' | ||
premake_command = "premake5 vs%s" % _visuals.get(str(self._conanfile.settings.compiler.version)) | ||
if "msvc" in self._conanfile.settings.compiler: | ||
_visuals = {'190': '2015', | ||
'191': '2017', | ||
'192': '2019', | ||
'193': '2022', | ||
'194': '2023'} | ||
version = _visuals.get(str(self._conanfile.settings.compiler.version)) | ||
premake_command = f"premake5 vs{version}" | ||
self._conanfile.run(premake_command) | ||
else: | ||
self._conanfile.run("premake5 gmake2") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import platform | ||
import textwrap | ||
|
||
import pytest | ||
|
||
from conan.test.assets.sources import gen_function_cpp | ||
|
||
|
||
@pytest.mark.skipif(platform.system() == "Darwin", reason="Not for MacOS") | ||
@pytest.mark.tool("premake") | ||
def test_premake(matrix_client): | ||
c = matrix_client | ||
conanfile = textwrap.dedent(""" | ||
import os | ||
from conan import ConanFile | ||
from conan.tools.premake import Premake | ||
from conan.tools.microsoft import MSBuild | ||
class Pkg(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
requires = "matrix/1.0" | ||
generators = "PremakeDeps", "VCVars" | ||
def build(self): | ||
p = Premake(self) | ||
p.configure() | ||
build_type = str(self.settings.build_type) | ||
if self.settings.os == "Windows": | ||
msbuild = MSBuild(self) | ||
msbuild.build("HelloWorld.sln") | ||
else: | ||
self.run(f"make config={build_type.lower()}_x86_64") | ||
p = os.path.join(self.build_folder, "bin", build_type, "HelloWorld") | ||
self.run(f'"{p}"') | ||
""") | ||
premake = textwrap.dedent(""" | ||
-- premake5.lua | ||
include('conandeps.premake5.lua') | ||
workspace "HelloWorld" | ||
conan_setup() | ||
configurations { "Debug", "Release" } | ||
platforms { "x86_64" } | ||
project "HelloWorld" | ||
kind "ConsoleApp" | ||
language "C++" | ||
targetdir "bin/%{cfg.buildcfg}" | ||
files { "**.h", "**.cpp" } | ||
filter "configurations:Debug" | ||
defines { "DEBUG" } | ||
symbols "On" | ||
filter "configurations:Release" | ||
defines { "NDEBUG" } | ||
optimize "On" | ||
filter "platforms:x86_64" | ||
architecture "x86_64" | ||
""") | ||
c.save({"conanfile.py": conanfile, | ||
"premake5.lua": premake, | ||
"main.cpp": gen_function_cpp(name="main", includes=["matrix"], calls=["matrix"])}) | ||
c.run("build .") | ||
assert "main: Release!" in c.out | ||
assert "matrix/1.0: Hello World Release!" in c.out | ||
if platform.system() == "Windows": | ||
assert "main _M_X64 defined" in c.out | ||
else: | ||
assert "main __x86_64__ defined" in c.out | ||
c.run("build . -s build_type=Debug --build=missing") | ||
assert "main: Debug!" in c.out | ||
assert "matrix/1.0: Hello World Debug!" in c.out |