aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/Conf.hpp59
-rw-r--r--src/Archive.cpp4
-rw-r--r--src/CmakeModule.cpp11
-rw-r--r--src/Conf.cpp194
-rw-r--r--tests/src/confTest/confTest.cpp19
-rw-r--r--tests/src/confTest/linux/x64/static/debug/libcool.a0
-rw-r--r--tests/src/confTest/linux/x64/static/release/libcool.a0
-rw-r--r--tests/src/confTest/platformConfig.conf41
8 files changed, 223 insertions, 105 deletions
diff --git a/include/Conf.hpp b/include/Conf.hpp
index 764b3f9..476e38b 100644
--- a/include/Conf.hpp
+++ b/include/Conf.hpp
@@ -109,32 +109,55 @@ namespace sibs
PLATFORM_WIN32,
PLATFORM_WIN64
};
+
+ const StringView CONFIGS[] = {
+ "config.win32",
+ "config.win32.static.debug",
+ "config.win32.static.release",
+
+ "config.win64",
+ "config.win64.static.debug",
+ "config.win64.static.release",
+
+ "config.linux32",
+ "config.linux32.static.debug",
+ "config.linux32.static.release",
+
+ "config.linux64",
+ "config.linux64.static.debug",
+ "config.linux64.static.release"
+ };
+ const int NUM_CONFIGS = 12;
// TODO: Detect this at runtime?
#if OS_TYPE == OS_TYPE_WINDOWS
#ifdef SIBS_ENV_32BIT
- const Platform SYSTEM_PLATFORM = Platform::PLATFORM_WIN32;
- const StringView CONFIG_SYSTEM_PLATFORM = "config.win32";
- const StringView CONFIG_STATIC_DEBUG_PLATFORM = "config.win32.static.debug";
- const StringView CONFIG_STATIC_RELEASE_PLATFORM = "config.win32.static.release";
+ #define SYSTEM_PLATFORM Platform::PLATFORM_WIN32
+ #define CONFIG_SYSTEM_PLATFORM 0
+ #define CONFIG_STATIC_DEBUG_PLATFORM 1
+ #define CONFIG_STATIC_RELEASE_PLATFORM 2
#else
- const Platform SYSTEM_PLATFORM = Platform::PLATFORM_WIN64;
- const StringView CONFIG_SYSTEM_PLATFORM = "config.win64";
- const StringView CONFIG_STATIC_DEBUG_PLATFORM = "config.win64.static.debug";
- const StringView CONFIG_STATIC_RELEASE_PLATFORM = "config.win64.static.release";
+ #define SYSTEM_PLATFORM Platform::PLATFORM_WIN64
+ #define CONFIG_SYSTEM_PLATFORM 3
+ #define CONFIG_STATIC_DEBUG_PLATFORM 4
+ #define CONFIG_STATIC_RELEASE_PLATFORM 5
#endif
+ #define CONFIG_STATIC_LIB_FILE_EXTENSION "lib"
+ #define CONFIG_DYNAMIC_LIB_FILE_EXTENSION "dll"
#elif OS_TYPE == OS_TYPE_LINUX
#ifdef SIBS_ENV_32BIT
- const Platform SYSTEM_PLATFORM = Platform::PLATFORM_LINUX32;
- const StringView CONFIG_SYSTEM_PLATFORM = "config.linux32";
- const StringView CONFIG_STATIC_DEBUG_PLATFORM = "config.linux32.static.debug";
- const StringView CONFIG_STATIC_RELEASE_PLATFORM = "config.linux32.static.release";
+ #define SYSTEM_PLATFORM Platform::PLATFORM_LINUX32
+ #define CONFIG_SYSTEM_PLATFORM 6
+ #define CONFIG_STATIC_DEBUG_PLATFORM 7
+ #define CONFIG_STATIC_RELEASE_PLATFORM 8
#else
- const Platform SYSTEM_PLATFORM = Platform::PLATFORM_LINUX64;
- const StringView CONFIG_SYSTEM_PLATFORM = "config.linux64";
- const StringView CONFIG_STATIC_DEBUG_PLATFORM = "config.linux64.static.debug";
- const StringView CONFIG_STATIC_RELEASE_PLATFORM = "config.linux64.static.release";
+ #define SYSTEM_PLATFORM Platform::PLATFORM_LINUX64
+ #define CONFIG_SYSTEM_PLATFORM 9
+ #define CONFIG_STATIC_DEBUG_PLATFORM 10
+ #define CONFIG_STATIC_RELEASE_PLATFORM 11
#endif
+ #define CONFIG_STATIC_LIB_FILE_EXTENSION "a"
+ #define CONFIG_DYNAMIC_LIB_FILE_EXTENSION "so"
#endif
bool containsPlatform(const std::vector<Platform> &platforms, Platform platform);
@@ -299,6 +322,10 @@ namespace sibs
virtual void finished() override;
void failInvalidFieldUnderObject(const StringView &fieldName) const;
private:
+ void parsePlatformConfigs(const StringView &fieldName, const ConfigValue &fieldValue);
+ void parsePlatformConfig(const StringView &fieldName, const ConfigValue &fieldValue);
+ void parsePlatformConfigStaticDebug(const StringView &fieldName, const ConfigValue &fieldValue);
+ void parsePlatformConfigStaticRelease(const StringView &fieldName, const ConfigValue &fieldValue);
void parseCmake(const StringView &fieldName, const ConfigValue &fieldValue, std::string &cmakeDir, std::string &cmakeArgs);
void validatePackageName() const;
protected:
diff --git a/src/Archive.cpp b/src/Archive.cpp
index 506b020..08106c3 100644
--- a/src/Archive.cpp
+++ b/src/Archive.cpp
@@ -45,7 +45,7 @@ namespace sibs
int r;
const void *buff;
size_t size;
- la_int64_t offset;
+ int64_t offset;
while(true)
{
@@ -178,4 +178,4 @@ namespace sibs
archive_write_free(ext);
return Result<bool>::Ok(true);
}
-} \ No newline at end of file
+}
diff --git a/src/CmakeModule.cpp b/src/CmakeModule.cpp
index 1995023..e05a65f 100644
--- a/src/CmakeModule.cpp
+++ b/src/CmakeModule.cpp
@@ -133,20 +133,14 @@ namespace sibs
if(config.getPackageType() != PackageType::EXECUTABLE)
{
- #if OS_TYPE == OS_TYPE_WINDOWS
- const _tinydir_char_t *libFileExtension = TINYDIR_STRING("lib");
- #elif OS_TYPE == OS_TYPE_LINUX
- const _tinydir_char_t *libFileExtension = TINYDIR_STRING("so");
- #endif
-
FileString libFile;
u64 libFileLastModified = 0;
string buildPathUtf8 = toUtf8(buildPath);
nprintf("Searching for library generate by cmake in build path: %s\n", buildPathUtf8.c_str());
- walkDirFiles(buildPath.c_str(), [&libFileExtension, &libFile, &libFileLastModified](tinydir_file *file)
+ walkDirFiles(buildPath.c_str(), [&libFile, &libFileLastModified](tinydir_file *file)
{
- if(_tinydir_strcmp(file->extension, libFileExtension) == 0)
+ if(_tinydir_strcmp(file->extension, CONFIG_DYNAMIC_LIB_FILE_EXTENSION) == 0)
{
u32 fileLastModified = getFileLastModifiedTime(file->path);
if(fileLastModified > libFileLastModified)
@@ -190,7 +184,6 @@ namespace sibs
// TODO: Clean this up. The below code is indentical to code in Ninja.cpp.......
string projectPathUtf8 = toUtf8(config.getProjectPath());
- printf("BUILD CMAKE MODULE!, num global include dirs: %d\n", config.getGlobalIncludeDirs().size());
for (const string &globalIncludeDir : config.getGlobalIncludeDirs())
{
string globalIncludeDirFull = projectPathUtf8;
diff --git a/src/Conf.cpp b/src/Conf.cpp
index 2d7db93..852fcd4 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -447,13 +447,13 @@ namespace sibs
{
case FileType::FILE_NOT_FOUND:
{
- string errMsg = "Path not found: ";
+ string errMsg = "Library path not found: ";
errMsg += libPath;
throw ParserException(errMsg);
}
case FileType::REGULAR:
{
- string errMsg = "Expected path ";
+ string errMsg = "Expected library path ";
errMsg += libPath;
errMsg += " to be a directory, was a regular file";
throw ParserException(errMsg);
@@ -462,7 +462,8 @@ namespace sibs
walkDirFiles(nativePath.c_str(), [&outputFiles](tinydir_file *file)
{
- outputFiles.push_back(toUtf8(file->path));
+ if(_tinydir_strcmp(file->extension, CONFIG_STATIC_LIB_FILE_EXTENSION) == 0)
+ outputFiles.push_back(toUtf8(file->path));
});
}
@@ -644,93 +645,34 @@ namespace sibs
else
failInvalidFieldUnderObject(name);
}
- else if(currentObject.equals("config"))
+ else if(currentObject.size >= 6 && strncmp(currentObject.data, "config", 6) == 0)
{
- if (name.equals("expose_include_dirs"))
+ if(currentObject.size == 6) // [config]
{
- if (value.isList())
+ if (name.equals("expose_include_dirs"))
{
- for (const StringView &includeDir : value.asList())
+ if (value.isList())
{
- exposeIncludeDirs.emplace_back(string(includeDir.data, includeDir.size));
+ for (const StringView &includeDir : value.asList())
+ {
+ exposeIncludeDirs.emplace_back(string(includeDir.data, includeDir.size));
+ }
}
- }
- else
- {
- string errMsg = "Expected ";
- errMsg += string(currentObject.data, currentObject.size);
- errMsg += " to be a list, was a single value";
- throw ParserException(errMsg);
- }
- }
- else
- failInvalidFieldUnderObject(name);
- }
- else if (currentObject.equals(CONFIG_SYSTEM_PLATFORM))
- {
- if (name.equals("expose_include_dirs"))
- {
- if (value.isList())
- {
- for (const StringView &includeDir : value.asList())
+ else
{
- exposeIncludeDirs.emplace_back(string(includeDir.data, includeDir.size));
+ string errMsg = "Expected ";
+ errMsg += string(currentObject.data, currentObject.size);
+ errMsg += " to be a list, was a single value";
+ throw ParserException(errMsg);
}
}
else
- {
- string errMsg = "Expected ";
- errMsg += string(currentObject.data, currentObject.size);
- errMsg += " to be a list, was a single value";
- throw ParserException(errMsg);
- }
+ failInvalidFieldUnderObject(name);
}
- else
- failInvalidFieldUnderObject(name);
- }
- else if (currentObject.equals(CONFIG_STATIC_DEBUG_PLATFORM))
- {
- if (name.equals("lib"))
+ else // [config.*]
{
- if (value.isSingle())
- {
- string debugStaticLibPath = toUtf8(projectPath);
- debugStaticLibPath += "/";
- debugStaticLibPath += string(value.asSingle().data, value.asSingle().size);
- getLibFiles(debugStaticLibPath, debugStaticLibs);
- }
- else
- {
- string errMsg = "Expected ";
- errMsg += string(currentObject.data, currentObject.size);
- errMsg += " to be a single value, was a list";
- throw ParserException(errMsg);
- }
+ parsePlatformConfigs(name, value);
}
- else
- failInvalidFieldUnderObject(name);
- }
- else if (currentObject.equals(CONFIG_STATIC_RELEASE_PLATFORM))
- {
- if (name.equals("lib"))
- {
- if (value.isSingle())
- {
- string releaseStaticLibPath = toUtf8(projectPath);
- releaseStaticLibPath += "/";
- releaseStaticLibPath += string(value.asSingle().data, value.asSingle().size);
- getLibFiles(releaseStaticLibPath, releaseStaticLibs);
- }
- else
- {
- string errMsg = "Expected ";
- errMsg += string(currentObject.data, currentObject.size);
- errMsg += " to be a single value, was a list";
- throw ParserException(errMsg);
- }
- }
- else
- failInvalidFieldUnderObject(name);
}
else if(currentObject.equals("dependencies"))
{
@@ -766,6 +708,102 @@ namespace sibs
}
}
+ void SibsConfig::parsePlatformConfigs(const StringView &fieldName, const ConfigValue &fieldValue)
+ {
+ for(int i = 0; i < NUM_CONFIGS; ++i)
+ {
+ const StringView &config = CONFIGS[i];
+ if(currentObject.equals(config))
+ {
+ switch(i)
+ {
+ case CONFIG_SYSTEM_PLATFORM:
+ return parsePlatformConfig(fieldName, fieldValue);
+ case CONFIG_STATIC_DEBUG_PLATFORM:
+ return parsePlatformConfigStaticDebug(fieldName, fieldValue);
+ case CONFIG_STATIC_RELEASE_PLATFORM:
+ return parsePlatformConfigStaticRelease(fieldName, fieldValue);
+ default:
+ return;
+ }
+ }
+ }
+
+ string errMsg = "Invalid config object \"";
+ errMsg += string(currentObject.data, currentObject.size);
+ errMsg += "\"";
+ throw ParserException(errMsg);
+ }
+
+ void SibsConfig::parsePlatformConfig(const StringView &fieldName, const ConfigValue &fieldValue)
+ {
+ if (fieldName.equals("expose_include_dirs"))
+ {
+ if (fieldValue.isList())
+ {
+ for (const StringView &includeDir : fieldValue.asList())
+ {
+ exposeIncludeDirs.emplace_back(string(includeDir.data, includeDir.size));
+ }
+ }
+ else
+ {
+ string errMsg = "Expected ";
+ errMsg += string(currentObject.data, currentObject.size);
+ errMsg += " to be a list, was a single value";
+ throw ParserException(errMsg);
+ }
+ }
+ else
+ failInvalidFieldUnderObject(fieldName);
+ }
+
+ void SibsConfig::parsePlatformConfigStaticDebug(const StringView &fieldName, const ConfigValue &fieldValue)
+ {
+ if (fieldName.equals("lib"))
+ {
+ if (fieldValue.isSingle())
+ {
+ string debugStaticLibPath = toUtf8(projectPath);
+ debugStaticLibPath += "/";
+ debugStaticLibPath += string(fieldValue.asSingle().data, fieldValue.asSingle().size);
+ getLibFiles(debugStaticLibPath, debugStaticLibs);
+ }
+ else
+ {
+ string errMsg = "Expected ";
+ errMsg += string(currentObject.data, currentObject.size);
+ errMsg += " to be a single value, was a list";
+ throw ParserException(errMsg);
+ }
+ }
+ else
+ failInvalidFieldUnderObject(fieldName);
+ }
+
+ void SibsConfig::parsePlatformConfigStaticRelease(const StringView &fieldName, const ConfigValue &fieldValue)
+ {
+ if (fieldName.equals("lib"))
+ {
+ if (fieldValue.isSingle())
+ {
+ string releaseStaticLibPath = toUtf8(projectPath);
+ releaseStaticLibPath += "/";
+ releaseStaticLibPath += string(fieldValue.asSingle().data, fieldValue.asSingle().size);
+ getLibFiles(releaseStaticLibPath, releaseStaticLibs);
+ }
+ else
+ {
+ string errMsg = "Expected ";
+ errMsg += string(currentObject.data, currentObject.size);
+ errMsg += " to be a single value, was a list";
+ throw ParserException(errMsg);
+ }
+ }
+ else
+ failInvalidFieldUnderObject(fieldName);
+ }
+
void SibsConfig::parseCmake(const StringView &fieldName, const ConfigValue &fieldValue, string &cmakeDir, string &cmakeArgs)
{
if(fieldName.equals("dir"))
diff --git a/tests/src/confTest/confTest.cpp b/tests/src/confTest/confTest.cpp
index a32f2ae..94cdb11 100644
--- a/tests/src/confTest/confTest.cpp
+++ b/tests/src/confTest/confTest.cpp
@@ -55,3 +55,22 @@ TEST_CASE("parse config - invalid field")
REQUIRE(result.isErr());
REQUIRE(result.getErrMsg() == "Invalid field \"invalidField\" under object \"package\"");
}
+
+TEST_CASE("parse config - use different config for different platforms")
+{
+ SibsConfig sibsConfig(Compiler::GCC, TINYDIR_STRING("tests/src/confTest"));
+ Result<bool> result = Config::readFromFile(TINYDIR_STRING("tests/src/confTest/platformConfig.conf"), sibsConfig);
+ if(result.isErr())
+ {
+ fprintf(stderr, "%s", result.getErrMsg().c_str());
+ exit(1);
+ }
+
+ #if OS_TYPE == OS_TYPE_LINUX and defined(SIBS_ENV_64BIT)
+ #ifdef DEBUG
+ REQUIRE(sibsConfig.getDebugStaticLibs()[0] == TINYDIR_STRING("tests/src/confTest/linux/x64/static/debug/libcool.a"));
+ #else
+ REQUIRE(sibsConfig.getDebugStaticLibs()[0] == TINYDIR_STRING("tests/src/confTest/linux/x64/static/release/libcool.a"));
+ #endif
+ #endif
+}
diff --git a/tests/src/confTest/linux/x64/static/debug/libcool.a b/tests/src/confTest/linux/x64/static/debug/libcool.a
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/src/confTest/linux/x64/static/debug/libcool.a
diff --git a/tests/src/confTest/linux/x64/static/release/libcool.a b/tests/src/confTest/linux/x64/static/release/libcool.a
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/src/confTest/linux/x64/static/release/libcool.a
diff --git a/tests/src/confTest/platformConfig.conf b/tests/src/confTest/platformConfig.conf
new file mode 100644
index 0000000..e74ab76
--- /dev/null
+++ b/tests/src/confTest/platformConfig.conf
@@ -0,0 +1,41 @@
+[package]
+name = "glew"
+version = "2.1.0"
+type = "library"
+platforms = ["any"]
+
+[config.linux32]
+expose_include_dirs = ["include_linux32"]
+
+[config.linux32.static.debug]
+lib = "linux/x86/static/debug"
+
+[config.linux32.static.release]
+lib = "linux/x86/static/release"
+
+[config.linux64]
+expose_include_dirs = ["include_linux64"]
+
+[config.linux64.static.debug]
+lib = "linux/x64/static/debug"
+
+[config.linux64.static.release]
+lib = "linux/x64/static/release"
+
+[config.win32]
+expose_include_dirs = ["include_win32"]
+
+[config.win32.static.debug]
+lib = "windows/x86/static/debug"
+
+[config.win32.static.release]
+lib = "windows/x86/static/release"
+
+[config.win64]
+expose_include_dirs = ["include_win64"]
+
+[config.win64.static.debug]
+lib = "windows/x64/static/debug"
+
+[config.win64.static.release]
+lib = "windows/x64/static/release"