diff --git a/Setup.py b/Setup.py index 38ac0548..c6c3c8fc 100644 --- a/Setup.py +++ b/Setup.py @@ -3,6 +3,7 @@ import os import shutil from enum import Enum +import fileinput from argparse import ArgumentParser, ArgumentTypeError import platform @@ -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(): diff --git a/conanfile.py b/conanfile.py index 88d92e57..de5d6969 100644 --- a/conanfile.py +++ b/conanfile.py @@ -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 @@ -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")