aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@dec05ebas-iMac.local>2018-09-29 22:03:50 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commite7ebd55c31148089eb54ffbd708216c1c7cb09ff (patch)
tree2a55e1bfe6ce3e2f8ca6c21d8046565abcafd4d9
parent19370a2213efe960e959832145a165d6e2ad6a65 (diff)
Add support for macos
-rw-r--r--.vscode/c_cpp_properties.json17
-rw-r--r--.vscode/settings.json63
-rw-r--r--CMakeLists.txt9
-rw-r--r--README.md1
-rw-r--r--backend/ninja/Ninja.cpp25
-rwxr-xr-xcmake/install.sh18
-rw-r--r--include/Conf.hpp31
-rw-r--r--include/env.hpp5
-rwxr-xr-xinstall.sh12
-rw-r--r--project.conf2
-rw-r--r--src/Conf.cpp12
-rw-r--r--src/FileUtil.cpp2
12 files changed, 101 insertions, 96 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
deleted file mode 100644
index 6ffabe5..0000000
--- a/.vscode/c_cpp_properties.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "configurations": [
- {
- "name": "Linux",
- "includePath": [
- "${workspaceFolder}/**"
- ],
- "defines": [],
- "compilerPath": "/opt/cuda/bin/gcc",
- "cStandard": "c11",
- "cppStandard": "c++17",
- "intelliSenseMode": "clang-x64",
- "compileCommands": "${workspaceFolder}/compile_commands.json"
- }
- ],
- "version": 4
-} \ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
deleted file mode 100644
index 57115ea..0000000
--- a/.vscode/settings.json
+++ /dev/null
@@ -1,63 +0,0 @@
-{
- "files.associations": {
- "bitset": "cpp",
- "vector": "cpp",
- "optional": "cpp",
- "string_view": "cpp",
- "system_error": "cpp",
- "thread": "cpp",
- "typeindex": "cpp",
- "variant": "cpp",
- "array": "cpp",
- "initializer_list": "cpp",
- "utility": "cpp",
- "hash_map": "cpp",
- "valarray": "cpp",
- "*.tcc": "cpp",
- "cctype": "cpp",
- "clocale": "cpp",
- "cmath": "cpp",
- "cstdarg": "cpp",
- "cstddef": "cpp",
- "cstdio": "cpp",
- "cstdlib": "cpp",
- "cstring": "cpp",
- "ctime": "cpp",
- "cwchar": "cpp",
- "cwctype": "cpp",
- "atomic": "cpp",
- "strstream": "cpp",
- "chrono": "cpp",
- "cinttypes": "cpp",
- "codecvt": "cpp",
- "complex": "cpp",
- "condition_variable": "cpp",
- "cstdint": "cpp",
- "deque": "cpp",
- "list": "cpp",
- "unordered_map": "cpp",
- "unordered_set": "cpp",
- "exception": "cpp",
- "fstream": "cpp",
- "functional": "cpp",
- "iomanip": "cpp",
- "iosfwd": "cpp",
- "iostream": "cpp",
- "istream": "cpp",
- "limits": "cpp",
- "memory": "cpp",
- "mutex": "cpp",
- "new": "cpp",
- "numeric": "cpp",
- "ostream": "cpp",
- "ratio": "cpp",
- "sstream": "cpp",
- "stdexcept": "cpp",
- "streambuf": "cpp",
- "type_traits": "cpp",
- "tuple": "cpp",
- "typeinfo": "cpp",
- "__config": "cpp",
- "__nullptr": "cpp"
- }
-} \ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a58a3cd..a7cd470 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,10 +22,15 @@ set(SOURCE_FILES
depends/libninja/src/Ninja.cpp)
find_package(CURL REQUIRED)
-find_package(LibArchive REQUIRED)
-add_executable(sibs ${SOURCE_FILES})
+if(APPLE)
+ set(LibArchive_LIBRARIES "/usr/local/opt/libarchive/lib/libarchive.dylib")
+ set(LibArchive_INCLUDE_DIR "/usr/local/opt/libarchive/include")
+else()
+ find_package(LibArchive REQUIRED)
+endif()
+add_executable(sibs ${SOURCE_FILES})
include_directories(${CURL_INCLUDE_DIR} ${LibArchive_INCLUDE_DIR} "depends/libninja/include")
if(WIN32)
diff --git a/README.md b/README.md
index d59b322..4879d33 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,7 @@ Dependencies that are required to build sibs from source are:
`libcurl, libarchive, libgit2, curl`
`Ninja (build system)` needs to be installed on the system to be able to build projects. CMake can be required for some projects that uses cmake files to build project instead of sibs.
+Ccache is currently required on non-windows platforms but it will later be removed and replaced with sibs own caching system. Ninja will also be removed as backend build system.
# IDE support
Sibs generates a compile_commands.json in the project root directory when executing `sibs build` and tools that support clang completion can be used, such as YouCompleteMe.
There are several editors that support YouCompleteMe, including Vim, Emacs and Visual Studio Code.
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index ac683a0..3d71574 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -635,6 +635,16 @@ namespace backend
Result<bool> Ninja::build(const SibsConfig &config, const _tinydir_char_t *savePath, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback, GlobalIncludeDirCallbackFunc globalIncludeDirCallback)
{
+ bool isCCompilerClang = false;
+ Result<ExecResult> cCompilerVersion = exec("cc --version");
+ if(cCompilerVersion && cCompilerVersion.unwrap().exitCode == 0 && cCompilerVersion.unwrap().execStdout.find("clang") != string::npos)
+ isCCompilerClang = true;
+
+ bool isCppCompilerClang = false;
+ Result<ExecResult> cppCompilerVersion = exec("c++ --version");
+ if(cppCompilerVersion && cppCompilerVersion.unwrap().exitCode == 0 && cppCompilerVersion.unwrap().execStdout.find("clang") != string::npos)
+ isCppCompilerClang = true;
+
Result<bool> createBuildDirResult = createDirectoryRecursive(savePath);
if (!createBuildDirResult)
return createBuildDirResult;
@@ -1073,6 +1083,15 @@ namespace backend
string projectGeneratedBinaryFlags;
if (!sourceFiles.empty() && !zigTest)
{
+ string noUndefinedFlag;
+ if(!onlyZigFiles)
+ {
+ if(usesCppFiles)
+ noUndefinedFlag = isCppCompilerClang ? "-Wl,-undefined,error" : "-Wl,--no-undefined,--as-needed";
+ else
+ noUndefinedFlag = isCCompilerClang ? "-Wl,-undefined,error" : "-Wl,--no-undefined,--as-needed";
+ }
+
string projectGeneratedBinary = "\"";
projectGeneratedBinary += savePathUtf8;
projectGeneratedBinary += "/";
@@ -1119,7 +1138,7 @@ namespace backend
ninja::NinjaArg::createRaw("-o"),
ninja::NinjaArg::createRaw("$out"),
ninja::NinjaArg::createRaw("$in"),
- ninja::NinjaArg::createRaw("-Wl,--no-undefined,--as-needed")
+ ninja::NinjaArg::createRaw(noUndefinedFlag)
});
if(config.getSanitize())
@@ -1307,7 +1326,7 @@ namespace backend
ninja::NinjaArg::createRaw("-shared"),
ninja::NinjaArg::createRaw("-o"),
ninja::NinjaArg::createRaw("$out"),
- ninja::NinjaArg::createRaw("-Wl,--no-undefined,--as-needed")
+ ninja::NinjaArg::createRaw(noUndefinedFlag)
});
if(config.getSanitize())
@@ -1529,7 +1548,7 @@ namespace backend
Result<bool> Ninja::compile(const _tinydir_char_t *buildFilePath)
{
-#if OS_FAMILY == OS_FAMILY_POSIX
+#if OS_TYPE == OS_TYPE_LINUX
FileString command = TINYDIR_STRING("script -eqc 'ninja -C \"");
command += buildFilePath;
command += TINYDIR_STRING("\"' /dev/null");
diff --git a/cmake/install.sh b/cmake/install.sh
index 384ad5d..595fd26 100755
--- a/cmake/install.sh
+++ b/cmake/install.sh
@@ -1,12 +1,24 @@
-#!/usr/bin/env bash
+#!/bin/sh
set -e
+case "$(uname -s)" in
+ Linux*) machine="Linux" ;;
+ Darwin*) machine="Mac" ;;
+ *) echo "The install file can only be run on linux and mac" && exit 1 ;;
+esac
+
scriptpath="$(dirname "$0")"
mkdir -p "$scriptpath/build/release"
cd "$scriptpath/build/release"
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ../../../
ninja
-sudo cp sibs /usr/bin/
-echo "Copied $scriptpath/build/release/sibs to /usr/bin/sibs"
+
+case $machine in
+ Linux) bin_dir="/usr/bin" ;;
+ Mac) bin_dir="/usr/local/bin" ;;
+esac
+
+sudo cp sibs "$bin_dir"
+echo "Copied $scriptpath/build/release/sibs to $bin_dir/sibs"
echo "Installation successful!"
diff --git a/include/Conf.hpp b/include/Conf.hpp
index 709d285..7e5bf69 100644
--- a/include/Conf.hpp
+++ b/include/Conf.hpp
@@ -117,7 +117,10 @@ namespace sibs
PLATFORM_LINUX64,
PLATFORM_WIN32,
- PLATFORM_WIN64
+ PLATFORM_WIN64,
+
+ PLATFORM_MACOS32,
+ PLATFORM_MACOS64
};
enum class CVersion
@@ -163,7 +166,15 @@ namespace sibs
"config.linux64",
"config.linux64.static.debug",
- "config.linux64.static.release"
+ "config.linux64.static.release",
+
+ "config.macos32",
+ "config.macos32.static.debug",
+ "config.macos32.static.release"
+
+ "config.macos64",
+ "config.macos64.static.debug",
+ "config.macos64.static.release"
};
const int NUM_CONFIGS = 12;
@@ -199,6 +210,22 @@ namespace sibs
#endif
#define CONFIG_STATIC_LIB_FILE_EXTENSION "a"
#define CONFIG_DYNAMIC_LIB_FILE_EXTENSION "so"
+ #elif OS_TYPE == OS_TYPE_APPLE
+ #ifdef SIBS_ENV_32BIT
+ const Platform SYSTEM_PLATFORM = PLATFORM_MACOS32;
+ #define SYSTEM_PLATFORM_NAME "macos32"
+ #define CONFIG_SYSTEM_PLATFORM 12
+ #define CONFIG_STATIC_DEBUG_PLATFORM 13
+ #define CONFIG_STATIC_RELEASE_PLATFORM 14
+ #else
+ const Platform SYSTEM_PLATFORM = PLATFORM_MACOS64;
+ #define SYSTEM_PLATFORM_NAME "macos64"
+ #define CONFIG_SYSTEM_PLATFORM 15
+ #define CONFIG_STATIC_DEBUG_PLATFORM 16
+ #define CONFIG_STATIC_RELEASE_PLATFORM 17
+ #endif
+ #define CONFIG_STATIC_LIB_FILE_EXTENSION "a"
+ #define CONFIG_DYNAMIC_LIB_FILE_EXTENSION "dylib"
#endif
bool containsPlatform(const std::vector<Platform> &platforms, Platform platform);
diff --git a/include/env.hpp b/include/env.hpp
index 1ea55ca..fa9c860 100644
--- a/include/env.hpp
+++ b/include/env.hpp
@@ -6,6 +6,7 @@
#define OS_TYPE_WINDOWS 0
#define OS_TYPE_LINUX 1
+#define OS_TYPE_APPLE 2
#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN64)
@@ -39,6 +40,10 @@
#define OS_TYPE OS_TYPE_LINUX
#endif
+#ifdef __APPLE__
+ #define OS_TYPE OS_TYPE_APPLE
+#endif
+
#if defined(__GNUC__)
#if defined(__x86_64__) || defined(__pc64__)
#define SIBS_ENV_64BIT
diff --git a/install.sh b/install.sh
index c73d777..775fa6b 100755
--- a/install.sh
+++ b/install.sh
@@ -2,8 +2,14 @@
set -e
+case "$(uname -s)" in
+ Linux*) bin_dir="/usr/bin" ;;
+ Darwin*) bin_dir="/usr/local/bin" ;;
+ *) echo "The install file can only be run on linux and mac" && exit 1 ;;
+esac
+
project_dir=`dirname $0`
sibs build $project_dir --release
-sudo cp "$project_dir/sibs-build/release/sibs" "/usr/bin/sibs"
-echo "Copied $project_dir/sibs-build/release/sibs to /usr/bin/sibs"
-echo "Installation successful!" \ No newline at end of file
+sudo cp "$project_dir/sibs-build/release/sibs" "$bin_dir/sibs"
+echo "Copied $project_dir/sibs-build/release/sibs to $bin_dir/sibs"
+echo "Installation successful!"
diff --git a/project.conf b/project.conf
index 6bf8884..48b19f4 100644
--- a/project.conf
+++ b/project.conf
@@ -3,7 +3,7 @@ name = "sibs"
type = "executable"
version = "0.1.5"
authors = ["DEC05EBA <0xdec05eba@gmail.com>"]
-platforms = ["linux32", "linux64", "win64"]
+platforms = ["linux32", "linux64", "win64", "macos32", "macos64"]
[config]
ignore_dirs = ["cmake", "cmake-build-debug", "build", "distribute", "examples", "msvc", "cmake_msvc"]
diff --git a/src/Conf.cpp b/src/Conf.cpp
index bad3c01..6645913 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -532,6 +532,8 @@ namespace sibs
case PLATFORM_LINUX64: return "linux64";
case PLATFORM_WIN32: return "win32";
case PLATFORM_WIN64: return "win64";
+ case PLATFORM_MACOS32: return "macos32";
+ case PLATFORM_MACOS64: return "macos64";
default: return nullptr;
}
}
@@ -801,11 +803,19 @@ namespace sibs
{
platforms.push_back(PLATFORM_WIN64);
}
+ else if (platform.equals("macos32"))
+ {
+ platforms.push_back(PLATFORM_MACOS32);
+ }
+ else if (platform.equals("macos64"))
+ {
+ platforms.push_back(PLATFORM_MACOS64);
+ }
else
{
string errMsg = "package.platforms contains invalid platform \"";
errMsg += string(platform.data, platform.size);
- errMsg += "\". Expected platform to be one of: any, linux32, linux64, win32 or win64";
+ errMsg += "\". Expected platform to be one of: any, linux32, linux64, win32, win64, macos32 or macos64";
throw ParserException(errMsg);
}
}
diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp
index 222edbb..e3d4c3c 100644
--- a/src/FileUtil.cpp
+++ b/src/FileUtil.cpp
@@ -129,7 +129,7 @@ namespace sibs
{
struct stat64 fileStat;
if (stat64(path, &fileStat) == 0)
- return Result<u64>::Ok(fileStat.st_mtim.tv_sec);
+ return Result<u64>::Ok(fileStat.st_mtime);
else
{
string errMsg = "File not found: ";