aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-21 11:06:17 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-21 11:06:17 +0200
commit445fd7c1968112664b1fbbe6215ed76609cfb8ac (patch)
treec46fbb8eb191945dc9ff5da48d9288fe0b206436
parent0941a99aa4ac45ebe4bea4705e4cd24aec156bf5 (diff)
Add lang.cpp.enable_exceptions option to enable/disable options, add c20, add c++03, c++98 and c++20
-rw-r--r--README.md11
-rw-r--r--backend/ninja/Ninja.cpp9
-rw-r--r--include/Conf.hpp10
-rw-r--r--src/Conf.cpp40
-rw-r--r--src/main.cpp6
5 files changed, 68 insertions, 8 deletions
diff --git a/README.md b/README.md
index 17b4b0f..8bdf058 100644
--- a/README.md
+++ b/README.md
@@ -116,6 +116,7 @@ version = "c11"
[lang.cpp]
version = "c++14"
+enable_exceptions = "true"
[define]
BOOST_ASIO_SEPERATE_COMPILATION = "1"
@@ -194,8 +195,14 @@ The best way to do this is to create another git project for the dependency and
Using sub projects allows you to modify dependency and propagate changes to dependant project without pushing changes to remote git repository (faster development).
## lang.*
Optional. Allows you to change language specific configuration. \[lang.c] is for C and \[lang.cpp] is for C++.
-Version specifies the language version, for \[lang.c] the version can be ansi (alias for c89), c89, c99 or c11 - if not set, c11 will be used.
-For \[lang.cpp] the version can be c++11, c++14 or c++17 - if not set, c++14 will be used
+## lang.c
+### version
+Optional. The c standard version to use. Should be either ansi (alias for c89), c89, c99, c11 or c17. The default value is c11.
+## lang.cpp
+### version
+Optional. The c++ standard version to use. Should be either c++03, c++98, c++11, c++14, c++17 or c++20. The default value is c++14.
+### enable_exceptions
+Optional. This option should be either "true" or "false" and specifies if exceptions should be enabled for the project. The default value is "true".
## define
Optional. A list of definitions which are specified in name-value pairs where the name is the preprocessor to define (in c: #define name value)
## define.static
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index f4beeb8..456eb27 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -122,6 +122,7 @@ namespace backend
case CVersion::C89: return { ninja::NinjaArg("-std=c89"), ninja::NinjaArg("-pedantic") };
case CVersion::C99: return { ninja::NinjaArg("-std=c99"), ninja::NinjaArg("-pedantic") };
case CVersion::C11: return { ninja::NinjaArg("-std=c11"), ninja::NinjaArg("-pedantic") };
+ case CVersion::C20: return { ninja::NinjaArg("-std=c20"), ninja::NinjaArg("-pedantic") };
}
break;
}
@@ -147,9 +148,12 @@ namespace backend
{
switch(cppVersion)
{
+ case CPPVersion::CPP03: return { ninja::NinjaArg("-std=c++03"), ninja::NinjaArg("-pedantic") };
+ case CPPVersion::CPP98: return { ninja::NinjaArg("-std=c++98"), ninja::NinjaArg("-pedantic") };
case CPPVersion::CPP11: return { ninja::NinjaArg("-std=c++11"), ninja::NinjaArg("-pedantic") };
case CPPVersion::CPP14: return { ninja::NinjaArg("-std=c++14"), ninja::NinjaArg("-pedantic") };
case CPPVersion::CPP17: return { ninja::NinjaArg("-std=c++17"), ninja::NinjaArg("-pedantic") };
+ case CPPVersion::CPP20: return { ninja::NinjaArg("-std=c++20"), ninja::NinjaArg("-pedantic") };
}
break;
}
@@ -158,9 +162,12 @@ namespace backend
switch(cppVersion)
{
// Use /Za flag?
+ case CPPVersion::CPP03: return { ninja::NinjaArg("/std:c++03") };
+ case CPPVersion::CPP98: return { ninja::NinjaArg("/std:c++98") };
case CPPVersion::CPP11: return { ninja::NinjaArg("/std:c++11") };
case CPPVersion::CPP14: return { ninja::NinjaArg("/std:c++14") };
case CPPVersion::CPP17: return { ninja::NinjaArg("/std:c++17") };
+ case CPPVersion::CPP20: return { ninja::NinjaArg("/std:c++20") };
}
break;
}
@@ -1006,7 +1013,7 @@ namespace backend
compileCppCommand = compileCCommand;
compileCppCommand.insert(compileCppCommand.end(), {
- ninja::NinjaArg("-fexceptions"),
+ ninja::NinjaArg(config.enableExceptions ? "-fexceptions" : "-fno-exceptions"),
ninja::NinjaArg("-Wnon-virtual-dtor")
});
diff --git a/include/Conf.hpp b/include/Conf.hpp
index a93b44f..574cf94 100644
--- a/include/Conf.hpp
+++ b/include/Conf.hpp
@@ -116,14 +116,18 @@ namespace sibs
{
C89, // aka ansi
C99,
- C11
+ C11,
+ C20
};
enum class CPPVersion
{
+ CPP03,
+ CPP98,
CPP11,
CPP14,
- CPP17
+ CPP17,
+ CPP20
};
enum class Language
@@ -227,6 +231,7 @@ namespace sibs
sanitize(Sanitize::NONE),
showWarnings(false),
errorOnWarning(false),
+ enableExceptions(true),
zigTestAllFiles(false),
packaging(false),
bundling(false),
@@ -420,6 +425,7 @@ namespace sibs
std::vector<FileString> zigTestFiles;
bool showWarnings;
bool errorOnWarning;
+ bool enableExceptions;
bool zigTestAllFiles;
bool packaging;
bool bundling;
diff --git a/src/Conf.cpp b/src/Conf.cpp
index 543c8d9..c2302e4 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -1125,9 +1125,13 @@ namespace sibs
{
cVersion = CVersion::C11;
}
+ else if(cVersionStr.equals("c20"))
+ {
+ cVersion = CVersion::C20;
+ }
else
{
- string errMsg = "Expected lang.c.version to be ansi, c89, c99 or c11, was ";
+ string errMsg = "Expected lang.c.version to be ansi, c89, c99, c11, c20, was ";
errMsg += string(cVersionStr.data, cVersionStr.size);
throw ParserException(errMsg);
}
@@ -1147,7 +1151,15 @@ namespace sibs
if(fieldValue.isSingle())
{
const StringView &cppVersionStr = fieldValue.asSingle();
- if(cppVersionStr.equals("c++11"))
+ if(cppVersionStr.equals("c++03"))
+ {
+ cppVersion = CPPVersion::CPP03;
+ }
+ else if(cppVersionStr.equals("c++98"))
+ {
+ cppVersion = CPPVersion::CPP98;
+ }
+ else if(cppVersionStr.equals("c++11"))
{
cppVersion = CPPVersion::CPP11;
}
@@ -1159,9 +1171,13 @@ namespace sibs
{
cppVersion = CPPVersion::CPP17;
}
+ else if(cppVersionStr.equals("c++20"))
+ {
+ cppVersion = CPPVersion::CPP20;
+ }
else
{
- string errMsg = "Expected lang.cpp.version to be c++11, c++14 or c++17, was ";
+ string errMsg = "Expected lang.cpp.version to be c++03, c++98, c++11, c++14, c++17 or c++20, was ";
errMsg += string(cppVersionStr.data, cppVersionStr.size);
throw ParserException(errMsg);
}
@@ -1169,6 +1185,24 @@ namespace sibs
else
throw ParserException("Expected lang.cpp.version to be a single value, was a list");
}
+ else if(fieldName.equals("enable_exceptions"))
+ {
+ if (fieldValue.isSingle())
+ {
+ StringView value_str = fieldValue.asSingle();
+ bool value_bool = false;
+ if(value_str.equals("true"))
+ value_bool = true;
+ else if(value_str.equals("false"))
+ value_bool = false;
+ else
+ throw ParserException("Expected " + string(currentObject.data, currentObject.size) + ".enable_exceptions to be either true or false");
+
+ enableExceptions = value_bool;
+ }
+ else
+ throw ParserException("Expected " + string(currentObject.data, currentObject.size) + ".enable_exceptions to be a single value, was a list");
+ }
else
failInvalidFieldUnderObject(fieldName);
}
diff --git a/src/main.cpp b/src/main.cpp
index 5c3ad8c..00b7e92 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -368,6 +368,12 @@ static int buildProject(const FileString &projectPath, const FileString &project
{
FileString buildPath;
readSibsConfig(projectPath, projectConfFilePath, sibsConfig, buildPath);
+
+ if(run && sibsConfig.getPackageType() != PackageType::EXECUTABLE) {
+ ferr << "Error: sibs run can only be used with executable projects" << endl;
+ exit(7);
+ }
+
// Test project has the main project as dependency, and therefore the main project can't be built as an executable
if(sibsConfig.shouldBuildTests())
{