Skip to content

Commit

Permalink
Conan use default profile (#140)
Browse files Browse the repository at this point in the history
* Use conan's default profile is no profile matches

* Check if default profile already exists.

* Windows support

* Force "compiler.cppstd" to gnu17/17

* Add additional c++ version check

---------

Co-authored-by: Philipp Basler <[email protected]>
Co-authored-by: Philipp Basler <[email protected]>
  • Loading branch information
3 people authored May 10, 2024
1 parent 5bad00e commit 486fc37
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 23 additions & 3 deletions Setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import shutil
from enum import Enum
import fileinput
from argparse import ArgumentParser, ArgumentTypeError
import platform

Expand Down Expand Up @@ -60,13 +61,32 @@ def get_profile(os: str, arch: str, build_type: BuildMode):

return profile

def set_setting(file, setting, value):
for line in fileinput.input([file], inplace=True):
if line.strip().startswith(setting):
line = setting + "=" + value + "\n"
sys.stdout.write(line)

def check_profile(profile):
path = os.path.join("profiles", "BSMPT", profile)
if not os.path.isfile(path):
raise Exception(
f"The desired profile {profile} does not exist in BSMPT/profiles. Please create it."
)
conan_home = subprocess.check_output("conan config home".split(), encoding="UTF-8").split("\n")[0]
print(f"Profile does not exist in BSMPT/profiles.\nUsing profile {profile} created from the default profile. Change it accordingly.")
if not os.path.isfile(conan_home + "/profiles/default"):
cmd = "conan profile detect".split()
subprocess.check_output(cmd)
if (sys.platform != "win32"):
cmd = "cp " + conan_home + "/profiles/default profiles/BSMPT/" + str(profile)
subprocess.check_call(cmd, shell=True)
set_setting(path, "compiler.cppstd", "gnu17")

else:
cmd = "copy " + conan_home + "\\profiles\\default profiles\\BSMPT\\" + str(profile)
subprocess.check_call(cmd, shell=True)
set_setting(path, "compiler.cppstd", "17")

setup_profiles()
check_profile(profile)


def get_gcc_version():
Expand Down
4 changes: 3 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from conan import ConanFile
from conan import ConanFile, tools
from conan.tools.cmake import cmake_layout, CMakeToolchain
from conan.tools.system.package_manager import Apt
from conan.errors import ConanInvalidConfiguration
Expand Down Expand Up @@ -82,3 +82,5 @@ def validate(self):

if self.settings.os != "Linux" and self.options.EnableCoverage:
raise ConanInvalidConfiguration("We depend on lcov for coverage.")

tools.build.check_min_cppstd(self, "17")

0 comments on commit 486fc37

Please sign in to comment.