mirror of
https://github.com/darlinghq/xcbuild.git
synced 2024-11-27 05:50:27 +00:00
Fixes for Linux and GCC builds.
- Use add_compile_options() in CMake to avoid duplicate lines. - Add missing includes as needed for Linux compilation. - Add required macro to access ftruncate() on Linux in C99 mode. - Switch to C++11 random numbers instead of arc4random for portability. - Workaround GCC issue with references to packed struct fields. - Fix missing default case required by GCC.
This commit is contained in:
parent
c1a1f83277
commit
2c18367d68
@ -19,25 +19,23 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
#set(CMAKE_BUILD_TYPE "Release")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
||||
|
||||
# Enable all warnings.
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
|
||||
add_compile_options(-Wall -Werror)
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")
|
||||
add_compile_options(-Wno-multichar -Wno-sign-compare)
|
||||
endif ()
|
||||
|
||||
# Enable color diagnostics.
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
|
||||
add_compile_options(-fcolor-diagnostics)
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER "5.0")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color")
|
||||
endif ()
|
||||
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics")
|
||||
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND "${CMAKE_C_COMPILER_VERSION}" VERSION_GREATER "5.0")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color")
|
||||
add_compile_options(-fdiagnostics-color)
|
||||
endif ()
|
||||
|
||||
# Enable unit testing.
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <acdriver/Output.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using acdriver::Output;
|
||||
|
||||
Output::
|
||||
@ -53,5 +55,7 @@ serialize(Format format) const
|
||||
return std::vector<uint8_t>(output.begin(), output.end());
|
||||
}
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <acdriver/Result.h>
|
||||
#include <acdriver/Output.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using acdriver::Result;
|
||||
using acdriver::Output;
|
||||
|
||||
@ -27,6 +29,8 @@ DocumentSeverityKey(Result::Severity severity)
|
||||
case Result::Severity::Notice:
|
||||
return "com.apple.actool.document.notices";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
static std::string
|
||||
@ -40,6 +44,8 @@ NormalSeverityKey(Result::Severity severity)
|
||||
case Result::Severity::Notice:
|
||||
return "com.apple.actool.notices";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
void Result::
|
||||
@ -97,6 +103,8 @@ SeverityText(Result::Severity severity)
|
||||
case Result::Severity::Notice:
|
||||
return "notice";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
std::unique_ptr<plist::Object> Result::
|
||||
|
@ -4,6 +4,7 @@
|
||||
#define _BOM_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -210,7 +210,7 @@ bom_index_get(struct bom_context *context, uint32_t index, size_t *data_len)
|
||||
size_t ioffset = ntohl(iindex->address);
|
||||
size_t ilength = ntohl(iindex->length);
|
||||
if (ioffset + ilength > context->memory.size) {
|
||||
printf("warning: %zd index length (%zd, %zd) extends outside buffer (%zx).\n", index, ioffset, ilength, context->memory.size);
|
||||
printf("warning: %d index length (%zd, %zd) extends outside buffer (%zx).\n", index, ioffset, ilength, context->memory.size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
/* Copyright 2013-present Facebook. All Rights Reserved. */
|
||||
|
||||
/* Enable access to ftruncate(). */
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include <bom/bom.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
@ -55,7 +58,7 @@ _bom_context_memory_mremap(struct bom_context_memory *memory, size_t size)
|
||||
|
||||
int prot = context->writeable ? PROT_READ | PROT_WRITE : PROT_READ;
|
||||
memory->data = mmap(NULL, size, prot, MAP_SHARED, context->fd, 0);
|
||||
assert((int)memory->data != -1);
|
||||
assert((intptr_t)memory->data != -1);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -3,9 +3,12 @@
|
||||
#include <bom/bom.h>
|
||||
#include <libutil/Options.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
class Options {
|
||||
private:
|
||||
bool _help;
|
||||
@ -412,7 +415,8 @@ main(int argc, char **argv)
|
||||
* Store file information for computing full path.
|
||||
*/
|
||||
struct file_info info = { file_key->parent, std::string(file_key->name) };
|
||||
context->files->insert({ path_info_1_value->id, info });
|
||||
uint32_t path_info_1_value_id = path_info_1_value->id;
|
||||
context->files->insert({ path_info_1_value_id, info });
|
||||
|
||||
/*
|
||||
* Extract the secondary information for the file. This information is structured differently
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <ext/optional>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
@ -80,7 +80,8 @@ Load(
|
||||
{
|
||||
std::unordered_map<enum car_attribute_identifier, uint16_t> attributes;
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
attributes.insert({ (enum car_attribute_identifier)pairs[i].identifier, pairs[i].value });
|
||||
uint16_t value = pairs[i].value;
|
||||
attributes.insert({ (enum car_attribute_identifier)pairs[i].identifier, value });
|
||||
}
|
||||
return AttributeList(attributes);
|
||||
}
|
||||
|
@ -5,7 +5,11 @@
|
||||
#include <car/Rendition.h>
|
||||
#include <car/car_format.h>
|
||||
|
||||
#include <limits>
|
||||
#include <random>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
using car::Reader;
|
||||
|
||||
@ -171,7 +175,13 @@ Create(unique_ptr_bom bom)
|
||||
header->rendition_count = 0;
|
||||
strncpy(header->file_creator, "asset catalog compiler\n", sizeof(header->file_creator));
|
||||
strncpy(header->other_creator, "version 1.0", sizeof(header->other_creator));
|
||||
arc4random_buf(&header->uuid, sizeof(header->uuid));
|
||||
|
||||
std::random_device device;
|
||||
std::uniform_int_distribution<int> distribution = std::uniform_int_distribution<int>(std::numeric_limits<uint8_t>::min(), std::numeric_limits<uint8_t>::max());
|
||||
for (size_t i = 0; i < sizeof(header->uuid); i++) {
|
||||
header->uuid[i] = distribution(device);
|
||||
}
|
||||
|
||||
header->associated_checksum = 0; // todo
|
||||
header->schema_version = 4; // todo
|
||||
header->color_space_id = 1; // todo
|
||||
|
@ -35,6 +35,8 @@ FormatSize(Rendition::Data::Format format)
|
||||
case Format::Data:
|
||||
return 1;
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
Rendition::
|
||||
|
@ -5,10 +5,14 @@
|
||||
#include <car/Facet.h>
|
||||
#include <car/Rendition.h>
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <zlib.h>
|
||||
|
||||
static ext::optional<std::vector<uint8_t>>
|
||||
|
@ -64,6 +64,9 @@
|
||||
* Number of matches in the current invocation of glob.
|
||||
*/
|
||||
|
||||
/* Enable access to strnlen(). */
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "bsd_glob.h"
|
||||
@ -84,6 +87,10 @@
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <strings.h>
|
||||
#if defined(__linux__)
|
||||
#include <linux/limits.h>
|
||||
#endif
|
||||
|
||||
#include "charclass.h"
|
||||
|
||||
@ -184,7 +191,7 @@ static int compare(const void *, const void *);
|
||||
static int compare_casefold(const void *, const void *);
|
||||
static int compare_gps(const void *, const void *);
|
||||
static int compare_gps_casefold(const void *, const void *);
|
||||
static int g_Ctoc(const Char *, char *, u_int);
|
||||
static int g_Ctoc(const Char *, char *, unsigned int);
|
||||
static int g_lstat(Char *, struct stat *, glob_t *);
|
||||
static DIR *g_opendir(Char *, glob_t *);
|
||||
static Char *g_strchr(const Char *, int);
|
||||
@ -217,7 +224,7 @@ int
|
||||
glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
|
||||
glob_t *pglob)
|
||||
{
|
||||
const u_char *patnext;
|
||||
const unsigned char *patnext;
|
||||
int c;
|
||||
Char *bufnext, *bufend, patbuf[PATH_MAX];
|
||||
struct glob_lim limit = { 0, 0, 0 };
|
||||
@ -225,7 +232,7 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
|
||||
if (strnlen(pattern, PATH_MAX) == PATH_MAX)
|
||||
return(GLOB_NOMATCH);
|
||||
|
||||
patnext = (u_char *) pattern;
|
||||
patnext = (unsigned char *) pattern;
|
||||
if (!(flags & GLOB_APPEND)) {
|
||||
pglob->gl_pathc = 0;
|
||||
pglob->gl_pathv = NULL;
|
||||
@ -789,7 +796,7 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
|
||||
else
|
||||
readdirfunc = (struct dirent *(*)(void *))readdir;
|
||||
while ((dp = (*readdirfunc)(dirp))) {
|
||||
u_char *sc;
|
||||
unsigned char *sc;
|
||||
Char *dc;
|
||||
|
||||
if ((pglob->gl_flags & GLOB_LIMIT) &&
|
||||
@ -805,7 +812,7 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
|
||||
if (dp->d_name[0] == DOT && *pattern != DOT)
|
||||
continue;
|
||||
dc = pathend;
|
||||
sc = (u_char *) dp->d_name;
|
||||
sc = (unsigned char *) dp->d_name;
|
||||
while (dc < pathend_last && (*dc++ = *sc++) != EOS)
|
||||
;
|
||||
if (dc >= pathend_last) {
|
||||
@ -1093,7 +1100,7 @@ g_strchr(const Char *str, int ch)
|
||||
}
|
||||
|
||||
static int
|
||||
g_Ctoc(const Char *str, char *buf, u_int len)
|
||||
g_Ctoc(const Char *str, char *buf, unsigned int len)
|
||||
{
|
||||
|
||||
while (len--) {
|
||||
|
@ -106,8 +106,9 @@ Deserialize(std::vector<uint8_t> const &contents, Any const &format)
|
||||
return DeserializeImpl<XML>(contents, format);
|
||||
case Type::ASCII:
|
||||
return DeserializeImpl<ASCII>(contents, format);
|
||||
default: abort();
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@ -132,8 +133,9 @@ Serialize(Object const *object, Any const &format)
|
||||
return SerializeImpl<XML>(object, format);
|
||||
case Type::ASCII:
|
||||
return SerializeImpl<ASCII>(object, format);
|
||||
default: abort();
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
} }
|
||||
|
@ -70,8 +70,9 @@ BOM(Encoding encoding)
|
||||
return { 0x00, 0x00, 0xFE, 0xFF };
|
||||
case Encoding::UTF32LE:
|
||||
return { 0xFF, 0xFE, 0x00, 0x00 };
|
||||
default: abort();
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
enum class Endian {
|
||||
@ -99,8 +100,9 @@ EncodingEndian(Encoding encoding)
|
||||
case Encoding::UTF32BE:
|
||||
case Encoding::UTF16BE:
|
||||
return Endian::Big;
|
||||
default: abort();
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -243,7 +243,7 @@ utf16_to_utf8(char *dst, size_t dst_len, uint16_t const *src, size_t src_len,
|
||||
CHECK_LENGTH(4);
|
||||
c = (((src[spos]&0x3ff) << 10) | (src[spos+1]&0x3ff)) + 0x10000;
|
||||
spos++;
|
||||
ADD_BYTE(0xf0 | (c>>18) & 0x7);
|
||||
ADD_BYTE(0xf0 | ((c>>18) & 0x7));
|
||||
ADD_BYTE(0x80 | ((c>>12) & 0x3f));
|
||||
ADD_BYTE(0x80 | ((c>>6) & 0x3f));
|
||||
ADD_BYTE(0x80 | (c & 0x3f));
|
||||
@ -289,7 +289,7 @@ utf32_to_utf8(char *dst, size_t dst_len, uint32_t const *src, size_t src_len,
|
||||
ADD_BYTE(0x80 | (src[spos] & 0x3f));
|
||||
} else if (src[spos] < 0x200000) {
|
||||
CHECK_LENGTH(4);
|
||||
ADD_BYTE(0xf0 | (src[spos]>>18) & 0x7);
|
||||
ADD_BYTE(0xf0 | ((src[spos]>>18) & 0x7));
|
||||
ADD_BYTE(0x80 | ((src[spos]>>12) & 0x3f));
|
||||
ADD_BYTE(0x80 | ((src[spos]>>6) & 0x3f));
|
||||
ADD_BYTE(0x80 | (src[spos] & 0x3f));
|
||||
|
@ -28,6 +28,11 @@ public:
|
||||
*/
|
||||
static ext::optional<Orientation>
|
||||
Parse(std::string const &value);
|
||||
|
||||
/*
|
||||
* Convert an orientation to a string.
|
||||
*/
|
||||
static std::string String(Orientation orientation);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <xcassets/MatchingStyle.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using xcassets::MatchingStyle;
|
||||
using xcassets::MatchingStyles;
|
||||
|
||||
@ -23,4 +25,6 @@ String(MatchingStyle style)
|
||||
case MatchingStyle::FullyQualifiedName:
|
||||
return "fully-qualified-name";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <xcassets/Slot/DeviceSubtype.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using xcassets::Slot::DeviceSubtype;
|
||||
using xcassets::Slot::DeviceSubtypes;
|
||||
|
||||
@ -31,5 +33,7 @@ String(DeviceSubtype deviceSubtype)
|
||||
case DeviceSubtype::Height736:
|
||||
return "736h";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <xcassets/Slot/GraphicsFeatureSet.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using xcassets::Slot::GraphicsFeatureSet;
|
||||
using xcassets::Slot::GraphicsFeatureSets;
|
||||
|
||||
@ -39,4 +41,6 @@ String(GraphicsFeatureSet graphicsFeatureSet)
|
||||
case GraphicsFeatureSet::MetalFamily3Version1:
|
||||
return "metal3v1";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <xcassets/Slot/Idiom.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using xcassets::Slot::Idiom;
|
||||
using xcassets::Slot::Idioms;
|
||||
|
||||
@ -43,4 +45,6 @@ String(Idiom idiom)
|
||||
case Idiom::Watch:
|
||||
return "watch";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <xcassets/Slot/LaunchImageExtent.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using xcassets::Slot::LaunchImageExtent;
|
||||
using xcassets::Slot::LaunchImageExtents;
|
||||
|
||||
@ -27,5 +29,7 @@ String(LaunchImageExtent extent)
|
||||
case LaunchImageExtent::FullScreen:
|
||||
return "regular";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <xcassets/Slot/MemoryRequirement.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using xcassets::Slot::MemoryRequirement;
|
||||
using xcassets::Slot::MemoryRequirements;
|
||||
|
||||
@ -31,4 +33,6 @@ String(MemoryRequirement memoryRequirement)
|
||||
case MemoryRequirement::Minimum4GB:
|
||||
return "4GB";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <xcassets/Slot/Orientation.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using xcassets::Slot::Orientation;
|
||||
using xcassets::Slot::Orientations;
|
||||
|
||||
@ -18,3 +20,15 @@ Parse(std::string const &value)
|
||||
}
|
||||
}
|
||||
|
||||
std::string Orientations::
|
||||
String(Orientation orientation)
|
||||
{
|
||||
switch (orientation) {
|
||||
case Orientation::Portrait:
|
||||
return "portrait";
|
||||
case Orientation::Landscape:
|
||||
return "landscape";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <xcassets/Slot/SizeClass.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using xcassets::Slot::SizeClass;
|
||||
using xcassets::Slot::SizeClasses;
|
||||
|
||||
@ -27,4 +29,6 @@ String(SizeClass sizeClass)
|
||||
case SizeClass::Regular:
|
||||
return "regular";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <xcassets/Slot/WatchIconRole.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using xcassets::Slot::WatchIconRole;
|
||||
using xcassets::Slot::WatchIconRoles;
|
||||
|
||||
@ -39,4 +41,6 @@ String(WatchIconRole watchIconRole)
|
||||
case WatchIconRole::ShortLookNotification:
|
||||
return "quickLook";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <xcassets/TemplateRenderingIntent.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using xcassets::TemplateRenderingIntent;
|
||||
using xcassets::TemplateRenderingIntents;
|
||||
|
||||
@ -27,4 +29,6 @@ String(TemplateRenderingIntent templateRenderingIntent)
|
||||
case TemplateRenderingIntent::Template:
|
||||
return "template";
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user