Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Add initial support for building on MacOS with homebrew #42

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ if platform == 'win32':
libenv.Append(LIBS = env['UV_LIBS'])
elif platform == 'posix':
libenv.Append(CCFLAGS = ['-Wall', '-Wno-format-extra-args'])
elif platform == 'darwin':
libenv.Append(CPPDEFINES = ['__STDC_WANT_LIB_EXT1__=0', 'DARWIN'])
libenv.Append(CCFLAGS = ['-Wall', '-Wno-format-extra-args'])

# Include the fuzzing hooks when the sanitizer is enabled
if platform == 'posix' and env['fsan'] == True:
Expand Down Expand Up @@ -106,7 +109,7 @@ if platform == 'posix':
libenv.Install('#/build/dist/lib', ns3shlib)

swig_docs = []
if env['python']:
if env['python'] and platform != 'darwin':
# Using SWIG to build the python wrapper
pyenv = libenv.Clone()
pyenv.VariantDir('swig/py', 'swig')
Expand Down Expand Up @@ -162,6 +165,8 @@ if env['nodejs'] and platform == 'posix':
testenv = env.Clone()
if testenv['PLATFORM'] == 'win32':
testenv.Append(CPPDEFINES = ['_CRT_SECURE_NO_WARNINGS', '__STDC_WANT_SECURE_LIB__=0'])
elif platform == 'darwin':
testenv.Append(CPPDEFINES = ['__STDC_WANT_LIB_EXT1__=0', 'DARWIN'])
testenv.Append(CPPPATH = ['#/ext/safestring/include', 'src'])
testenv.Append(LIBS = [lib, env['UV_LIBS']])

Expand Down Expand Up @@ -221,6 +226,8 @@ if platform == 'posix' and env['fsan'] == True:
exampleenv = env.Clone()
if exampleenv['PLATFORM'] == 'win32':
exampleenv.Append(CPPDEFINES = ['_CRT_SECURE_NO_WARNINGS'])
elif platform == 'darwin':
exampleenv.Append(CPPDEFINES = ['__STDC_WANT_LIB_EXT1__=0', 'DARWIN'])
exampleenv.Append(LIBS = [lib, env['UV_LIBS']])

examplesrcs = ['examples/pub_many.c',
Expand Down
32 changes: 31 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ if platform.system() == 'Linux':
BoolVariable('fsan', 'Enable fuzzer sanitizer?', False),
BoolVariable('cov', 'Enable code coverage?', False))

# Darwin-specific command line variables
if platform.system() == 'Darwin':
vars.AddVariables(
PathVariable('UV_PATH', 'Path where libuv is installed', '', PathVariable.PathAccept))

tools=['default', 'textfile', DPS]
# Doxygen is optional
try:
Expand Down Expand Up @@ -213,8 +218,33 @@ elif env['PLATFORM'] == 'posix':
env.Prepend(LIBPATH = env['UV_PATH'])
env.Prepend(CPPPATH = env['UV_PATH'] + '/include')

elif env['PLATFORM'] == 'darwin':

# Treat warnings as errors
env.Append(CCFLAGS = ['-Werror'])

if env['variant'] == 'debug':
env.Append(CCFLAGS = ['-O', '-DDPS_DEBUG'])
else:
env.Append(CCFLAGS = ['-O3', '-DNDEBUG'])

# Where to find Python.h
if env['target'] == 'yocto':
env['PY_CPPPATH'] = [os.getenv('SYSROOT') + '/usr/include/python2.7']
else:
env['PY_CPPPATH'] = ['/usr/include/python2.7']
env['PY_LIBPATH'] = []

# Where to find libuv and the libraries it needs
env['UV_LIBS'] = ['uv', 'pthread']

if env['UV_PATH']:
env.Prepend(LIBPATH = env['UV_PATH'])
env.Prepend(CPPPATH = env['UV_PATH'] + '/include')

else:
print('Unsupported system')

print('Unsupported system: ' + env['PLATFORM'])
exit()

env.Append(LIBPATH=['./ext'])
Expand Down
3 changes: 3 additions & 0 deletions ext/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ if scEnv['PLATFORM'] == 'win32':
elif scEnv['PLATFORM'] == 'posix':
scEnv.Append(CPPDEFINES = ['_ISCO99_SOURCE'])
scEnv.Append(CFLAGS = ['-Os', '-fPIC', '-std=c99', '-Wall', '-Wextra', '-Wno-unused-parameter', '-Wno-implicit-fallthrough', '-MMD'])
elif scEnv['PLATFORM'] == 'darwin':
scEnv.Append(CPPDEFINES = ['_ISCO99_SOURCE'])
scEnv.Append(CFLAGS = ['-Os', '-fPIC', '-std=c99', '-Wall', '-Wextra', '-Wno-unused-parameter', '-Wno-implicit-fallthrough', '-MMD'])
else:
print('Unsupported system')
exit()
Expand Down
2 changes: 2 additions & 0 deletions src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ inline char* strndup(const char* str, size_t maxLen)

#else // posix

#ifndef DARWIN
#include <endian.h>
#endif

#define BSWAP_32(n) __builtin_bswap32(n)
#define BSWAP_64(n) __builtin_bswap64(n)
Expand Down